Search in sources :

Example 1 with SymmetricRelationship

use of org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship in project context-mapper-dsl by ContextMapper.

the class SplitSystemIntoSubsystemsTest method canRenameContextInRelationships.

@Test
public void canRenameContextInRelationships() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("split-system-tier-test-7-input.cml");
    SplitSystemIntoSubsystems ar = new SplitSystemIntoSubsystems("TestBackend", "TestBackendLogic", "TestBackendDatabase");
    // when
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(3, model.getBoundedContexts().size());
    assertTrue(getBoundedContextNames(model.getBoundedContexts()).contains("TestBackendLogic"));
    assertFalse(getBoundedContextNames(model.getBoundedContexts()).contains("TestBackend"));
    Set<String> namesOnContextMap = getBoundedContextNames(model.getMap().getBoundedContexts());
    assertTrue(namesOnContextMap.contains("TestBackendLogic"));
    assertFalse(namesOnContextMap.contains("TestBackend"));
    UpstreamDownstreamRelationship upDownRel1 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("upDownTestRel1")).map(r -> (UpstreamDownstreamRelationship) r).findFirst().get();
    UpstreamDownstreamRelationship upDownRel2 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("upDownTestRel2")).map(r -> (UpstreamDownstreamRelationship) r).findFirst().get();
    SymmetricRelationship symRel1 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("symTestRel1")).map(r -> (SymmetricRelationship) r).findFirst().get();
    SymmetricRelationship symRel2 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("symTestRel2")).map(r -> (SymmetricRelationship) r).findFirst().get();
    assertEquals("TestBackendLogic", upDownRel1.getUpstream().getName());
    assertEquals("TestBackendLogic", upDownRel2.getDownstream().getName());
    assertEquals("TestBackendLogic", symRel1.getParticipant1().getName());
    assertEquals("TestBackendLogic", symRel2.getParticipant2().getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CsvSource(org.junit.jupiter.params.provider.CsvSource) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) UpstreamRole(org.contextmapper.dsl.contextMappingDSL.UpstreamRole) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Charset(java.nio.charset.Charset) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ACL(org.contextmapper.dsl.refactoring.ContextSplittingIntegrationType.ACL) ValueSource(org.junit.jupiter.params.provider.ValueSource) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) Test(org.junit.jupiter.api.Test) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) DownstreamRole(org.contextmapper.dsl.contextMappingDSL.DownstreamRole) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) NullSource(org.junit.jupiter.params.provider.NullSource) SplitBoundedContextRelationshipType(org.contextmapper.dsl.refactoring.SplitSystemIntoSubsystems.SplitBoundedContextRelationshipType) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) CMLResource(org.contextmapper.dsl.cml.CMLResource) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with SymmetricRelationship

use of org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship in project context-mapper-dsl by ContextMapper.

the class MergeBoundedContextsTest method doesFixSymRelationshipsFromBC2ToBC1.

@Test
void doesFixSymRelationshipsFromBC2ToBC1() throws IOException {
    // given
    String inputModelName = "merge-bounded-contexts-test-6-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    MergeBoundedContextsRefactoring refactoring = new MergeBoundedContextsRefactoring("CustomerManagement", "AnotherContext");
    // when
    refactoring.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(2, model.getMap().getRelationships().size());
    SymmetricRelationship relationship1 = (SymmetricRelationship) model.getMap().getRelationships().get(0);
    SymmetricRelationship relationship2 = (SymmetricRelationship) model.getMap().getRelationships().get(1);
    assertEquals("DeptColletion", relationship1.getParticipant1().getName());
    assertEquals("CustomerManagement", relationship1.getParticipant2().getName());
    assertEquals("CustomerManagement", relationship2.getParticipant1().getName());
    assertEquals("DeptColletion", relationship2.getParticipant2().getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) Test(org.junit.jupiter.api.Test)

Example 3 with SymmetricRelationship

use of org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship in project context-mapper-dsl by ContextMapper.

the class BoundedContextRelationshipSemanticsValidator method prohibitSelfRelationship.

@Check
public void prohibitSelfRelationship(final ContextMap contextMap) {
    int relationshipIndex = 0;
    for (Relationship relationship : contextMap.getRelationships()) {
        BoundedContext context1;
        BoundedContext context2;
        if (relationship instanceof SymmetricRelationship) {
            context1 = ((SymmetricRelationship) relationship).getParticipant1();
            context2 = ((SymmetricRelationship) relationship).getParticipant2();
        } else {
            context1 = ((UpstreamDownstreamRelationship) relationship).getUpstream();
            context2 = ((UpstreamDownstreamRelationship) relationship).getDownstream();
        }
        if (context1 == context2) {
            error(String.format(SELF_RELATIONSHIP_NOT_ALLOWED), contextMap, ContextMappingDSLPackage.Literals.CONTEXT_MAP__RELATIONSHIPS, relationshipIndex);
        }
        relationshipIndex++;
    }
}
Also used : SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) CustomerSupplierRelationship(org.contextmapper.dsl.contextMappingDSL.CustomerSupplierRelationship) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) Check(org.eclipse.xtext.validation.Check)

