Search in sources :

Example 1 with MyService

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;
    }
}
Also used : CamelContext(org.apache.camel.CamelContext) LanguageResolver(org.apache.camel.spi.LanguageResolver) SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage) Language(org.apache.camel.spi.Language) MyService(org.apache.camel.core.osgi.test.MyService) FileComponent(org.apache.camel.component.file.FileComponent) ComponentResolver(org.apache.camel.spi.ComponentResolver) SimpleLanguage(org.apache.camel.language.simple.SimpleLanguage)

Example 2 with MyService

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();
}
Also used : MyService(org.apache.camel.core.osgi.test.MyService) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) Test(org.junit.Test)

Aggregations

MyService (org.apache.camel.core.osgi.test.MyService)2 CamelContext (org.apache.camel.CamelContext)1 FileComponent (org.apache.camel.component.file.FileComponent)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 SimpleLanguage (org.apache.camel.language.simple.SimpleLanguage)1 ComponentResolver (org.apache.camel.spi.ComponentResolver)1 Language (org.apache.camel.spi.Language)1 LanguageResolver (org.apache.camel.spi.LanguageResolver)1 Test (org.junit.Test)1