Search in sources :

Example 61 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class FrontendFunctionDescriptorTest method testServiceLoader.

@SuppressWarnings("rawtypes")
@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(UrlRewriteFunctionDescriptor.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof FrontendFunctionDescriptor) {
            return;
        }
    }
    fail("Failed to find " + FrontendFunctionDescriptor.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 62 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class Log4jMessageLoggerFactoryTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(MessageLoggerFactory.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof Log4jMessageLoggerFactory) {
            return;
        }
    }
    fail("Failed to find " + Log4jMessageLoggerFactory.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 63 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class Sl4jMessageLoggerFactoryTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(MessageLoggerFactory.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof Sl4jMessageLoggerFactory) {
            return;
        }
    }
    fail("Failed to find " + Sl4jMessageLoggerFactory.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 64 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class HtmlPostfixProcessorTest method testServiceLoader.

@SuppressWarnings("rawtypes")
@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(UrlRewriteFunctionProcessor.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof HtmlPostfixProcessor) {
            return;
        }
    }
    fail("Failed to find " + HtmlPostfixProcessor.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 65 with ServiceLoader

use of java.util.ServiceLoader in project knox by apache.

the class AnonymousAuthDeploymentContributorTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(ProviderDeploymentContributor.class);
    Iterator iterator = loader.iterator();
    assertThat("Service iterator empty.", iterator.hasNext());
    while (iterator.hasNext()) {
        Object object = iterator.next();
        if (object instanceof AnonymousAuthDeploymentContributor) {
            return;
        }
    }
    fail("Failed to find " + AnonymousAuthDeploymentContributor.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Aggregations

ServiceLoader (java.util.ServiceLoader)68 Iterator (java.util.Iterator)46 Test (org.junit.Test)46 HashMap (java.util.HashMap)6 ArrayList (java.util.ArrayList)5 List (java.util.List)4 NoSuchElementException (java.util.NoSuchElementException)3 Optional (java.util.Optional)3 ServiceConfigurationError (java.util.ServiceConfigurationError)3 ServletContext (javax.servlet.ServletContext)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 IOException (java.io.IOException)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CharsetProvider (java.nio.charset.spi.CharsetProvider)2 Map (java.util.Map)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2