Search in sources :

Example 1 with SplitBoundedContextByOwner

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

the class SplitBoundedContextByOwnerTest method canSplitWithMultipleAggregatesPerOwner.

@Test
void canSplitWithMultipleAggregatesPerOwner() throws IOException {
    // given
    String inputModelName = "split-bc-by-owner-test-2-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    SplitBoundedContextByOwner ar = new SplitBoundedContextByOwner("CustomerManagement");
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(4, model.getBoundedContexts().size());
    List<String> boundedContextNames = model.getBoundedContexts().stream().map(bc -> bc.getName()).collect(Collectors.toList());
    assertTrue(boundedContextNames.contains("CustomerManagement"));
    assertTrue(boundedContextNames.contains("NewBoundedContext1"));
}
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) SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) 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) SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) CMLResource(org.contextmapper.dsl.cml.CMLResource) Test(org.junit.jupiter.api.Test)

Example 2 with SplitBoundedContextByOwner

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

the class SplitBoundedContextByOwnerTest method canSplitIfThereIsNothingToSplit.

@Test
void canSplitIfThereIsNothingToSplit() throws IOException {
    // given
    String inputModelName = "split-bc-by-owner-test-3-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    SplitBoundedContextByOwner ar = new SplitBoundedContextByOwner("CustomerManagement");
    ar.refactor(input);
    // then
    assertEquals(1, input.getContextMappingModel().getBoundedContexts().size());
}
Also used : SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) CMLResource(org.contextmapper.dsl.cml.CMLResource) Test(org.junit.jupiter.api.Test)

Example 3 with SplitBoundedContextByOwner

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

the class SplitBoundedContextByOwnerTest method canSplitByOwner.

@Test
void canSplitByOwner() throws IOException {
    // given
    String inputModelName = "split-bc-by-owner-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    // when
    SplitBoundedContextByOwner ar = new SplitBoundedContextByOwner("CustomerManagement");
    ar.refactor(input);
    // then
    ContextMappingModel model = input.getContextMappingModel();
    assertEquals(4, model.getBoundedContexts().size());
    List<String> boundedContextNames = model.getBoundedContexts().stream().map(bc -> bc.getName()).collect(Collectors.toList());
    assertTrue(boundedContextNames.contains("CustomerManagement"));
    assertTrue(boundedContextNames.contains("NewBoundedContext1"));
}
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) SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) 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) SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) CMLResource(org.contextmapper.dsl.cml.CMLResource) Test(org.junit.jupiter.api.Test)

Example 4 with SplitBoundedContextByOwner

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

the class StandaloneAPITest method canApplyRefactoring.

@Test
public void canApplyRefactoring() throws IOException {
    // given
    File originalFile = new File("./integ-test-files/standalone/refactoring-test.cml");
    File cmlTestFile = new File("./out/refactoring-test.cml");
    ensureFileDoesNotExist(cmlTestFile);
    FileUtils.copyFile(originalFile, cmlTestFile);
    StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI();
    CMLResource cml = contextMapper.loadCML(cmlTestFile);
    // when
    contextMapper.applyRefactoring(cml, new SplitBoundedContextByOwner("PolicyManagementContext"));
    // then
    ContextMappingModel model = cml.getContextMappingModel();
    assertEquals(10, model.getBoundedContexts().size());
    assertNotNull(model.getBoundedContexts().stream().filter(bc -> bc.getName().equals("NewBoundedContext1")).findFirst().get());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContextMapGenerator(org.contextmapper.dsl.generator.ContextMapGenerator) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) SaveOptions(org.eclipse.xtext.resource.SaveOptions) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) Test(org.junit.jupiter.api.Test) Charset(java.nio.charset.Charset) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) ContextMapFormat(org.contextmapper.dsl.generator.contextmap.ContextMapFormat) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) CMLResource(org.contextmapper.dsl.cml.CMLResource) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 5 with SplitBoundedContextByOwner

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

the class SplitBoundedContextByOwnerRefactoringHandler method executeRefactoring.

@Override
protected void executeRefactoring(CMLResource resource, ExecutionEvent event) {
    BoundedContext bc = (BoundedContext) getSelectedElement();
    SemanticCMLRefactoring ar = new SplitBoundedContextByOwner(bc.getName());
    ar.refactor(resource, getAllResources());
    ar.persistChanges(serializer);
}
Also used : SplitBoundedContextByOwner(org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner) SemanticCMLRefactoring(org.contextmapper.dsl.refactoring.SemanticCMLRefactoring) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext)

Aggregations

SplitBoundedContextByOwner (org.contextmapper.dsl.refactoring.SplitBoundedContextByOwner)7 CMLResource (org.contextmapper.dsl.cml.CMLResource)6 Test (org.junit.jupiter.api.Test)6 IOException (java.io.IOException)5 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)5 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)2 File (java.io.File)1 Charset (java.nio.charset.Charset)1 FileUtils (org.apache.commons.io.FileUtils)1 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)1 ContextMapGenerator (org.contextmapper.dsl.generator.ContextMapGenerator)1 ContextMapFormat (org.contextmapper.dsl.generator.contextmap.ContextMapFormat)1 SemanticCMLRefactoring (org.contextmapper.dsl.refactoring.SemanticCMLRefactoring)1 SaveOptions (org.eclipse.xtext.resource.SaveOptions)1