use of org.talend.esb.servicelocator.client.SLProperties in project tesb-rt-se by Talend.
the class LocatorFeatureTest method initializeServer.
@Test
public void initializeServer() throws EndpointException {
LocatorClientEnabler enabler = new LocatorClientEnabler();
enabler.setLocatorSelectionStrategyMap(locatorSelectionStrategyMap);
enabler.setDefaultLocatorSelectionStrategy("evenDistributionSelectionStrategy");
ClientLifeCycleManager clcm = new ClientLifeCycleManagerImpl();
expect(busMock.getExtension(ClientLifeCycleManager.class)).andStubReturn(clcm);
ServerLifeCycleManager slcm = new ServerLifeCycleManagerImpl();
expect(busMock.getExtension(ServerLifeCycleManager.class)).andStubReturn(slcm);
replayAll();
Map<String, String> locatorProps = new HashMap<String, String>();
locatorProps.put("key1", "value1");
locatorProps.put("key2", "value2");
JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();
factory.setServiceName(SERVICE_NAME);
factory.setEndpointName(new QName(SERVICE_NS, "HelloWorldImplServiceInstance1"));
factory.setServiceClass(HelloWorld.class);
factory.setAddress("som.address/service");
Server srv = factory.create();
srv.getEndpoint().put(LocatorFeature.LOCATOR_PROPERTIES, locatorProps);
srv.getEndpoint().put(LocatorFeature.KEY_STRATEGY, "randomSelectionStrategy");
LocatorRegistrar registrar = new LocatorRegistrar();
ServiceLocator serviceLocator = new ServiceLocatorMock();
registrar.setServiceLocator(serviceLocator);
Bus bus = BusFactory.newInstance().createBus();
EndpointInfo ei = new EndpointInfo();
Service service = new org.apache.cxf.service.ServiceImpl();
EndpointImpl endpoint = new EndpointImpl(busMock, service, ei);
LocatorTargetSelector selector = new LocatorTargetSelector();
selector.setEndpoint(endpoint);
LocatorFeatureImpl lf = new LocatorFeatureImpl();
lf.setLocatorRegistrar(registrar);
lf.setClientEnabler(enabler);
lf.initialize(srv, bus);
SLEndpoint slEp = null;
try {
slEp = serviceLocator.getEndpoint(SERVICE_NAME, "HelloWorldImplServiceInstance1");
} catch (Throwable t) {
t.printStackTrace();
Assert.fail(t.getMessage());
}
Assert.assertNotNull(slEp);
SLProperties slProps = slEp.getProperties();
Assert.assertNotNull(slProps);
Assert.assertTrue(slProps.getPropertyNames().contains("key1"));
Assert.assertTrue(slProps.getPropertyNames().contains("key2"));
}
Aggregations