use of org.apache.camel.core.osgi.test.MyService in project camel by apache.
the class CamelMockBundleContext method getService.
public Object getService(@SuppressWarnings("rawtypes") ServiceReference reference) {
String[] classNames = (String[]) reference.getProperty(Constants.OBJECTCLASS);
String classNames0 = classNames != null ? classNames[0] : null;
String pid = (String) reference.getProperty(Constants.SERVICE_PID);
if (classNames0 != null && classNames0.equals("org.apache.camel.core.osgi.test.MyService")) {
return new MyService();
} else if (pid != null && pid.equals(SERVICE_PID_PREFIX + "org.apache.camel.core.osgi.test.MyService")) {
return new MyService();
} else if (classNames0 != null && classNames0.equals(ComponentResolver.class.getName())) {
return new ComponentResolver() {
public Component resolveComponent(String name, CamelContext context) throws Exception {
if (name.equals("file_test")) {
return new FileComponent();
}
return null;
}
};
} else if (classNames0 != null && classNames0.equals(LanguageResolver.class.getName())) {
return new LanguageResolver() {
public Language resolveLanguage(String name, CamelContext context) {
if (name.equals("simple")) {
return new SimpleLanguage();
}
return null;
}
};
} else {
return null;
}
}
use of org.apache.camel.core.osgi.test.MyService in project camel by apache.
the class ServiceRegistryTest method camelContextFactoryServiceRegistryTest.
@Test
public void camelContextFactoryServiceRegistryTest() throws Exception {
DefaultCamelContext context = new OsgiDefaultCamelContext(getBundleContext());
context.start();
MyService myService = context.getRegistry().lookupByNameAndType(MyService.class.getName(), MyService.class);
assertNotNull("MyService should not be null", myService);
myService = context.getRegistry().lookupByNameAndType("test", MyService.class);
assertNull("We should not get the MyService Object here", myService);
Object service = context.getRegistry().lookupByName(MyService.class.getName());
assertNotNull("MyService should not be null", service);
assertTrue("It should be the instance of MyService ", service instanceof MyService);
Object serviceByPid = context.getRegistry().lookupByName(CamelMockBundleContext.SERVICE_PID_PREFIX + MyService.class.getName());
assertNotNull("MyService should not be null", serviceByPid);
assertTrue("It should be the instance of MyService ", serviceByPid instanceof MyService);
Map<String, MyService> collection = context.getRegistry().findByTypeWithName(MyService.class);
assertNotNull("MyService should not be null", collection);
assertNotNull("There should have one MyService.", collection.get(MyService.class.getName()));
Set<MyService> collection2 = context.getRegistry().findByType(MyService.class);
assertNotNull("MyService should not be null", collection2);
assertEquals(1, collection2.size());
context.stop();
}
Aggregations