[Fusionforge-commits] r8394 - in branches/Branch_4_8/tests/func: . Soap

Roland Mas lolando at libremir.placard.fr.eu.org
Wed Nov 18 18:12:28 CET 2009


Author: lolando
Date: 2009-11-18 18:12:28 +0100 (Wed, 18 Nov 2009)
New Revision: 8394

Added:
   branches/Branch_4_8/tests/func/Soap/
   branches/Branch_4_8/tests/func/Soap/AllTests.php
   branches/Branch_4_8/tests/func/Soap/config.php
   branches/Branch_4_8/tests/func/Soap/login.php
   branches/Branch_4_8/tests/func/Soap/usergroup.php
Log:
Adding unit tests for SOAP server


Added: branches/Branch_4_8/tests/func/Soap/AllTests.php
===================================================================
--- branches/Branch_4_8/tests/func/Soap/AllTests.php	                        (rev 0)
+++ branches/Branch_4_8/tests/func/Soap/AllTests.php	2009-11-18 17:12:28 UTC (rev 8394)
@@ -0,0 +1,84 @@
+<?php
+/*
+ * Copyright (C) 2008 Alain Peyrat <aljeux at free.fr>
+ * Copyright (C) 2009 Alain Peyrat, Alcatel-Lucent
+ * Copyright (c) 2009 Olivier Berger, Institut Télécom
+ *
+ * This file is part of FusionForge.
+ *
+ * FusionForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ * 
+ * FusionForge is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FusionForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+/*
+ * Standard Alcatel-Lucent disclaimer for contributing to open source
+ *
+ * "The test suite ("Contribution") has not been tested and/or
+ * validated for release as or in products, combinations with products or
+ * other commercial use. Any use of the Contribution is entirely made at
+ * the user's own responsibility and the user can not rely on any features,
+ * functionalities or performances Alcatel-Lucent has attributed to the
+ * Contribution.
+ *
+ * THE CONTRIBUTION BY ALCATEL-LUCENT IS PROVIDED AS IS, WITHOUT WARRANTY
+ * OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
+ * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, COMPLIANCE,
+ * NON-INTERFERENCE AND/OR INTERWORKING WITH THE SOFTWARE TO WHICH THE
+ * CONTRIBUTION HAS BEEN MADE, TITLE AND NON-INFRINGEMENT. IN NO EVENT SHALL
+ * ALCATEL-LUCENT BE LIABLE FOR ANY DAMAGES OR OTHER LIABLITY, WHETHER IN
+ * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * CONTRIBUTION OR THE USE OR OTHER DEALINGS IN THE CONTRIBUTION, WHETHER
+ * TOGETHER WITH THE SOFTWARE TO WHICH THE CONTRIBUTION RELATES OR ON A STAND
+ * ALONE BASIS."
+ */
+
+if (!defined('PHPUnit_MAIN_METHOD')) {
+    define('PHPUnit_MAIN_METHOD', 'Site_AllTests::main');
+}
+ 
+require_once 'PHPUnit/Framework.php';
+require_once 'PHPUnit/TextUI/TestRunner.php';
+ 
+require_once 'Soap/login.php';
+require_once 'Soap/usergroup.php';
+// ...
+ 
+class Soap_AllTests
+{
+    public static function main()
+    {
+        PHPUnit_TextUI_TestRunner::run(self::suite());
+    }
+ 
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('PHPUnit Framework');
+ 
+        // $suite->addTestSuite('CreateProject');
+        $suite->addTestSuite('LoginProcess');
+        $suite->addTestSuite('UserGroupProcess');
+        
+        // FIXME: Do not run this test as it requires the cron to be launched
+        //        $suite->addTestSuite('Top');
+        // ...
+ 
+        return $suite;
+    }
+}
+ 
+if (PHPUnit_MAIN_METHOD == 'Soap_AllTests::main') {
+    Soap_AllTests::main();
+}
+?>

