Search in sources :

Example 1 with ContextMapModelConverter

use of org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter in project context-mapper-dsl by ContextMapper.

the class ContextMapModelConverterTest method canConvertSimpleTeamMap.

@Test
public void canConvertSimpleTeamMap() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("test-team-map-1.cml");
    ContextMappingModel model = input.getContextMappingModel();
    // when
    ContextMap contextMap = new ContextMapModelConverter().convert(model.getMap());
    // then
    assertEquals(1, contextMap.getRelationships().size());
    assertEquals(2, contextMap.getBoundedContexts().size());
    assertEquals(BoundedContextType.TEAM, contextMap.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomersTeam")).findFirst().get().getType());
    assertEquals(BoundedContextType.TEAM, contextMap.getBoundedContexts().stream().filter(bc -> bc.getName().equals("ContractsTeam")).findFirst().get().getType());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) ContextMapModelConverter(org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter) CMLResource(org.contextmapper.dsl.cml.CMLResource) ContextMap(org.contextmapper.contextmap.generator.model.ContextMap) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 2 with ContextMapModelConverter

use of org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter in project context-mapper-dsl by ContextMapper.

the class ContextMapModelConverterTest method canConvertTeamMapWithRealizingRelationships.

@Test
public void canConvertTeamMapWithRealizingRelationships() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("test-team-map-2.cml");
    ContextMappingModel model = input.getContextMappingModel();
    // when
    ContextMap contextMap = new ContextMapModelConverter().convert(model.getMap());
    // then
    assertEquals(2, contextMap.getRelationships().size());
    assertEquals(4, contextMap.getBoundedContexts().size());
    BoundedContext customersTeam = contextMap.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomersTeam")).findFirst().get();
    BoundedContext contractsTeam = contextMap.getBoundedContexts().stream().filter(bc -> bc.getName().equals("ContractsTeam")).findFirst().get();
    BoundedContext customerContext = contextMap.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagementContext")).findFirst().get();
    BoundedContext policyContext = contextMap.getBoundedContexts().stream().filter(bc -> bc.getName().equals("PolicyManagementContext")).findFirst().get();
    assertEquals(BoundedContextType.TEAM, customersTeam.getType());
    assertEquals(BoundedContextType.TEAM, contractsTeam.getType());
    assertEquals(BoundedContextType.GENERIC, customerContext.getType());
    assertEquals(BoundedContextType.GENERIC, policyContext.getType());
    assertEquals(1, customersTeam.getRealizedBoundedContexts().size());
    assertEquals(1, contractsTeam.getRealizedBoundedContexts().size());
    assertEquals("CustomerManagementContext", customersTeam.getRealizedBoundedContexts().iterator().next().getName());
    assertEquals("PolicyManagementContext", contractsTeam.getRealizedBoundedContexts().iterator().next().getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) ContextMapModelConverter(org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.contextmap.generator.model.BoundedContext) ContextMap(org.contextmapper.contextmap.generator.model.ContextMap) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 3 with ContextMapModelConverter

use of org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter in project context-mapper-dsl by ContextMapper.

the class ContextMapModelConverterTest method canConvertContextMap.

