Search in sources :

Example 66 with ServiceLoader

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

the class ShiroDeploymentContributorTest 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 ShiroDeploymentContributor) {
            return;
        }
    }
    fail("Failed to find " + ShiroDeploymentContributor.class.getName() + " via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 67 with ServiceLoader

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

the class UsernameFunctionProcessorTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(UrlRewriteFunctionProcessor.class);
    for (Object object : loader) {
        if (object instanceof UsernameFunctionProcessor) {
            return;
        }
    }
    fail("Failed to find UsernameFunctionProcessor via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) UsernameFunctionProcessor(org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionProcessor) Test(org.junit.Test)

Example 68 with ServiceLoader

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

the class UsernameFunctionDescriptorTest method testServiceLoader.

@Test
public void testServiceLoader() throws Exception {
    ServiceLoader loader = ServiceLoader.load(UrlRewriteFunctionDescriptor.class);
    for (Object object : loader) {
        if (object instanceof UsernameFunctionDescriptor) {
            return;
        }
    }
    fail("Failed to find UsernameFunctionDescriptor via service loader.");
}
Also used : ServiceLoader(java.util.ServiceLoader) UsernameFunctionDescriptor(org.apache.knox.gateway.identityasserter.common.function.UsernameFunctionDescriptor) 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