[otrs-cvs] iPhoneHandle/scripts/test/iPhoneHandle JSONGateway.t, 1.2, 1.3

"CVS commits notifications of OTRS.org" <[email protected]> Wed, 10 Jul 2013 14:56:25 +0000
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/iPhoneHandle/scripts/test/iPhoneHandle
In directory lancelot:/tmp/cvs-serv11598/scripts/test/iPhoneHandle

Modified Files:
	JSONGateway.t 
Log Message:
Made unit tests use the web server instead of starting bin/cgi-bin/json.pl on the command line.

Author: mb

Index: JSONGateway.t
===================================================================
RCS file: /home/cvs/iPhoneHandle/scripts/test/iPhoneHandle/JSONGateway.t,v
retrieving revision 1.2
retrieving revision 1.3
diff -2 -u -d -r1.2 -r1.3
--- JSONGateway.t	3 Jan 2013 23:33:44 -0000	1.2
+++ JSONGateway.t	10 Jul 2013 14:56:20 -0000	1.3
@@ -19,4 +19,5 @@
 use Kernel::System::UnitTest::Helper;
 use Kernel::System::VariableCheck qw(IsArrayRefWithData IsHashRefWithData IsStringWithData);
+use Kernel::System::WebUserAgent;
 
 # helper object
@@ -28,21 +29,35 @@
 
 # create other objects
-my $ConfigObject = Kernel::Config->new();
-my $JSONObject   = Kernel::System::JSON->new( %{$Self} );
+my $ConfigObject       = Kernel::Config->new();
+my $JSONObject         = Kernel::System::JSON->new( %{$Self} );
+my $WebUserAgentObject = Kernel::System::WebUserAgent->new( %{$Self} );
 
-my $Home = $ConfigObject->Get('Home');
+# get remote host with some precautions for certain unit test systems
+my $Host;
+my $FQDN = $Self->{ConfigObject}->Get('FQDN');
 
-my $JSONCGI = $Home . '/bin/cgi-bin/json.pl';
+# try to resolve fqdn host
+if ( $FQDN ne 'yourhost.example.com' && gethostbyname($FQDN) ) {
+    $Host = $FQDN;
+}
 
-my $FileExists;
-if ( -e $JSONCGI ) {
-    $FileExists = 1;
+# try to resolve localhost instead
+if ( !$Host && gethostbyname('localhost') ) {
+    $Host = 'localhost';
 }
 
-# sanity test
-$Self->True(
-    $FileExists,
-    "$JSONCGI exists in the file system",
-);
+# use hardcoded localhost ip address
+if ( !$Host ) {
+    $Host = '127.0.0.1';
+}
+
+# prepare webservice config
+my $URL =
+    $Self->{ConfigObject}->Get('HttpType')
+    . '://'
+    . $Host
+    . '/'
+    . $Self->{ConfigObject}->Get('ScriptAlias')
+    . 'json.pl';
 
 my $CallJSONCGI = sub {
@@ -55,47 +70,28 @@
 
     # copy JSON CGI handler
-    my $Command = $JSONCGI;
+    my $JSONUrl = $URL . '?';
 
     for my $Item ( keys %JSONParams ) {
-        $Command .= " $Item=$JSONParams{$Item}";
+        $JSONUrl .= "$Item=$JSONParams{$Item};";
     }
-
-    # execute JSON CGI with all parameters
-    my $RawResponse = `$Command` || '';
-
-    $Self->IsNot(
-        $RawResponse,
-        '',
-        "JSON CGI - Test $Param{TestName} - response is not empty",
-    );
-
-    # JSON response in this mode should be always a 3 lines string, the important result is the
-    # line number 3
-    my @Response = split /\n/, $RawResponse;
-
-    $Self->Is(
-        scalar @Response,
-        3,
-        "JSON CGI - Test $Param{TestName} - response contains 3 lines",
+    my %Response = $WebUserAgentObject->Request(
+        URL => $JSONUrl,
     );
 
     $Self->Is(
-        $Response[0],
-        'Content-Type: text/plain; ',
-        "JSON CGI - Test $Param{TestName} - response line 1 match expected results",
-    );
-
-    $Self->IsNot(
-        $Response[2],
-        '',
-        "JSON CGI - Test $Param{TestName} - response line 2 is not empty",
+        $Response{Status},
+        '200 OK',
+        "JSON CGI - Test $Param{TestName} - response is 200 OK",
     );
 
-    # return line number 3 (position 2 in the array)
-    return $Response[2];
+    return $Response{Content};
 };
 
-my $User     = 'root@localhost';
-my $Password = 'root';
+# create test user
+my $User = $HelperObject->TestUserCreate(
+    Groups => ['users'],
+);
+my $Password = $User;
+
 my $RandomID = $HelperObject->GetRandomID();
 
@@ -261,5 +257,5 @@
     );
 
-    my $Response = $JSONObject->Decode( Data => $JSONResponse );
+    my $Response = $JSONObject->Decode( Data => ${$JSONResponse} );
 
     $Self->Is(
---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log