Search in sources :

Example 1 with ExtractPartnershipRefactoring

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

the class ExtractPartnershipRefactoringTest method canCheck4MultiplePartnershipRelationships.

@Test
void canCheck4MultiplePartnershipRelationships() throws IOException {
    // given
    String boundedContext1 = "CustomerManagement";
    String boundedContext2 = "AnotherContext";
    CMLResource input = getResourceCopyOfTestCML("extract-partnership-precondition-checks-multiple-rels-input.cml");
    // when, then
    Assertions.assertThrows(RefactoringInputException.class, () -> {
        new ExtractPartnershipRefactoring(boundedContext1, boundedContext2).refactor(input);
    });
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ExtractPartnershipRefactoring

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

the class ExtractPartnershipRefactoringTest method canCheck4NullBoundedContext2.

@Test
void canCheck4NullBoundedContext2() throws IOException {
    // given
    String boundedContext1 = null;
    String boundedContext2 = "TestContext";
    CMLResource input = getResourceCopyOfTestCML("extract-partnership-precondition-checks-input.cml");
    // when, then
    Assertions.assertThrows(RefactoringInputException.class, () -> {
        new ExtractPartnershipRefactoring(boundedContext1, boundedContext2).refactor(input);
    });
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ExtractPartnershipRefactoring

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

the class ExtractPartnershipRefactoringTest method canCheck4EqualBoundedContexts.

@Test
void canCheck4EqualBoundedContexts() throws IOException {
    // given
    String boundedContext1 = "TestContext";
    String boundedContext2 = "TestContext";
    CMLResource input = getResourceCopyOfTestCML("extract-partnership-precondition-checks-input.cml");
    // when, then
    Assertions.assertThrows(RefactoringInputException.class, () -> {
        new ExtractPartnershipRefactoring(boundedContext1, boundedContext2).refactor(input);
    });
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ExtractPartnershipRefactoring

use of org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring 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 ExtractPartnershipRefactoring

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

the class ExtractPartnershipRefactoringTest method canCreateAggregateInNewBoundedContext.

@Test
public void canCreateAggregateInNewBoundedContext() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("extract-partnership-test-1-input.cml");
    // when
    new ExtractPartnershipRefactoring("CustomerManagement", "AnotherContext").refactor(input);
    // then
    ContextMap map = input.getContextMappingModel().getMap();
    BoundedContext newBC = map.getBoundedContexts().stream().filter(bc -> bc.getName().equals("CustomerManagement_AnotherContext_Partnership")).findFirst().get();
    assertEquals(1, newBC.getAggregates().size());
    Aggregate aggregate = newBC.getAggregates().get(0);
    assertEquals("CommonModelAggregate", aggregate.getName());
    assertEquals(1, aggregate.getDomainObjects().size());
    assertEquals("CommonModelPartRoot", 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) ExtractPartnershipRefactoring(org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

ExtractPartnershipRefactoring (org.contextmapper.dsl.refactoring.ExtractPartnershipRefactoring)10 CMLResource (org.contextmapper.dsl.cml.CMLResource)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Test (org.junit.jupiter.api.Test)7 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)2 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)2 ChangePartnershipToUpstreamDownstreamRefactoring (org.contextmapper.dsl.refactoring.ChangePartnershipToUpstreamDownstreamRefactoring)2 JsonArray (com.google.gson.JsonArray)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)1 Partnership (org.contextmapper.dsl.contextMappingDSL.Partnership)1 Relationship (org.contextmapper.dsl.contextMappingDSL.Relationship)1 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)1 MergeBoundedContextsRefactoring (org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring)1 SuspendPartnershipMode (org.contextmapper.dsl.refactoring.SuspendPartnershipMode)1 SuspendPartnershipContext (org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipContext)1 SuspendPartnershipRefactoringWizard (org.contextmapper.dsl.ui.handler.wizard.SuspendPartnershipRefactoringWizard)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1