Search in sources :

Example 1 with Instance

use of javax.enterprise.inject.Instance in project ART-TIME by Artezio.

the class CDIUtilsTest method testGetBean.

@Test
public void testGetBean() {
    CDI cdi = createMock(CDI.class);
    Instance instance = createMock(Instance.class);
    ProjectsBean projectsBean = createMock(ProjectsBean.class);
    PowerMock.mockStatic(CDI.class);
    expect(CDI.current()).andReturn(cdi);
    expect(cdi.select(ProjectsBean.class)).andReturn(instance);
    expect(instance.get()).andReturn(projectsBean);
    PowerMock.replayAll(CDI.class, cdi, instance);
    ProjectsBean actual = CDIUtils.getBean(ProjectsBean.class);
    PowerMock.verifyAll();
}
Also used : Instance(javax.enterprise.inject.Instance) ProjectsBean(com.artezio.arttime.web.ProjectsBean) CDI(javax.enterprise.inject.spi.CDI) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with Instance

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Instance(javax.enterprise.inject.Instance) Annotation(java.lang.annotation.Annotation) Bean(javax.enterprise.inject.spi.Bean)

Example 3 with Instance

use of javax.enterprise.inject.Instance in project kie-wb-common by kiegroup.

the class DataObjectBrowserViewImplTest method addPropertyTypeBrowseColumn.

@Test
public void addPropertyTypeBrowseColumn() {
    FieldMetadataProvider fieldMetadataProvider = objectProperty -> {
        if ("testField".equals(objectProperty.getName())) {
            ImageWrapper imageWrapper = new ImageWrapper("testUri", "testDescription");
            FieldMetadata fieldMetadata = new FieldMetadata(imageWrapper);
            return Optional.of(fieldMetadata);
        }
        return Optional.empty();
    };
    Instance<FieldMetadataProvider> fieldMetadataProviderInstance = new MockInstanceImpl<>(fieldMetadataProvider);
    view = new DataObjectBrowserViewImpl(validationPopup, fieldMetadataProviderInstance);
    Column<ObjectProperty, List<ImageWrapper>> column = view.createPropertyTypeBrowseColumn();
    ObjectProperty matchingObjectProperty = new ObjectPropertyImpl("testField", "className", false);
    List<ImageWrapper> imageWrapperList = column.getValue(matchingObjectProperty);
    assertEquals(1, imageWrapperList.size());
    ObjectProperty nonMatchingObjectProperty = new ObjectPropertyImpl("nonMatchingTestField", "className", false);
    imageWrapperList = column.getValue(nonMatchingObjectProperty);
    assertEquals(0, imageWrapperList.size());
}
Also used : GwtMockitoTestRunner(com.google.gwtmockito.GwtMockitoTestRunner) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) FieldMetadata(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadata) Mock(org.mockito.Mock) ValidationMessage(org.guvnor.common.services.shared.validation.model.ValidationMessage) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) FieldMetadataProvider(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadataProvider) ValidationPopup(org.kie.workbench.common.widgets.client.popups.validation.ValidationPopup) ImageWrapper(org.kie.workbench.common.screens.datamodeller.model.editor.ImageWrapper) Mockito(org.mockito.Mockito) List(java.util.List) Column(com.google.gwt.user.cellview.client.Column) Optional(java.util.Optional) MockInstanceImpl(org.uberfire.mocks.MockInstanceImpl) Assert(org.junit.Assert) Collections(java.util.Collections) Instance(javax.enterprise.inject.Instance) Command(org.uberfire.mvp.Command) Before(org.junit.Before) ObjectProperty(org.kie.workbench.common.services.datamodeller.core.ObjectProperty) ObjectPropertyImpl(org.kie.workbench.common.services.datamodeller.core.impl.ObjectPropertyImpl) FieldMetadataProvider(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadataProvider) FieldMetadata(org.kie.workbench.common.screens.datamodeller.model.editor.FieldMetadata) ImageWrapper(org.kie.workbench.common.screens.datamodeller.model.editor.ImageWrapper) MockInstanceImpl(org.uberfire.mocks.MockInstanceImpl) List(java.util.List) Test(org.junit.Test)

Example 4 with Instance

use of javax.enterprise.inject.Instance in project kie-wb-common by kiegroup.

the class VerifierWebWorkerRegistryTest method wrongId.

@Test
public void wrongId() throws Exception {
    final Instance verifierWebWorkerProviders = mock(Instance.class);
    final ArrayList<Object> webWorkerProviders = new ArrayList<>();
    webWorkerProviders.add(getWebWorkerProvider("somethingElse"));
    doReturn(webWorkerProviders.iterator()).when(verifierWebWorkerProviders).iterator();
    assertFalse(new VerifierWebWorkerRegistry(verifierWebWorkerProviders).get("something").isPresent());
}
Also used : Instance(javax.enterprise.inject.Instance) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with Instance

use of javax.enterprise.inject.Instance in project kie-wb-common by kiegroup.

the class VerifierWebWorkerRegistryTest method correctId.

@Test
public void correctId() throws Exception {
    final Instance verifierWebWorkerProviders = mock(Instance.class);
    final ArrayList<Object> webWorkerProviders = new ArrayList<>();
    webWorkerProviders.add(getWebWorkerProvider("something"));
    doReturn(webWorkerProviders.iterator()).when(verifierWebWorkerProviders).iterator();
    assertTrue(new VerifierWebWorkerRegistry(verifierWebWorkerProviders).get("something").isPresent());
}
Also used : Instance(javax.enterprise.inject.Instance) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Instance (javax.enterprise.inject.Instance)15 Test (org.junit.Test)13 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 ArrayList (java.util.ArrayList)4 Settings (com.artezio.arttime.config.Settings)3 Annotation (java.lang.annotation.Annotation)2 Bean (javax.enterprise.inject.spi.Bean)2 CDI (javax.enterprise.inject.spi.CDI)2 ProjectsBean (com.artezio.arttime.web.ProjectsBean)1 Column (com.google.gwt.user.cellview.client.Column)1 GwtMockitoTestRunner (com.google.gwtmockito.GwtMockitoTestRunner)1 AnnotatedElement (java.lang.reflect.AnnotatedElement)1 Array (java.lang.reflect.Array)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 Type (java.lang.reflect.Type)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1