Search in sources :

Example 6 with VerificationsInOrder

use of mockit.VerificationsInOrder in project streamline by hortonworks.

the class TopologyTestRunnerTest method runTest_withTestCaseId.

@Test
public void runTest_withTestCaseId() throws Exception {
    Topology topology = createSimpleDAGInjectedTestTopology();
    Long topologyId = topology.getId();
    Long testCaseId = 1L;
    TopologyTestRunCase testCase = new TopologyTestRunCase();
    testCase.setId(testCaseId);
    testCase.setTopologyId(topology.getId());
    testCase.setName("testcase1");
    testCase.setTimestamp(System.currentTimeMillis());
    setTopologyCurrentVersionExpectation(topology);
    setTopologyTestRunCaseExpectations(topology, testCase);
    setTopologyTestRunCaseSinkNotFoundExpectations(topology, testCase);
    setTopologyTestRunHistoryExpectations();
    setSucceedTopologyActionsExpectations();
    long sourceCount = topology.getTopologyDag().getOutputComponents().stream().filter(c -> c instanceof StreamlineSource).count();
    long sinkCount = topology.getTopologyDag().getInputComponents().stream().filter(c -> c instanceof StreamlineSink).count();
    TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
    waitForTopologyTestRunToFinish(resultHistory);
    assertNotNull(resultHistory);
    assertTrue(resultHistory.getFinished());
    assertTrue(resultHistory.getSuccess());
    new VerificationsInOrder() {

        {
            catalogService.getTopologyTestRunCaseSourceBySourceId(testCaseId, anyLong);
            times = (int) sourceCount;
            catalogService.getTopologyTestRunCaseSinkBySinkId(testCaseId, anyLong);
            times = (int) sinkCount;
            TopologyTestRunHistory runHistory;
            // some fields are already modified after calling the method, so don't need to capture it
            catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
            times = 1;
            catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
            times = 1;
            assertEquals(topology.getId(), runHistory.getTopologyId());
            assertEquals(topology.getVersionId(), runHistory.getVersionId());
            assertTrue(runHistory.getFinished());
            assertTrue(runHistory.getSuccess());
            assertNotNull(runHistory.getStartTime());
            assertNotNull(runHistory.getFinishTime());
            assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
            assertTrue(isEmptyJson(runHistory.getExpectedOutputRecords()));
            assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
            assertFalse(runHistory.getMatched());
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) BeforeClass(org.junit.BeforeClass) Expectations(mockit.Expectations) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) TopologyActions(com.hortonworks.streamline.streams.actions.TopologyActions) Edge(com.hortonworks.streamline.streams.layout.component.Edge) TopologyDag(com.hortonworks.streamline.streams.layout.component.TopologyDag) VerificationsInOrder(mockit.VerificationsInOrder) Collectors.toMap(java.util.stream.Collectors.toMap) Files(com.google.common.io.Files) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) Map(java.util.Map) JMockit(mockit.integration.junit4.JMockit) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) Before(org.junit.Before) Stream(com.hortonworks.streamline.streams.layout.component.Stream) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Assert.assertNotNull(org.junit.Assert.assertNotNull) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileWriter(java.io.FileWriter) Assert.assertTrue(org.junit.Assert.assertTrue) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) IOException(java.io.IOException) Delegate(mockit.Delegate) TopologyTestRunCaseSource(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource) File(java.io.File) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) TopologyTestHelper(com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper) Assert.assertFalse(org.junit.Assert.assertFalse) StreamCatalogService(com.hortonworks.streamline.streams.catalog.service.StreamCatalogService) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) Optional(java.util.Optional) StreamlineProcessor(com.hortonworks.streamline.streams.layout.component.StreamlineProcessor) Injectable(mockit.Injectable) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) TopologyTestRunCaseSink(com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) StreamlineSource(com.hortonworks.streamline.streams.layout.component.StreamlineSource) StreamlineSink(com.hortonworks.streamline.streams.layout.component.StreamlineSink) Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 7 with VerificationsInOrder

use of mockit.VerificationsInOrder in project streamline by hortonworks.

the class TopologyTestRunnerTest method runTest_withMatchedExpectedOutputRecords.

@Test
public void runTest_withMatchedExpectedOutputRecords() throws Exception {
    Topology topology = createSimpleDAGInjectedTestTopology();
    Long testCaseId = 1L;
    TopologyTestRunCase testCase = new TopologyTestRunCase();
    testCase.setId(testCaseId);
    testCase.setTopologyId(topology.getId());
    testCase.setName("testcase1");
    testCase.setTimestamp(System.currentTimeMillis());
    setTopologyCurrentVersionExpectation(topology);
    setTopologyTestRunCaseExpectations(topology, testCase);
    setTopologyTestRunCaseSinkExpectations(topology, testCase);
    setTopologyTestRunHistoryExpectations();
    setSucceedTopologyActionsExpectations();
    TopologyTestRunHistory resultHistory = topologyTestRunner.runTest(topologyActions, topology, testCase, null);
    assertNotNull(resultHistory);
    waitForTopologyTestRunToFinish(resultHistory);
    new VerificationsInOrder() {

        {
            TopologyTestRunHistory runHistory;
            // some fields are already modified after calling the method, so don't need to capture it
            catalogService.addTopologyTestRunHistory(withInstanceOf(TopologyTestRunHistory.class));
            times = 1;
            catalogService.addOrUpdateTopologyTestRunHistory(anyLong, runHistory = withCapture());
            times = 1;
            assertEquals(topology.getId(), runHistory.getTopologyId());
            assertEquals(topology.getVersionId(), runHistory.getVersionId());
            assertTrue(runHistory.getFinished());
            assertTrue(runHistory.getSuccess());
            assertNotNull(runHistory.getStartTime());
            assertNotNull(runHistory.getFinishTime());
            assertTrue(runHistory.getFinishTime() - runHistory.getStartTime() >= 0);
            assertTrue(isNotEmptyJson(runHistory.getExpectedOutputRecords()));
            assertTrue(isNotEmptyJson(runHistory.getActualOutputRecords()));
            assertTrue(runHistory.getMatched());
        }
    };
}
Also used : Topology(com.hortonworks.streamline.streams.catalog.Topology) TopologyTestRunCase(com.hortonworks.streamline.streams.catalog.TopologyTestRunCase) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 8 with VerificationsInOrder

