protected CommandService getCommandService() { ServiceLoader loader = serviceLoader.get(); if (loader == null) { throw new IllegalStateException("No " + ServiceLoader.class.getName() + " found in context"); } CommandService service = loader.onlyOne(CommandService.class); if (service == null) { throw new IllegalStateException("No " + CommandService.class.getName() + " found in context"); } return service; } }
private CommandService getCommandService() { ServiceLoader loader = serviceLoader.get(); if (loader == null) { throw new IllegalStateException("No " + ServiceLoader.class.getName() + " found in context"); } CommandService service = loader.onlyOne(CommandService.class); if (service == null) { throw new IllegalStateException("No " + CommandService.class.getName() + " found in context"); } return service; } }
private CommandService getCommandService() { ServiceLoader loader = serviceLoader.get(); if (loader == null) { throw new IllegalStateException("No " + ServiceLoader.class.getName() + " found in context"); } CommandService service = loader.onlyOne(CommandService.class); if (service == null) { throw new IllegalStateException("No " + CommandService.class.getName() + " found in context"); } return service; } }
protected CommandService getCommandService() { ServiceLoader loader = serviceLoader.get(); if (loader == null) { throw new IllegalStateException("No " + ServiceLoader.class.getName() + " found in context"); } CommandService service = loader.onlyOne(CommandService.class); if (service == null) { throw new IllegalStateException("No " + CommandService.class.getName() + " found in context"); } return service; } }
/** * @param dataSourceName * @return * @throws IllegalStateException when more than one data source provider exists on the classpath */ private DataSource loadDataSource(String dataSourceName) { final DataSourceProvider dataSourceProvider = serviceLoaderInstance.get() .onlyOne(DataSourceProvider.class, JndiDataSourceProvider.class); return dataSourceProvider.lookupDataSource(dataSourceName); } }
@Override public <X> X onlyOne(Class<X> serviceClass) { if (serviceClass == DeployableContainer.class) { return serviceClass.cast(injectorInst.get().inject( new ServerGroupContainer(managementClient, archiveDeployer, domain, serverGroup, operationTimeout))); } return serviceLoaderInstance.get().onlyOne(serviceClass); }
@Before public void addServiceLoader() { Mockito.when(serviceLoader.onlyOne(DeployableContainer.class)).thenReturn(deployableContainer); bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader); }
@Before public void setup() throws Exception { Mockito.when(serviceLoader.onlyOne(Mockito.same(DeployableContainer.class))).thenReturn(deployableContainer); Mockito.when(deployableContainer.getConfigurationClass()).thenReturn(DummyContainerConfiguration.class); }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionIfMultipleDeployableContainersFoundOnClassapth() { Mockito.when(serviceLoader.onlyOne(DeployableContainer.class)) .thenThrow(new IllegalStateException("Multiple service implementations found for ...")); try { fire(Descriptors.create(ArquillianDescriptor.class)); } catch (IllegalStateException e) { Assert.assertTrue(e.getMessage().startsWith("Could not add a default container")); throw e; } }
@Override public boolean isTransactionSupported(TestEvent testEvent) { final TransactionProvider transactionProvider = serviceLoaderInstance.get().onlyOne(TransactionProvider.class); if (transactionProvider == null) { return false; } return new ModeChecker(deploymentInstance.get(), containerInstance.get()).isClientMode(testEvent); } }
public void install(@Observes(precedence = 100) CubeDockerConfiguration configuration) { StandaloneManager installer = serviceLoaderInst.get().onlyOne(StandaloneManager.class); if (installer != null) { DockerCompositions cubes = configuration.getDockerContainersContent(); final StandaloneContainer install = installer.install(); final CubeContainer cube = install.getCube(); cubes.add(install.getName(), cube); standaloneContainerInst.set(install); System.out.println("STANDALONE CONTAINER INSTALLED"); System.out.println(ConfigUtil.dump(cubes)); } }
/** * Sets {@link ActivityManagerProvider} for {@code AndroidDevice} and produces {@link AndroidApplicationManager}. * * @param event */ public void onAndroidDeviceReady(@Observes AndroidDeviceReady event) { ActivityManager activityManager = serviceLoader.get().onlyOne(ActivityManager.class, DefaultActivityManager.class); if (activityManager instanceof DefaultActivityManager) { androidDevice.get().setActivityManager(new DefaultActivityManager(androidDevice.get())); } }
@Test public void shouldBeAbleToLoadDefaultIfNoneFound() throws Exception { ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); Assert.assertNull(registry.getServiceLoader().onlyOne(FakeService.class)); FakeService service = registry.getServiceLoader().onlyOne(FakeService.class, ShouldBeIncluded.class); Assert.assertNotNull(service); Assert.assertTrue( "Verify service is of expected type", service instanceof ShouldBeIncluded); }
@Test public void shouldBeAbleToLoadDefaultIfNoneFound() throws Exception { ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); Assert.assertNull(registry.getServiceLoader().onlyOne(FakeService.class)); FakeService service = registry.getServiceLoader().onlyOne(FakeService.class, ShouldBeIncluded.class); Assert.assertNotNull(service); Assert.assertTrue( "Verify service is of expected type", service instanceof ShouldBeIncluded); }
@SuppressWarnings("unchecked") @Test public void shouldBeAbleToLoadProtectedServices() throws Exception { ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); registry.addService( FakeService.class, (Class<FakeService>) Class.forName("org.jboss.arquillian.core.impl.loadable.util.PackageProtectedService")); FakeService service = registry.getServiceLoader().onlyOne(FakeService.class); Assert.assertNotNull("Could load package protected service", service); } }
@Test public void loadedDefaultServicesShouldBeStaticallyInjected() throws Exception { bind(ApplicationScoped.class, String.class, "TEST"); ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); Assert.assertNull(registry.getServiceLoader().onlyOne(FakeService.class)); FakeService service = registry.getServiceLoader().onlyOne(FakeService.class, ShouldBeIncluded.class); Assert.assertTrue( "Verify service has been statically injected", service.isValid()); }
@Test(expected = IllegalStateException.class) public void shouldThrowExceptionIfMultipleFoundWhenTryingOnlyOne() throws Exception { ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); registry.addService(FakeService.class, ShouldBeIncluded.class); registry.addService(FakeService.class, ShouldBeExcluded.class); // throws exception registry.getServiceLoader().onlyOne(FakeService.class); }
@Test public void shouldBeAbleToLoadOnlyOne() throws Exception { ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); registry.addService(FakeService.class, ShouldBeIncluded.class); FakeService service = registry.getServiceLoader().onlyOne(FakeService.class); Assert.assertNotNull(service); Assert.assertTrue( "Verify service is of expected type", service instanceof ShouldBeIncluded); }
@Test public void shouldBeAbleToLoadOnlyOne() throws Exception { ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); registry.addService(FakeService.class, ShouldBeIncluded.class); FakeService service = registry.getServiceLoader().onlyOne(FakeService.class); Assert.assertNotNull(service); Assert.assertTrue( "Verify service is of expected type", service instanceof ShouldBeIncluded); }
@Test public void loadedServicesShouldBeStaticallyInjected() throws Exception { bind(ApplicationScoped.class, String.class, "TEST"); ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>()); registry.addService(FakeService.class, ShouldBeIncluded.class); FakeService service = registry.getServiceLoader().onlyOne(FakeService.class); Assert.assertTrue( "Verify service has been statically injected", service.isValid()); }