[jboss-svn-commits] JBL Code SVN: r7330 - in labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services: . registry

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Nov 2 10:31:02 EST 2006


Author: kurt.stam at jboss.com
Date: 2006-11-02 10:31:00 -0500 (Thu, 02 Nov 2006)
New Revision: 7330

Added:
   labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/
   labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java
Log:
moving test

Added: labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java
===================================================================
--- labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java	2006-11-02 15:03:24 UTC (rev 7329)
+++ labs/jbossesb/trunk/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java	2006-11-02 15:31:00 UTC (rev 7330)
@@ -0,0 +1,282 @@
+/*
+* 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.internal.soa.esb.services.registry;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.InputStream;
+import java.net.URLDecoder;
+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.JAXRException;
+import javax.xml.registry.RegistryService;
+import javax.xml.registry.infomodel.Classification;
+import javax.xml.registry.infomodel.ClassificationScheme;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.User;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Logger;
+import org.apache.log4j.Priority;
+import org.apache.log4j.xml.DOMConfigurator;
+import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.tests.HsqldbUtil;
+import org.jboss.soa.esb.common.tests.TestUtil;
+import org.jboss.soa.esb.services.registry.RegistryException;
+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 JAXRRegistryUnitTest
+{
+	private static Logger logger = Logger.getLogger(JAXRRegistryUnitTest.class);
+    private static String mDbDriver;
+	private static String mDbUrl;
+	private static String mDbUsername;
+	private static String mDbPassword;
+	/**
+	 * Tests the successful creation of the RED HAT/JBossESB Organization.
+	 */
+	@Test
+	public void publishOrganization() 
+	{
+		try {
+			Organization org = JAXRRegistryImpl.createJBossESBOrganization();
+			logger.log(Priority.INFO, "Succesfully created organization: " + org.getName().getValue());
+			assertEquals("Red Hat/JBossESB", org.getName().getValue());
+		} catch (JAXRException je) {
+			logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+			assertTrue(false);
+		}
+	}
+	@Test
+	public void findOrganization() 
+	{
+		try {
+			Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB");
+			logger.log(Priority.INFO, "Succesfully created organization: " + org.getName().getValue());
+			assertEquals("Red Hat/JBossESB", org.getName().getValue());
+		} catch (JAXRException je) {
+			logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+			assertTrue(false);
+		}
+		try {
+			Organization org = JAXRRegistryImpl.findOrganization("Not Existing Org");
+			logger.log(Priority.INFO, "Could not find non-existing organization.");
+			assertEquals(null, org);
+		} catch (JAXRException je) {
+			logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+			assertTrue(false);
+		}
+	}
+	/**
+	 * Tests the successful registration of a Service.
+	 *
+	 */
+	@Test
+	public void publishService()
+	{
+		try {
+			JAXRRegistryImpl registry = new JAXRRegistryImpl();
+			registry.registerService("registry", "Registry Test ServiceName", "Registry Test Service Description");
+		} catch (JAXRException je) {
+			logger.log(Priority.ERROR, je.getLocalizedMessage(), je);
+			assertTrue(false);
+		}
+	}
+	@Test
+	public void publishServiceBinding()
+	{
+		try {
+			EPR epr = new EPR();
+			JAXRRegistryImpl registry = new JAXRRegistryImpl();
+			registry.registerEPR("registry", "Registry Test ServiceName", "Registry Test Service Description",
+					epr, "EPR description");
+		} catch (RegistryException re) {
+			logger.log(Priority.ERROR, re.getLocalizedMessage(), re);
+			assertTrue(false);
+		}
+	}
+	/**
+	 * Queries the newly added information
+	 * @throws Exception
+	 */
+	@Test
+	public void findServicesForAnOrganization()
+    {
+		try {
+			Organization org = JAXRRegistryImpl.findOrganization("Red Hat/JBossESB");
+			//Listing out the services and their Bindings
+			logger.log(Priority.INFO, "-------------------------------------------------");
+			logger.log(Priority.INFO, "Organization name: " + org.getName().getValue());
+			logger.log(Priority.INFO, "Description: " + org.getDescription().getValue());
+			logger.log(Priority.INFO, "Key id: " + org.getKey().getId());
+			User primaryContact = org.getPrimaryContact();
+			logger.log(Priority.INFO, "Primary Contact: " + primaryContact.getPersonName().getFullName());
+			Collection services = org.getServices();
+			for (Iterator serviceIter = services.iterator();serviceIter.hasNext();) {
+				Service service = (Service) serviceIter.next();
+				logger.log(Priority.INFO, "- Service Name: " + service.getName().getValue());
+				logger.log(Priority.INFO, "  Service Key : " + service.getKey().getId());
+				Collection serviceBindings = service.getServiceBindings();
+				for (Iterator serviceBindingIter = serviceBindings.iterator();serviceBindingIter.hasNext();){
+					ServiceBinding serviceBinding = (ServiceBinding) serviceBindingIter.next();
+					logger.log(Priority.INFO, "  ServiceBinding Description: " + serviceBinding.getDescription().getValue());
+					String xml = URLDecoder.decode(serviceBinding.getAccessURI(),"UTF-8");
+					logger.log(Priority.INFO, "  ServiceBinding URI: " + xml);
+					assertEquals(EPRHelper.toXMLString(new EPR()),xml);
+				}
+			}
+			logger.log(Priority.INFO, "-------------------------------------------------");
+	    } catch (Exception je) {
+			je.printStackTrace();
+			assertTrue(false);
+		}
+    }
+	/**
+	 * This doesn't work because scout drops the classifications on the floor.
+	 * We're ignoring this test until I come up with a patch.
+	 *
+	 */
+	public void findServicesByClassification()
+	{
+		Connection connection = JAXRRegistryImpl.getConnection();
+		try {
+			// Get registry service and business query manager
+			RegistryService rs = connection.getRegistryService();
+			BusinessQueryManager bqm = rs.getBusinessQueryManager();
+			BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+			ClassificationScheme classificationScheme = bqm.findClassificationSchemeByName(null, "uddi-org:general_keywords");
+			Classification classification = blm.createClassification(classificationScheme,
+					"Test transformation service", "transformation");
+			Collection<Classification> classifications = new ArrayList<Classification>();
+			classifications.add(classification);
+			//Here I'd like to test filtering by this classification, but scout ignored the classification
+			String name=classificationScheme.getName().getValue();
+			System.out.println("Name=" + name);
+			Collection<String> nameParams = new ArrayList<String>();
+			//The name of the service is wild
+			nameParams.add("%");
+			BulkResponse bs = bqm.findServices(null, null,nameParams,classifications, null);
+			int status = bs.getStatus();
+			System.out.println("status=" + status);
+		} catch (JAXRException je) {
+			je.printStackTrace();
+		}
+		finally{}
+	}
+	/**
+	 * Setup the database.
+	 * @throws Exception
+	 */
+	@BeforeClass
+	public static void runBeforeAllTests() throws Exception {
+		try {
+			DOMConfigurator.configure(TestUtil.getPrefix() + "etc/test/resources/log4j.xml");
+			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(JAXRRegistryUnitTest.class);
+	}
+
+}




More information about the jboss-svn-commits mailing list