Search in sources :

Example 1 with UpstreamDownstreamRelationship

use of org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship in project context-mapper-dsl by ContextMapper.

the class SplitAggregateByEntitiesTest method canHandleContextMapInDifferentFile.

@Test
void canHandleContextMapInDifferentFile() throws IOException {
    // given
    CMLResource mainResource = getResourceCopyOfTestCML("split-agg-by-entities-test-4-input-2.cml");
    ResourceSet additionalResources = getResourceSetOfTestCMLFiles("split-agg-by-entities-test-4-input-1.cml");
    // when
    SplitAggregateByEntitiesRefactoring ar = new SplitAggregateByEntitiesRefactoring("Customers");
    ar.refactor(mainResource, additionalResources);
    ar.persistChanges(serializer);
    CMLResource contextMapResource = new CMLResource(additionalResources.getResources().stream().filter(r -> r.getURI().toString().endsWith("split-agg-by-entities-test-4-input-1.cml")).findFirst().get());
    contextMapResource = reloadResource(contextMapResource);
    // then
    ContextMap contextMap = contextMapResource.getContextMappingModel().getMap();
    assertEquals(2, contextMap.getBoundedContexts().size());
    UpstreamDownstreamRelationship rel = (UpstreamDownstreamRelationship) contextMap.getRelationships().get(0);
    assertEquals(2, rel.getUpstreamExposedAggregates().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) 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) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) 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) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Example 2 with UpstreamDownstreamRelationship

use of org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship 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 3 with UpstreamDownstreamRelationship

use of org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship in project context-mapper-dsl by ContextMapper.

the class SplitSystemIntoSubsystemsTest method canSwitchIntegrationTypeToACL.

@Test
public void canSwitchIntegrationTypeToACL() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("split-system-tier-test-5-input.cml");
    SplitSystemIntoSubsystems ar = new SplitSystemIntoSubsystems("TestBackend", "TestBackendLogic", "TestBackendDatabase");
    ar.setIntegrationType(ACL);
    // when
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertNotNull(model.getMap());
    assertEquals(1, model.getMap().getRelationships().size());
    UpstreamDownstreamRelationship relationship = (UpstreamDownstreamRelationship) model.getMap().getRelationships().get(0);
    assertEquals("TestBackendDatabase", relationship.getDownstream().getName());
    assertEquals("TestBackendLogic", relationship.getUpstream().getName());
    assertTrue(relationship.getUpstreamRoles().contains(UpstreamRole.PUBLISHED_LANGUAGE));
    assertTrue(relationship.getDownstreamRoles().contains(DownstreamRole.ANTICORRUPTION_LAYER));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with UpstreamDownstreamRelationship

use of org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship 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 5 with UpstreamDownstreamRelationship

use of org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship in project context-mapper-dsl by ContextMapper.

the class DeriveFrontendAndBackendSystemsFromFeatureTest method canChangeDownstreamRole.

@Test
public void canChangeDownstreamRole() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("derive-frontend-backend-from-feature-test-1-input.cml");
    DeriveFrontendAndBackendSystemsFromFeature ar = new DeriveFrontendAndBackendSystemsFromFeature("TestFeature", ACL);
    // when
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    UpstreamDownstreamRelationship relationship = (UpstreamDownstreamRelationship) reloadResource(input).getContextMappingModel().getMap().getRelationships().get(0);
    assertFalse(relationship.getDownstreamRoles().contains(DownstreamRole.CONFORMIST));
    assertTrue(relationship.getDownstreamRoles().contains(DownstreamRole.ANTICORRUPTION_LAYER));
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)44 Test (org.junit.jupiter.api.Test)29 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)28 CMLResource (org.contextmapper.dsl.cml.CMLResource)25 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)23 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)23 Collectors (java.util.stream.Collectors)17 List (java.util.List)15 IOException (java.io.IOException)14 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)14 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)14 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)11 Optional (java.util.Optional)8 Relationship (org.contextmapper.dsl.contextMappingDSL.Relationship)8 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)8 SymmetricRelationship (org.contextmapper.dsl.contextMappingDSL.SymmetricRelationship)6 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)5 DomainObject (org.contextmapper.tactic.dsl.tacticdsl.DomainObject)5