[jboss-svn-commits] JBL Code SVN: r6886 - in labs/jbossesb/trunk/product: core/services/src/org/jboss/soa/esb/services/registry core/services/tests/src/org/jboss/soa/esb/services/registry etc/schemas/validation

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Oct 18 08:56:08 EDT 2006


Author: kurt.stam at jboss.com
Date: 2006-10-18 08:56:05 -0400 (Wed, 18 Oct 2006)
New Revision: 6886

Added:
   labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java
Removed:
   labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/PublishOrgUnitTest.java
Modified:
   labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
   labs/jbossesb/trunk/product/etc/schemas/validation/
Log:
Working on Registry unittest

Modified: labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java	2006-10-18 11:23:44 UTC (rev 6885)
+++ labs/jbossesb/trunk/product/core/services/src/org/jboss/soa/esb/services/registry/Registry.java	2006-10-18 12:56:05 UTC (rev 6886)
@@ -60,7 +60,7 @@
 	}
 
 	/** 
-	 * The connecton to a JAXR registy.
+	 * Creates a connecton to a JAXR capable registy.
 	 * 
 	 * @return Connection to a Registry using JAXR. 
 	 */
@@ -79,4 +79,17 @@
 	    }
 	    return connection;
 	}
+	/**
+	 * Closes the connection to the Registry
+	 */
+	public static void closeConnection(Connection connection)
+	{
+		try {
+			if (connection!=null && !connection.isClosed()) {
+				connection.close();
+			}
+		} catch (JAXRException je) {
+			logger.log(Priority.ERROR, je.getMessage(), je);
+		}
+	}
 }

