Search in sources :

Example 6 with Aggregate

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());
}
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 7 with Aggregate

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());
}
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) CMLResource(org.contextmapper.dsl.cml.CMLResource) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 8 with Aggregate

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"));
}
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) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Example 9 with Aggregate

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

Example 10 with Aggregate

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());
}
Also used : 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)

Aggregations

Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)103 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)79 Test (org.junit.jupiter.api.Test)51 List (java.util.List)36 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)36 Collectors (java.util.stream.Collectors)35 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)35 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)28 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)26 CMLResource (org.contextmapper.dsl.cml.CMLResource)24 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)24 Optional (java.util.Optional)20 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)20 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)18 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)17 SimpleDomainObject (org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject)17 Set (java.util.Set)16 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)16 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)15 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)15