Search in sources :

Example 96 with CMLResource

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

the class ExtractAggregatesByCohesionTest method canExtractAggregatesByGivenInputList.

@Test
void canExtractAggregatesByGivenInputList() throws IOException {
    // given
    String inputModelName = "extract-aggregates-by-nfr-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    List<String> aggregatesToExtract = Arrays.asList(new String[] { "Customers", "Addresses" });
    ExtractAggregatesByCohesion ar = new ExtractAggregatesByCohesion("CustomerManagement", "CustomerManagement_Extracted", aggregatesToExtract);
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(3, model.getBoundedContexts().size());
    Optional<BoundedContext> bc = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement")).findFirst();
    Optional<BoundedContext> newBC = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement_Extracted")).findFirst();
    assertTrue(bc.isPresent());
    assertTrue(newBC.isPresent());
    assertEquals(1, bc.get().getAggregates().size());
    assertEquals(2, newBC.get().getAggregates().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Arrays(java.util.Arrays) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Lists(com.google.common.collect.Lists) 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) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Test(org.junit.jupiter.api.Test)

Example 97 with CMLResource

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

the class ExtractAggregatesByCohesionTest method canExtractAggregatesAndFixExposedReferencesInContextMap.

@Test
void canExtractAggregatesAndFixExposedReferencesInContextMap() throws IOException {
    // given
    String inputModelName = "extract-aggregates-by-nfr-test-2-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    List<String> aggregatesToExtract = Arrays.asList(new String[] { "Addresses" });
    ExtractAggregatesByCohesion ar = new ExtractAggregatesByCohesion("CustomerManagement", "CustomerManagement_Extracted", aggregatesToExtract);
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(3, model.getBoundedContexts().size());
    assertEquals(3, model.getMap().getRelationships().size());
    Optional<BoundedContext> bc = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement")).findFirst();
    Optional<BoundedContext> newBC = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement_Extracted")).findFirst();
    assertTrue(bc.isPresent());
    assertTrue(newBC.isPresent());
    assertEquals(2, bc.get().getAggregates().size());
    assertEquals(1, newBC.get().getAggregates().size());
    List<UpstreamDownstreamRelationship> relationships = model.getMap().getRelationships().stream().filter(rel -> rel instanceof UpstreamDownstreamRelationship).map(rel -> (UpstreamDownstreamRelationship) rel).collect(Collectors.toList());
    UpstreamDownstreamRelationship rel1 = relationships.get(0);
    UpstreamDownstreamRelationship rel2 = relationships.get(1);
    assertEquals("CustomerManagement", rel1.getUpstream().getName());
    assertEquals("CustomerManagement_Extracted", rel2.getUpstream().getName());
    assertEquals("AnotherContext", rel1.getDownstream().getName());
    assertEquals("AnotherContext", rel2.getDownstream().getName());
    assertEquals(1, rel1.getUpstreamExposedAggregates().size());
    assertEquals("Customers", rel1.getUpstreamExposedAggregates().get(0).getName());
    assertEquals(1, rel2.getUpstreamExposedAggregates().size());
    assertEquals("Addresses", rel2.getUpstreamExposedAggregates().get(0).getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Arrays(java.util.Arrays) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Lists(com.google.common.collect.Lists) 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) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Test(org.junit.jupiter.api.Test)

Example 98 with CMLResource

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

the class ExtractAggregatesByCohesionTest method noErrorIfAggregateIsGivenWhichDoesNotExist.

@Test
void noErrorIfAggregateIsGivenWhichDoesNotExist() throws IOException {
    // given
    String inputModelName = "extract-aggregates-by-nfr-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    List<String> aggregatesToExtract = Arrays.asList(new String[] { "Customers", "Addresses", "ThisAggregateDoesNotExist" });
    ExtractAggregatesByCohesion ar = new ExtractAggregatesByCohesion("CustomerManagement", "CustomerManagement_Extracted", aggregatesToExtract);
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(3, model.getBoundedContexts().size());
    Optional<BoundedContext> bc = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement")).findFirst();
    Optional<BoundedContext> newBC = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement_Extracted")).findFirst();
    assertTrue(bc.isPresent());
    assertTrue(newBC.isPresent());
    assertEquals(1, bc.get().getAggregates().size());
    assertEquals(2, newBC.get().getAggregates().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Arrays(java.util.Arrays) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Lists(com.google.common.collect.Lists) 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) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Test(org.junit.jupiter.api.Test)

Example 99 with CMLResource

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

the class ExtractAggregatesByCohesionTest method noErrorIfContextMapIsNull.

@Test
void noErrorIfContextMapIsNull() throws IOException {
    // given
    String inputModelName = "extract-aggregates-by-nfr-test-3-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    List<String> aggregatesToExtract = Arrays.asList(new String[] { "Customers", "Addresses" });
    ExtractAggregatesByCohesion ar = new ExtractAggregatesByCohesion("CustomerManagement", "CustomerManagement_Extracted", aggregatesToExtract);
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(2, model.getBoundedContexts().size());
    Optional<BoundedContext> bc = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement")).findFirst();
    Optional<BoundedContext> newBC = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement_Extracted")).findFirst();
    assertTrue(bc.isPresent());
    assertTrue(newBC.isPresent());
    assertEquals(1, bc.get().getAggregates().size());
    assertEquals(2, newBC.get().getAggregates().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Arrays(java.util.Arrays) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Lists(com.google.common.collect.Lists) 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) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Test(org.junit.jupiter.api.Test)

Example 100 with CMLResource

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

the class ExtractAggregatesByCohesionTest method noErrorIfNoAggregatesGivenAsParameter.

@Test
void noErrorIfNoAggregatesGivenAsParameter() throws IOException {
    // given
    String inputModelName = "extract-aggregates-by-nfr-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    List<String> aggregatesToExtract = Lists.newArrayList();
    ExtractAggregatesByCohesion ar = new ExtractAggregatesByCohesion("CustomerManagement", "CustomerManagement_Extracted", aggregatesToExtract);
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(2, model.getBoundedContexts().size());
    Optional<BoundedContext> bc = model.getBoundedContexts().stream().filter(b -> b.getName().equals("CustomerManagement")).findFirst();
    assertTrue(bc.isPresent());
    assertEquals(3, bc.get().getAggregates().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Arrays(java.util.Arrays) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Lists(com.google.common.collect.Lists) 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) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) CMLResource(org.contextmapper.dsl.cml.CMLResource) ExtractAggregatesByCohesion(org.contextmapper.dsl.refactoring.ExtractAggregatesByCohesion) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) 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