// Verify that things are as expected and save off information for later asserts
// after the closes.
// Make sure all the Service Delegates are unique.
ServiceDelegate sd1 = DescriptionTestUtils2.getServiceDelegate(svc1);
ServiceDelegate sd2 = DescriptionTestUtils2.getServiceDelegate(svc2);
ServiceDelegate sd3 = DescriptionTestUtils2.getServiceDelegate(svc3);
assertNotSame(sd1, sd2);
assertNotSame(sd2, sd3);
assertNotSame(sd1, sd3);
// Make sure the ServiceDescription is shared across the delegate instances.
ServiceDescription svcDesc1 = sd1.getServiceDescription();
ServiceDescription svcDesc2 = sd2.getServiceDescription();
ServiceDescription svcDesc3 = sd3.getServiceDescription();
AxisConfiguration axisConfig = svcDesc1.getAxisConfigContext().getAxisConfiguration();
assertSame(svcDesc1, svcDesc2);
assertSame(svcDesc1, svcDesc3);
// Since the services descriptions are shared, use this in the rest of the test for clarity
ServiceDescription svcDesc = svcDesc1;
// Make sure the endpoint descriptions for the same ports are not shared across the
// delegate instances
EndpointDescription epDesc1_port1 = svcDesc.getEndpointDescription(portQN1, sd1);
EndpointDescription epDesc2_port1 = svcDesc.getEndpointDescription(portQN1, sd2);
assertNotSame(epDesc1_port1, epDesc2_port1);
AxisService axisSvc1_port1 = epDesc1_port1.getAxisService();
AxisService axisSvc2_port1 = epDesc2_port1.getAxisService();
assertNotSame(axisSvc1_port1, axisSvc2_port1);
AxisService portQN1_AxisService = axisSvc1_port1;
AxisService portQN3_AxisService = svcDesc.getEndpointDescription(portQN3, sd1).getAxisService();
assertNull(svcDesc.getEndpointDescription(portQN1, sd3));
EndpointDescription epDesc1_port2 = svcDesc.getEndpointDescription(portQN2, sd1);
EndpointDescription epDesc2_port2 = svcDesc.getEndpointDescription(portQN2, sd2);
assertNotSame(epDesc1_port2, epDesc2_port2);
AxisService axisSvc1_port2 = epDesc1_port2.getAxisService();
AxisService axisSvc2_port2 = epDesc2_port2.getAxisService();
assertNotSame(axisSvc1_port2, axisSvc2_port2);
AxisService portQN2_AxisService = axisSvc1_port2;
EndpointDescription epDesc3_port4 = svcDesc.getEndpointDescription(portQN4, sd3);
assertNotNull(epDesc3_port4);
AxisService portQN4_AxisService = epDesc3_port4.getAxisService();
// Make sure all the AxisServices we expect exist. When the resoureces associated
// with a port are release below after the closes, the AxisServices are released.
assertTrue(axisConfig.getServiceGroup(portQN1_AxisService.getAxisServiceGroup().getServiceGroupName()) != null);
assertTrue(axisConfig.getServiceGroup(portQN2_AxisService.getAxisServiceGroup().getServiceGroupName()) != null);
assertTrue(axisConfig.getServiceGroup(portQN3_AxisService.getAxisServiceGroup().getServiceGroupName()) != null);
assertTrue(axisConfig.getServiceGroup(portQN4_AxisService.getAxisServiceGroup().getServiceGroupName()) != null);
// First close
org.apache.axis2.jaxws.spi.ServiceDelegate.releaseService(svc1);
// Should remove the entries for this delegate
assertNull(svcDesc.getEndpointDescription(portQN1, sd1));
assertNull(svcDesc.getEndpointDescription(portQN2, sd1));
// Should only release all ports added to this service; 4 wasn't added to this delegate
assertTrue(axisConfig.getServiceGroup(portQN1_AxisService.getAxisServiceGroup().getServiceGroupName()) == null);
assertTrue(axisConfig.getServiceGroup(portQN2_AxisService.getAxisServiceGroup().getServiceGroupName()) == null);
assertTrue(axisConfig.getServiceGroup(portQN3_AxisService.getAxisServiceGroup().getServiceGroupName()) == null);
assertTrue(axisConfig.getServiceGroup(portQN4_AxisService.getAxisServiceGroup().getServiceGroupName()) != null);
// Make sure the close didn't change anything unexpected
ServiceDescription svcDesc2_afterClose = sd2.getServiceDescription();
assertSame(svcDesc2, svcDesc2_afterClose);
EndpointDescription epDesc2_port1_afterClose =
svcDesc2_afterClose.getEndpointDescription(portQN1, sd2);
assertSame(epDesc2_port1, epDesc2_port1_afterClose);
EndpointDescription epDesc2_port2_afterClose =
svcDesc2_afterClose.getEndpointDescription(portQN2, sd2);
assertSame(epDesc2_port2, epDesc2_port2_afterClose);
// Second close.
// This should remove all entries for this delegate
// This should cause ports 1 and 2 to be released as both service 1 and 2 that were
// using them are now closed. Service 4 should be unaffected
org.apache.axis2.jaxws.spi.ServiceDelegate.releaseService(svc2);
assertNull(svcDesc.getEndpointDescription(portQN1, sd2));
assertNull(svcDesc.getEndpointDescription(portQN2, sd2));
assertNull(svcDesc.getEndpointDescription(portQN4, sd2));
assertTrue(axisConfig.getServiceGroup(portQN1_AxisService.getAxisServiceGroup().getServiceGroupName()) == null);
assertTrue(axisConfig.getServiceGroup(portQN2_AxisService.getAxisServiceGroup().getServiceGroupName()) == null);
assertTrue(axisConfig.getServiceGroup(portQN3_AxisService.getAxisServiceGroup().getServiceGroupName()) == null);
assertTrue(axisConfig.getServiceGroup(portQN4_AxisService.getAxisServiceGroup().getServiceGroupName()) != null);
// Make sure the close didn't change anything unexpected
ServiceDescription svcDesc3_afterClose = sd3.getServiceDescription();
assertSame(svcDesc3_afterClose, svcDesc3);
// Close the last delegate then verify all the services have been removed
// from the AxisConfiguration
org.apache.axis2.jaxws.spi.ServiceDelegate.releaseService(svc3);