Deleted: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/PublishOrgUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/PublishOrgUnitTest.java	2006-10-18 11:23:44 UTC (rev 6885)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/PublishOrgUnitTest.java	2006-10-18 12:56:05 UTC (rev 6886)
@@ -1,256 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source
-* Copyright 2006, JBoss Inc., and individual contributors as indicated
-* by the @authors tag. See the copyright.txt in the distribution for a
-* full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software 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
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.soa.esb.services.registry;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.InputStream;
-import java.sql.DriverManager;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Iterator;
-import java.util.Properties;
-
-import javax.xml.registry.BulkResponse;
-import javax.xml.registry.BusinessLifeCycleManager;
-import javax.xml.registry.Connection;
-import javax.xml.registry.JAXRException;
-import javax.xml.registry.JAXRResponse;
-import javax.xml.registry.RegistryService;
-import javax.xml.registry.infomodel.Classification;
-import javax.xml.registry.infomodel.ClassificationScheme;
-import javax.xml.registry.infomodel.EmailAddress;
-import javax.xml.registry.infomodel.ExternalIdentifier;
-import javax.xml.registry.infomodel.Key;
-import javax.xml.registry.infomodel.Organization;
-import javax.xml.registry.infomodel.PersonName;
-import javax.xml.registry.infomodel.PostalAddress;
-import javax.xml.registry.infomodel.Service;
-import javax.xml.registry.infomodel.TelephoneNumber;
-import javax.xml.registry.infomodel.User;
-
-import junit.framework.JUnit4TestAdapter;
-
-import org.apache.log4j.Logger;
-import org.apache.log4j.Priority;
-import org.jboss.soa.esb.common.tests.HsqldbUtil;
-import org.jboss.soa.esb.common.tests.TestUtil;
-import org.jboss.soa.esb.services.util.FileUtil;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-/**
- * Testing the registry.
- * 
- * @author kstam
- *
- */
-public class PublishOrgUnitTest
-{
-    private static Logger log = Logger.getLogger(PublishOrgUnitTest.class);
-    private static String mDbDriver;
-	private static String mDbUrl;
-	private static String mDbUsername;
-	private static String mDbPassword;
-	
-	@Test
-	public void testPublishOrganization() {
-		try { //Getting the connection to the Registry (reading config)
-			Connection connection = Registry.getConnection();
-			connection.setCredentials(Registry.creds);
-			RegistryService rs = connection.getRegistryService();
-			//Building organization
-			BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
-			Collection<Organization> orgs = new ArrayList<Organization>();
-			Organization org = createOrganization(blm);
-			orgs.add(org);
-			//Saving the organization (this make the actual calls)
-			BulkResponse br = blm.saveOrganizations(orgs);
-
-			//Verify the return
-			if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
-				log.info("Organization Saved");
-				Collection coll = br.getCollection();
-				Iterator iter = coll.iterator();
-				while (iter.hasNext()) {
-					Key key = (Key) iter.next();
-					log.info("Saved Key=" + key.getId());
-				}
-			} else {
-				log.error("JAXRExceptions " + "occurred during save:");
-				Collection exceptions = br.getExceptions();
-				Iterator iter = exceptions.iterator();
-				while (iter.hasNext()) {
-					Exception e = (Exception) iter.next();
-					log.error(e.toString());
-				}
-				assertTrue(false);
-			}
-		} catch (Exception e) {
-			e.printStackTrace();
-			assertTrue(false);
-		}
-	}
-
-	/**
-	 * Creates a Jaxr Organization with 1 or more services
-	 * @return
-	 * @throws JAXRException
-	 */
-	@SuppressWarnings("unused")
-	private Organization createOrganization(BusinessLifeCycleManager blm)
-			throws JAXRException {
-		Organization org = blm.createOrganization(blm
-				.createInternationalString("USA -- JBOSS ORG"));
-		org.setDescription(blm
-				.createInternationalString("JBoss Professional Open Source"));
-		Service service = blm.createService(blm
-				.createInternationalString("JBossESB TEST Service"));
-		service
-				.setDescription(blm
-						.createInternationalString("Services of the ESB UDDI Registry"));
-		User user = blm.createUser();
-		org.setPrimaryContact(user);
-		PersonName personName = blm.createPersonName("Kurt Stam");
-		TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
-		telephoneNumber.setNumber("404 467-8555");
-		telephoneNumber.setType(null);
-		PostalAddress address = blm.createPostalAddress("3340",
-				"Peachtree Road, NE, Suite 1200", "Atlanta", "GA", "USA",
-				"30326", "");
-		Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
-		postalAddresses.add(address);
-		Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
-		EmailAddress emailAddress = blm
-				.createEmailAddress("kurt.stam at jboss.org");
-		emailAddresses.add(emailAddress);
-
-		Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
-		numbers.add(telephoneNumber);
-		user.setPersonName(personName);
-		user.setPostalAddresses(postalAddresses);
-		user.setEmailAddresses(emailAddresses);
-		user.setTelephoneNumbers(numbers);
-
-		ClassificationScheme cScheme = getClassificationScheme(blm,
-				"ntis-gov:naics", "");
-		Key cKey = blm.createKey("uuid:C0B9FE13-324F-413D-5A5B-2004DB8E5CC2");
-		cScheme.setKey(cKey);
-		Classification classification = blm.createClassification(cScheme,
-				"Professional Open Source", "5415");
-		org.addClassification(classification);
-		ClassificationScheme cScheme1 = getClassificationScheme(blm, "D-U-N-S",
-				"");
-		Key cKey1 = blm.createKey("uuid:3367C81E-FF1F-4D5A-B202-3EB13AD02423");
-		cScheme1.setKey(cKey1);
-		ExternalIdentifier ei = blm.createExternalIdentifier(cScheme1,
-				"D-U-N-S number", "08-146-6849");
-		org.addExternalIdentifier(ei);
-		org.addService(service);
-		return org;
-	}
-
-	private ClassificationScheme getClassificationScheme(
-			BusinessLifeCycleManager blm, String str1, String str2)
-			throws JAXRException {
-		ClassificationScheme cs = blm.createClassificationScheme(blm
-				.createInternationalString(str1), blm
-				.createInternationalString(str2));
-		return cs;
-	}
-
-	
-	/**
-	 * Setup the database.
-	 * @throws Exception
-	 */
-	@BeforeClass
-	public static void runBeforeAllTests() throws Exception {
-		try {
-			TestUtil.setESBPropertiesFileToUse();
-			//Set the juddi properties file in System so juddi will pick it up later and use the test values.
-			String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-unittest.properties";
-			System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
-			//Read this properties file to get the db connection string
-			Properties props = new Properties();
-			InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
-			props.load(inStream);
-			mDbDriver    = props.getProperty("juddi.jdbcDriver");
-			mDbUrl       = props.getProperty("juddi.jdbcUrl");
-			mDbUsername  = props.getProperty("juddi.jdbcUsername");
-			mDbPassword  = props.getProperty("juddi.jdbcPassword");
-			
-			String database="not tested yet";
-			if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
-				database = "hsqldb";
-				//Bring up hsql on default port 9001
-				HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "juddi");
-			} else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
-				database = "mysql";
-			} //add and test your own database..
-			
-			//Get the registry-schema create scripts
-			String sqlDir = TestUtil.getPrefix() + "install/jUDDI-registry/sql/" + database + "/";
-			//Drop what is there now, if exists. We want to start fresh.
-			String sqlDropCmd      = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
-			String sqlCreateCmd    = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
-			String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
-			
-			try {
-				Class.forName(mDbDriver);
-			} catch (Exception e) {
-				System.out.println("ERROR: failed to load " + database + " JDBC driver.");
-				e.printStackTrace();
-				return;
-			}
-			java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
-			Statement stmnt = con.createStatement();
-			log.log(Priority.INFO, "Dropping the schema if exist");
-			stmnt.execute(sqlDropCmd);
-			log.log(Priority.INFO, "Creating the juddi-schema");
-			stmnt.execute(sqlCreateCmd);
-			log.log(Priority.INFO, "Adding the jbossesb publisher");
-			stmnt.execute(sqlInsertPubCmd);
-		} catch (Exception e) {
-			log.log(Priority.ERROR, e.getMessage(), e);
-			log.log(Priority.ERROR, "We should stop testing, since we don't have a db.");
-			assertTrue(false);
-		}
-	}
-	/**
-	 * Shutdown the database
-	 * @throws Exception
-	 */
-	@AfterClass
-	public static void runAfterAllTests() throws Exception {
-		if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
-			HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
-		}
-	}
-
-	public static junit.framework.Test suite() {
-		return new JUnit4TestAdapter(PublishOrgUnitTest.class);
-	}
-
-}

