Search in sources :

Example 1 with SplitBoundedContextByFeatures

use of org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures in project context-mapper-dsl by ContextMapper.

the class SplitBoundedContextByUseCasesTest method canSplitIfThereIsNothingToSplit.

@Test
void canSplitIfThereIsNothingToSplit() throws IOException {
    // given
    String inputModelName = "split-bc-by-use-cases-test-3-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    SplitBoundedContextByFeatures ar = new SplitBoundedContextByFeatures("CustomerManagement");
    ar.refactor(input);
    // then
    assertEquals(1, input.getContextMappingModel().getBoundedContexts().size());
}
Also used : SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) CMLResource(org.contextmapper.dsl.cml.CMLResource) Test(org.junit.jupiter.api.Test)

Example 2 with SplitBoundedContextByFeatures

use of org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures in project context-mapper-dsl by ContextMapper.

the class SplitBoundedContextByUseCasesTest method canSplitWithSingleUseCases.

@Test
void canSplitWithSingleUseCases() throws IOException {
    // given
    String inputModelName = "split-bc-by-use-cases-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    SplitBoundedContextByFeatures ar = new SplitBoundedContextByFeatures("CustomerManagement");
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(2, model.getBoundedContexts().size());
    List<String> boundedContextNames = model.getBoundedContexts().stream().map(bc -> bc.getName()).collect(Collectors.toList());
    assertTrue(boundedContextNames.contains("CustomerManagement"));
    assertTrue(boundedContextNames.contains("NewBoundedContext1"));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) IOException(java.io.IOException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors(java.util.stream.Collectors) CMLResource(org.contextmapper.dsl.cml.CMLResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) CMLResource(org.contextmapper.dsl.cml.CMLResource) Test(org.junit.jupiter.api.Test)

Example 3 with SplitBoundedContextByFeatures

use of org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures in project context-mapper-dsl by ContextMapper.

the class SplitBoundedContextByUseCasesTest method canSplitAndFixExposedAggregatesInContextMapRelationships.

@Test
void canSplitAndFixExposedAggregatesInContextMapRelationships() throws IOException {
    // given
    String inputModelName = "split-bc-by-use-cases-test-4-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    SplitBoundedContextByFeatures ar = new SplitBoundedContextByFeatures("CustomerManagement");
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(3, model.getBoundedContexts().size());
    List<String> boundedContextNames = model.getBoundedContexts().stream().map(bc -> bc.getName()).collect(Collectors.toList());
    assertTrue(boundedContextNames.contains("CustomerManagement"));
    assertTrue(boundedContextNames.contains("NewBoundedContext1"));
    List<UpstreamDownstreamRelationship> relationships = model.getMap().getRelationships().stream().filter(rel -> rel instanceof UpstreamDownstreamRelationship).map(rel -> (UpstreamDownstreamRelationship) rel).collect(Collectors.toList());
    assertEquals(2, relationships.size());
    assertEquals(1, relationships.get(0).getUpstreamExposedAggregates().size());
    assertEquals(1, relationships.get(1).getUpstreamExposedAggregates().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) IOException(java.io.IOException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors(java.util.stream.Collectors) CMLResource(org.contextmapper.dsl.cml.CMLResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) CMLResource(org.contextmapper.dsl.cml.CMLResource) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Test(org.junit.jupiter.api.Test)

Example 4 with SplitBoundedContextByFeatures

use of org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures in project context-mapper-dsl by ContextMapper.

the class SplitBoundedContextByUseCasesRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    BoundedContext bc = (BoundedContext) getSelectedElement();
    SemanticCMLRefactoring ar = new SplitBoundedContextByFeatures(bc.getName());
    ar.refactor(resource, getAllResources());
    ar.persistChanges(serializer);
}
Also used : SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) SemanticCMLRefactoring(org.contextmapper.dsl.refactoring.SemanticCMLRefactoring) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext)

Example 5 with SplitBoundedContextByFeatures

use of org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures in project context-mapper-dsl by ContextMapper.

the class SplitBoundedContextByUseCasesTest method canUpdateContextMapInDifferentFile.

@Test
void canUpdateContextMapInDifferentFile() throws IOException {
    // given
    CMLResource mainResource = getResourceCopyOfTestCML("split-bc-by-use-cases-test-5-input-2.cml");
    ResourceSet additionalResources = getResourceSetOfTestCMLFiles("split-bc-by-use-cases-test-5-input-1.cml");
    // when
    SplitBoundedContextByFeatures ar = new SplitBoundedContextByFeatures("CustomerManagement");
    ar.refactor(mainResource, additionalResources);
    ar.persistChanges(serializer);
    CMLResource contextMapResource = new CMLResource(additionalResources.getResources().stream().filter(r -> r.getURI().toString().endsWith("split-bc-by-use-cases-test-5-input-1.cml")).findFirst().get());
    contextMapResource = reloadResource(contextMapResource);
    // then
    ContextMappingModel model = contextMapResource.getContextMappingModel();
    assertEquals(2, model.getMap().getRelationships().size());
    UpstreamDownstreamRelationship rel1 = (UpstreamDownstreamRelationship) model.getMap().getRelationships().get(0);
    UpstreamDownstreamRelationship rel2 = (UpstreamDownstreamRelationship) model.getMap().getRelationships().get(1);
    assertEquals(1, rel1.getUpstreamExposedAggregates().size());
    assertEquals(1, rel2.getUpstreamExposedAggregates().size());
}
Also used : Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) IOException(java.io.IOException) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collectors(java.util.stream.Collectors) CMLResource(org.contextmapper.dsl.cml.CMLResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) SplitBoundedContextByFeatures(org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures) CMLResource(org.contextmapper.dsl.cml.CMLResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Test(org.junit.jupiter.api.Test)

Aggregations

SplitBoundedContextByFeatures (org.contextmapper.dsl.refactoring.SplitBoundedContextByFeatures)6 CMLResource (org.contextmapper.dsl.cml.CMLResource)5 Test (org.junit.jupiter.api.Test)5 IOException (java.io.IOException)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)4 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)4 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)4 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)1 SemanticCMLRefactoring (org.contextmapper.dsl.refactoring.SemanticCMLRefactoring)1