本文整理了Java中org.jboss.arquillian.core.spi.ServiceLoader.all()
方法的一些代码示例,展示了ServiceLoader.all()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ServiceLoader.all()
方法的具体详情如下:
包路径:org.jboss.arquillian.core.spi.ServiceLoader
类名称:ServiceLoader
方法名:all
[英]Load multiple service implementations.
[中]加载多个服务实现。
代码示例来源: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-transaction-impl-base
/**
* Finds custom implementations of {@link TransactionEnabler} SPI
* including the default one which will be first on the list.
*/
public List<TransactionEnabler> getTransactionEnablers() {
List<TransactionEnabler> transactionEnablers = new ArrayList<TransactionEnabler>();
transactionEnablers.add(new AnnotationBasedTransactionEnabler());
transactionEnablers.addAll(serviceLoader.all(TransactionEnabler.class));
return transactionEnablers;
}
}
代码示例来源:origin: org.jboss.as/jboss-as-arquillian-common-domain
@Override
public <X> Collection<X> all(Class<X> serviceClass) {
return serviceLoaderInstance.get().all(serviceClass);
}
});
代码示例来源:origin: arquillian/arquillian-core
private List<Archive<?>> loadAuxiliaryArchives(DeploymentDescription deployment) {
List<Archive<?>> archives = new ArrayList<Archive<?>>();
// load based on the Containers ClassLoader
Collection<AuxiliaryArchiveAppender> archiveAppenders = serviceLoader.get().all(AuxiliaryArchiveAppender.class);
for (AuxiliaryArchiveAppender archiveAppender : archiveAppenders) {
Archive<?> auxiliaryArchive = archiveAppender.createAuxiliaryArchive();
if (auxiliaryArchive != null) {
archives.add(auxiliaryArchive);
}
}
return archives;
}
代码示例来源:origin: org.jboss.arquillian.extension/arquillian-drone-impl
public void registerInstantiators() {
@SuppressWarnings("rawtypes")
List<Instantiator> list = new ArrayList<Instantiator>(serviceLoader.get().all(Instantiator.class));
Collections.sort(list, PrecedenceComparator.getReversedOrder());
for (Instantiator<?, ?> instantiator : list) {
Class<?> type = getFirstGenericParameterType(instantiator.getClass(), Instantiator.class);
if (type != null) {
droneRegistry.get().registerInstantiatorFor(type, instantiator);
}
}
}
代码示例来源:origin: arquillian/arquillian-core
@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
@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: org.jboss.arquillian.junit/arquillian-junit-core
public void enrichInstances(List<Object> toEnrich) {
Collection<TestEnricher> testEnrichers = serviceLoader.get().all(TestEnricher.class);
for (Object instance : toEnrich) {
enrichmentEvent.fire(new BeforeEnrichment(instance));
for (TestEnricher enricher : testEnrichers) {
enricher.enrich(instance);
}
enrichmentEvent.fire(new AfterEnrichment(instance));
}
}
代码示例来源:origin: arquillian/arquillian-core
public void enrichInstances(List<Object> toEnrich) {
Collection<TestEnricher> testEnrichers = serviceLoader.get().all(TestEnricher.class);
for (Object instance : toEnrich) {
enrichmentEvent.fire(new BeforeEnrichment(instance));
for (TestEnricher enricher : testEnrichers) {
enricher.enrich(instance);
}
enrichmentEvent.fire(new AfterEnrichment(instance));
}
}
代码示例来源: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
@Test
public void shouldTransformException() throws Exception {
TestExceptionDeployThrower.shouldThrow = new IllegalStateException();
Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class))
.thenReturn(Collections.singletonList(transformer));
Mockito.when(transformer.transform(TestExceptionDeployThrower.shouldThrow))
.thenReturn(new IllegalArgumentException());
fire(new DeployDeployment(
container,
new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class))
.setExpectedException(IllegalArgumentException.class))));
}
代码示例来源:origin: arquillian/arquillian-core
@Before
public void injectConfigurationRegistrar() {
ConfigurationPlaceholderResolver configurationSysPropResolver = new SystemPropertiesConfigurationPlaceholderResolver();
Mockito.when(serviceLoader.all(ConfigurationPlaceholderResolver.class))
.thenReturn(Arrays.asList(configurationSysPropResolver));
bind(SuiteScoped.class, ServiceLoader.class, serviceLoader);
registrar = injectorInst.get().inject(new ConfigurationRegistrar());
}
代码示例来源:origin: arquillian/arquillian-core
@Test
public void shouldBeAbleToLoadAllEvenIfNonRegistered() throws Exception {
ServiceRegistry registry = new ServiceRegistry(injector.get(), new LinkedHashMap<Class<?>, Set<Class<?>>>());
Collection<FakeService> services = registry.getServiceLoader().all(FakeService.class);
Assert.assertNotNull(services);
Assert.assertEquals(
"Verify no services were loaded",
0, services.size());
}
代码示例来源:origin: arquillian/arquillian-core
@Test
@SuppressWarnings("rawtypes")
public void shouldSetDefaultDefinedProtocolAsDefault() {
String protocolName = "default-protocol";
when(protocol.getDescription()).thenReturn(new ProtocolDescription(protocolName));
when(serviceLoader.all(Protocol.class)).thenReturn(Collections.singletonList((Protocol) protocol));
fire(createDescriptor(protocolName));
ProtocolDefinition protocol = verifyRegistryProtocol(protocolName);
Assert.assertTrue(protocol.isDefaultProtocol());
}
代码示例来源:origin: arquillian/arquillian-core
@Test
@SuppressWarnings("rawtypes")
public void shouldBindFoundProtocolsToRegistry() throws Exception {
String protocolName = "protocol";
when(protocol.getDescription()).thenReturn(new ProtocolDescription(protocolName));
when(serviceLoader.all(Protocol.class)).thenReturn(Collections.singletonList((Protocol) protocol));
fire(createDescriptor());
ProtocolDefinition protocol = verifyRegistryProtocol(protocolName);
Assert.assertFalse(protocol.isDefaultProtocol());
}
代码示例来源:origin: arquillian/arquillian-core
@Test
public void shouldSwallawExceptionIfExpectedAndDeploymentExceptionIsFieldOfThrownAndCauseOfOther() throws Exception {
IllegalArgumentException recursiveException = new IllegalArgumentException(new MyDeploymentException(
"My special exception", new NullPointerException()));
TestExceptionDeployThrower.shouldThrow = recursiveException;
Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class))
.thenReturn(Collections.singletonList(transformer));
Mockito.when(transformer.transform(TestExceptionDeployThrower.shouldThrow)).thenReturn(
((MyDeploymentException) recursiveException.getCause()).getDeploymentException());
fire(new DeployDeployment(container, new Deployment(new DeploymentDescription("test",
ShrinkWrap.create(JavaArchive.class)).setExpectedException(NullPointerException.class))));
}
代码示例来源:origin: arquillian/arquillian-core
@Test
public void shouldSwallawExceptionIfExpectedAndDeploymentExceptionIsFieldOfThrown() throws Exception {
MyDeploymentException myException = new MyDeploymentException("My special exception", new NullPointerException());
TestExceptionDeployThrower.shouldThrow = myException;
Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class))
.thenReturn(Collections.singletonList(transformer));
Mockito.when(transformer.transform(TestExceptionDeployThrower.shouldThrow)).thenReturn(
myException.getDeploymentException());
fire(new DeployDeployment(container, new Deployment(new DeploymentDescription("test",
ShrinkWrap.create(JavaArchive.class)).setExpectedException(NullPointerException.class))));
}
代码示例来源:origin: arquillian/arquillian-core
@Test(expected = DeploymentException.class)
public void shouldRethrowExceptionIfWrongExpectedType() throws Exception {
TestExceptionDeployThrower.shouldThrow =
new DeploymentException("Could not handle ba", new NullPointerException());
Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class))
.thenReturn(Collections.singletonList(transformer));
fire(new DeployDeployment(
container,
new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class))
.setExpectedException(IllegalArgumentException.class))));
}
代码示例来源:origin: arquillian/arquillian-core
@Test
public void shouldCallDeploymentTransformersWithEmptyCauseException() throws Exception {
TestExceptionDeployThrower.shouldThrow =
new DeploymentException("Could not handle ba", null);
Mockito.when(serviceLoader.all(DeploymentExceptionTransformer.class))
.thenReturn(Collections.singletonList(transformer));
fire(new DeployDeployment(
container,
new Deployment(new DeploymentDescription("test", ShrinkWrap.create(JavaArchive.class))
.setExpectedException(DeploymentException.class))));
Mockito.verify(transformer, Mockito.times(1)).transform(TestExceptionDeployThrower.shouldThrow);
}
代码示例来源:origin: arquillian/arquillian-core
public void enrich(@Observes Before event) throws Exception {
Object instance = event.getTestInstance();
Method method = event.getTestMethod();
enrichmentEvent.fire(new BeforeEnrichment(instance, method));
Collection<TestEnricher> testEnrichers = serviceLoader.get().all(TestEnricher.class);
for (TestEnricher enricher : testEnrichers) {
enricher.enrich(instance);
}
enrichmentEvent.fire(new AfterEnrichment(instance, method));
}
}
内容来源于网络,如有侵权,请联系作者删除!