use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.
the class ContextMapSemanticsValidator method validateThatExposedAggregateIsPartOfUpstreamContext.
@Check
public void validateThatExposedAggregateIsPartOfUpstreamContext(final ContextMap map) {
for (Relationship rel : map.getRelationships()) {
if (rel instanceof UpstreamDownstreamRelationship) {
UpstreamDownstreamRelationship relationship = (UpstreamDownstreamRelationship) rel;
BoundedContext upstreamContext = ((UpstreamDownstreamRelationship) relationship).getUpstream();
int aggregateRefIndex = 0;
for (Aggregate aggregate : relationship.getUpstreamExposedAggregates()) {
List<String> aggregates = upstreamContext.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
for (SculptorModule module : upstreamContext.getModules()) {
aggregates.addAll(module.getAggregates().stream().map(b -> b.getName()).collect(Collectors.toList()));
}
if (!aggregates.contains(aggregate.getName()))
error(String.format(EXPOSED_AGGREGATE_NOT_PART_OF_UPSTREAM_CONTEXT, aggregate.getName(), upstreamContext.getName()), relationship, UPSTREAM_DOWNSTREAM_RELATIONSHIP__UPSTREAM_EXPOSED_AGGREGATES, aggregateRefIndex);
aggregateRefIndex++;
}
}
}
}
use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.
the class CMLModelObjectsResolvingHelper method resolveAllAccessibleAggregates.
public List<Aggregate> resolveAllAccessibleAggregates(BoundedContext bc) {
List<Aggregate> aggregates = Lists.newLinkedList();
aggregates.addAll(EcoreUtil2.eAllOfType(bc, Aggregate.class));
ContextMap contextMap = getContextMap(bc);
if (contextMap != null) {
for (Relationship rel : contextMap.getRelationships()) {
if (isBCDownstreamInRelationship(rel, bc))
aggregates.addAll(getExposedAggregates(rel));
}
}
return aggregates;
}
use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.
the class ExtractPartnershipRefactoringTest method canExtractPartnership.
@ParameterizedTest
@MethodSource("createExtractPartnershipParameters")
void canExtractPartnership(String inputFile, String resultingNewBC) throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML(inputFile);
// when
new ExtractPartnershipRefactoring("CustomerManagement", "AnotherContext").refactor(input);
// then
ContextMap map = input.getContextMappingModel().getMap();
BoundedContext bc1 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement")).findFirst().get();
BoundedContext bc2 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("AnotherContext")).findFirst().get();
BoundedContext newBC = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals(resultingNewBC)).findFirst().get();
assertEquals(2, map.getRelationships().size());
assertEquals(3, map.getBoundedContexts().size());
Relationship rel1 = map.getRelationships().get(0);
Relationship rel2 = map.getRelationships().get(1);
assertTrue(rel1 instanceof UpstreamDownstreamRelationship);
assertTrue(rel2 instanceof UpstreamDownstreamRelationship);
UpstreamDownstreamRelationship upDown1 = (UpstreamDownstreamRelationship) rel1;
UpstreamDownstreamRelationship upDown2 = (UpstreamDownstreamRelationship) rel2;
assertTrue(upDown1.getUpstream().equals(newBC));
assertTrue(upDown1.getDownstream().equals(bc1));
assertTrue(upDown2.getUpstream().equals(newBC));
assertTrue(upDown2.getDownstream().equals(bc2));
}
use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.
the class ChangePartnershipToUpstreamDownstreamRefactoringTest method canChangePartnershipToUpstreamDownstream.
@Test
void canChangePartnershipToUpstreamDownstream() throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML("change-partnership-to-upstream-downstream-test-1-input.cml");
// when
SemanticCMLRefactoring ar = new ChangePartnershipToUpstreamDownstreamRefactoring("CustomerManagement", "AnotherContext");
ar.refactor(input);
ar.persistChanges(serializer);
// then
List<ContextMappingModel> contextMappingModels = IteratorExtensions.<ContextMappingModel>toList(Iterators.<ContextMappingModel>filter(reloadResource(input).getAllContents(), ContextMappingModel.class));
ContextMap map = contextMappingModels.get(0).getMap();
BoundedContext upstreamContext = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement")).findFirst().get();
BoundedContext downstreamContext = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("AnotherContext")).findFirst().get();
assertEquals(1, map.getRelationships().size());
Relationship rel = map.getRelationships().get(0);
assertTrue(rel instanceof UpstreamDownstreamRelationship);
UpstreamDownstreamRelationship upDown = (UpstreamDownstreamRelationship) rel;
assertTrue(upDown.getUpstream().equals(upstreamContext));
assertTrue(upDown.getDownstream().equals(downstreamContext));
}
use of org.contextmapper.dsl.contextMappingDSL.Relationship in project context-mapper-dsl by ContextMapper.
the class ExtractSharedKernelRefactoringTest method canExtractSharedKernel.
@ParameterizedTest
@MethodSource("createExtractSharedKernelParameters")
void canExtractSharedKernel(String inputFile, String resultingNewBC) throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML(inputFile);
// when
new ExtractSharedKernelRefactoring("CustomerManagement", "AnotherContext").refactor(input);
// then
ContextMap map = input.getContextMappingModel().getMap();
BoundedContext bc1 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement")).findFirst().get();
BoundedContext bc2 = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("AnotherContext")).findFirst().get();
BoundedContext newBC = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals(resultingNewBC)).findFirst().get();
assertEquals(2, map.getRelationships().size());
assertEquals(3, map.getBoundedContexts().size());
Relationship rel1 = map.getRelationships().get(0);
Relationship rel2 = map.getRelationships().get(1);
assertTrue(rel1 instanceof UpstreamDownstreamRelationship);
assertTrue(rel2 instanceof UpstreamDownstreamRelationship);
UpstreamDownstreamRelationship upDown1 = (UpstreamDownstreamRelationship) rel1;
UpstreamDownstreamRelationship upDown2 = (UpstreamDownstreamRelationship) rel2;
assertTrue(upDown1.getUpstream().equals(newBC));
assertTrue(upDown1.getDownstream().equals(bc1));
assertTrue(upDown2.getUpstream().equals(newBC));
assertTrue(upDown2.getDownstream().equals(bc2));
}
Aggregations