Search in sources :

Example 1 with SharedKernel

use of org.contextmapper.contextmap.generator.model.SharedKernel 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 2 with SharedKernel

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

the class ContextMapModelConverter method convert.

private Relationship convert(org.contextmapper.dsl.contextMappingDSL.Relationship cmlRelationship) {
    AbstractRelationship relationship = null;
    if (cmlRelationship instanceof org.contextmapper.dsl.contextMappingDSL.Partnership) {
        org.contextmapper.dsl.contextMappingDSL.Partnership cmlPartnership = (org.contextmapper.dsl.contextMappingDSL.Partnership) cmlRelationship;
        relationship = new Partnership(bcMap.get(cmlPartnership.getParticipant1().getName()), bcMap.get(cmlPartnership.getParticipant2().getName()));
    } else if (cmlRelationship instanceof org.contextmapper.dsl.contextMappingDSL.SharedKernel) {
        org.contextmapper.dsl.contextMappingDSL.SharedKernel cmlSharedKernel = (org.contextmapper.dsl.contextMappingDSL.SharedKernel) cmlRelationship;
        relationship = new SharedKernel(bcMap.get(cmlSharedKernel.getParticipant1().getName()), bcMap.get(cmlSharedKernel.getParticipant2().getName()));
    } else if (cmlRelationship instanceof org.contextmapper.dsl.contextMappingDSL.CustomerSupplierRelationship) {
        org.contextmapper.dsl.contextMappingDSL.CustomerSupplierRelationship cmlCustomerSupplier = (org.contextmapper.dsl.contextMappingDSL.CustomerSupplierRelationship) cmlRelationship;
        relationship = new UpstreamDownstreamRelationship(bcMap.get(cmlCustomerSupplier.getUpstream().getName()), bcMap.get(cmlCustomerSupplier.getDownstream().getName()));
        ((UpstreamDownstreamRelationship) relationship).setCustomerSupplier(true);
        ((UpstreamDownstreamRelationship) relationship).setUpstreamPatterns(convertUpstreamRoles(cmlCustomerSupplier.getUpstreamRoles()));
        ((UpstreamDownstreamRelationship) relationship).setDownstreamPatterns(convertDownstreamRoles(cmlCustomerSupplier.getDownstreamRoles()));
    } else {
        org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship cmlUpstreamDownstream = (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) cmlRelationship;
        relationship = new UpstreamDownstreamRelationship(bcMap.get(cmlUpstreamDownstream.getUpstream().getName()), bcMap.get(cmlUpstreamDownstream.getDownstream().getName()));
        ((UpstreamDownstreamRelationship) relationship).setUpstreamPatterns(convertUpstreamRoles(cmlUpstreamDownstream.getUpstreamRoles()));
        ((UpstreamDownstreamRelationship) relationship).setDownstreamPatterns(convertDownstreamRoles(cmlUpstreamDownstream.getDownstreamRoles()));
    }
    if (useNameAndImplementationTechnologyLabels && cmlRelationship.getName() != null)
        relationship.setName(cmlRelationship.getName());
    if (useNameAndImplementationTechnologyLabels && cmlRelationship.getImplementationTechnology() != null)
        relationship.setImplementationTechnology(cmlRelationship.getImplementationTechnology());
    return relationship;
}
Also used : AbstractRelationship(org.contextmapper.contextmap.generator.model.AbstractRelationship) Partnership(org.contextmapper.contextmap.generator.model.Partnership) SharedKernel(org.contextmapper.contextmap.generator.model.SharedKernel) UpstreamDownstreamRelationship(org.contextmapper.contextmap.generator.model.UpstreamDownstreamRelationship)

Aggregations

Partnership (org.contextmapper.contextmap.generator.model.Partnership)2 SharedKernel (org.contextmapper.contextmap.generator.model.SharedKernel)2 UpstreamDownstreamRelationship (org.contextmapper.contextmap.generator.model.UpstreamDownstreamRelationship)2 IOException (java.io.IOException)1 AbstractRelationship (org.contextmapper.contextmap.generator.model.AbstractRelationship)1 BoundedContext (org.contextmapper.contextmap.generator.model.BoundedContext)1 BoundedContextType (org.contextmapper.contextmap.generator.model.BoundedContextType)1 ContextMap (org.contextmapper.contextmap.generator.model.ContextMap)1 DownstreamPatterns (org.contextmapper.contextmap.generator.model.DownstreamPatterns)1 UpstreamPatterns (org.contextmapper.contextmap.generator.model.UpstreamPatterns)1 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)1 CMLResource (org.contextmapper.dsl.cml.CMLResource)1 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)1 ContextMapModelConverter (org.contextmapper.dsl.generator.contextmap.ContextMapModelConverter)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assertions.assertFalse (org.junit.jupiter.api.Assertions.assertFalse)1 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)1 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)1 Test (org.junit.jupiter.api.Test)1