Added: branches/Branch_4_8/tests/func/Soap/config.php
===================================================================
--- branches/Branch_4_8/tests/func/Soap/config.php	                        (rev 0)
+++ branches/Branch_4_8/tests/func/Soap/config.php	2009-11-18 17:12:28 UTC (rev 8394)
@@ -0,0 +1,11 @@
+<?php
+
+define ('WSDL_URL', 'http://vm2/soap/index.php?wsdl');
+
+// this should be an existing user of the forge together with its password (the password should be different from 'xxxxxx')
+//define ('EXISTING_USER', 'admin');
+//define ('PASSWD_OF_EXISTING_USER', 'xxxx');
+define ('EXISTING_USER', 'toto');
+define ('PASSWD_OF_EXISTING_USER', 'toto123');
+
+?>

Added: branches/Branch_4_8/tests/func/Soap/login.php
===================================================================
--- branches/Branch_4_8/tests/func/Soap/login.php	                        (rev 0)
+++ branches/Branch_4_8/tests/func/Soap/login.php	2009-11-18 17:12:28 UTC (rev 8394)
@@ -0,0 +1,201 @@
+<?php
+/*
+ * Copyright (C) 2009 Olivier Berger, Institut TELECOM
+ *
+ * This file is part of FusionForge.
+ *
+ * FusionForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ * 
+ * FusionForge is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FusionForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+require_once 'PHPUnit/Framework/TestCase.php';
+require_once 'Soap/config.php';
+
+class LoginProcess extends PHPUnit_Framework_TestCase
+{
+
+	function setUp()
+	{
+
+	  //	  print_r("setup\n");
+
+	  $this->loggedIn = FALSE;
+	  $this->session = NULL;
+	  //print_r("session :".$this->session);
+
+	  $this->assertRegExp('/http.?:\/\//', WSDL_URL);
+
+	  //	  try {
+
+	  $this->soapclient = new SoapClient(WSDL_URL,
+					     array('cache_wsdl' => WSDL_CACHE_NONE, 
+						   'trace' => true));
+	  
+	  //	  } catch (SoapFault $fault) {
+	  //	    $fault->faultstring;
+	  //	    print_r($fault);
+	  //	  }
+	  //	  print_r($this->soapclient);
+
+	}
+
+	// function tearDown()
+	// {
+	//   //
+	// }
+
+
+	// performs a login and returns a session "cookie"
+	function login($userid, $passwd)
+	{
+	  $response = $this->soapclient->login($userid, $passwd);
+
+	  if ($response) {
+	    $this->loggedIn = TRUE;
+
+	    $this->session = $response;
+
+	    //	    print_r($this->session);
+
+	  }
+
+	  return $response;
+	}
+
+// Name: version
+// Binding: GForgeAPIBinding
+// Input:
+//   use: encoded
+//   message: versionRequest
+//   parts:
+// Output:
+//   use: encoded
+//   message: versionResponse
+//   parts:
+//     versionResponse: xsd:string
+
+	function testVersion()
+	{
+	  $version = $this->soapclient->version();
+	  
+	  $this->assertEquals('4.8.1', $version);
+
+	}
+
+	function testGETFUNCTIONS()
+	{
+	  $response = $this->soapclient->__getFunctions();
+	  //	  print_r($response);
+	}
+
+// Name: login
+// Binding: GForgeAPIBinding
+// Input:
+//   use: encoded
+//   message: loginRequest
+//   parts:
+//     userid: xsd:string
+//     passwd: xsd:string
+// Output:
+//   use: encoded
+//   message: loginResponse
+//   parts:
+//     loginResponse: xsd:string
+
+	function testLoginNonExistantUser()
+	{
+	  $userid = 'coin';
+	  
+	  try {
+	    
+	    $response = $this->soapclient->login($userid, 'pan');
+	    
+	  }
+	  catch (SoapFault $expected) {
+
+	    $this->assertEquals("Unable to log in with userid of ".$userid, $expected->faultstring);
+
+	    print_r($response);
+            
+	    return;
+	  }
+ 
+	  $this->fail('An expected exception has not been raised.');
+	}
+
+	function testLoginWrongPwd()
+	{
+	  $userid = EXISTING_USER;
+	  
+	  try {
+	    
+	    $response = $this->soapclient->login($userid, 'xxxxxx');
+	    
+	  }
+	  catch (SoapFault $expected) {
+
+	    $this->assertEquals("Unable to log in with userid of ".$userid, $expected->faultstring);
+
+	    //	    print_r($response);
+            
+	    return;
+	  }
+ 
+	  $this->fail('An expected exception has not been raised.');
+	}
+
+	function testLoginSuccesful()
+	{
+	  $userid = EXISTING_USER;
+	  $passwd = PASSWD_OF_EXISTING_USER;
+
+	  $response = $this->login($userid, $passwd);
+
+	  $this->assertNotNull($response);
+
+	}
+
+
+// Name: logout
+// Binding: GForgeAPIBinding
+// Input:
+//   use: encoded
+//   message: logoutRequest
+//   parts:
+//     session_ser: xsd:string
+// Output:
+//   use: encoded
+//   message: logoutResponse
+//   parts:
+//     logoutResponse: xsd:string
+
+        /**
+	 * @depends testLoginSuccesful
+	 */
+	/*	function testLogout()
+	{
+
+	  print_r($this->loggedIn);
+
+	  $this->assertNotNull($this->loggedIn);
+
+	  $response = $this->soapclient->logout('coin');
+
+	  print_r('logout response :'. $response);
+
+	}
+	*/
+}
+?>

