[jboss-svn-commits] JBL Code SVN: r34952 - in labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta: 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 Sep 1 09:30:19 EDT 2010
Author: tcunning
Date: 2010-09-01 09:30:19 -0400 (Wed, 01 Sep 2010)
New Revision: 34952
Added:
labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRCoalesceUnitTest.java
Modified:
labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
Log:
JBESB-3344
Coalesce duplicate services into a single aggregate service and add a
test for the coalesce methods.
Modified: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2010-09-01 13:24:38 UTC (rev 34951)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/src/org/jboss/internal/soa/esb/services/registry/JAXRRegistryImpl.java 2010-09-01 13:30:19 UTC (rev 34952)
@@ -25,6 +25,7 @@
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
@@ -80,7 +81,7 @@
private ClassificationScheme jbossESBScheme;
private static Concept jbossTModelXXX;
public static final String JBOSS_ESB_CATEGORY = "org.jboss.soa.esb.:category";
- private static final String REGISTERED_BY_JBOSSESB = "Registered by JBoss ESB";
+ public static final String REGISTERED_BY_JBOSSESB = "Registered by JBoss ESB";
public String orgCategory;
private static final boolean isV3;
@@ -91,6 +92,10 @@
/**
* Publish an EPR to the Registry
+ * @param category
+ * @param serviceName
+ * @return Service
+ * @throws JAXRException
*/
protected Service registerService(String category, String serviceName, String serviceDescription) throws JAXRException
{
@@ -116,6 +121,10 @@
}
/**
* Remove an EPR from the Registry
+ * @param category
+ * @param serviceName
+ * @throws RegistryException
+ * @throws ServiceNotFoundException
*/
public void unRegisterService(String category, String serviceName) throws RegistryException, ServiceNotFoundException{
// first find the ServiceBindings for this service
@@ -139,6 +148,11 @@
}
/**
* Publish an EPR to the Registry
+ * @param category
+ * @param serviceName
+ * @param serviceDescription
+ * @param epr
+ * @param eprDescription
*/
public void registerEPR(String category, String serviceName, String serviceDescription, EPR epr, String eprDescription)
throws RegistryException
@@ -202,6 +216,11 @@
}
/**
* Remove an EPR from the Registry
+ * @param category
+ * @param serviceName
+ * @param toBeDeletedEPR
+ * @throws RegistryException
+ * @throws ServiceNotFoundException
*/
public void unRegisterEPR(String category, String serviceName, EPR toBeDeletedEPR) throws RegistryException, ServiceNotFoundException{
//first find the ServiceBindings for this service
@@ -270,7 +289,7 @@
}
/**
* Find Services based on a category ("transformation").
- *
+ * @param category
* @return collection services
*/
public List<String> findServices(String category) throws RegistryException
@@ -289,8 +308,11 @@
return serviceNames;
}
/**
- *
- * @return
+ * @param category
+ * @param serviceName
+ * @return epr list
+ * @throws RegistryException
+ * @throws ServiceNotFoundException
*/
public List<EPR> findEPRs(String category, String serviceName) throws RegistryException, ServiceNotFoundException
{
@@ -339,9 +361,13 @@
}
return eprs;
}
+
/**
- *
- * @return
+ * @param category
+ * @param serviceName
+ * @return epr
+ * @throws RegistryException
+ * @throws ServiceNotFoundException
*/
public EPR findEPR(String category, String serviceName) throws RegistryException, ServiceNotFoundException
{
@@ -391,7 +417,9 @@
* Find all Organizations with a name mathing the queryString parameter.
*
* @param organizationName used to match with the name of the organization.
+ * @param jaxrConnectionFactory
* @return the Organization.
+ * @throws JAXRException
*/
public static Organization findOrganization(String organizationName, JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException {
if (organizationName==null) {
@@ -439,10 +467,11 @@
}
/**
- *
+ * Find Service.
* @param category
* @param serviceName
* @return Service
+ * @throws JAXRException
*/
protected Service findService(String category, String serviceName) throws JAXRException
{
@@ -480,20 +509,29 @@
BulkResponse response = bqm.findServices(null, findQualifiers,
namePatterns, classifications, specifications);
if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
- for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();)
- {
- Service service = (Service) servIter.next();
- logger.log(Level.DEBUG, "Service name: " + service.getName().getValue());
- if (service.getDescription()!=null) {
- logger.log(Level.DEBUG, "Description: " + service.getDescription().getValue());
+ if (response.getCollection().size() <= 1) {
+ for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();)
+ {
+ Service service = (Service) servIter.next();
+ logger.log(Level.DEBUG, "Service name: " + service.getName().getValue());
+ if (service.getDescription()!=null) {
+ logger.log(Level.DEBUG, "Description: " + service.getDescription().getValue());
+ }
+ return service;
+ }
+ } else {
+ logger.log(Level.ERROR, "Found " + response.getCollection().size()
+ + " Services, while expecting only one by the name of "
+ + serviceName + " in category " + category);
+
+
+ ArrayList services = new ArrayList<Service>();
+ for (Iterator servIter = response.getCollection().iterator(); servIter.hasNext();)
+ {
+ Service service = (Service) servIter.next();
+ services.add(service);
}
- logger.log(Level.DEBUG, "Key id: " + service.getKey().getId());
- if (servIter.hasNext()) {
- logger.log(Level.ERROR, "Found " + response.getCollection().size()
- + " Services, while expecting only one by the name of "
- + serviceName + " in category " + category);
- }
- return service;
+ return coalesceServices(services, connection);
}
}
return null;
@@ -503,9 +541,145 @@
}
/**
+ * Coalesce duplicate services into a single aggregate service.
+ * EPRs are aggregated, duplicates are removed and duplicate
+ * services are removed.
+ *
+ * @param category
+ * @return Service
+ * @throws JAXRException
+ */
+ @SuppressWarnings("unchecked")
+ protected Service coalesceServices(List<Service> services, Connection connection)
+ throws JAXRException {
+ logger.error("begin coalesceServices");
+
+ Service aggService = null;
+ Hashtable eprHash = new Hashtable();
+
+ for (Service s : services) {
+ if (aggService == null) {
+ aggService = s;
+ for (Iterator i = s.getServiceBindings().iterator(); i.hasNext();) {
+ ServiceBinding sb = (ServiceBinding) i.next();
+ eprHash.put(sb.getAccessURI(), sb);
+ logger.log(Level.DEBUG, "Found initial binding " + sb.getAccessURI());
+ }
+ } else {
+ // Transfer unique EPRs over
+ Collection bindings = s.getServiceBindings();
+ Collection bindingsToRemove = new ArrayList();
+ for (Iterator i = bindings.iterator(); i.hasNext();) {
+ ServiceBinding sb = (ServiceBinding) i.next();
+ try {
+ if (eprHash.containsKey(sb.getAccessURI())) {
+ logger.log(Level.DEBUG, "Removed binding " + sb.getAccessURI());
+ i.remove();
+ bindingsToRemove.add(sb.getKey());
+ } else {
+ logger.log(Level.DEBUG, "Transferring epr " + sb.getAccessURI());
+ i.remove();
+ transferEPR(aggService, s, sb, connection);
+ eprHash.put(sb.getAccessURI(), sb);
+ }
+ } catch (JAXRException e) {
+ throw e;
+ } finally {
+ removeBindings(bindingsToRemove, connection);
+ }
+ }
+ // Remove the Service
+ removeService(s, connection);
+ }
+ }
+ logger.error("end coalesceServices");
+
+ return aggService;
+ }
+
+ /**
+ * Transfers a binding from one service to another.
+ * @param service the binding is copied to
+ * @param service the binding is coming from
+ * @param service binding
+ * @return Service
+ * @throws JAXRException
+ */
+ @SuppressWarnings("unchecked")
+ private void transferEPR(Service toService, Service fromService, ServiceBinding binding,
+ Connection connection)
+ throws JAXRException
+ {
+ String eprDescription = binding.getDescription().getValue();
+ try {
+ final Concept jbossTModel = getJBossESBTModel(connection);
+
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+
+ fromService.removeServiceBinding(binding);
+ Collection bindings = new ArrayList();
+ bindings.add(binding.getKey());
+ blm.deleteServiceBindings(bindings);
+
+ toService.addServiceBinding(binding);
+ bindings = new ArrayList();
+ bindings.add(binding);
+ blm.saveServiceBindings(bindings);
+
+ } catch (JAXRException je) {
+ throw je;
+ }
+ }
+
+ /**
+ * Removes service bindings.
+ * @param servicebinding
+ * @throws JAXRException
+ */
+ @SuppressWarnings("unchecked")
+ private void removeBindings(Collection keys, Connection connection)
+ throws JAXRException
+ {
+ try {
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+
+ blm.deleteServiceBindings(keys);
+ } catch (JAXRException je) {
+ throw je;
+ }
+ }
+
+ /**
+ * Removes a service.
+ * @param service
+ * @throws JAXRException
+ */
+ @SuppressWarnings("unchecked")
+ private void removeService(Service service, Connection connection)
+ throws JAXRException
+ {
+ try {
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+
+ Collection<Key> serviceKeys = new ArrayList<Key>();
+ serviceKeys.add(service.getKey());
+ blm.deleteServices(serviceKeys);
+ } catch (JAXRException je) {
+ throw je;
+ }
+ }
+
+ /**
* Finds all services for a given category.
* @param category
* @return Service
+ * @throws JAXRException
*/
@SuppressWarnings("unchecked")
protected Collection<Service> findServicesForCategory(String category) throws JAXRException
@@ -548,8 +722,8 @@
/**
* Create a jbossesb organization under which we will register all our services.
- *
- * @return
+ * @param jaxrConnectionFactory
+ * @return organization
* @throws JAXRException
*/
protected static Organization createJBossESBOrganization(JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException
@@ -603,11 +777,11 @@
/**
* Create a jbossesb organization under which we will register all our services.
- *
- * @return
+ * @param Connection connection
+ * @return Concept
* @throws JAXRException
*/
- private synchronized Concept getJBossESBTModel(Connection connection) throws JAXRException
+ protected synchronized Concept getJBossESBTModel(Connection connection) throws JAXRException
{
if (jbossTModelXXX == null) {
RegistryService rs = connection.getRegistryService();
@@ -638,8 +812,11 @@
/**
* Save Registry Object
+ * @param RegistryObject registry object
+ * @param JAXRConnectionFactory JAXR connection factory
+ * @throws JAXRException For errors during querying/creating.
*/
- private static void saveRegistryObject(RegistryObject registryObject, JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException
+ protected static void saveRegistryObject(RegistryObject registryObject, JAXRConnectionFactory jaxrConnectionFactory) throws JAXRException
{
// Getting the connection to the Registry (reading config)
Connection connection = jaxrConnectionFactory.getConnection();
@@ -686,17 +863,19 @@
logger.log(Level.ERROR, "Errors occurred during save.");
if (br!=null) {
Collection exceptions = br.getExceptions();
- Iterator iter = exceptions.iterator();
- StringBuilder errors = new StringBuilder();
- JAXRException je = new JAXRException("JAXRExceptions occurred during save");
- while (iter.hasNext()) {
- Exception e = (Exception) iter.next();
- errors.append(e.getLocalizedMessage()).append("\n");
- je.setStackTrace(e.getStackTrace());
- logger.log(Level.ERROR, e.getLocalizedMessage(), e);
- //if it's the last error, throw it now and set the current stacktrace
- if (!iter.hasNext()) {
- throw new JAXRException(errors.toString(), e);
+ if (exceptions != null) {
+ Iterator iter = exceptions.iterator();
+ StringBuilder errors = new StringBuilder();
+ JAXRException je = new JAXRException("JAXRExceptions occurred during save");
+ while (iter.hasNext()) {
+ Exception e = (Exception) iter.next();
+ errors.append(e.getLocalizedMessage()).append("\n");
+ je.setStackTrace(e.getStackTrace());
+ logger.log(Level.ERROR, e.getLocalizedMessage(), e);
+ //if it's the last error, throw it now and set the current stacktrace
+ if (!iter.hasNext()) {
+ throw new JAXRException(errors.toString(), e);
+ }
}
}
throw new JAXRException("Errors occurred during save. Response status=" + br.getStatus());
@@ -727,10 +906,12 @@
/**
* finds the JBossESB category classification scheme and creates one if it is not there.
*
+ * @param BusinessQueryManager business query manager
+ * @param BusinessLifeCycleManager business lifecycle manager
* @return JBossESB category classification scheme
* @throws JAXRException For errors during querying/creating.
*/
- private synchronized ClassificationScheme getClassificationScheme(final BusinessQueryManager bqm, final BusinessLifeCycleManager blm) throws JAXRException
+ protected synchronized ClassificationScheme getClassificationScheme(final BusinessQueryManager bqm, final BusinessLifeCycleManager blm) throws JAXRException
{
if (jbossESBScheme == null) {
// Define find qualifiers and name patterns
@@ -801,7 +982,6 @@
slink.setSpecificationObject(jbossTModel);
bindingSpecs.add(slink);
-
}
}
return serviceBindings;
@@ -816,5 +996,3 @@
isV3 = "3.0".equals(Configuration.getRegistryUDDIVersion());
}
}
-
-
Added: labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRCoalesceUnitTest.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRCoalesceUnitTest.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_9_CP/product/rosetta/tests/src/org/jboss/internal/soa/esb/services/registry/JAXRCoalesceUnitTest.java 2010-09-01 13:30:19 UTC (rev 34952)
@@ -0,0 +1,364 @@
+/*
+* 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 java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Iterator;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.addressing.eprs.InVMEpr;
+
+import junit.framework.TestCase;
+
+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.Concept;
+import javax.xml.registry.infomodel.Organization;
+import javax.xml.registry.infomodel.Service;
+import javax.xml.registry.infomodel.ServiceBinding;
+import javax.xml.registry.infomodel.SpecificationLink;
+import javax.xml.registry.infomodel.User;
+
+import junit.framework.JUnit4TestAdapter;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.apache.ws.scout.registry.infomodel.SpecificationLinkImpl;
+import org.jboss.internal.soa.esb.addressing.helpers.EPRHelper;
+import org.jboss.soa.esb.addressing.EPR;
+import org.jboss.soa.esb.common.Configuration;
+import org.jboss.soa.esb.services.registry.RegistryException;
+import org.jboss.soa.esb.services.registry.ServiceNotFoundException;
+import org.jboss.soa.esb.testutils.TestEnvironmentUtil;
+import org.jboss.soa.esb.ConfigurationException;
+import org.jboss.soa.esb.MarshalException;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Testing the ability of the JAXRRegistryImpl to coalesce duplicate
+ * services into an aggregate service. EPRs from the duplicate
+ * service entries are copied to the aggregate service, and the duplicate entries
+ * are deleted.
+ *
+ * @author <a href="tcunning at redhat.com">Tom Cunningham</a>
+ */
+public class JAXRCoalesceUnitTest extends TestCase
+{
+ private static Logger logger = Logger.getLogger(JAXRCoalesceUnitTest.class);
+
+ private ClassificationScheme jbossESBScheme;
+
+ private static final String TEST_SERVICE_CATEGORY = "ESB_CATEGORY";
+ private static final String TEST_SERVICE_NAME = "SERVICE_NAME";
+ private static final String TEST_SERVICE_DESC = "SERVICE_DESCRIPTION";
+
+ private static boolean startflag = false;
+
+ /**
+ * Setup the database.
+ * @throws Exception
+ */
+ public void setUp() throws Exception {
+ if (!startflag) {
+ TestEnvironmentUtil.setESBPropertiesFileToUse();
+ TestEnvironmentUtil.startJAXRDatabase();
+ startflag = true;
+ }
+ }
+
+ @AfterClass
+ public void afterClass() throws Exception {
+ TestEnvironmentUtil.stopJAXRDatabase();
+ startflag = false;
+ }
+
+ public static void scenarioOne() throws Exception {
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ Service s1 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME, TEST_SERVICE_DESC);
+ Service s2 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME, TEST_SERVICE_DESC);
+
+ // Attach EPRs
+ InVMEpr epr1 = new InVMEpr(new URI("invm://service1epr1"));
+ InVMEpr epr2 = new InVMEpr(new URI("invm://service1epr2"));
+ registerEPR(registry, s1, epr1, "epr1");
+ registerEPR(registry, s1, epr2, "epr2");
+
+ InVMEpr epr3 = new InVMEpr(new URI("invm://service2epr1"));
+ InVMEpr epr4 = new InVMEpr(new URI("invm://service2epr2"));
+ registerEPR(registry, s2, epr3, "epr3");
+ registerEPR(registry, s2, epr4, "epr4");
+ }
+
+ public static void scenarioTwo() throws Exception {
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ Service s1 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME+"2", TEST_SERVICE_DESC);
+ Service s2 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME+"2", TEST_SERVICE_DESC);
+
+ // Attach EPRs
+ InVMEpr epr1 = new InVMEpr(new URI("invm://service1epr1"));
+ InVMEpr epr2 = new InVMEpr(new URI("invm://service1epr2"));
+ registerEPR(registry, s1, epr1, "epr1");
+ registerEPR(registry, s1, epr2, "epr2");
+
+ InVMEpr epr3 = new InVMEpr(new URI("invm://service1epr1"));
+ InVMEpr epr4 = new InVMEpr(new URI("invm://service1epr2"));
+ registerEPR(registry, s2, epr3, "epr1");
+ registerEPR(registry, s2, epr4, "epr2");
+ }
+
+ public static void scenarioThree() throws ConfigurationException, URISyntaxException, JAXRException, RegistryException {
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ Service s1 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME+"3", TEST_SERVICE_DESC);
+ Service s2 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME+"3", TEST_SERVICE_DESC);
+
+ InVMEpr epr3 = new InVMEpr(new URI("invm://service1epr1"));
+ InVMEpr epr4 = new InVMEpr(new URI("invm://service1epr2"));
+ registerEPR(registry, s2, epr3, "epr1");
+ registerEPR(registry, s2, epr4, "epr2");
+ }
+
+ public static void scenarioFour() throws ConfigurationException, URISyntaxException, JAXRException, RegistryException {
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ Service s1 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME+"4", TEST_SERVICE_DESC);
+ Service s2 = registry.registerService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME+"4second", TEST_SERVICE_DESC);
+ InVMEpr epr3 = new InVMEpr(new URI("invm://service1epr1"));
+ InVMEpr epr4 = new InVMEpr(new URI("invm://service1epr2"));
+ registerEPR(registry, s1, epr3, "epr1");
+ registerEPR(registry, s1, epr4, "epr2");
+ }
+
+ /**
+ * Publish an EPR to the Registry
+ */
+ public static void registerEPR(JAXRRegistryImpl registry, Service service, EPR epr, String eprDescription)
+ throws RegistryException, ConfigurationException
+ {
+ if (epr == null)
+ {
+ throw new RegistryException("Null EPR argument specified") ;
+ }
+ JAXRConnectionFactory jaxrConnectionFactory = new JAXRConnectionFactory();
+ Connection connection = jaxrConnectionFactory.getConnection();
+ try {
+ final Concept jbossTModel = registry.getJBossESBTModel(connection);
+
+ RegistryService rs = connection.getRegistryService();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ ServiceBinding serviceBinding = blm.createServiceBinding();
+ String xml = EPRHelper.toXMLString(epr);
+ serviceBinding.setAccessURI(xml);
+
+ ArrayList<ServiceBinding> serviceBindings = new ArrayList<ServiceBinding>();
+ SpecificationLink sl = new SpecificationLinkImpl(blm);
+ sl.setSpecificationObject(jbossTModel);
+ serviceBinding.getSpecificationLinks().add(sl);
+ if ("3.0".equals(Configuration.getRegistryUDDIVersion())) {
+ if ((eprDescription == null) || ("".equals(eprDescription))) {
+ serviceBinding.setDescription(blm.createInternationalString(JAXRRegistryImpl.REGISTERED_BY_JBOSSESB));
+ }
+ } else {
+ serviceBinding.setDescription(blm.createInternationalString(eprDescription));
+ }
+ serviceBindings.add(serviceBinding);
+
+ service.addServiceBindings(serviceBindings);
+ ClassificationScheme cScheme = registry.getClassificationScheme(bqm, blm);
+ Classification classification = blm.createClassification(cScheme, "category", TEST_SERVICE_CATEGORY);
+ service.addClassification(classification);
+
+ registry.saveRegistryObject(serviceBinding, jaxrConnectionFactory);
+ } catch (JAXRException je) {
+ throw new RegistryException(je.getLocalizedMessage(), je);
+ } catch (MarshalException me) {
+ throw new RegistryException(me.getLocalizedMessage(), me);
+ } finally {
+ jaxrConnectionFactory.closeConnection(connection);
+ }
+ }
+
+ public Collection findMultipleServices(String category, String name) throws ConfigurationException, JAXRException, RegistryException {
+ JAXRConnectionFactory jaxrConnectionFactory = new JAXRConnectionFactory();
+ Connection connection = jaxrConnectionFactory.getConnection();
+ try {
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+
+ final Concept jbossTModel = registry.getJBossESBTModel(connection);
+ // Get registry service and business query manager
+ RegistryService rs = connection.getRegistryService();
+ BusinessQueryManager bqm = rs.getBusinessQueryManager();
+ BusinessLifeCycleManager blm = rs.getBusinessLifeCycleManager();
+ final ClassificationScheme cScheme = registry.getClassificationScheme(bqm, blm) ;
+ Collection<Classification> classifications = new ArrayList<Classification>();
+ Classification classification =
+ blm.createClassification(
+ cScheme,
+ "category", category);
+ classifications.add(classification);
+ Collection<String> namePatterns = new ArrayList<String>();
+ namePatterns.add(name);
+
+ Collection<SpecificationLink> specifications = new ArrayList<SpecificationLink>();
+
+ //Find based upon qualifier type and values
+ Collection<String> findQualifiers = new ArrayList<String>();
+ findQualifiers.add(FindQualifier.AND_ALL_KEYS);
+ findQualifiers.add(FindQualifier.EXACT_NAME_MATCH);
+ findQualifiers.add(FindQualifier.SORT_BY_NAME_DESC);
+ logger.log(Level.DEBUG, "Going to query the registry for name pattern " + namePatterns);
+ BulkResponse response = bqm.findServices(null, findQualifiers,
+ namePatterns, classifications, specifications);
+ if (response.getStatus()==JAXRResponse.STATUS_SUCCESS) {
+ return response.getCollection();
+ } else {
+ throw new RegistryException();
+ }
+ } finally {
+ jaxrConnectionFactory.closeConnection(connection);
+ }
+ }
+
+ /*
+ * testScenarioOne tests a scenario where two duplicate services each have
+ * two unique EPRs. The result is that the EPRs from the second service
+ * are merged over to the first.
+ */
+ public void testScenarioOne() throws ConfigurationException, JAXRException, RegistryException, URISyntaxException, Exception
+ {
+ scenarioOne();
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ registry.findService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME);
+ Collection services = findMultipleServices(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME);
+ assertEquals(1, services.size());
+
+ for (Iterator iter = services.iterator(); iter.hasNext();) {
+ Service s = (Service) iter.next();
+ assertEquals(s.getName().getValue(), TEST_SERVICE_NAME);
+ assertEquals(s.getDescription().getValue(), TEST_SERVICE_DESC);
+ assertEquals(4, s.getServiceBindings().size());
+ }
+
+ }
+
+ /*
+ * testScenarioTwo tests a scenario where two duplicate services each
+ * have the same two EPRs. The result should be that the second service
+ * and the duplicate EPRs are removed and you have the original service
+ * with the original EPRs.
+ */
+ public void testScenarioTwo() throws ConfigurationException, JAXRException, RegistryException, URISyntaxException, Exception
+ {
+ scenarioTwo();
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ registry.findService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME + "2");
+ Collection services = findMultipleServices(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME + "2");
+ assertEquals(1, services.size());
+
+ for (Iterator iter = services.iterator(); iter.hasNext();) {
+ Service s = (Service) iter.next();
+ assertEquals(s.getName().getValue(), TEST_SERVICE_NAME + "2");
+ assertEquals(s.getDescription().getValue(), TEST_SERVICE_DESC);
+ assertEquals(2, s.getServiceBindings().size());
+ }
+ }
+
+ /*
+ * testScenarioThree tests a scenario where there are two duplicate
+ * services and one of the services has two EPRs and the other has none.
+ * The result should be a service with the two EPRs.
+ */
+ public void testScenarioThree() throws ConfigurationException, JAXRException, RegistryException, URISyntaxException
+ {
+ scenarioThree();
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ registry.findService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME + "3");
+ Collection services = findMultipleServices(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME + "3");
+ assertEquals(1, services.size());
+
+ for (Iterator iter = services.iterator(); iter.hasNext();) {
+ Service s = (Service) iter.next();
+ assertEquals(s.getName().getValue(), TEST_SERVICE_NAME+"3");
+ assertEquals(s.getDescription().getValue(), TEST_SERVICE_DESC);
+ assertEquals(2, s.getServiceBindings().size());
+ }
+ }
+
+ /*
+ * testScenarioFour tests a scenario one service has two EPRs and the
+ * another service with a different name has none. The result should
+ * be no change - two services, one with 2 eprs.
+ */
+ public void testScenarioFour() throws ConfigurationException, JAXRException, RegistryException, URISyntaxException
+ {
+ scenarioFour();
+ JAXRRegistryImpl registry = new JAXRRegistryImpl();
+ registry.findService(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME + "4");
+ Collection services = findMultipleServices(TEST_SERVICE_CATEGORY, TEST_SERVICE_NAME + "4");
+ assertEquals(1, services.size());
+
+ boolean foundService = false;
+ for (Iterator iter = services.iterator(); iter.hasNext();) {
+ Service s = (Service) iter.next();
+ if ((TEST_SERVICE_NAME+"4").equals(s.getName().getValue())) {
+ assertEquals(s.getName().getValue(), TEST_SERVICE_NAME + "4");
+ assertEquals(s.getDescription().getValue(), TEST_SERVICE_DESC);
+ assertEquals(2, s.getServiceBindings().size());
+ foundService = true;
+ }
+ }
+ assertTrue(foundService);
+ }
+
+ /*
+ * Debugging method that is not used.
+ */
+ public static void printService(Service service) throws JAXRException {
+ logger.debug("Service name: " + service.getName().getValue());
+ if (service.getDescription()!=null) {
+ logger.debug("Description: " + service.getDescription().getValue());
+ }
+ for (Object c : service.getClassifications()) {
+ Classification classific = (Classification ) c;
+ logger.debug(" Service Category: " + classific.getName().getValue());
+ logger.debug(" Service Description: " + classific.getDescription().getValue());
+ logger.debug(" Service Category: " + classific.getValue());
+ logger.debug(" Number of EPRs : " + service.getServiceBindings().size());
+ }
+ logger.debug("Key id: " + service.getKey().getId());
+ }
+
+ public static junit.framework.Test suite() {
+ return new JUnit4TestAdapter(JAXRCoalesceUnitTest.class);
+ }
+}
\ No newline at end of file
More information about the jboss-svn-commits
mailing list