Search in sources :

Example 1 with ExtractSharedKernelRefactoring

use of org.contextmapper.dsl.refactoring.ExtractSharedKernelRefactoring 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 2 with ExtractSharedKernelRefactoring

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

the class ExtractSharedKernelRefactoringTest method canCheck4NoRelationshipAvailable.

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

Example 3 with ExtractSharedKernelRefactoring

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

the class ExtractSharedKernelRefactoringTest method canCheck4EqualBoundedContexts.

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

Example 4 with ExtractSharedKernelRefactoring

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

the class ExtractSharedKernelRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    SharedKernel sk = (SharedKernel) getSelectedElement();
    SemanticCMLRefactoring ar = new ExtractSharedKernelRefactoring(sk.getParticipant1().getName(), sk.getParticipant2().getName());
    ar.refactor(resource);
    ar.persistChanges(serializer);
}
Also used : SemanticCMLRefactoring(org.contextmapper.dsl.refactoring.SemanticCMLRefactoring) SharedKernel(org.contextmapper.dsl.contextMappingDSL.SharedKernel) ExtractSharedKernelRefactoring(org.contextmapper.dsl.refactoring.ExtractSharedKernelRefactoring)

Example 5 with ExtractSharedKernelRefactoring

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

the class ExtractSharedKernelRefactoringTest method canCheck4NullBoundedContext2.

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

Aggregations

ExtractSharedKernelRefactoring (org.contextmapper.dsl.refactoring.ExtractSharedKernelRefactoring)9 CMLResource (org.contextmapper.dsl.cml.CMLResource)7 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Test (org.junit.jupiter.api.Test)6 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)2 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)2 JsonPrimitive (com.google.gson.JsonPrimitive)1 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)1 Relationship (org.contextmapper.dsl.contextMappingDSL.Relationship)1 SharedKernel (org.contextmapper.dsl.contextMappingDSL.SharedKernel)1 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)1 SemanticCMLRefactoring (org.contextmapper.dsl.refactoring.SemanticCMLRefactoring)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1