public void observeFirstEvent(@Observes(precedence = 100) ManagerStarted event) { if (report.get() == null) { ExecutionReport executionReport = new ExecutionReport(); report.set(executionReport); BuilderLoader.load(); Collection<StringKey> allStringKeys = serviceLoader.get().all(StringKey.class); allStringKeys.forEach(StringKeysBuilder::buildStringKey); } }
public void createInstanceProducer( @Observes ArquillianDescriptor arquillianDescriptor) { ServiceLoader serviceLoader = _serviceLoaderInstance.get(); _importPackageManagerInstanceProducer.set( serviceLoader.onlyOne(ImportPackageManager.class)); _manifestManagerInstanceProducer.set( serviceLoader.onlyOne(ManifestManager.class)); _bundleActivatorsManagerInstanceProducer.set( serviceLoader.onlyOne(BundleActivatorsManager.class)); }
@Test public void shouldCallAllEnrichers() throws Exception { Mockito.when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(enricher, enricher)); bind(SuiteScoped.class, ServiceLoader.class, serviceLoader); fire(new Before(this, getClass().getMethod("shouldCallAllEnrichers"))); Mockito.verify(enricher, Mockito.times(2)).enrich(this); assertEventFired(BeforeEnrichment.class, 1); assertEventFired(AfterEnrichment.class, 1); } }
@Before public void setup() { when(deployableContainer.getConfigurationClass()).thenReturn(DummyContainerConfiguration.class); when(serviceLoader.onlyOne(eq(DeployableContainer.class))).thenReturn(deployableContainer); when(container1.getContainerName()).thenReturn(CONTAINER_1_NAME); when(container2.getContainerName()).thenReturn(CONTAINER_2_NAME); when(container3.getContainerName()).thenReturn(CONTAINER_3_NAME); when(container4.getContainerName()).thenReturn(CONTAINER_4_NAME); when(container5.getContainerName()).thenReturn(CONTAINER_5_NAME); when(container1.getMode()).thenReturn("suite"); when(container2.getMode()).thenReturn("suite"); when(container3.getMode()).thenReturn("class"); when(container4.getMode()).thenReturn("class"); when(container5.getMode()).thenReturn("custom"); registry = new LocalContainerRegistry(injector.get()); bind(ApplicationScoped.class, ContainerRegistry.class, registry); }
@Before public void addServiceLoaderAndLogCapturer() throws Exception { resourceProviders.add(resourceProvider); Mockito.when(serviceLoader.all(ResourceProvider.class)).thenReturn(resourceProviders); Mockito.when(resourceProvider.canProvide(Object.class)).thenReturn(true); bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader); attachLogCapturer(); }
@Test // ARQ-971 @SuppressWarnings("unchecked") public void shouldFilterNullAuxiliaryArchiveAppenderResulsts() throws Exception { when(serviceLoader.all(eq(AuxiliaryArchiveAppender.class))) .thenReturn( create(AuxiliaryArchiveAppender.class, injectorInst.get().inject(new NullAuxiliaryArchiveAppender()))); addContainer(CONTAINER_NAME_1); addProtocol(PROTOCOL_NAME_1, true); fire(createEvent(DeploymentWithDefaults.class)); CallMap spi = getManager().resolve(CallMap.class); Assert.assertTrue(spi.wasCalled(AuxiliaryArchiveAppender.class)); DeploymentScenario scenario = getManager().resolve(DeploymentScenario.class); Assert.assertEquals(1, scenario.deployments().size()); ArgumentCaptor<TestDeployment> captor = ArgumentCaptor.forClass(TestDeployment.class); verify(packager).generateDeployment(captor.capture(), Mockito.any(Collection.class)); Assert.assertEquals(0, captor.getValue().getAuxiliaryArchives().size()); }
@Override protected void beforeStartManager(Manager manager) { final ServiceLoader serviceLoader = Mockito.mock(ServiceLoader.class); startContexts(manager); final ConfigurationPlaceholderResolver configurationSysPropResolver = new SystemPropertiesConfigurationPlaceholderResolver(); final ConfigurationPlaceholderResolver classpathConfigurationPlaceholderResolver = new ClasspathConfigurationPlaceholderResolver(); Mockito.when(serviceLoader.all(ConfigurationPlaceholderResolver.class)) .thenReturn(Arrays.asList(classpathConfigurationPlaceholderResolver, configurationSysPropResolver)); bind(SuiteScoped.class, ServiceLoader.class, serviceLoader); }
@Before public void addServiceLoader() throws Exception { resourceProvider = getResourceProvider(); injector.get().inject(resourceProvider); List<ResourceProvider> resourceProviders = Arrays.asList(resourceProvider); Mockito.when(serviceLoader.all(ResourceProvider.class)).thenReturn(resourceProviders); 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); }
@Before public void addServiceLoader() { Mockito.when(serviceLoader.onlyOne(DeployableContainer.class)).thenReturn(deployableContainer); bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader); }
@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; } }
private void registerBrowserCapabilities() { List<BrowserCapabilities> list = new ArrayList<BrowserCapabilities>(serviceLoader.get().all(BrowserCapabilities.class)); Collections.sort(list, SORTABLE_COMPARATOR); for (BrowserCapabilities browser : list) { final String browserReadableName = browser.getReadableName(); final String browserName = browserReadableName != null ? browserReadableName.toLowerCase() : null; browserCapabilitiesRegistry.get().registerBrowserCapabilitiesFor(browserName, browser); } } }
public void deployPortal(@Observes AfterStart afterStartEvent) throws DeploymentException { Collection<PortletContainerDeploymentProvider> providers = loader.get().all(PortletContainerDeploymentProvider.class); for (PortletContainerDeploymentProvider provider : providers) { Archive<?> tmp = provider.build(); deployments.add(tmp); afterStartEvent.getDeployableContainer().deploy(tmp); tmp = null; } }
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 List<ConfigurationPlaceholderResolver> loadAndOrderPlaceholderResolvers() { final List<ConfigurationPlaceholderResolver> configurationPlaceholderResolvers = new ArrayList<ConfigurationPlaceholderResolver>(serviceLoaderInstance.get().all(ConfigurationPlaceholderResolver.class)); Collections.sort(configurationPlaceholderResolvers, new Comparator<ConfigurationPlaceholderResolver>() { public int compare(ConfigurationPlaceholderResolver firstResolver, ConfigurationPlaceholderResolver secondResolver) { Integer a = firstResolver.precedence(); Integer b = secondResolver.precedence(); return b.compareTo(a); } }); return configurationPlaceholderResolvers; }
public void processHttpRequest(@Observes ProcessHttpRequest event, ServiceLoader services, HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws IOException, ServletException { // setup responsePayload with temporary serialId before requestPayload is de-serialized responsePayload.set(new ResponsePayload(RequestPayload.FAILURE_SERIAL_ID)); HttpRequestDeenricher requestDeenricher = services.onlyOne(HttpRequestDeenricher.class); if (requestDeenricher.isEnriched()) { RequestPayload p = requestDeenricher.resolvePayload(); long serialId = p.getSerialId(); responsePayload.set(new ResponsePayload(serialId)); response.setHeader(WarpCommons.ENRICHMENT_RESPONSE, Long.toString(serialId)); requestPayload.set(p); processWarpRequest.fire(new ProcessWarpRequest()); } else { filterChain.doFilter(request, response); } }
@Test public void shouldCallAllEnrichers() throws Exception { Mockito.when(serviceLoader.all(TestEnricher.class)).thenReturn(Arrays.asList(enricher, enricher)); bind(SuiteScoped.class, ServiceLoader.class, serviceLoader); fire(new Before(this, getClass().getMethod("shouldCallAllEnrichers"))); Mockito.verify(enricher, Mockito.times(2)).enrich(this); assertEventFired(BeforeEnrichment.class, 1); assertEventFired(AfterEnrichment.class, 1); } }