ServiceManager serviceManager = new ServiceManager(registry);
Service service = serviceManager.newService(new QName("http://wso2.com/test234/xxxxx", "myServicxcde"));
serviceManager.addService(service);
EndpointManager endpointManager = new EndpointManager(registry);
Endpoint ep1 = endpointManager.newEndpoint("http://endpoint1xx");
endpointManager.addEndpoint(ep1);
Endpoint ep2 = endpointManager.newEndpoint("http://endpoint2xx");
ep2.setAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR, "QA");
endpointManager.addEndpoint(ep2);
service.attachEndpoint(ep1);
service.attachEndpoint(ep2);
Endpoint[] endpoints = service.getAttachedEndpoints();
assertEquals(2, endpoints.length);
assertEquals("http://endpoint1xx", endpoints[0].getUrl());
assertEquals(0, endpoints[0].getAttributeKeys().length);
assertEquals("http://endpoint2xx", endpoints[1].getUrl());
assertEquals(1, endpoints[1].getAttributeKeys().length);
assertEquals("QA", endpoints[1].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
service.detachEndpoint(ep1.getId());
endpoints = service.getAttachedEndpoints();
assertEquals(1, endpoints.length);
assertEquals("http://endpoint2xx", endpoints[0].getUrl());
assertEquals(1, endpoints[0].getAttributeKeys().length);
assertEquals("QA", endpoints[0].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
// now update the endpoints in the service
service.setAttributes("endpoints_entry", new String[] {
"Dev:http://endpoint3",
"Production:http://endpoint4",
"QA:http://endpoint2xx",
});
serviceManager.updateService(service);
endpoints = service.getAttachedEndpoints();
assertEquals(3, endpoints.length);
assertEquals("http://endpoint3", endpoints[0].getUrl());
assertEquals(1, endpoints[0].getAttributeKeys().length);
assertEquals("Dev", endpoints[0].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
assertEquals("http://endpoint4", endpoints[1].getUrl());
assertEquals(1, endpoints[1].getAttributeKeys().length);
assertEquals("Production", endpoints[1].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
assertEquals("http://endpoint2xx", endpoints[2].getUrl());
assertEquals(1, endpoints[2].getAttributeKeys().length);
assertEquals("QA", endpoints[2].getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
Endpoint ep5 = endpointManager.getEndpointByUrl("http://endpoint2");
assertEquals("QA", ep5.getAttribute(CommonConstants.ENDPOINT_ENVIRONMENT_ATTR));
}