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());
}
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());
}
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++;
}
}
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);
}
}
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);
}
Aggregations