use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class DeriveFrontendAndBackendSystemsFromFeatureTest method canCopyBackendDomainModel.
@Test
public void canCopyBackendDomainModel() throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML("derive-frontend-backend-from-feature-test-5-input.cml");
DeriveFrontendAndBackendSystemsFromFeature ar = new DeriveFrontendAndBackendSystemsFromFeature("TestFeature", ACL);
ar.deriveViewModelInFronted(false);
// when
ar.refactor(input);
ar.persistChanges(serializer);
// then
BoundedContext backend = reloadResource(input).getContextMappingModel().getBoundedContexts().stream().filter(bc -> bc.getName().equals("TestFeatureBackend")).findFirst().get();
BoundedContext frontend = reloadResource(input).getContextMappingModel().getBoundedContexts().stream().filter(bc -> bc.getName().equals("TestFeatureFrontend")).findFirst().get();
assertNotNull(backend);
assertNotNull(frontend);
assertEquals(1, backend.getAggregates().size());
assertEquals(1, backend.getModules().size());
Aggregate aggregate = backend.getAggregates().get(0);
SculptorModule module = backend.getModules().get(0);
assertEquals("TestAggregateBackend", aggregate.getName());
assertEquals(1, aggregate.getDomainObjects().size());
assertEquals("TestModuleBackend", module.getName());
assertEquals(1, module.getAggregates().size());
Aggregate aggInModule = module.getAggregates().get(0);
assertEquals("TestAggregateInModuleBackend_2", aggInModule.getName());
assertEquals(1, aggInModule.getDomainObjects().size());
assertEquals(1, frontend.getAggregates().size());
assertEquals("ViewModel", frontend.getAggregates().get(0).getName());
assertEquals(0, frontend.getModules().size());
}
use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class MergeAggregatesTest method canHandleAggregateRoots.
@Test
void canHandleAggregateRoots() throws IOException {
// given
String inputModelName = "merge-aggregates-test-6-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
MergeAggregatesRefactoring refactoring = new MergeAggregatesRefactoring("agg1", "agg2", true);
// when
refactoring.refactor(input);
// then
ContextMappingModel model = input.getContextMappingModel();
assertEquals(1, model.getBoundedContexts().size());
BoundedContext bc = model.getBoundedContexts().get(0);
assertEquals(1, bc.getAggregates().size());
Aggregate aggregate = bc.getAggregates().get(0);
List<DomainObject> aggregateRoots = aggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).collect(Collectors.toList());
assertEquals(1, aggregateRoots.size());
}
use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class MergeAggregatesTest method canMergeAndUpdateContextMap.
@Test
void canMergeAndUpdateContextMap() throws IOException {
// given
String inputModelName = "merge-aggregates-test-3-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
MergeAggregatesRefactoring refactoring = new MergeAggregatesRefactoring("Customers", "Addresses");
// when
refactoring.refactor(input);
// then
ContextMappingModel model = input.getContextMappingModel();
assertEquals(2, model.getBoundedContexts().size());
BoundedContext bc = model.getBoundedContexts().get(0);
assertEquals("CustomerManagement", bc.getName());
List<String> aggregateNames = bc.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
assertEquals(1, aggregateNames.size());
assertTrue(aggregateNames.contains("Customers"));
Aggregate agg = bc.getAggregates().get(0);
assertEquals(3, agg.getDomainObjects().size());
List<String> domainObjectNames = agg.getDomainObjects().stream().map(o -> o.getName()).collect(Collectors.toList());
assertTrue(domainObjectNames.contains("Customer"));
assertTrue(domainObjectNames.contains("Account"));
assertTrue(domainObjectNames.contains("Address"));
ContextMap map = model.getMap();
assertEquals(2, map.getRelationships().size());
Optional<UpstreamDownstreamRelationship> relationshipOpt = map.getRelationships().stream().filter(rel -> rel instanceof UpstreamDownstreamRelationship).map(rel -> (UpstreamDownstreamRelationship) rel).findFirst();
assertTrue(relationshipOpt.isPresent());
UpstreamDownstreamRelationship relationship = relationshipOpt.get();
List<String> exposedAggregates = relationship.getUpstreamExposedAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
assertEquals(1, exposedAggregates.size());
assertTrue(exposedAggregates.contains("Customers"));
}
use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class ExtractSharedKernelRefactoringTest method canCreateAggregateInNewBoundedContext.
@Test
public void canCreateAggregateInNewBoundedContext() throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML("extract-shared-kernel-test-1-input.cml");
// when
new ExtractSharedKernelRefactoring("CustomerManagement", "AnotherContext").refactor(input);
// then
ContextMap map = input.getContextMappingModel().getMap();
BoundedContext newBC = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement_AnotherContext_SharedKernel")).findFirst().get();
assertEquals(1, newBC.getAggregates().size());
Aggregate aggregate = newBC.getAggregates().get(0);
assertEquals("SharedKernelAggregate", aggregate.getName());
assertEquals(1, aggregate.getDomainObjects().size());
assertEquals("SharedKernelRoot", aggregate.getDomainObjects().get(0).getName());
assertTrue(((Entity) aggregate.getDomainObjects().get(0)).isAggregateRoot());
}
use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class ExtractSuggestedServiceTest method canExtractServiceFromDDDSample.
@Test
public void canExtractServiceFromDDDSample() throws IOException {
// given
CMLResource model = getResourceCopyOfTestCML("extract-suggested-service-DDD-sample.cml");
BoundedContext contextToExtract = getResourceCopyOfTestCML("extract-suggested-service-DDD-sample_Markov_Clustering_Cut_1.cml").getContextMappingModel().getBoundedContexts().stream().filter(bc -> bc.getName().equals("Service_A")).findFirst().get();
// when
ExtractSuggestedService ar = new ExtractSuggestedService(contextToExtract, "ExtractedBC");
ar.refactor(model);
ar.persistChanges(serializer);
model = reloadResource(model);
// then
assertEquals(2, model.getContextMappingModel().getBoundedContexts().size());
BoundedContext newBC = model.getContextMappingModel().getBoundedContexts().stream().filter(bc -> bc.getName().equals("ExtractedBC")).findFirst().get();
assertNotNull(newBC);
assertEquals(1, newBC.getAggregates().size());
Aggregate aggregate = newBC.getAggregates().get(0);
assertNotNull(aggregate);
assertEquals(10, aggregate.getDomainObjects().size());
}
Aggregations