[jboss-svn-commits] JBL Code SVN: r9852 - in labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services: registry and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Feb 28 15:06:27 EST 2007
Author: driedtoast
Date: 2007-02-28 15:06:26 -0500 (Wed, 28 Feb 2007)
New Revision: 9852
Added:
labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/
labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java
labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java
labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistryUnitTest.java
Log:
Adding more things to respository
Added: labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryUnitTest.java 2007-02-28 20:06:26 UTC (rev 9852)
@@ -0,0 +1,285 @@
+/*
+* 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.services.registry.RegistryException;
+import org.jboss.soa.esb.testutils.FileUtil;
+import org.jboss.soa.esb.testutils.HsqldbUtil;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+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");
+ registry.registerEPR("registry", "Registry Test ServiceName", "Registry Test Service Description",
+ epr, "EPR description");
+ registry.unRegisterEPR("registry", "Registry Test ServiceName", epr);
+ } 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(TestEnvironmentUtil.getUserDir() + "etc/test/resources/log4j.xml");
+ TestEnvironmentUtil.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(TestEnvironmentUtil.getUserDir() + "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 = TestEnvironmentUtil.getUserDir() + "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);
+ }
+
+}
Added: labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java
===================================================================
--- labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java (rev 0)
+++ labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistry.java 2007-02-28 20:06:26 UTC (rev 9852)
@@ -0,0 +1,210 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.internal.soa.esb.services.registry;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.common.ModulePropertyManager;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+
+import com.arjuna.common.util.propertyservice.PropertyManager;
+
+/**
+ * Mock Registry implementation.
+ * <p/>
+ * Avoids the need to setup HSQLDB etc.
+ * <p/>
+ * Just call {@link #install()} and {@link #uninstall()} from inside your test setUp and tearDown
+ * methods respectfully.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MockRegistry implements Registry {
+
+ private static final String REGISTRY_IMPEMENTATION_CLASS_ORIGINAL = Environment.REGISTRY_IMPEMENTATION_CLASS + "#Original";
+ public static PropertyManager regPropManager = ModulePropertyManager.getPropertyManager(ModulePropertyManager.REGISTRY_MODULE);
+ public List<RepositoryEntry> repository = new ArrayList<RepositoryEntry>();
+
+ /**
+ * Install this Mock Registry impl as the registry implementation to be used.
+ * <p/>
+ * Call this method in the test setUp.
+ */
+ public static void install() {
+ if(regPropManager == null) {
+ TestCase.fail("Failed to locate PropertyManager for [" + ModulePropertyManager.REGISTRY_MODULE + "].");
+ }
+ String currentRegImpl = regPropManager.getProperty(Environment.REGISTRY_IMPEMENTATION_CLASS);
+
+ if(currentRegImpl != null) {
+ // Save the current/original.
+ regPropManager.setProperty(REGISTRY_IMPEMENTATION_CLASS_ORIGINAL, currentRegImpl);
+ }
+ regPropManager.setProperty(Environment.REGISTRY_IMPEMENTATION_CLASS, MockRegistry.class.getName());
+ }
+
+ /**
+ * Uninstall this Mock Registry impl as the registry implementation to be used. Reinstate the reg impl that was
+ * specified prior to the install.
+ * <p/>
+ * Call this method in the test tearDown.
+ */
+ public static void uninstall() {
+ if(regPropManager == null) {
+ TestCase.fail("Failed to locate PropertyManager for [" + ModulePropertyManager.REGISTRY_MODULE + "].");
+ }
+ String originalRegImpl = regPropManager.getProperty(REGISTRY_IMPEMENTATION_CLASS_ORIGINAL);
+
+ if(originalRegImpl != null) {
+ // Reset the original.
+ regPropManager.setProperty(Environment.REGISTRY_IMPEMENTATION_CLASS, originalRegImpl);
+ regPropManager.removeProperty(REGISTRY_IMPEMENTATION_CLASS_ORIGINAL);
+ } else {
+ // It wasn't set in the first place, so just unset the impl
+ regPropManager.removeProperty(Environment.REGISTRY_IMPEMENTATION_CLASS);
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.registry.Registry#registerEPR(java.lang.String, java.lang.String, java.lang.String, org.jboss.soa.esb.addressing.EPR, java.lang.String)
+ */
+ public void registerEPR(String serviceCategoryName, String serviceName,
+ String serviceDescription, EPR epr, String eprDescription)
+ throws RegistryException {
+
+ repository.add(new RepositoryEntry(serviceCategoryName, serviceName, serviceDescription, epr, eprDescription));
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.registry.Registry#unRegisterService(java.lang.String, java.lang.String)
+ */
+ public void unRegisterService(String category, String serviceName) throws RegistryException {
+ unRegisterEPR(category, serviceName, null);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.registry.Registry#unRegisterEPR(java.lang.String, java.lang.String, org.jboss.soa.esb.addressing.EPR)
+ */
+ public void unRegisterEPR(String serviceCategoryName, String serviceName, EPR epr) throws RegistryException {
+ int indexOf = repository.indexOf(new RepositoryEntry(serviceCategoryName, serviceName, null, epr, null));
+
+ if(indexOf == -1) {
+ throw new RegistryException("Registry entry [" + serviceCategoryName + "][" + serviceName + "] not found.");
+ }
+ repository.remove(indexOf);
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.registry.Registry#findAllServices()
+ */
+ public Collection<String> findAllServices() throws RegistryException {
+ Collection<String> services = new ArrayList<String>();
+ for(RepositoryEntry entry : repository) {
+ services.add(entry.serviceName);
+ }
+ return services;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.registry.Registry#findServices(java.lang.String)
+ */
+ public Collection<String> findServices(String serviceCategoryName)
+ throws RegistryException {
+ Collection<String> services = new ArrayList<String>();
+ for(RepositoryEntry entry : repository) {
+ if(serviceCategoryName.equals(entry.serviceCategoryName)) {
+ services.add(entry.serviceName);
+ }
+ }
+ return services;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.registry.Registry#findEPRs(java.lang.String, java.lang.String)
+ */
+ public Collection<EPR> findEPRs(String serviceCategoryName,
+ String serviceName) throws RegistryException {
+ Collection<EPR> services = new ArrayList<EPR>();
+ for(RepositoryEntry entry : repository) {
+ if(serviceCategoryName.equals(entry.serviceCategoryName) && serviceName.equals(entry.serviceName)) {
+ services.add(entry.epr);
+ }
+ }
+ return services;
+ }
+
+ /* (non-Javadoc)
+ * @see org.jboss.soa.esb.services.registry.Registry#findEPR(java.lang.String, java.lang.String)
+ */
+ public EPR findEPR(String serviceCategoryName, String serviceName)
+ throws RegistryException {
+ for(RepositoryEntry entry : repository) {
+ if(serviceCategoryName.equals(entry.serviceCategoryName) && serviceName.equals(entry.serviceName)) {
+ return entry.epr;
+ }
+ }
+ return null;
+ }
+
+ public class RepositoryEntry {
+ public String serviceCategoryName;
+ public String serviceName;
+ public String serviceDescription;
+ public EPR epr;
+ public String eprDescription;
+
+ public RepositoryEntry(String serviceCategoryName, String serviceName, String serviceDescription, EPR epr, String eprDescription) {
+ this.serviceCategoryName = serviceCategoryName;
+ this.serviceName = serviceName;
+ this.serviceDescription = serviceDescription;
+ this.epr = epr;
+ this.eprDescription = eprDescription;
+ }
+
+ public boolean equals(Object obj) {
+ if(obj instanceof RepositoryEntry) {
+ RepositoryEntry entry = (RepositoryEntry)obj;
+
+ if(serviceCategoryName != null && !serviceCategoryName.equalsIgnoreCase(entry.serviceCategoryName)) {
+ return false;
+ }
+ if(serviceName != null && !serviceName.equalsIgnoreCase(entry.serviceName)) {
+ return false;
+ }
+ if(epr != null && epr != entry.epr) {
+ return false;
+ }
+
+ return true;
+ }
+
+ return false;
+ }
+ }
+}
Added: labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistryUnitTest.java
===================================================================
--- labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistryUnitTest.java (rev 0)
+++ labs/jbossesb/workspace/dmarchant/product/core/services/tests/src/org/jboss/internal/soa/esb/services/registry/MockRegistryUnitTest.java 2007-02-28 20:06:26 UTC (rev 9852)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006,
+ * @author JBoss Inc.
+ */
+
+package org.jboss.internal.soa.esb.services.registry;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.TestCase;
+
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.Environment;
+import org.jboss.soa.esb.services.registry.Registry;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.RegistryFactory;
+
+/**
+ * MockRegistry Unit Test.
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class MockRegistryUnitTest extends TestCase {
+
+ public void test_install_uninstall() throws RegistryException {
+ assertNotSame(MockRegistry.class.getName(), MockRegistry.regPropManager.getProperty(Environment.REGISTRY_IMPEMENTATION_CLASS));
+
+ MockRegistry.install();
+ assertEquals(MockRegistry.class.getName(), MockRegistry.regPropManager.getProperty(Environment.REGISTRY_IMPEMENTATION_CLASS));
+ Registry registry = RegistryFactory.getRegistry();
+ assertTrue(registry instanceof MockRegistry);
+
+ MockRegistry.uninstall();
+ assertNotSame(MockRegistry.class.getName(), MockRegistry.regPropManager.getProperty(Environment.REGISTRY_IMPEMENTATION_CLASS));
+ }
+
+ public void test_features() throws RegistryException {
+ MockRegistry registry = new MockRegistry();
+ EPR epr = new EPR();
+ List<String> services = new ArrayList<String>();
+ List<EPR> eprs = new ArrayList<EPR>();
+
+ registry.registerEPR("cat1", "cat1-service1", "service-desc", epr, "epr-desc");
+ registry.registerEPR("cat1", "cat1-service2", "service-desc", epr, "epr-desc");
+ registry.registerEPR("cat1", "cat1-service3", "service-desc", epr, "epr-desc");
+ registry.registerEPR("cat2", "cat2-service1", "service-desc", epr, "epr-desc");
+ registry.registerEPR("cat2", "cat2-service2", "service-desc", epr, "epr-desc");
+ registry.registerEPR("cat2", "cat2-service3", "service-desc", epr, "epr-desc");
+
+ services.addAll(registry.findAllServices());
+ assertEquals(6, services.size());
+ assertEquals("cat1-service1", services.get(0));
+ assertEquals("cat2-service1", services.get(3));
+ assertEquals("cat2-service3", services.get(5));
+
+ services.clear();
+ services.addAll(registry.findServices("cat1"));
+ assertEquals(3, services.size());
+ assertEquals("cat1-service1", services.get(0));
+ assertEquals("cat1-service2", services.get(1));
+ assertEquals("cat1-service3", services.get(2));
+
+ assertEquals(epr, registry.findEPR("cat1", "cat1-service1"));
+
+ try {
+ registry.unRegisterService("cat2", "cat1-service2");
+ fail("Expected RegistryException for unknown service.");
+ } catch(RegistryException e) {
+ //OK
+ }
+
+ eprs.addAll(registry.findEPRs("cat1", "cat1-service1"));
+ assertEquals(1, eprs.size());
+ assertEquals(epr, eprs.get(0));
+
+ registry.unRegisterService("cat1", "cat1-service2");
+ services.clear();
+ services.addAll(registry.findAllServices());
+ assertEquals(5, services.size());
+ assertEquals("cat1-service1", services.get(0));
+ assertEquals("cat1-service3", services.get(1));
+ assertEquals("cat2-service1", services.get(2));
+
+ registry.unRegisterEPR("cat2", "cat2-service2", epr);
+ services.clear();
+ services.addAll(registry.findAllServices());
+ assertEquals(4, services.size());
+ assertEquals("cat1-service1", services.get(0));
+ assertEquals("cat1-service3", services.get(1));
+ assertEquals("cat2-service1", services.get(2));
+ }
+}
More information about the jboss-svn-commits
mailing list