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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations