org.jboss.arquillian.core.spi.ServiceLoader类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(103)

本文整理了Java中org.jboss.arquillian.core.spi.ServiceLoader类的一些代码示例,展示了ServiceLoader类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServiceLoader类的具体详情如下:
包路径:org.jboss.arquillian.core.spi.ServiceLoader
类名称:ServiceLoader

ServiceLoader介绍

[英]ServiceLoader.

This is the mechanism that can be used to load services registered by LoadableExtension's. For example, to make a service available for dependency injection:

@Inject 
private Instance<ServiceLoader> serviceLoader; 
@Inject 
@ApplicationScoped 
private InstanceProducer<MyService> myService; 
public void provideMyService(@Observes ManagerStarted event) { 
MyService service = serviceLoader.get().onlyOne(MyService.class, MyDefaultService.class); 
myService.set(service); 
}

[中]ServiceLoader。
这是一种机制,可用于加载LoadableExtension注册的服务。例如,要使服务可用于依赖项注入:

@Inject 
private Instance<ServiceLoader> serviceLoader; 
@Inject 
@ApplicationScoped 
private InstanceProducer<MyService> myService; 
public void provideMyService(@Observes ManagerStarted event) { 
MyService service = serviceLoader.get().onlyOne(MyService.class, MyDefaultService.class); 
myService.set(service); 
}

代码示例

代码示例来源:origin: org.arquillian.reporter/arquillian-reporter-impl

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);
  }
}

代码示例来源:origin: org.arquillian.liferay/arquillian-processor-osgi-allin

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));
}

代码示例来源:origin: arquillian/arquillian-core

@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);
  }
}

代码示例来源:origin: arquillian/arquillian-core

@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);
}

代码示例来源:origin: org.jboss.arquillian.test/arquillian-test-impl-base

@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();
}

代码示例来源:origin: arquillian/arquillian-core

@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());
}

代码示例来源:origin: arquillian/arquillian-core

@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);
}

代码示例来源:origin: arquillian/arquillian-core

@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);
}

代码示例来源:origin: arquillian/arquillian-core

@Before
public void setup() throws Exception {
  Mockito.when(serviceLoader.onlyOne(Mockito.same(DeployableContainer.class))).thenReturn(deployableContainer);
  Mockito.when(deployableContainer.getConfigurationClass()).thenReturn(DummyContainerConfiguration.class);
}

代码示例来源:origin: arquillian/arquillian-core

@Before
public void addServiceLoader() {
  Mockito.when(serviceLoader.onlyOne(DeployableContainer.class)).thenReturn(deployableContainer);
  bind(ApplicationScoped.class, ServiceLoader.class, serviceLoader);
}

代码示例来源:origin: arquillian/arquillian-core

@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;
  }
}

代码示例来源:origin: org.jboss.arquillian.extension/arquillian-drone-webdriver

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);
    }
  }
}

代码示例来源:origin: org.jboss.arquillian.graphene/graphene-webdriver-impl

public void injectGrapheneRuntime(@Observes BeforeSuite event) {
  GrapheneRuntime runtime = serviceLoader.get().onlyOne(GrapheneRuntime.class);
  GrapheneRuntime.pushInstance(runtime);
}

代码示例来源:origin: org.jboss.arquillian.extension/arquillian-portal-impl-base

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;
  }
}

代码示例来源:origin: arquillian/arquillian-core

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;
  }
}

代码示例来源:origin: org.jboss.arquillian.extension/arquillian-drone-webdriver

private void initializePermanentStorage() {
  ReusedSessionPermanentStorage instance = serviceLoader.get().onlyOne(ReusedSessionPermanentStorage.class);
  permanentStorage.set(instance);
}

代码示例来源:origin: arquillian/arquillian-core

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;
}

代码示例来源:origin: org.jboss.arquillian.extension/arquillian-warp-impl

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);
  }
}

代码示例来源:origin: org.jboss.arquillian.extension/arquillian-warp-impl

public void enrichHttpResponse(@Observes EnrichHttpResponse event, ServiceLoader services) {
    HttpResponseEnricher responseEnricher = services.onlyOne(HttpResponseEnricher.class);
    responseEnricher.enrichResponse();
  }
}

代码示例来源:origin: org.jboss.arquillian.test/arquillian-test-impl-base

@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);
  }
}

相关文章