Search in sources :

Example 1 with SculptorModule

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"));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 2 with SculptorModule

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());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) IOException(java.io.IOException) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) CMLResource(org.contextmapper.dsl.cml.CMLResource) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test)

Example 3 with SculptorModule

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());
}
Also used : SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with SculptorModule

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());
}
Also used : SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with SculptorModule

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"));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Volatility(org.contextmapper.dsl.contextMappingDSL.Volatility) IOException(java.io.IOException) KnowledgeLevel(org.contextmapper.dsl.contextMappingDSL.KnowledgeLevel) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Test(org.junit.jupiter.api.Test) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Aggregations

SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)22 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)15 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)15 Test (org.junit.jupiter.api.Test)13 CMLResource (org.contextmapper.dsl.cml.CMLResource)8 List (java.util.List)7 Collectors (java.util.stream.Collectors)6 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)6 Optional (java.util.Optional)5 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)5 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)4 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)4 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)4 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 IOException (java.io.IOException)3 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)3 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)3 DomainObject (org.contextmapper.tactic.dsl.tacticdsl.DomainObject)3 SimpleDomainObject (org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject)3