Added: branches/Branch_4_8/tests/func/Soap/usergroup.php
===================================================================
--- branches/Branch_4_8/tests/func/Soap/usergroup.php	                        (rev 0)
+++ branches/Branch_4_8/tests/func/Soap/usergroup.php	2009-11-18 17:12:28 UTC (rev 8394)
@@ -0,0 +1,379 @@
+<?php
+/*
+ * Copyright (C) 2009 Olivier Berger, Institut TELECOM
+ *
+ * This file is part of FusionForge.
+ *
+ * FusionForge is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published
+ * by the Free Software Foundation; either version 2 of the License,
+ * or (at your option) any later version.
+ * 
+ * FusionForge is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with FusionForge; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+ * USA
+ */
+
+require_once 'PHPUnit/Framework/TestCase.php';
+require_once 'Soap/config.php';
+
+class UserGroupProcess extends PHPUnit_Framework_TestCase
+{
+
+	function setUp()
+	{
+
+	  //	  print_r("setup\n");
+
+	  $this->loggedIn = FALSE;
+	  $this->session = NULL;
+	  //print_r("session :".$this->session);
+
+	  $this->assertRegExp('/http.?:\/\//', WSDL_URL);
+
+	  //	  try {
+
+	  $this->soapclient = new SoapClient(WSDL_URL,
+					     array('cache_wsdl' => WSDL_CACHE_NONE, 
+						   'trace' => true));
+	  
+	  //	  } catch (SoapFault $fault) {
+	  //	    $fault->faultstring;
+	  //	    print_r($fault);
+	  //	  }
+	  //	  print_r($this->soapclient);
+
+	}
+
+	// function tearDown()
+	// {
+	//   //
+	// }
+
+
+	// performs a login and returns a session "cookie"
+	function login($userid, $passwd)
+	{
+	  $response = $this->soapclient->login($userid, $passwd);
+
+	  if ($response) {
+	    $this->loggedIn = TRUE;
+
+	    $this->session = $response;
+
+	    //	    print_r($this->session);
+
+	  }
+
+	  return $response;
+	}
+
+	function testLoginSuccesful()
+	{
+	  $userid = EXISTING_USER;
+	  $passwd = PASSWD_OF_EXISTING_USER;
+
+	  $response = $this->login($userid, $passwd);
+
+	  $this->assertNotNull($response);
+
+	}
+
+
+// Name: getGroups
+// Binding: GForgeAPIBinding
+// Style: rpc
+// Input:
+//   use: encoded
+//   message: getGroupsRequest
+//   parts:
+//     session_ser: xsd:string
+//     group_ids: tns:ArrayOfint
+// Output:
+//   use: encoded
+//   message: getGroupsResponse
+//   parts:
+//     return: tns:ArrayOfGroup
+
+// Name: getGroupsByName
+// Binding: GForgeAPIBinding
+// Input:
+//   use: encoded
+//   message: getGroupsByNameRequest
+//   parts:
+//     session_ser: xsd:string
+//     group_names: tns:ArrayOfstring
+// Output:
+//   use: encoded
+//   message: getGroupsByNameResponse
+//   parts:
+//     return: tns:ArrayOfGroup
+
+        /**
+	 * @depends testLoginSuccesful
+	 */
+	function testGetGroupsByNameEmpty()
+	{
+
+	  //	  print_r($this->loggedIn);
+
+	  $this->login(EXISTING_USER, PASSWD_OF_EXISTING_USER);
+	  $this->assertNotNull($this->loggedIn);
+	  $this->assertNotNull($this->session);
+
+	  try {
+	    $response = $this->soapclient->getGroupsByName($this->session);
+	  }
+	  catch (SoapFault $expected) {
+	    //	    print_r($expected->faultstring);
+	    $this->assertStringStartsWith('Could Not Get Groups by Name', $expected->faultstring);
+
+	    return;
+	  }
+ 
+	  $this->fail('An expected exception has not been raised. Got response :'.$response);
+	}
+
+        /**
+	 * @depends testLoginSuccesful
+	 */
+	function testGetGroupsByName()
+	{
+
+	  //	  print_r($this->loggedIn);
+
+	  $this->login(EXISTING_USER, PASSWD_OF_EXISTING_USER);
+	  $this->assertNotNull($this->loggedIn);
+	  $this->assertNotNull($this->session);
+
+	  $groups = array('template' => 'template',
+			  'stats' => 'stats',
+			  'peerrating' => 'peerrating',
+			  'siteadmin' => 'siteadmin',
+			  'newsadmin' => 'newsadmin'
+			  );
+
+	  // individual retrieval for each of the default groups
+	  foreach (array_keys($groups) as $group_name) {
+	    //print_r($group_name);
+	    $response = $this->soapclient->getGroupsByName($this->session,array($group_name));
+
+	    $group = $response[0];
+	    //	    print_r($group);
+	    $this->assertEquals($group_name, $group->unix_group_name);
+	  }
+
+	  // retrieval of a list of groups
+	  $response = $this->soapclient->getGroupsByName($this->session, array_keys($groups));
+	  foreach ($response as $group) {
+	    //	    print_r($group);
+	    $this->assertEquals($groups[$group->unix_group_name], $group->unix_group_name);
+
+	    $group_id = $group->group_id;
+
+	    // now verify that getGroups() returns the same
+	    $response = $this->soapclient->getGroups($this->session, array($group_id));
+	    $group2 = $response[0];
+	    //	    print_r($group);
+	    $this->assertEquals($group_id, $group2->group_id);
+	    $this->assertEquals($group->unix_group_name, $group2->unix_group_name);
+	  }
+	  
+	}
+
+
+// Name: getPublicProjectNames
+// Binding: GForgeAPIBinding
+// Input:
+//   use: encoded
+//   message: getPublicProjectNamesRequest
+//   parts:
+//     session_ser: xsd:string
+// Output:
+//   use: encoded
+//   message: getPublicProjectNamesResponse
+//   parts:
+//     return: tns:ArrayOfstring
+
+
+        /**
+	 * @depends testLoginSuccesful
+	 */
+	function testGetPublicProjectNamesNotLoggedIn()
+	{
+
+	  //	  print_r($this->loggedIn);
+	  $this->assertNotNull($this->loggedIn);
+
+	  $response = $this->soapclient->getPublicProjectNames();
+	  $this->assertContains("newsadmin", $response);
+	  $this->assertContains("siteadmin", $response);
+
+	  //	  print_r($response);
+	}
+
+        /**
+	 * @depends testLoginSuccesful
+	 */
+	function testGetPublicProjectNamesLoggedIn()
+	{
+
+	  $this->login(EXISTING_USER, PASSWD_OF_EXISTING_USER);
+	  $this->assertNotNull($this->loggedIn);
+	  $this->assertNotNull($this->session);
+
+	  //	  print_r($this->loggedIn);
+	  $this->assertNotNull($this->loggedIn);
+
+	  $response = $this->soapclient->getPublicProjectNames($this->session);
+	  	  $this->assertContains("newsadmin", $response);
+	  	  $this->assertContains("siteadmin", $response);
+
+		  //print_r($response);
+	}
+
+// Name: getUsers
+// Binding: GForgeAPIBinding
+// Style: rpc
+// Input:
+//   use: encoded
+//   message: getUsersRequest
+//   parts:
+//     session_ser: string
+//     user_ids: tns:ArrayOfint
+// Output:
+//   use: encoded
+//   message: getUsersResponse
+//   parts:
+//     userResponse: tns:ArrayOfUser
+
+
+// Name: getUsersByName
+// Binding: GForgeAPIBinding
+// Input:
+//   use: encoded
+//   message: getUsersByNameRequest
+//   parts:
+//     session_ser: string
+//     user_ids: tns:ArrayOfstring
+// Output:
+//   use: encoded
+//   message: getUsersByNameResponse
+//   parts:
+//     userResponse: tns:ArrayOfUser
+
+// Name: userGetGroups
+// Binding: GForgeAPIBinding
+// Style: rpc
+// Input:
+//   use: encoded
+//   message: userGetGroupsRequest
+//   parts:
+//     session_ser: string
+//     user_id: xsd:int
+// Output:
+//   use: encoded
+//   message: userGetGroupsResponse
+//   parts:
+//     groupResponse: tns:ArrayOfGroup
+
+
+        /**
+	 * @depends testLoginSuccesful
+	 */
+	function testGetUsersByNameEmpty()
+	{
+
+	  //	  print_r($this->loggedIn);
+
+	  $this->login(EXISTING_USER, PASSWD_OF_EXISTING_USER);
+	  $this->assertNotNull($this->loggedIn);
+	  $this->assertNotNull($this->session);
+
+	  try {
+	    $response = $this->soapclient->getUsersByName($this->session);
+	  }
+	  catch (SoapFault $expected) {
+	    //	    print_r($expected->faultstring);
+	    $this->assertStringStartsWith('Could Not Get Users By Name', $expected->faultstring);
+
+	    return;
+	  }
+ 
+	  $this->fail('An expected exception has not been raised. Got response :'.$response);
+	}
+
+        /**
+	 * @depends testLoginSuccesful
+	 */
+	function testGetUsersByName()
+	{
+
+	  //	  print_r($this->loggedIn);
+
+	  $this->login(EXISTING_USER, PASSWD_OF_EXISTING_USER);
+	  $this->assertNotNull($this->loggedIn);
+	  $this->assertNotNull($this->session);
+
+	  $users = array('admin'=>'admin',
+			 'None'=>'None', 
+			 EXISTING_USER => EXISTING_USER);
+
+	  foreach (array_keys($users) as $user_name) {
+	    //	    print_r($user_name);
+	    //	  $user_name='admin';
+	    $response = $this->soapclient->getUsersByName($this->session,array($user_name));
+	  //	  $response = $this->soapclient->__soapCall('getUsersByName', 
+	  //						    array('session_ser' => $this->session,
+	  //							  'user_ids' => array('admin')));
+
+	    $user = $response[0];
+	    //print_r($user);
+	    $this->assertEquals($user_name, $user->user_name);
+	  }
+
+	  $response = $this->soapclient->getUsersByName($this->session, array_keys($users));
+	  foreach ($response as $user) {
+	    //print_r($user);
+	    $this->assertEquals($users[$user->user_name], $user->user_name);
+
+	    $user_id = $user->user_id;
+
+	    // now verify that getUsers() returns the same
+	    $response = $this->soapclient->getUsers($this->session, array($user_id));
+	    $user2 = $response[0];
+	    //print_r($user2);
+	    $this->assertEquals($user_id, $user2->user_id);
+	    $this->assertEquals($user->user_name, $user2->user_name);
+
+	    //	    print_r($user->user_name);
+	    $response = $this->soapclient->userGetGroups($this->session, $user_id);
+
+	    if ($user->user_name == 'None') {
+	      $this->assertEquals(0,count($response));
+	    }
+
+	    if ($user->user_name == 'admin') {
+
+	      $adminGroups = array('template','stats','peerrating','siteadmin','newsadmin');
+
+	      foreach ($response as $group) {
+		//		print_r($group->unix_group_name);
+
+		$this->assertContains($group->unix_group_name, $adminGroups);
+	      }
+
+	    }
+	      
+	  }
+	  
+	}
+
+}
+?>




More information about the Fusionforge-commits mailing list