use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.
the class SplitAggregateByEntitiesTest method canSplitInModule.
@Test
void canSplitInModule() throws IOException {
// given
String inputModelName = "split-agg-by-entities-test-2-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
SplitAggregateByEntitiesRefactoring refactoring = new SplitAggregateByEntitiesRefactoring("Customers");
// when
refactoring.refactor(input);
refactoring.persistChanges(serializer);
// then
BoundedContext bc = reloadResource(input).getContextMappingModel().getBoundedContexts().get(0);
SculptorModule testModule = bc.getModules().get(0);
assertEquals(2, testModule.getAggregates().size());
for (Aggregate aggregate : testModule.getAggregates()) {
assertEquals(1, aggregate.getDomainObjects().size());
}
List<String> aggregateNames = testModule.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
assertTrue(aggregateNames.contains("Customers"));
assertTrue(aggregateNames.contains("Account"));
}
use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.
the class SplitAggregateByEntitiesTest method canHandleContextMapInDifferentFile.
@Test
void canHandleContextMapInDifferentFile() throws IOException {
// given
CMLResource mainResource = getResourceCopyOfTestCML("split-agg-by-entities-test-4-input-2.cml");
ResourceSet additionalResources = getResourceSetOfTestCMLFiles("split-agg-by-entities-test-4-input-1.cml");
// when
SplitAggregateByEntitiesRefactoring ar = new SplitAggregateByEntitiesRefactoring("Customers");
ar.refactor(mainResource, additionalResources);
ar.persistChanges(serializer);
CMLResource contextMapResource = new CMLResource(additionalResources.getResources().stream().filter(r -> r.getURI().toString().endsWith("split-agg-by-entities-test-4-input-1.cml")).findFirst().get());
contextMapResource = reloadResource(contextMapResource);
// then
ContextMap contextMap = contextMapResource.getContextMappingModel().getMap();
assertEquals(2, contextMap.getBoundedContexts().size());
UpstreamDownstreamRelationship rel = (UpstreamDownstreamRelationship) contextMap.getRelationships().get(0);
assertEquals(2, rel.getUpstreamExposedAggregates().size());
}
use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.
the class SplitAggregateByEntitiesTest method canSplitWithTwoAggregates.
@Test
void canSplitWithTwoAggregates() throws IOException {
// given
String inputModelName = "split-agg-by-entities-test-1-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
SplitAggregateByEntitiesRefactoring refactoring = new SplitAggregateByEntitiesRefactoring("Customers");
// when
refactoring.refactor(input);
refactoring.persistChanges(serializer);
// then
BoundedContext bc = reloadResource(input).getContextMappingModel().getBoundedContexts().get(0);
assertEquals(2, bc.getAggregates().size());
for (Aggregate aggregate : bc.getAggregates()) {
assertEquals(1, aggregate.getDomainObjects().size());
}
List<String> aggregateNames = bc.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
assertTrue(aggregateNames.contains("Customers"));
assertTrue(aggregateNames.contains("Account"));
for (Aggregate aggregate : bc.getAggregates()) {
SimpleDomainObject obj = aggregate.getDomainObjects().get(0);
if (obj instanceof DomainObject)
assertTrue(((DomainObject) obj).isAggregateRoot());
}
}
use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.
the class SplitBoundedContextByOwnerTest method canSplitWithMultipleAggregatesPerOwner.
@Test
void canSplitWithMultipleAggregatesPerOwner() throws IOException {
// given
String inputModelName = "split-bc-by-owner-test-2-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
// when
SplitBoundedContextByOwner ar = new SplitBoundedContextByOwner("CustomerManagement");
ar.refactor(input);
// then
ContextMappingModel model = input.getContextMappingModel();
assertEquals(4, model.getBoundedContexts().size());
List<String> boundedContextNames = model.getBoundedContexts().stream().map(bc -> bc.getName()).collect(Collectors.toList());
assertTrue(boundedContextNames.contains("CustomerManagement"));
assertTrue(boundedContextNames.contains("NewBoundedContext1"));
}
use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.
the class SplitBoundedContextByOwnerTest method canSplitIfThereIsNothingToSplit.
@Test
void canSplitIfThereIsNothingToSplit() throws IOException {
// given
String inputModelName = "split-bc-by-owner-test-3-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
// when
SplitBoundedContextByOwner ar = new SplitBoundedContextByOwner("CustomerManagement");
ar.refactor(input);
// then
assertEquals(1, input.getContextMappingModel().getBoundedContexts().size());
}
Aggregations