EasyMock.expect(dswContext.getService(httpSvcSR)).andReturn(httpService).anyTimes();
EasyMock.replay(dswContext);
final ServerFactoryBean sfb = createMockServerFactoryBean();
DistributionProviderImpl dp = new DistributionProviderImpl(dswContext);
Map<String, Object> handlerProps = new HashMap<String, Object>();
HttpServiceConfigurationTypeHandler h =
new HttpServiceConfigurationTypeHandler(dswContext, dp, handlerProps) {
@Override
ServerFactoryBean createServerFactoryBean() {
return sfb;
}
@Override
String[] applyIntents(BundleContext dswContext, BundleContext callingContext,
List<AbstractFeature> features, AbstractEndpointFactory factory,
ServiceEndpointDescription sd) {
return new String [] {"a.b.c"};
}
};
h.httpServiceReferences.add(httpSvcSR);
Runnable myService = new Runnable() {
public void run() {
System.out.println("blah");
}
};
ServiceReference sr = EasyMock.createNiceMock(ServiceReference.class);
BundleContext callingContext = EasyMock.createNiceMock(BundleContext.class);
EasyMock.replay(sr);
EasyMock.replay(callingContext);
Map<String, Object> props = new HashMap<String, Object>();
props.put(Constants.POJO_HTTP_SERVICE_CONTEXT, "/myRunnable");
ServiceEndpointDescription sd = new ServiceEndpointDescriptionImpl(Runnable.class.getName(), props);
assertEquals("Precondition failed", 0, dp.getExposedServices().size());
assertEquals("Precondition failed", "", sfb.getAddress());
h.createServer(sr, dswContext, callingContext, sd, Runnable.class, myService);
assertEquals("The address should be set to '/'. The Servlet context dictates the actual location.", "/", sfb.getAddress());
assertEquals(1, dp.getExposedServices().size());
assertSame(sr, dp.getExposedServices().iterator().next());
String hostName = InetAddress.getLocalHost().getHostName();
Map<String, String> expected = new HashMap<String, String>();
expected.put("osgi.remote.configuration.type", "pojo");
expected.put("osgi.remote.configuration.pojo.address", "http://" + hostName + ":1327/myRunnable");
expected.put("osgi.deployment.intents", "a.b.c");
assertEquals(expected, dp.getExposedProperties(sr));
}