use of mockit.VerificationsInOrder in project registry by hortonworks.

the class ManagedTransactionTest method testCaseCommitTransactionThrowsException.

@Test
public void testCaseCommitTransactionThrowsException() {
    final Exception commitException = new Exception("Commit exception");
    new Expectations() {

        {
            mockedTransactionManager.commitTransaction();
            result = commitException;
        }
    };
    try {
        managedTransaction.executeConsumer(this::callHelperWithReturn);
        Assert.fail("It should propagate Exception");
    } catch (Exception e) {
        Assert.assertEquals(commitException, e);
        Assert.assertTrue(testHelper.isCalled());
        new VerificationsInOrder() {

            {
                mockedTransactionManager.beginTransaction(transactionIsolation);
                times = 1;
                mockedTransactionManager.commitTransaction();
                times = 1;
                mockedTransactionManager.rollbackTransaction();
                times = 1;
            }
        };
    }
}
Also used : Expectations(mockit.Expectations) IgnoreTransactionRollbackException(com.hortonworks.registries.storage.exception.IgnoreTransactionRollbackException) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 9 with VerificationsInOrder

use of mockit.VerificationsInOrder in project docker-maven-plugin by fabric8io.

the class ComposeUtilsTest method resolveComposeFileWithRelativeComposeFileAndAbsoluteBaseDir.

@Test
public void resolveComposeFileWithRelativeComposeFileAndAbsoluteBaseDir() throws Exception {
    // relative/path/to/docker-compose.yaml
    String relComposeFile = join(SEP, "relative", "path", "to", "docker-compose.yaml");
    final String absMavenProjectDir = createTmpFile(className).getAbsolutePath();
    new Expectations() {

        {
            project.getBasedir();
            result = new File(absMavenProjectDir);
        }
    };
    assertEquals(new File(ABS_BASEDIR, relComposeFile), ComposeUtils.resolveComposeFileAbsolutely(ABS_BASEDIR, relComposeFile, project));
    new VerificationsInOrder() {

        {
            project.getBasedir();
        }
    };
}
Also used : Expectations(mockit.Expectations) PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Example 10 with VerificationsInOrder

use of mockit.VerificationsInOrder in project docker-maven-plugin by fabric8io.

the class ComposeUtilsTest method resolveComposeFileWithRelativeComposeFileAndRelativeBaseDir.

@Test
public void resolveComposeFileWithRelativeComposeFileAndRelativeBaseDir() throws Exception {
    // relative/path/to/docker-compose.yaml
    String relComposeFile = join(SEP, "relative", "path", "to", "docker-compose.yaml");
    String relBaseDir = "basedir" + SEP;
    final String absMavenProjectDir = createTmpFile(className).getAbsolutePath();
    new Expectations() {

        {
            project.getBasedir();
            result = new File(absMavenProjectDir);
        }
    };
    assertEquals(new File(new File(absMavenProjectDir, relBaseDir), relComposeFile), ComposeUtils.resolveComposeFileAbsolutely(relBaseDir, relComposeFile, project));
    new VerificationsInOrder() {

        {
            project.getBasedir();
        }
    };
}
Also used : Expectations(mockit.Expectations) PathTestUtil.createTmpFile(io.fabric8.maven.docker.util.PathTestUtil.createTmpFile) File(java.io.File) VerificationsInOrder(mockit.VerificationsInOrder) Test(org.junit.Test)

Aggregations

VerificationsInOrder (mockit.VerificationsInOrder)14 Test (org.junit.Test)12 Expectations (mockit.Expectations)9 File (java.io.File)6 Topology (com.hortonworks.streamline.streams.catalog.Topology)4 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)4 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)4 IgnoreTransactionRollbackException (com.hortonworks.registries.storage.exception.IgnoreTransactionRollbackException)3 HashMap (java.util.HashMap)3 Values (org.apache.storm.tuple.Values)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Files (com.google.common.io.Files)2 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)2 TopologyTestHelper (com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper)2 TopologyTestRunCaseSink (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink)2 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)2 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)2 Edge (com.hortonworks.streamline.streams.layout.component.Edge)2 Stream (com.hortonworks.streamline.streams.layout.component.Stream)2