Search in sources :

Example 1 with MergeBoundedContextsRefactoring

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

the class MergeBoundedContextsTest method canFixImportsWhenMergingAcrossFiles.

@Test
void canFixImportsWhenMergingAcrossFiles() throws IOException {
    // given
    CMLResource mainResource = getResourceCopyOfTestCML("merge-bounded-contexts-fix-import-test-1.cml");
    ResourceSet additionalResources = getResourceSetOfTestCMLFiles("merge-bounded-contexts-fix-import-test-2.cml", "merge-bounded-contexts-fix-import-test-3.cml", "merge-bounded-contexts-fix-import-test-4.cml");
    // when
    MergeBoundedContextsRefactoring ar = new MergeBoundedContextsRefactoring("CustomerManagement", "AnotherContext");
    ar.refactor(mainResource, additionalResources);
    ar.persistChanges(serializer);
    mainResource = reloadResource(mainResource);
    // then
    CMLResource updatedImportResource = new CMLResource(additionalResources.getResources().stream().filter(r -> r.getURI().toString().endsWith("merge-bounded-contexts-fix-import-test-4.cml")).findFirst().get());
    updatedImportResource = reloadResource(updatedImportResource);
    Optional<Import> neededImport = updatedImportResource.getContextMappingModel().getImports().stream().filter(i -> i.getImportURI().endsWith("merge-bounded-contexts-fix-import-test-3.cml")).findFirst();
    assertTrue(neededImport.isPresent());
}
Also used : SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) Import(org.contextmapper.dsl.contextMappingDSL.Import) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) IOException(java.io.IOException) KnowledgeLevel(org.contextmapper.dsl.contextMappingDSL.KnowledgeLevel) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) BoundedContextType(org.contextmapper.dsl.contextMappingDSL.BoundedContextType) 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) 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) Import(org.contextmapper.dsl.contextMappingDSL.Import) CMLResource(org.contextmapper.dsl.cml.CMLResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) Test(org.junit.jupiter.api.Test)

Example 2 with MergeBoundedContextsRefactoring

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

the class MergeBoundedContextsTest method doNotMergeIfBC1DoesNotExist.

@Test
void doNotMergeIfBC1DoesNotExist() throws IOException {
    // given
    String inputModelName = "merge-bounded-contexts-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    MergeBoundedContextsRefactoring refactoring = new MergeBoundedContextsRefactoring("ThisBCDoesNotExist", "AnotherContext");
    // when
    refactoring.refactor(input);
    // then
    assertEquals(2, input.getContextMappingModel().getBoundedContexts().size());
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) Test(org.junit.jupiter.api.Test)

Example 3 with MergeBoundedContextsRefactoring

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

the class MergeBoundedContextsTest method doNotMergeIfBC2DoesNotExist.

@Test
void doNotMergeIfBC2DoesNotExist() throws IOException {
    // given
    String inputModelName = "merge-bounded-contexts-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    MergeBoundedContextsRefactoring refactoring = new MergeBoundedContextsRefactoring("CustomerManagement", "ThisBCDoesNotExist");
    // when
    refactoring.refactor(input);
    // then
    assertEquals(2, input.getContextMappingModel().getBoundedContexts().size());
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) Test(org.junit.jupiter.api.Test)

Example 4 with MergeBoundedContextsRefactoring

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

the class SuspendPartnershipRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    Partnership partnership = (Partnership) getSelectedElement();
    SuspendPartnershipContext refactoringContext = new SuspendPartnershipContext(partnership.getParticipant1().getName(), partnership.getParticipant2().getName());
    new WizardDialog(HandlerUtil.getActiveShell(event), new SuspendPartnershipRefactoringWizard(refactoringContext, executionContext -> {
        if (refactoringContext.getMode() == SuspendPartnershipMode.MERGE_BOUNDED_CONTEXTS) {
            // just use the 'Merge Bounded Contexts' AR in this case ...
            return finishRefactoring(new MergeBoundedContextsRefactoring(executionContext.getMergeModeSelectedBoundedContext1(), executionContext.getMergeModeSelectedBoundedContext2(), executionContext.isMergeModeTakeAttributesFromSecondBoundedContext()), resource, event);
        } else if (refactoringContext.getMode() == SuspendPartnershipMode.EXTRACT_NEW_BOUNDED_CONTEXT) {
            return finishRefactoring(new ExtractPartnershipRefactoring(refactoringContext.getBoundedContext1(), refactoringContext.getBoundedContext2()), resource, event);
        } else {
            String upstream = refactoringContext.getBoundedContext1();
            String downstream = refactoringContext.getBoundedContext2();
            if (refactoringContext.getReplaceModeUpstreamBoundedContext().equals(refactoringContext.getBoundedContext2())) {
                upstream = refactoringContext.getBoundedContext2();
                downstream = refactoringContext.getBoundedContext1();
            }
            return finishRefactoring(new ChangePartnershipToUpstreamDownstreamRefactoring(upstream, downstream), resource, event);
        }
    })).open();
}
Also used : ChangePartnershipToUpstreamDownstreamRefactoring(org.contextmapper.dsl.refactoring.ChangePartnershipToUpstreamDownstreamRefactoring) Partnership(org.contextmapper.dsl.contextMappingDSL.Partnership) SuspendPartnershipRefactoringWizard(org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipRefactoringWizard) SuspendPartnershipContext(org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipContext) WizardDialog(org.eclipse.jface.wizard.WizardDialog) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring)

Example 5 with MergeBoundedContextsRefactoring

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

the class MergeBoundedContextsTest method canMergeWithModules.

@Test
void canMergeWithModules() throws IOException {
    // given
    String inputModelName = "merge-bounded-contexts-test-2-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    MergeBoundedContextsRefactoring refactoring = new MergeBoundedContextsRefactoring("CustomerManagement", "AnotherContext");
    // when
    refactoring.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(1, model.getBoundedContexts().size());
    assertEquals("CustomerManagement", model.getBoundedContexts().get(0).getName());
    List<String> moduleNames = model.getBoundedContexts().get(0).getModules().stream().map(a -> a.getName()).collect(Collectors.toList());
    assertTrue(moduleNames.contains("mod1"));
    assertTrue(moduleNames.contains("mod2"));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) Import(org.contextmapper.dsl.contextMappingDSL.Import) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) IOException(java.io.IOException) KnowledgeLevel(org.contextmapper.dsl.contextMappingDSL.KnowledgeLevel) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) BoundedContextType(org.contextmapper.dsl.contextMappingDSL.BoundedContextType) 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) 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) MergeBoundedContextsRefactoring(org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring) Test(org.junit.jupiter.api.Test)

Aggregations

MergeBoundedContextsRefactoring (org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring)20 CMLResource (org.contextmapper.dsl.cml.CMLResource)17 Test (org.junit.jupiter.api.Test)17 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)12 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)11 SymmetricRelationship (org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship)6 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)6 IOException (java.io.IOException)5 List (java.util.List)5 Optional (java.util.Optional)5 Collectors (java.util.stream.Collectors)5 BoundedContextType (org.contextmapper.dsl.contextMappingDSL.BoundedContextType)5 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)5 Import (org.contextmapper.dsl.contextMappingDSL.Import)5 KnowledgeLevel (org.contextmapper.dsl.contextMappingDSL.KnowledgeLevel)5 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertNull (org.junit.jupiter.api.Assertions.assertNull)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2