Search in sources :

Example 6 with SLProperties

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"));
}
Also used : ClientLifeCycleManagerImpl(org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl) ServerLifeCycleManagerImpl(org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl) HashMap(java.util.HashMap) SLEndpoint(org.talend.esb.servicelocator.client.SLEndpoint) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) JaxWsServerFactoryBean(org.apache.cxf.jaxws.JaxWsServerFactoryBean) Bus(org.apache.cxf.Bus) QName(javax.xml.namespace.QName) Service(org.apache.cxf.service.Service) ServiceLocator(org.talend.esb.servicelocator.client.ServiceLocator) SLProperties(org.talend.esb.servicelocator.client.SLProperties) ServiceLocatorMock(org.talend.esb.servicelocator.cxf.internal.internal.ServiceLocatorMock) Test(org.junit.Test)

Aggregations

SLProperties (org.talend.esb.servicelocator.client.SLProperties)6 SLEndpoint (org.talend.esb.servicelocator.client.SLEndpoint)4 Test (org.junit.Test)3 DOMResult (javax.xml.transform.dom.DOMResult)2 W3CEndpointReferenceBuilder (javax.xml.ws.wsaddressing.W3CEndpointReferenceBuilder)2 ServiceLocatorException (org.talend.esb.servicelocator.client.ServiceLocatorException)2 EndpointTransformerImpl (org.talend.esb.servicelocator.client.internal.EndpointTransformerImpl)2 Document (org.w3c.dom.Document)2 HashMap (java.util.HashMap)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 QName (javax.xml.namespace.QName)1 Bus (org.apache.cxf.Bus)1 ClientLifeCycleManagerImpl (org.apache.cxf.bus.managers.ClientLifeCycleManagerImpl)1 ServerLifeCycleManagerImpl (org.apache.cxf.bus.managers.ServerLifeCycleManagerImpl)1 JaxWsServerFactoryBean (org.apache.cxf.jaxws.JaxWsServerFactoryBean)1 Service (org.apache.cxf.service.Service)1 EndpointInfo (org.apache.cxf.service.model.EndpointInfo)1 ServiceLocator (org.talend.esb.servicelocator.client.ServiceLocator)1 ServiceLocatorMock (org.talend.esb.servicelocator.cxf.internal.internal.ServiceLocatorMock)1 InterruptionFaultDetail (org.talend.schemas.esb.locator._2011._11.InterruptionFaultDetail)1