Copied: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java (from rev 6854, labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/PublishOrgUnitTest.java)
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/PublishOrgUnitTest.java	2006-10-17 13:18:44 UTC (rev 6854)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/soa/esb/services/registry/RegistryUnitTest.java	2006-10-18 12:56:05 UTC (rev 6886)
@@ -0,0 +1,372 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt in the distribution for a
+* full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software 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
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.soa.esb.services.registry;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.sql.DriverManager;
+import java.sql.Statement;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Properties;
+
+import javax.xml.registry.BulkResponse;
+import javax.xml.registry.BusinessLifeCycleManager;
+import javax.xml.registry.BusinessQueryManager;
+import javax.xml.registry.Connection;
+import javax.xml.registry.FindQualifier;
+import javax.xml.registry.JAXRException;
+import javax.xml.registry.JAXRResponse;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.Classification;
+import javax.xml.registry.infomodel.ClassificationScheme;
+import javax.xml.registry.infomodel.EmailAddress;
+import javax.xml.registry.infomodel.ExternalIdentifier;
+import javax.xml.registry.infomodel.Key;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.PersonName;
+import javax.xml.registry.infomodel.PostalAddress;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.TelephoneNumber;
+import javax.xml.registry.infomodel.User;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.common.tests.TestUtil;
+import org.jboss.soa.esb.services.util.FileUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+/**
+ * Testing the registry.
+ * 
+ * @author kstam
+ *
+ */
+public class RegistryUnitTest
+{
+    private static String mDbDriver;
+	private static String mDbUrl;
+	private static String mDbUsername;
+	private static String mDbPassword;
+	
+	@SuppressWarnings("unchecked")
+	@Test
+	public void publishOrganization() 
+	{
+		//Getting the connection to the Registry (reading config)
+		Connection connection = Registry.getConnection();
+		try {
+			//Logging in
+			connection.setCredentials(Registry.creds);
+			RegistryService rs = connection.getRegistryService();
+			//Building organization
+			BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+			Collection<Organization> orgs = new ArrayList<Organization>();
+			Organization org = createOrganization(blm);
+			orgs.add(org);
+			//Saving the organization (this make the actual calls)
+			BulkResponse br = blm.saveOrganizations(orgs);
+//			Verify the return
+			if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
+				System.out.println("Organization Saved");
+				Collection coll = br.getCollection();
+				Iterator iter = coll.iterator();
+				while (iter.hasNext()) {
+					Key key = (Key) iter.next();
+					org.setKey(key);
+					System.out.println("Saved Key=" + key.getId());
+				}
+			} else {
+				System.out.println("JAXRExceptions " + "occurred during save:");
+				Collection exceptions = br.getExceptions();
+				Iterator iter = exceptions.iterator();
+				while (iter.hasNext()) {
+					Exception e = (Exception) iter.next();
+					e.printStackTrace();
+				}
+				assertTrue(false);
+			}
+			
+			//Add a Service
+			Service service = blm.createService(blm.createInternationalString("JBossESB TEST Service"));
+			service.setDescription(blm.createInternationalString("Services of the ESB UDDI Registry"));
+			org.addService(service);
+			Collection services = new ArrayList();
+			services.add(service);
+			br=blm.saveServices(services);
+//			Verify the return
+			if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
+				System.out.println("Service Saved");
+				Collection coll = br.getCollection();
+				Iterator iter = coll.iterator();
+				while (iter.hasNext()) {
+					Key key = (Key) iter.next();
+					System.out.println("Saved Key=" + key.getId());
+					service.setKey(key);
+				}
+			} else {
+				System.out.println("JAXRExceptions " + "occurred during save:");
+				Collection exceptions = br.getExceptions();
+				Iterator iter = exceptions.iterator();
+				while (iter.hasNext()) {
+					Exception e = (Exception) iter.next();
+					e.printStackTrace();
+				}
+				assertTrue(false);
+			}
+			
+			//Add a serviceBinding
+			ServiceBinding serviceBinding = blm.createServiceBinding();
+			serviceBinding.setName(blm.createInternationalString("JBossESB Test ServiceBinding"));
+			serviceBinding.setDescription(blm.createInternationalString("Binding Description"));
+			serviceBinding.setAccessURI("http://www.jboss.com/services/TestService");
+		    ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
+		    serviceBindings.add(serviceBinding);
+		    service.addServiceBindings(serviceBindings);
+			br=blm.saveServiceBindings(serviceBindings);
+			
+//			Verify the return
+			if (br.getStatus() == JAXRResponse.STATUS_SUCCESS) {
+				System.out.println("Service Binding Saved");
+				Collection coll = br.getCollection();
+				Iterator iter = coll.iterator();
+				while (iter.hasNext()) {
+					Key key = (Key) iter.next();
+					System.out.println("Saved Key=" + key.getId());
+					serviceBinding.setKey(key);
+				}
+			} else {
+				System.out.println("JAXRExceptions " + "occurred during save:");
+				Collection exceptions = br.getExceptions();
+				Iterator iter = exceptions.iterator();
+				while (iter.hasNext()) {
+					Exception e = (Exception) iter.next();
+					e.printStackTrace();
+				}
+				assertTrue(false);
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			assertTrue(false);
+		} finally {
+			Registry.closeConnection(connection);
+		}
+	}
+	/**
+	 * Queries the newly added information
+	 * @throws Exception
+	 */
+	@Test
+	public void queryForOrganizations()
+    {
+		String queryString = "JBOSS"; //All organization with JBOSS in the name.
+		Connection connection = Registry.getConnection();
+		try {
+			// Get registry service and business query manager
+			RegistryService rs = connection.getRegistryService();
+			BusinessQueryManager bqm = rs.getBusinessQueryManager();
+			// Define find qualifiers and name patterns
+			Collection<String> findQualifiers = new ArrayList<String>();
+			findQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
+			Collection<String> namePatterns = new ArrayList<String>();
+			namePatterns.add("%" + queryString + "%");
+//			 Find based upon qualifier type and values
+			System.out.println("Going to query the registry for name pattern " + namePatterns);
+			BulkResponse response = bqm.findOrganizations(findQualifiers,
+					namePatterns, null, null, null, null);
+
+			System.out.println("Found " + response.getCollection().size() + " organization.");
+			for (Iterator orgIter = response.getCollection().iterator(); orgIter.hasNext();) 
+			{
+				Organization org = (Organization) orgIter.next();
+				System.out.println("Orginazation name: " + org.getName().getValue());
+				System.out.println("Description: " + org.getDescription().getValue());
+				System.out.println("Key id: " + org.getKey().getId());
+				User primaryContact = org.getPrimaryContact();
+				System.out.println(primaryContact.getPersonName().getFullName());
+				Collection services = org.getServices();
+				for (Iterator serviceIter = services.iterator();serviceIter.hasNext();) {
+					Service service = (Service) serviceIter.next();
+					System.out.println("Service: " + service.getName().getValue());
+					Collection<String> findBindingQualifiers = new ArrayList<String>();
+					findBindingQualifiers.add(FindQualifier.SORT_BY_NAME_ASC);
+					BulkResponse bulkResponse = bqm.findServiceBindings(service.getKey(), findBindingQualifiers ,null , null);
+					Collection serviceBindings = bulkResponse.getCollection();
+					for (Iterator serviceBindingIter = serviceBindings.iterator();serviceBindingIter.hasNext();){
+						ServiceBinding serviceBinding = (ServiceBinding) serviceBindingIter.next();
+						System.out.println("ServiceBinding: " + serviceBinding.getName());
+						System.out.println("URI: " + serviceBinding.getAccessURI());
+					}
+					
+				}
+			}
+			
+		} catch (JAXRException e) {
+			e.printStackTrace();
+			// fail(e.getMessage());
+		} finally {
+			Registry.closeConnection(connection);
+		}
+
+}
+
+	/**
+	 * Creates a Jaxr Organization with 1 or more services
+	 * 
+	 * @return
+	 * @throws JAXRException
+	 */
+	@SuppressWarnings("unused")
+	private Organization createOrganization(BusinessLifeCycleManager blm)
+			throws JAXRException {
+		Organization org = blm.createOrganization(blm.createInternationalString("USA -- JBOSS ORG"));
+		org.setDescription(blm.createInternationalString("JBoss Professional Open Source"));
+		
+		User user = blm.createUser();
+		org.setPrimaryContact(user);
+		PersonName personName = blm.createPersonName("Kurt Stam");
+		TelephoneNumber telephoneNumber = blm.createTelephoneNumber();
+		telephoneNumber.setNumber("404 467-8555");
+		telephoneNumber.setType(null);
+		PostalAddress address = blm.createPostalAddress("3340",
+				"Peachtree Road, NE, Suite 1200", "Atlanta", "GA", "USA",
+				"30326", "");
+		Collection<PostalAddress> postalAddresses = new ArrayList<PostalAddress>();
+		postalAddresses.add(address);
+		Collection<EmailAddress> emailAddresses = new ArrayList<EmailAddress>();
+		EmailAddress emailAddress = blm
+				.createEmailAddress("kurt.stam at jboss.org");
+		emailAddresses.add(emailAddress);
+
+		Collection<TelephoneNumber> numbers = new ArrayList<TelephoneNumber>();
+		numbers.add(telephoneNumber);
+		user.setPersonName(personName);
+		user.setPostalAddresses(postalAddresses);
+		user.setEmailAddresses(emailAddresses);
+		user.setTelephoneNumbers(numbers);
+
+		ClassificationScheme cScheme = getClassificationScheme(blm,
+				"ntis-gov:naics", "");
+		Key cKey = blm.createKey("uuid:C0B9FE13-324F-413D-5A5B-2004DB8E5CC2");
+		cScheme.setKey(cKey);
+		Classification classification = blm.createClassification(cScheme,
+				"Professional Open Source", "5415");
+		org.addClassification(classification);
+		ClassificationScheme cScheme1 = getClassificationScheme(blm, "D-U-N-S",
+				"");
+		Key cKey1 = blm.createKey("uuid:3367C81E-FF1F-4D5A-B202-3EB13AD02423");
+		cScheme1.setKey(cKey1);
+		ExternalIdentifier ei = blm.createExternalIdentifier(cScheme1,
+				"D-U-N-S number", "08-146-6849");
+		org.addExternalIdentifier(ei);
+		return org;
+	}
+
+	private ClassificationScheme getClassificationScheme(
+			BusinessLifeCycleManager blm, String str1, String str2)
+			throws JAXRException {
+		ClassificationScheme cs = blm.createClassificationScheme(blm
+				.createInternationalString(str1), blm
+				.createInternationalString(str2));
+		return cs;
+	}
+
+	
+	/**
+	 * Setup the database.
+	 * @throws Exception
+	 */
+	@BeforeClass
+	public static void runBeforeAllTests() throws Exception {
+		try {
+			TestUtil.setESBPropertiesFileToUse();
+			//Set the juddi properties file in System so juddi will pick it up later and use the test values.
+			String juddiPropertiesFile = "/org/jboss/soa/esb/services/registry/juddi-unittest.properties";
+			System.setProperty("juddi.propertiesFile", juddiPropertiesFile);
+			//Read this properties file to get the db connection string
+			Properties props = new Properties();
+			InputStream inStream = Class.class.getResourceAsStream(juddiPropertiesFile);
+			props.load(inStream);
+			mDbDriver    = props.getProperty("juddi.jdbcDriver");
+			mDbUrl       = props.getProperty("juddi.jdbcUrl");
+			mDbUsername  = props.getProperty("juddi.jdbcUsername");
+			mDbPassword  = props.getProperty("juddi.jdbcPassword");
+			
+			String database="not tested yet";
+			if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+				database = "hsqldb";
+				//Bring up hsql on default port 9001
+				HsqldbUtil.startHsqldb(TestUtil.getPrefix() + "build/hsqltestdb", "juddi");
+			} else if ("com.mysql.jdbc.Driver".equals(mDbDriver)) {
+				database = "mysql";
+			} //add and test your own database..
+			
+			//Get the registry-schema create scripts
+			String sqlDir = TestUtil.getPrefix() + "install/jUDDI-registry/sql/" + database + "/";
+			//Drop what is there now, if exists. We want to start fresh.
+			String sqlDropCmd      = FileUtil.readTextFile(new File(sqlDir + "drop_database.sql"));
+			String sqlCreateCmd    = FileUtil.readTextFile(new File(sqlDir + "create_database.sql"));
+			String sqlInsertPubCmd = FileUtil.readTextFile(new File(sqlDir + "insert_publishers.sql"));
+			
+			try {
+				Class.forName(mDbDriver);
+			} catch (Exception e) {
+				System.out.println("ERROR: failed to load " + database + " JDBC driver.");
+				e.printStackTrace();
+				return;
+			}
+			java.sql.Connection con = DriverManager.getConnection(mDbUrl, mDbUsername, mDbPassword);
+			Statement stmnt = con.createStatement();
+			System.out.println("Dropping the schema if exist");
+			stmnt.execute(sqlDropCmd);
+			System.out.println("Creating the juddi-schema");
+			stmnt.execute(sqlCreateCmd);
+			System.out.println("Adding the jbossesb publisher");
+			stmnt.execute(sqlInsertPubCmd);
+		} catch (Exception e) {
+			e.printStackTrace();
+			System.out.println("We should stop testing, since we don't have a db.");
+			assertTrue(false);
+		}
+	}
+	/**
+	 * Shutdown the database
+	 * @throws Exception
+	 */
+	@AfterClass
+	public static void runAfterAllTests() throws Exception {
+		if ("org.hsqldb.jdbcDriver".equals(mDbDriver)) {
+			HsqldbUtil.stopHsqldb(mDbUrl, mDbUsername, mDbPassword);
+		}
+	}
+
+	public static junit.framework.Test suite() {
+		return new JUnit4TestAdapter(RegistryUnitTest.class);
+	}
+
+}


Property changes on: labs/jbossesb/trunk/product/etc/schemas/validation
___________________________________________________________________
Name: svn:ignore
   + build





More information about the jboss-svn-commits mailing list