use of org.contextmapper.dsl.contextMappingDSL.SculptorModule 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.contextMappingDSL.SculptorModule in project context-mapper-dsl by ContextMapper.
the class ExtractIDValueObjectQuickFixTest method canExtractValueObjectFromPrimitiveAttributeInModule.
@Test
public void canExtractValueObjectFromPrimitiveAttributeInModule() throws IOException {
// given
CMLResource cmlResource = getResourceCopyOfTestCML("extract-vo-for-primitive-id-test-2.cml");
ContextMappingModel model = cmlResource.getContextMappingModel();
Attribute idAttr = EcoreUtil2.getAllContentsOfType(model, Attribute.class).stream().filter(a -> a.getName().equals("customerId")).findFirst().get();
// when
new ExtractIDValueObjectQuickFix().applyQuickfix(idAttr);
// then
SculptorModule module = model.getBoundedContexts().get(0).getModules().get(0);
assertEquals("TestModule", module.getName());
assertEquals(2, module.getDomainObjects().size());
Entity entity = (Entity) module.getDomainObjects().stream().filter(o -> o.getName().equals("Customer")).findFirst().get();
assertEquals(2, entity.getAttributes().size());
assertEquals(1, entity.getReferences().size());
ValueObject vo = (ValueObject) module.getDomainObjects().stream().filter(o -> o.getName().equals("CustomerId")).findFirst().get();
assertNotNull(vo);
assertEquals(1, vo.getAttributes().size());
assertEquals("id", vo.getAttributes().get(0).getName());
}
use of org.contextmapper.dsl.contextMappingDSL.SculptorModule 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.SculptorModule in project context-mapper-dsl by ContextMapper.
the class ExtractSuggestedServiceTest method canExtractServiceUsingModules.
@Test
public void canExtractServiceUsingModules() throws IOException {
// given
CMLResource model = getResourceCopyOfTestCML("extract-suggested-service-with-modules-test.cml");
BoundedContext contextToExtract = getResourceCopyOfTestCML("extract-suggested-service-with-modules-test_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 origBC = model.getContextMappingModel().getBoundedContexts().stream().filter(bc -> bc.getName().equals("Monolith")).findFirst().get();
BoundedContext newBC = model.getContextMappingModel().getBoundedContexts().stream().filter(bc -> bc.getName().equals("ExtractedBC")).findFirst().get();
assertNotNull(origBC);
assertNotNull(newBC);
assertEquals(2, origBC.getModules().size());
assertEquals(1, newBC.getAggregates().size());
SculptorModule mod1 = origBC.getModules().stream().filter(m -> m.getName().equals("Module1")).findFirst().get();
assertNotNull(mod1);
assertEquals(1, mod1.getDomainObjects().size());
}
use of org.contextmapper.dsl.contextMappingDSL.SculptorModule in project context-mapper-dsl by ContextMapper.
the class MergeAggregatesTest method canMergeAggregatesInModule.
@Test
void canMergeAggregatesInModule() throws IOException {
// given
String inputModelName = "merge-aggregates-test-2-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
MergeAggregatesRefactoring refactoring = new MergeAggregatesRefactoring("Customers", "Addresses");
// when
refactoring.refactor(input);
// then
ContextMappingModel model = input.getContextMappingModel();
assertEquals(1, model.getBoundedContexts().size());
BoundedContext bc = model.getBoundedContexts().get(0);
assertEquals("CustomerManagement", bc.getName());
SculptorModule module = bc.getModules().get(0);
List<String> aggregateNames = module.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
assertEquals(1, aggregateNames.size());
assertTrue(aggregateNames.contains("Customers"));
Aggregate agg = module.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"));
}
Aggregations