@Test
public void canConvertContextMap() throws IOException {
    // given
    String inputModelName = "test-context-map-1.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    ContextMappingModel model = input.getContextMappingModel();
    // when
    ContextMap contextMap = new ContextMapModelConverter().convert(model.getMap());
    // then
    assertEquals(6, contextMap.getBoundedContexts().size());
    assertEquals(5, contextMap.getRelationships().size());
    assertTrue(contextMap.getBoundedContexts().contains(new BoundedContext("CustomerManagementContext")));
    assertTrue(contextMap.getBoundedContexts().contains(new BoundedContext("CustomerSelfServiceContext")));
    assertTrue(contextMap.getBoundedContexts().contains(new BoundedContext("PrintingContext")));
    assertTrue(contextMap.getBoundedContexts().contains(new BoundedContext("PolicyManagementContext")));
    assertTrue(contextMap.getBoundedContexts().contains(new BoundedContext("RiskManagementContext")));
    assertTrue(contextMap.getBoundedContexts().contains(new BoundedContext("DebtCollection")));
    UpstreamDownstreamRelationship rel1 = contextMap.getRelationships().stream().filter(r -> r instanceof UpstreamDownstreamRelationship).map(r -> (UpstreamDownstreamRelationship) r).filter(r -> r.getUpstreamBoundedContext().getName().equals("CustomerManagementContext") && r.getDownstreamBoundedContext().getName().equals("CustomerSelfServiceContext")).findFirst().get();
    assertNotNull(rel1);
    assertTrue(rel1.isCustomerSupplier());
    UpstreamDownstreamRelationship rel2 = contextMap.getRelationships().stream().filter(r -> r instanceof UpstreamDownstreamRelationship).map(r -> (UpstreamDownstreamRelationship) r).filter(r -> r.getUpstreamBoundedContext().getName().equals("PrintingContext") && r.getDownstreamBoundedContext().getName().equals("CustomerManagementContext")).findFirst().get();
    assertNotNull(rel2);
    assertFalse(rel2.isCustomerSupplier());
    assertTrue(rel2.getUpstreamPatterns().contains(UpstreamPatterns.OPEN_HOST_SERVICE));
    assertTrue(rel2.getUpstreamPatterns().contains(UpstreamPatterns.PUBLISHED_LANGUAGE));
    assertTrue(rel2.getDownstreamPatterns().contains(DownstreamPatterns.ANTICORRUPTION_LAYER));
    Partnership rel3 = contextMap.getRelationships().stream().filter(r -> r instanceof Partnership).map(r -> (Partnership) r).filter(r -> r.getFirstParticipant().getName().equals("RiskManagementContext") && r.getSecondParticipant().getName().equals("PolicyManagementContext")).findFirst().get();
    assertNotNull(rel3);
    UpstreamDownstreamRelationship rel4 = contextMap.getRelationships().stream().filter(r -> r instanceof UpstreamDownstreamRelationship).map(r -> (UpstreamDownstreamRelationship) r).filter(r -> r.getUpstreamBoundedContext().getName().equals("CustomerManagementContext") && r.getDownstreamBoundedContext().getName().equals("PolicyManagementContext")).findFirst().get();
    assertNotNull(rel4);
    assertFalse(rel4.isCustomerSupplier());
    assertTrue(rel4.getUpstreamPatterns().contains(UpstreamPatterns.OPEN_HOST_SERVICE));
    assertTrue(rel4.getDownstreamPatterns().contains(DownstreamPatterns.CONFORMIST));
    SharedKernel rel5 = contextMap.getRelationships().stream().filter(r -> r instanceof SharedKernel).map(r -> (SharedKernel) r).filter(r -> r.getFirstParticipant().getName().equals("PolicyManagementContext") && r.getSecondParticipant().getName().equals("DebtCollection")).findFirst().get();
    assertNotNull(rel5);
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) UpstreamPatterns(org.contextmapper.contextmap.generator.model.UpstreamPatterns) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IOException(java.io.IOException) BoundedContext(org.contextmapper.contextmap.generator.model.BoundedContext) BoundedContextType(org.contextmapper.contextmap.generator.model.BoundedContextType) ContextMap(org.contextmapper.contextmap.generator.model.ContextMap) ContextMapModelConverter(org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter) Test(org.junit.jupiter.api.Test) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SharedKernel(org.contextmapper.contextmap.generator.model.SharedKernel) Partnership(org.contextmapper.contextmap.generator.model.Partnership) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) UpstreamDownstreamRelationship(org.contextmapper.contextmap.generator.model.UpstreamDownstreamRelationship) DownstreamPatterns(org.contextmapper.contextmap.generator.model.DownstreamPatterns) CMLResource(org.contextmapper.dsl.cml.CMLResource) ContextMapModelConverter(org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter) Partnership(org.contextmapper.contextmap.generator.model.Partnership) SharedKernel(org.contextmapper.contextmap.generator.model.SharedKernel) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.contextmap.generator.model.BoundedContext) UpstreamDownstreamRelationship(org.contextmapper.contextmap.generator.model.UpstreamDownstreamRelationship) ContextMap(org.contextmapper.contextmap.generator.model.ContextMap) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 4 with ContextMapModelConverter

use of org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter in project context-mapper-dsl by ContextMapper.

the class ContextMapGenerator method generateFromContextMap.

@Override
protected void generateFromContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap cmlContextMap, IFileSystemAccess2 fsa, URI inputFileURI) {
    String fileName = inputFileURI.trimFileExtension().lastSegment();
    ContextMap contextMap = new ContextMapModelConverter().convert(cmlContextMap, printAdditionalLabels);
    org.contextmapper.contextmap.generator.ContextMapGenerator generator = createContextMapGenerator();
    generator.setLabelSpacingFactor(labelSpacingFactor);
    generator.clusterTeams(clusterTeams);
    if (this.width > 0 && useWidth)
        generator.setWidth(width);
    else if (this.height > 0)
        generator.setHeight(height);
    for (ContextMapFormat format : formats) {
        try (ByteArrayOutputStream outputstream = new ByteArrayOutputStream()) {
            generator.generateContextMapGraphic(contextMap, getGraphvizLibFormat(format), outputstream);
            try (InputStream inputstream = new ByteArrayInputStream(outputstream.toByteArray())) {
                fsa.generateFile(fileName + "_ContextMap." + format.getFileExtension(), inputstream);
            }
        } catch (IOException e) {
            throw new RuntimeException("An error occured while generating the Context Map!", e);
        }
    }
}
Also used : ContextMapModelConverter(org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ContextMapFormat(org.contextmapper.dsl.generator.contextmap.ContextMapFormat) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ContextMap(org.contextmapper.contextmap.generator.model.ContextMap)

Aggregations

ContextMap (org.contextmapper.contextmap.generator.model.ContextMap)4 ContextMapModelConverter (org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter)4 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)3 CMLResource (org.contextmapper.dsl.cml.CMLResource)3 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)3 Test (org.junit.jupiter.api.Test)3 IOException (java.io.IOException)2 BoundedContext (org.contextmapper.contextmap.generator.model.BoundedContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 BoundedContextType (org.contextmapper.contextmap.generator.model.BoundedContextType)1 DownstreamPatterns (org.contextmapper.contextmap.generator.model.DownstreamPatterns)1 Partnership (org.contextmapper.contextmap.generator.model.Partnership)1 SharedKernel (org.contextmapper.contextmap.generator.model.SharedKernel)1 UpstreamDownstreamRelationship (org.contextmapper.contextmap.generator.model.UpstreamDownstreamRelationship)1 UpstreamPatterns (org.contextmapper.contextmap.generator.model.UpstreamPatterns)1 ContextMapFormat (org.contextmapper.dsl.generator.contextmap.ContextMapFormat)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1