Search in sources :

Example 1 with Delegate

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

the class VolumeServiceTest method testCreateVolumeConfig.

@Test
public void testCreateVolumeConfig() throws Exception {
    final VolumeConfiguration config = new VolumeConfiguration.Builder().name("testVolume").driver("test").opts(withMap("opts")).labels(withMap("labels")).build();
    new Expectations() {

        {
            // Use a 'delegate' to verify the argument given directly. No need
            // for an 'intermediate' return method in the service just to check this.
            docker.createVolume(with(new Delegate<VolumeCreateConfig>() {

                void check(VolumeCreateConfig vcc) {
                    assertThat(vcc.getName(), is("testVolume"));
                    JSONObject vccJson = (JSONObject) JSONParser.parseJSON(vcc.toJson());
                    assertEquals(vccJson.get("Driver"), "test");
                }
            }));
            result = "testVolume";
        }
    };
    String volume = new VolumeService(docker).createVolume(config);
    assertEquals(volume, "testVolume");
}
Also used : Expectations(mockit.Expectations) VolumeCreateConfig(io.fabric8.maven.docker.access.VolumeCreateConfig) JSONObject(org.json.JSONObject) Delegate(mockit.Delegate) VolumeConfiguration(io.fabric8.maven.docker.config.VolumeConfiguration) Test(org.junit.Test)

Example 2 with Delegate

use of mockit.Delegate in project tutorials by eugenp.

the class ExpectationsIntegrationTest method testDelegate.

@Test
public void testDelegate(@Mocked ExpectationsCollaborator mock) {
    new Expectations() {

        {
            mock.methodForDelegate(anyInt);
            result = new Delegate() {

                public int delegate(int i) throws Exception {
                    if (i < 3) {
                        return 5;
                    } else {
                        throw new Exception();
                    }
                }
            };
        }
    };
    assertEquals("Should return 5", 5, mock.methodForDelegate(1));
    try {
        mock.methodForDelegate(3);
    } catch (Exception e) {
    }
}
Also used : Expectations(mockit.Expectations) StrictExpectations(mockit.StrictExpectations) Delegate(mockit.Delegate) Test(org.junit.Test)

Example 3 with Delegate

use of mockit.Delegate in project streamline by hortonworks.

the class TopologyTestRunnerTest method setSucceedTopologyActionsExpectations.

private void setSucceedTopologyActionsExpectations() throws Exception {
    new Expectations() {

        {
            topologyActions.runTest(withInstanceOf(TopologyLayout.class), withInstanceOf(TopologyTestRunHistory.class), anyString, withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Map.class), withInstanceOf(Optional.class));
            result = new Delegate<Object>() {

                Object delegate(TopologyLayout topology, TopologyTestRunHistory testRunHistory, String mavenArtifacts, Map<String, TestRunSource> testRunSourcesForEachSource, Map<String, TestRunProcessor> testRunProcessorsForEachProcessor, Map<String, TestRunRulesProcessor> testRunRulesProcessorsForEachProcessor, Map<String, TestRunSink> testRunSinksForEachSink, Optional<Long> durationSecs) throws Exception {
                    Map<String, List<Map<String, Object>>> testOutputRecords = TopologyTestHelper.createTestOutputRecords(testRunSinksForEachSink.keySet());
                    testRunSinksForEachSink.entrySet().forEach(entry -> {
                        String sinkName = entry.getKey();
                        TestRunSink sink = entry.getValue();
                        try (FileWriter fw = new FileWriter(sink.getOutputFilePath())) {
                            List<Map<String, Object>> outputRecords = testOutputRecords.get(sinkName);
                            for (Map<String, Object> record : outputRecords) {
                                fw.write(objectMapper.writeValueAsString(record) + "\n");
                            }
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    });
                    return null;
                }
            };
        }
    };
}
Also used : Expectations(mockit.Expectations) 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) TestRunProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunProcessor) Optional(java.util.Optional) TestRunRulesProcessor(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunRulesProcessor) FileWriter(java.io.FileWriter) TestRunSink(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSink) IOException(java.io.IOException) TopologyTestRunHistory(com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) TopologyLayout(com.hortonworks.streamline.streams.layout.component.TopologyLayout) List(java.util.List) TestRunSource(com.hortonworks.streamline.streams.layout.component.impl.testing.TestRunSource) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map)

Aggregations

Delegate (mockit.Delegate)3 Expectations (mockit.Expectations)3 Test (org.junit.Test)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Files (com.google.common.io.Files)1 TopologyActions (com.hortonworks.streamline.streams.actions.TopologyActions)1 TopologyTestHelper (com.hortonworks.streamline.streams.actions.utils.TopologyTestHelper)1 Topology (com.hortonworks.streamline.streams.catalog.Topology)1 TopologyTestRunCase (com.hortonworks.streamline.streams.catalog.TopologyTestRunCase)1 TopologyTestRunCaseSink (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSink)1 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)1 TopologyTestRunHistory (com.hortonworks.streamline.streams.catalog.TopologyTestRunHistory)1 StreamCatalogService (com.hortonworks.streamline.streams.catalog.service.StreamCatalogService)1 Edge (com.hortonworks.streamline.streams.layout.component.Edge)1 Stream (com.hortonworks.streamline.streams.layout.component.Stream)1 StreamlineProcessor (com.hortonworks.streamline.streams.layout.component.StreamlineProcessor)1 StreamlineSink (com.hortonworks.streamline.streams.layout.component.StreamlineSink)1 StreamlineSource (com.hortonworks.streamline.streams.layout.component.StreamlineSource)1 TopologyDag (com.hortonworks.streamline.streams.layout.component.TopologyDag)1