Search in sources :

Example 16 with CMLResource

use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.

the class SplitSystemIntoSubsystemsTest method canSplitTierIfNewSystemNamesAlreadyExist.

@ParameterizedTest
@ValueSource(strings = { "split-system-tier-test-3" })
public void canSplitTierIfNewSystemNamesAlreadyExist(String testBasefileName) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(testBasefileName + "-input.cml");
    SplitSystemIntoSubsystems ar = new SplitSystemIntoSubsystems("TestBackend", "TestBackendLogic", "TestBackendDatabase");
    // when
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    String dslText = FileUtils.readFileToString(new File(input.getURI().toFileString()), "UTF-8");
    String expectedResult = FileUtils.readFileToString(new File(Paths.get("").toAbsolutePath().toString(), "/integ-test-files/refactorings/" + testBasefileName + "-output.cml"), Charset.forName("UTF-8"));
    assertEquals(expectedResult, dslText);
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) File(java.io.File) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 17 with CMLResource

use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.

the class SplitSystemIntoSubsystemsTest method canRenameContextInRelationships.

@Test
public void canRenameContextInRelationships() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("split-system-tier-test-7-input.cml");
    SplitSystemIntoSubsystems ar = new SplitSystemIntoSubsystems("TestBackend", "TestBackendLogic", "TestBackendDatabase");
    // when
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(3, model.getBoundedContexts().size());
    assertTrue(getBoundedContextNames(model.getBoundedContexts()).contains("TestBackendLogic"));
    assertFalse(getBoundedContextNames(model.getBoundedContexts()).contains("TestBackend"));
    Set<String> namesOnContextMap = getBoundedContextNames(model.getMap().getBoundedContexts());
    assertTrue(namesOnContextMap.contains("TestBackendLogic"));
    assertFalse(namesOnContextMap.contains("TestBackend"));
    UpstreamDownstreamRelationship upDownRel1 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("upDownTestRel1")).map(r -> (UpstreamDownstreamRelationship) r).findFirst().get();
    UpstreamDownstreamRelationship upDownRel2 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("upDownTestRel2")).map(r -> (UpstreamDownstreamRelationship) r).findFirst().get();
    SymmetricRelationship symRel1 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("symTestRel1")).map(r -> (SymmetricRelationship) r).findFirst().get();
    SymmetricRelationship symRel2 = model.getMap().getRelationships().stream().filter(r -> r.getName().equals("symTestRel2")).map(r -> (SymmetricRelationship) r).findFirst().get();
    assertEquals("TestBackendLogic", upDownRel1.getUpstream().getName());
    assertEquals("TestBackendLogic", upDownRel2.getDownstream().getName());
    assertEquals("TestBackendLogic", symRel1.getParticipant1().getName());
    assertEquals("TestBackendLogic", symRel2.getParticipant2().getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) CsvSource(org.junit.jupiter.params.provider.CsvSource) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) UpstreamRole(org.contextmapper.dsl.contextMappingDSL.UpstreamRole) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertFalse(org.junit.jupiter.api.Assertions.assertFalse) Charset(java.nio.charset.Charset) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ACL(org.contextmapper.dsl.refactoring.ContextSplittingIntegrationType.ACL) ValueSource(org.junit.jupiter.params.provider.ValueSource) Set(java.util.Set) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Collectors(java.util.stream.Collectors) File(java.io.File) Test(org.junit.jupiter.api.Test) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Paths(java.nio.file.Paths) DownstreamRole(org.contextmapper.dsl.contextMappingDSL.DownstreamRole) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) NullSource(org.junit.jupiter.params.provider.NullSource) SplitBoundedContextRelationshipType(org.contextmapper.dsl.refactoring.SplitSystemIntoSubsystems.SplitBoundedContextRelationshipType) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) CMLResource(org.contextmapper.dsl.cml.CMLResource) SymmetricRelationship(org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with CMLResource

use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.

the class SplitSystemIntoSubsystemsTest method canCheckIfBoundedContextNameExists.

@ParameterizedTest
@ValueSource(strings = { "SomeContextThatDoesNotExist" })
@NullSource
public void canCheckIfBoundedContextNameExists(String inputBoundedContextName) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("split-system-tier-test-1-input.cml");
    SplitSystemIntoSubsystems ar = new SplitSystemIntoSubsystems(inputBoundedContextName, "NewName4ExistingTier", "NewTierName");
    // when, then
    assertThrows(RefactoringInputException.class, () -> {
        ar.refactor(input);
    });
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) NullSource(org.junit.jupiter.params.provider.NullSource)

Example 19 with CMLResource

use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.

the class SwitchFromPartnershipToSharedKernelRefactoringTest method canCheck4MultipleSKRelationships.

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

Example 20 with CMLResource

use of org.contextmapper.dsl.cml.CMLResource in project context-mapper-dsl by ContextMapper.

the class SwitchFromPartnershipToSharedKernelRefactoringTest method canCheck4NullBoundedContext2.

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

Aggregations

CMLResource (org.contextmapper.dsl.cml.CMLResource)192 Test (org.junit.jupiter.api.Test)155 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)87 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)73 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)59 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)48 Collectors (java.util.stream.Collectors)44 IOException (java.io.IOException)43 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)43 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)41 List (java.util.List)40 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)35 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)32 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)29 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)28 Optional (java.util.Optional)27 File (java.io.File)26 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)22 ValueSource (org.junit.jupiter.params.provider.ValueSource)22 MergeBoundedContextsRefactoring (org.contextmapper.dsl.refactoring.MergeBoundedContextsRefactoring)14