use of javax.enterprise.inject.Instance in project kernel by exoplatform.
the class WeldContainer method getComponentAdapter.
/**
* {@inheritDoc}
*/
@SuppressWarnings("unchecked")
@Override
public <T> ComponentAdapter<T> getComponentAdapter(final Object componentKey, Class<T> bindType, boolean autoRegistration) {
ComponentAdapter<T> result = super.getComponentAdapter(componentKey, bindType, autoRegistration);
if (weld != null && result == null) {
if (componentKey instanceof Class<?> && !((Class<?>) componentKey).isAnnotation()) {
return getAdapterOfType((Class<T>) componentKey);
} else if (componentKey instanceof String) {
Set<Bean<?>> beans = container.getBeanManager().getBeans(bindType, createNamed((String) componentKey));
if (beans != null && !beans.isEmpty()) {
return createComponentAdapter(bindType, (Instance<T>) container.instance().select(beans.iterator().next().getBeanClass()));
}
} else if (componentKey instanceof Class<?>) {
final Class<? extends Annotation> annotationType = (Class<? extends Annotation>) componentKey;
Annotation annotation = createAnnotation(annotationType);
Set<Bean<?>> beans = container.getBeanManager().getBeans(bindType, annotation);
if (beans != null && !beans.isEmpty()) {
return createComponentAdapter(bindType, (Instance<T>) container.instance().select(beans.iterator().next().getBeanClass()));
}
}
}
return result;
}
use of javax.enterprise.inject.Instance in project kie-wb-common by kiegroup.
the class VerifierWebWorkerRegistryTest method noWebWorkerProviders.
@Test
public void noWebWorkerProviders() throws Exception {
final Instance verifierWebWorkerProviders = mock(Instance.class);
doReturn(new ArrayList<>().iterator()).when(verifierWebWorkerProviders).iterator();
assertFalse(new VerifierWebWorkerRegistry(verifierWebWorkerProviders).get("something").isPresent());
}
use of javax.enterprise.inject.Instance in project tomee by apache.
the class TomEEOpenAPIExtension method createOpenApi.
private OpenAPI createOpenApi(final Class<?> application, final Stream<Class<?>> beans) {
final CDI<Object> current = CDI.current();
final OpenAPI api = ofNullable(config.read(OASConfig.MODEL_READER, null)).map(value -> newInstance(current, value)).map(it -> OASModelReader.class.cast(it).buildModel()).orElseGet(() -> current.select(DefaultLoader.class).get().loadDefaultApi());
final BeanManager beanManager = current.getBeanManager();
processor.processApplication(api, new ElementImpl(beanManager.createAnnotatedType(application)));
if (skipScan) {
return api.paths(new PathsImpl());
}
// adds the context path to the base
final Instance<ServletContext> servletContextInstance = current.select(ServletContext.class);
final boolean appendContextPath = Boolean.valueOf(config.read("application.append-context-path", "true"));
String contextPath = "";
if (appendContextPath && !servletContextInstance.isAmbiguous() && !servletContextInstance.isUnsatisfied()) {
contextPath = servletContextInstance.get().getContextPath();
}
final String base = contextPath + processor.getApplicationBinding(application);
processor.beforeProcessing();
beans.filter(c -> (excludeClasses == null || !excludeClasses.contains(c.getName()))).filter(c -> (excludePackages == null || excludePackages.stream().noneMatch(it -> c.getName().startsWith(it)))).map(beanManager::createAnnotatedType).forEach(at -> processor.processClass(base, api, new ElementImpl(at), at.getMethods().stream().map(MethodElementImpl::new)));
return ofNullable(config.read(OASConfig.FILTER, null)).map(it -> newInstance(current, it)).map(i -> new FilterImpl(OASFilter.class.cast(i)).filter(api)).orElse(api);
}
use of javax.enterprise.inject.Instance in project ART-TIME by Artezio.
the class TrackingSystemProducerTest method testGetTeamTrackingSystem.
@Test
public void testGetTeamTrackingSystem() throws NoSuchFieldException {
Settings settings = createMock(Settings.class);
Instance instance = createMock(Instance.class);
trackingSystemProducer = createMockBuilder(TrackingSystemProducer.class).addMockedMethod("findImplementationByName", Instance.class, String.class).createMock();
setField(trackingSystemProducer, "teamTrackingSystems", instance);
setField(trackingSystemProducer, "settings", settings);
TeamTrackingSystem expectedImpl = createMock(TeamTrackingSystem.class);
expect(trackingSystemProducer.findImplementationByName(instance, "ExpectedImpl")).andReturn(expectedImpl);
expect(settings.getTeamTrackingSystemName()).andReturn("ExpectedImpl");
replayAll(instance, settings, expectedImpl, trackingSystemProducer);
TeamTrackingSystem actual = trackingSystemProducer.getTeamTrackingSystem();
PowerMock.verifyAll();
assertEquals(expectedImpl, actual);
}
use of javax.enterprise.inject.Instance in project ART-TIME by Artezio.
the class TrackingSystemProducerTest method testGetEmployeeTrackingSystemNames.
@Test
public void testGetEmployeeTrackingSystemNames() throws NoSuchFieldException {
Instance instance = createMock(Instance.class);
trackingSystemProducer = createMockBuilder(TrackingSystemProducer.class).addMockedMethod("getTrackingSystemsNames", Instance.class).createMock();
setField(trackingSystemProducer, "employeeTrackingSystems", instance);
Set<String> expected = Sets.newHashSet("A", "B");
expect(trackingSystemProducer.getTrackingSystemsNames(instance)).andReturn(expected);
replayAll(instance, trackingSystemProducer);
Set<String> actual = trackingSystemProducer.getEmployeeTrackingSystemNames();
verifyAll();
assertEquals(expected, actual);
}
Aggregations