public void testMultipleGeneratedServiceWithMultipleComposite() {
try {
installCachingFactory();
// Create the first service with a sparse composite
DescriptionBuilderComposite sparseComposite1 = new DescriptionBuilderComposite();
ServiceDelegate.setServiceMetadata(sparseComposite1);
Service service1 = new ClientMetadataGeneratedService(getWsdlURL(otherWsdl),
new QName(namespaceURI, svcLocalPart));
assertNotNull(service1);
assertNull(ServiceDelegate.getServiceMetadata());
// Create the second service with a sparse composite
DescriptionBuilderComposite sparseComposite2 = new DescriptionBuilderComposite();
ServiceDelegate.setServiceMetadata(sparseComposite2);
Service service2 = new ClientMetadataGeneratedService(getWsdlURL(otherWsdl),
new QName(namespaceURI, svcLocalPart));
assertNotNull(service2);
assertNull(ServiceDelegate.getServiceMetadata());
// Verifiy the service delegates are different and the service descriptions are the same
// since we installed a caching factory above.
ServiceDelegate serviceDelegate1 = DescriptionTestUtils2.getServiceDelegate(service1);
assertNotNull(serviceDelegate1);
ServiceDescription serviceDesc1 = serviceDelegate1.getServiceDescription();
assertNotNull(serviceDesc1);
ServiceDelegate serviceDelegate2 = DescriptionTestUtils2.getServiceDelegate(service2);
assertNotNull(serviceDelegate2);
ServiceDescription serviceDesc2 = serviceDelegate2.getServiceDescription();
assertNotNull(serviceDesc2);
assertNotSame(serviceDelegate1, serviceDelegate2);
assertSame(serviceDesc1, serviceDesc2);
// There should be a sparse composite for the first service delegate and
// one for the second service delegate
assertSame(sparseComposite1,
DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc2).getSparseComposite(serviceDelegate1));
assertSame(sparseComposite2, DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc2).getSparseComposite(serviceDelegate2));
DescriptionBuilderComposite dbcInServiceDesc = DescriptionTestUtils2.getServiceDescriptionComposite(serviceDesc1);
assertEquals(ClientMetadataGeneratedService.class, dbcInServiceDesc.getCorrespondingClass());
// WSDL was specified on the generated Service constructor, and none in the composite
// so should get the WSDL specified on the constructor
assertTrue("Wrong WSDL used", validatePort(service1, otherWsdl_portLocalPart));
assertTrue("Wrong WSDL used", validatePort(service2, otherWsdl_portLocalPart));