Example 4 with SymmetricRelationship

use of org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship in project context-mapper-dsl by ContextMapper.

the class ContextMapSemanticsValidator method validateThatRelationshipContextArePartOfMap.

@Check
public void validateThatRelationshipContextArePartOfMap(final ContextMap map) {
    for (Relationship relationship : map.getRelationships()) {
        BoundedContext context1 = null;
        BoundedContext context2 = null;
        EReference attributeRelContext1 = null;
        EReference attributeRelContext2 = null;
        if (relationship instanceof SymmetricRelationship) {
            context1 = ((SymmetricRelationship) relationship).getParticipant1();
            context2 = ((SymmetricRelationship) relationship).getParticipant2();
            attributeRelContext1 = SYMMETRIC_RELATIONSHIP__PARTICIPANT1;
            attributeRelContext2 = SYMMETRIC_RELATIONSHIP__PARTICIPANT2;
        } else if (relationship instanceof UpstreamDownstreamRelationship) {
            context1 = ((UpstreamDownstreamRelationship) relationship).getUpstream();
            context2 = ((UpstreamDownstreamRelationship) relationship).getDownstream();
            attributeRelContext1 = UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM;
            attributeRelContext2 = UPSTREAM_DOWNSTREAM_RELATIONSHIP__DOWNSTREAM;
        }
        if (context1 != null && !isContextPartOfMap(map, context1))
            error(String.format(RELATIONSHIP_CONTEXT_NOT_ON_MAP_ERROR_MESSAGE, context1.getName()), relationship, attributeRelContext1);
        if (context2 != null && !isContextPartOfMap(map, context2))
            error(String.format(RELATIONSHIP_CONTEXT_NOT_ON_MAP_ERROR_MESSAGE, context2.getName()), relationship, attributeRelContext2);
    }
}
Also used : SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Relationship(org.contextmapper.dsl.contextMappingDSL.Relationship) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) EReference(org.eclipse.emf.ecore.EReference) Check(org.eclipse.xtext.validation.Check)

Example 5 with SymmetricRelationship

use of org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship in project context-mapper-dsl by ContextMapper.

the class AbstractToggleSymmetricRelationshipRefactoring method doRefactor.

@Override
protected void doRefactor() {
    checkPreconditions();
    ContextMap contextMap = model.getMap();
    SymmetricRelationship originalRelationship = getMatchingRelationship();
    SymmetricRelationship newRelationship;
    if ("SharedKernel".equals(getRelationshipType())) {
        newRelationship = ContextMappingDSLFactory.eINSTANCE.createPartnership();
    } else {
        newRelationship = ContextMappingDSLFactory.eINSTANCE.createSharedKernel();
    }
    newRelationship.setImplementationTechnology(originalRelationship.getImplementationTechnology());
    newRelationship.setName(originalRelationship.getName());
    newRelationship.setParticipant1(originalRelationship.getParticipant1());
    newRelationship.setParticipant2(originalRelationship.getParticipant2());
    removeElementFromEList(contextMap.getRelationships(), originalRelationship);
    addElementToEList(contextMap.getRelationships(), newRelationship);
}
Also used : SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap)

Aggregations

SymmetricRelationship (org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship)6 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)4 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)3 Relationship (org.contextmapper.dsl.contextMappingDSL.Relationship)3 CMLResource (org.contextmapper.dsl.cml.CMLResource)2 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)2 Check (org.eclipse.xtext.validation.Check)2 Test (org.junit.jupiter.api.Test)2 File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 Paths (java.nio.file.Paths)1 List (java.util.List)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 FileUtils (org.apache.commons.io.FileUtils)1 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)1 CustomerSupplierRelationship (org.contextmapper.dsl.contextMappingDSL.CustomerSupplierRelationship)1 DownstreamRole (org.contextmapper.dsl.contextMappingDSL.DownstreamRole)1 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)1