Author: tcunning
Date: Wed Mar 18 13:58:55 2009
New Revision: 755598
URL: http://svn.apache.org/viewvc?rev=755598&view=rev
Log:
SCOUT-55
Add test for SCOUT-55, add ability to use two logins to BaseTestCase.
Added:
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/OwnershipTest.java
Modified:
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/BaseTestCase.java
Modified:
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/BaseTestCase.java
URL:
http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/BaseTestCase.java?rev=755598&r1=755597&r2=755598&view=diff
==============================================================================
---
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/BaseTestCase.java
(original)
+++
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/BaseTestCase.java
Wed Mar 18 13:58:55 2009
@@ -37,12 +37,18 @@
public class BaseTestCase
{
protected Connection connection;
+ protected Connection connection2;
+
protected BusinessLifeCycleManager blm;
protected BusinessQueryManager bqm;
//Set some default values
protected String userid = System.getProperty("uddi.test.uid") == null ?
"jdoe" : System.getProperty("uddi.test.uid");
protected String passwd = System.getProperty("uddi.test.pass") == null ?
"password" : System.getProperty("uddi.test.pass");
+
+ protected String userid2 = System.getProperty("uddi.test.uid2") == null ?
"jdoe2" : System.getProperty("uddi.test.uid2");
+ protected String passwd2 = System.getProperty("uddi.test.pass2") == null ?
"password2" : System.getProperty("uddi.test.pass2");
+
protected int maxRows = 100;
/**
@@ -93,6 +99,7 @@
ConnectionFactory factory = ConnectionFactory.newInstance();
factory.setProperties(props);
connection = factory.createConnection();
+ connection2 = factory.createConnection();
} catch (Exception e)
{
e.printStackTrace();
@@ -134,6 +141,24 @@
}
}
+ /**
+ * Does authentication with the uddi registry
+ */
+ public void loginSecondUser()
+ {
+ PasswordAuthentication passwdAuth = new PasswordAuthentication(userid2,
+ passwd2.toCharArray());
+ Set<PasswordAuthentication> creds = new
HashSet<PasswordAuthentication>();
+ creds.add(passwdAuth);
+
+ try
+ {
+ connection2.setCredentials(creds);
+ } catch (JAXRException e)
+ {
+ e.printStackTrace();
+ }
+ }
}
Added:
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/OwnershipTest.java
URL:
http://svn.apache.org/viewvc/webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/OwnershipTest.java?rev=755598&view=auto
==============================================================================
---
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/OwnershipTest.java
(added)
+++
webservices/scout/trunk/scout/src/test/java/org/apache/ws/scout/registry/OwnershipTest.java
Wed Mar 18 13:58:55 2009
@@ -0,0 +1,205 @@
+/*
+ * Copyright 2001-2009 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.ws.scout.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Locale;
+
+import javax.xml.registry.BulkResponse;
+import javax.xml.registry.BusinessLifeCycleManager;
+import javax.xml.registry.BusinessQueryManager;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.JAXRResponse;
+import javax.xml.registry.LifeCycleManager;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.Association;
+import javax.xml.registry.infomodel.ClassificationScheme;
+import javax.xml.registry.infomodel.Concept;
+import javax.xml.registry.infomodel.InternationalString;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.RegistryPackage;
+import javax.xml.registry.infomodel.User;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.ws.scout.BaseTestCase;
+
+/**
+ *
+ * Test for SCOUT-55 which attempts to test whether getRegistryObjects()
returns caller structures, or all structures.
+ * At the moment there appears no way of implementing this using the UDDI API,
so the actual test is being checked in
+ * commented out (it will fail). Would be good to have if we can figure out
how to fix SCOUT-55.
+ *
+ * @author <a href="mailto:[email protected]">Tom Cunningham</a>
+ */
+public class OwnershipTest extends BaseTestCase {
+ RegistryService rs, rs2;
+ private BusinessQueryManager bqm, bqm2;
+ private BusinessLifeCycleManager blm, blm2;
+ Collection associationKeys = null;
+
+ @Before
+ public void setUp() {
+ super.setUp();
+ login();
+ loginSecondUser();
+ try {
+ rs = connection.getRegistryService();
+ bqm = rs.getBusinessQueryManager();
+ blm = rs.getBusinessLifeCycleManager();
+
+ rs2 = connection2.getRegistryService();
+ blm2 = rs2.getBusinessLifeCycleManager();
+ bqm2 = rs2.getBusinessQueryManager();
+
+ } catch (JAXRException e) {
+ fail(e.getMessage());
+ }
+ }
+
+ @After
+ public void tearDown() {
+ super.tearDown();
+
+ }
+
+ private InternationalString getIString(String str)
+ throws JAXRException
+ {
+ return blm.createInternationalString(str);
+ }
+
+
+ private Organization createTempOrg(String tempOrgName,
BusinessLifeCycleManager blm) throws JAXRException {
+ Key orgKey = null;
+ Organization org = blm.createOrganization(getIString(tempOrgName));
+ org.setDescription(getIString("Temporary organization to test
saveService()"));
+
+ Collection<Organization> orgs = new ArrayList<Organization>();
+ orgs.add(org);
+ BulkResponse br = blm.saveOrganizations(orgs);
+
+ if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
+ {
+ orgKey = (Key) br.getCollection().iterator().next();
+ System.out.println("Temporary Organization Created with id=" +
orgKey.getId());
+ org.setKey(orgKey);
+ } else
+ {
+ System.err.println("JAXRExceptions " +
+ "occurred during creation of temporary organization:");
+
+ Iterator iter = br.getCollection().iterator();
+
+ while (iter.hasNext()) {
+ Exception e = (Exception) iter.next();
+ System.err.println(e.toString());
+ }
+
+ fail();
+ }
+ return org;
+ }
+
+ private void deleteTempOrg(Key key) throws JAXRException {
+
+ if (key == null) {
+ return;
+ }
+
+ String id = key.getId();
+
+ System.out.println("\nDeleting temporary organization with id " + id +
"\n");
+
+ Collection<Key> keys = new ArrayList<Key>();
+ keys.add(key);
+ BulkResponse response = blm.deleteOrganizations(keys);
+
+ Collection exceptions = response.getExceptions();
+ if (exceptions == null) {
+ Collection retKeys = response.getCollection();
+ Iterator keyIter = retKeys.iterator();
+ Key orgKey = null;
+ if (keyIter.hasNext()) {
+ orgKey =
+ (javax.xml.registry.infomodel.Key)
keyIter.next();
+ id = orgKey.getId();
+ System.out.println("Organization with ID=" + id + "
was deleted");
+ }
+ }
+ }
+
+ @Test
+ public void testGetRegistryObjects() {
+/*
+ login();
+ try {
+
+ Organization org1 = createTempOrg("OWNERSHIPTEST Organization
1", blm);
+ Organization org2 = createTempOrg("OWNERSHIPTEST Organization
2", blm);
+
+ BulkResponse br =
bqm.getRegistryObjects(LifeCycleManager.ORGANIZATION);
+ if (br.getStatus() == JAXRResponse.STATUS_SUCCESS)
+ {
+ System.out.println("BR.size : " + br.getCollection().size());
+ Collection coll = br.getCollection();
+ Iterator iterator = coll.iterator();
+ while (iterator.hasNext()) {
+ Organization org = (Organization) iterator.next();
+ System.out.println("BR " +
org.getName().getValue(Locale.US));
+ }
+
+ if (br.getCollection().size() == 0) {
+ fail("Found no organizations for user 1");
+ }
+
+ }
+
+ BulkResponse br2 =
bqm2.getRegistryObjects(LifeCycleManager.ORGANIZATION);
+ if (br2.getStatus() == JAXRResponse.STATUS_SUCCESS)
+ {
+ if (br2.getCollection().size() != 0) {
+ fail("There should be no found organizations for user
2, found "
+ + br2.getCollection().size());
+ }
+ Collection coll = br2.getCollection();
+ Iterator iterator = coll.iterator();
+ while (iterator.hasNext()) {
+ Organization org = (Organization) iterator.next();
+ System.out.println("BR2 " +
org.getName().getValue(Locale.US));
+ }
+ }
+
+ deleteTempOrg(org1.getKey());
+ deleteTempOrg(org2.getKey());
+
+ } catch (JAXRException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ */
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]