Search in sources :

Example 21 with Instance

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

the class TrackingSystemProducerTest method getTrackingSystemsNames.

@Test
public void getTrackingSystemsNames() {
    Instance instance = createMock(Instance.class);
    trackingSystemProducer = createMockBuilder(TrackingSystemProducer.class).createMock();
    TrackingSystem impl1 = createMock(TrackingSystem.class);
    TrackingSystem impl2 = createMock(TrackingSystem.class);
    List<TrackingSystem> implementations = Arrays.asList(impl1, impl2);
    expect(instance.spliterator()).andReturn(implementations.spliterator());
    expect(impl1.getName()).andReturn("Impl1");
    expect(impl2.getName()).andReturn("Impl2");
    replayAll(trackingSystemProducer, instance, impl1, impl2);
    Set<String> actual = trackingSystemProducer.getTrackingSystemsNames(instance);
    PowerMock.verifyAll();
    assertTrue(actual.contains("Impl1"));
    assertTrue(actual.contains("Impl2"));
}
Also used : Instance(javax.enterprise.inject.Instance) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 22 with Instance

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

the class TrackingSystemProducerTest method testGetEmployeeTrackingSystem.

@Test
public void testGetEmployeeTrackingSystem() 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, "employeeTrackingSystems", instance);
    setField(trackingSystemProducer, "settings", settings);
    EmployeeTrackingSystem expectedImpl = createMock(EmployeeTrackingSystem.class);
    expect(trackingSystemProducer.findImplementationByName(instance, "ExpectedImpl")).andReturn(expectedImpl);
    expect(settings.getEmployeeTrackingSystemName()).andReturn("ExpectedImpl");
    replayAll(instance, settings, expectedImpl, trackingSystemProducer);
    EmployeeTrackingSystem actual = trackingSystemProducer.getEmployeeTrackingSystem();
    PowerMock.verifyAll();
    assertEquals(expectedImpl, actual);
}
Also used : Instance(javax.enterprise.inject.Instance) Settings(com.artezio.arttime.config.Settings) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 23 with Instance

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

the class TrackingSystemProducerTest method testFindImplementationByName.

@Test
public void testFindImplementationByName() {
    Instance instance = createMock(Instance.class);
    trackingSystemProducer = createMockBuilder(TrackingSystemProducer.class).createMock();
    TrackingSystem expectedImpl = createMock(TrackingSystem.class);
    TrackingSystem unexpectedImpl = createMock(TrackingSystem.class);
    List<TrackingSystem> implementations = Arrays.asList(expectedImpl, unexpectedImpl);
    expect(instance.iterator()).andReturn(implementations.iterator());
    expect(expectedImpl.getName()).andReturn("Expected").anyTimes();
    expect(unexpectedImpl.getName()).andReturn("UnExpected").anyTimes();
    replayAll(trackingSystemProducer, instance, expectedImpl, unexpectedImpl);
    TrackingSystem actual = trackingSystemProducer.findImplementationByName(instance, "Expected");
    PowerMock.verifyAll();
    assertEquals(expectedImpl, actual);
}
Also used : Instance(javax.enterprise.inject.Instance) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 24 with Instance

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

the class TrackingSystemProducerTest method getDepartmentTrackingSystemNames.

@Test
public void getDepartmentTrackingSystemNames() throws NoSuchFieldException {
    Instance instance = createMock(Instance.class);
    trackingSystemProducer = createMockBuilder(TrackingSystemProducer.class).addMockedMethod("getTrackingSystemsNames", Instance.class).createMock();
    setField(trackingSystemProducer, "departmentTrackingSystems", instance);
    Set<String> expected = Sets.newHashSet("A", "B");
    expect(trackingSystemProducer.getTrackingSystemsNames(instance)).andReturn(expected);
    replayAll(instance, trackingSystemProducer);
    Set<String> actual = trackingSystemProducer.getDepartmentTrackingSystemNames();
    verifyAll();
    assertEquals(expected, actual);
}
Also used : Instance(javax.enterprise.inject.Instance) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 25 with Instance

use of javax.enterprise.inject.Instance in project wildfly-swarm by wildfly-swarm.

the class ArtifactDeployerTest method stubRuntimeDeployer.

private RuntimeDeployer stubRuntimeDeployer(ArtifactDeployer artifactDeployer) throws NoSuchFieldException, IllegalAccessException {
    RuntimeDeployer runtimeDeployer = mock(RuntimeDeployer.class);
    Instance runtimeDeployerInstance = mock(Instance.class);
    when(runtimeDeployerInstance.get()).thenReturn(runtimeDeployer);
    Field deployer = ArtifactDeployer.class.getDeclaredField("deployer");
    deployer.setAccessible(true);
    deployer.set(artifactDeployer, runtimeDeployerInstance);
    return runtimeDeployer;
}
Also used : Field(java.lang.reflect.Field) Instance(javax.enterprise.inject.Instance)

Aggregations

Instance (javax.enterprise.inject.Instance)41 Test (org.junit.Test)14 List (java.util.List)12 Inject (javax.inject.Inject)12 ArrayList (java.util.ArrayList)11 Map (java.util.Map)10 Optional (java.util.Optional)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 IOException (java.io.IOException)5 InjectionPoint (javax.enterprise.inject.spi.InjectionPoint)4 Path (javax.ws.rs.Path)4 MediaType (javax.ws.rs.core.MediaType)4 ProcessInstanceExporter (io.automatiko.engine.addons.process.management.export.ProcessInstanceExporter)3 ErrorInfoDTO (io.automatiko.engine.addons.process.management.model.ErrorInfoDTO)3 JsonExportedProcessInstance (io.automatiko.engine.addons.process.management.model.JsonExportedProcessInstance)3 ProcessDTO (io.automatiko.engine.addons.process.management.model.ProcessDTO)3 ProcessInstanceDTO (io.automatiko.engine.addons.process.management.model.ProcessInstanceDTO)3