Search in sources :

Example 1 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver in project camel by apache.

the class AnnotationModuleLoaderTest method testLoadModels.

@Test
public void testLoadModels() throws Exception {
    AnnotationModelLoader loader = new AnnotationModelLoader(new DefaultPackageScanClassResolver());
    Set<Class<?>> classes = loader.loadModels("org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink");
    assertNotNull("The findForFormattingOptions classes should not be null ", classes);
    assertEquals("There should have 3 classes", 3, classes.size());
    assertTrue(classes.contains(Client.class));
    assertTrue(classes.contains(Order.class));
    assertTrue(classes.contains(Security.class));
}
Also used : Order(org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Order) DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver) Client(org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Client) Security(org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Security) Test(org.junit.Test)

Example 2 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver in project camel by apache.

the class DefaultPackageResolverConfigureTest method testSetAcceptableSchema.

public void testSetAcceptableSchema() throws Exception {
    DefaultPackageScanClassResolver resolver = (DefaultPackageScanClassResolver) context.getPackageScanClassResolver();
    assertNotNull(resolver);
    // just check the accept schema
    assertTrue("We should accept the test:!", resolver.isAcceptableScheme("test://test"));
    assertTrue("We should accept the test2:!", resolver.isAcceptableScheme("test2://test"));
}
Also used : DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver)

Example 3 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver in project camel by apache.

the class DefaultPackageScanClassResolverTest method setUp.

public void setUp() throws Exception {
    super.setUp();
    resolver = new DefaultPackageScanClassResolver();
    annotations.add(org.apache.camel.spring.scan.ScannableOne.class);
    annotations.add(org.apache.camel.spring.scan.ScannableTwo.class);
}
Also used : DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver)

Example 4 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver in project camel by apache.

the class DefaultPackageScanClassResolverTest method testFindByFilterPackageInJarUrl.

public void testFindByFilterPackageInJarUrl() throws Exception {
    ClassLoader savedClassLoader = null;
    try {
        savedClassLoader = Thread.currentThread().getContextClassLoader();
        URL url = getClass().getResource("/package_scan_test.jar");
        URL[] urls = { new URL("jar:" + url.toString() + "!/") };
        URLClassLoader classLoader = new URLClassLoader(urls, savedClassLoader);
        Thread.currentThread().setContextClassLoader(classLoader);
        // recreate resolver since we mess with context class loader
        resolver = new DefaultPackageScanClassResolver();
        filter.addIncludePattern("a.*.c.*");
        resolver.addFilter(filter);
        Set<Class<?>> scanned = resolver.findByFilter(filter, "a.b.c");
        assertEquals(1, scanned.size());
        assertEquals("class a.b.c.Test", scanned.iterator().next().toString());
    } finally {
        if (savedClassLoader != null) {
            Thread.currentThread().setContextClassLoader(savedClassLoader);
        }
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver) URL(java.net.URL)

Example 5 with DefaultPackageScanClassResolver

use of org.apache.camel.impl.DefaultPackageScanClassResolver in project camel by apache.

the class DefaultPackageScanClassResolverTest method testFindByFilterPackageInJarUrlWithPlusChars.

public void testFindByFilterPackageInJarUrlWithPlusChars() throws Exception {
    ClassLoader savedClassLoader = null;
    try {
        savedClassLoader = Thread.currentThread().getContextClassLoader();
        URL url = getClass().getResource("/package+scan+test.jar");
        URL[] urls = { new URL("jar:" + url.toString() + "!/") };
        URLClassLoader classLoader = new URLClassLoader(urls, savedClassLoader);
        Thread.currentThread().setContextClassLoader(classLoader);
        // recreate resolver since we mess with context class loader
        resolver = new DefaultPackageScanClassResolver();
        filter.addIncludePattern("a.*.c.*");
        resolver.addFilter(filter);
        Set<Class<?>> scanned = resolver.findByFilter(filter, "a.b.c");
        assertEquals(1, scanned.size());
        assertEquals("class a.b.c.Test", scanned.iterator().next().toString());
    } finally {
        if (savedClassLoader != null) {
            Thread.currentThread().setContextClassLoader(savedClassLoader);
        }
    }
}
Also used : URLClassLoader(java.net.URLClassLoader) URLClassLoader(java.net.URLClassLoader) DefaultPackageScanClassResolver(org.apache.camel.impl.DefaultPackageScanClassResolver) URL(java.net.URL)

Aggregations

DefaultPackageScanClassResolver (org.apache.camel.impl.DefaultPackageScanClassResolver)8 URL (java.net.URL)2 URLClassLoader (java.net.URLClassLoader)2 DefaultTypeConverter (org.apache.camel.impl.converter.DefaultTypeConverter)2 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 NoTypeConversionAvailableException (org.apache.camel.NoTypeConversionAvailableException)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 Client (org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Client)1 Order (org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Order)1 Security (org.apache.camel.dataformat.bindy.model.complex.twoclassesandonelink.Security)1 DefaultClassResolver (org.apache.camel.impl.DefaultClassResolver)1 DefaultFactoryFinderResolver (org.apache.camel.impl.DefaultFactoryFinderResolver)1 PackageScanClassResolver (org.apache.camel.spi.PackageScanClassResolver)1 TypeConverterLoader (org.apache.camel.spi.TypeConverterLoader)1 ReflectionInjector (org.apache.camel.util.ReflectionInjector)1 Before (org.junit.Before)1 Test (org.junit.Test)1 ServiceReference (org.osgi.framework.ServiceReference)1