Search in sources :

Example 26 with CMLResource

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

the class StandaloneAPITest method canCreateNewCMLModelViaFile.

@Test
public void canCreateNewCMLModelViaFile() throws IOException {
    // given
    StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI();
    File file = new File("./out/test-new-cml-model-via-file.cml");
    // when
    ensureFileDoesNotExist(file);
    CMLResource newCMLModel = contextMapper.createCML(file);
    BoundedContext testContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    testContext.setName("TestContext");
    newCMLModel.getContextMappingModel().getBoundedContexts().add(testContext);
    newCMLModel.save(SaveOptions.defaultOptions().toOptionsMap());
    // then
    assertTrue(file.exists());
    assertEquals(System.lineSeparator() + System.lineSeparator() + "BoundedContext TestContext", FileUtils.readFileToString(file, Charset.forName("UTF-8")));
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) File(java.io.File) Test(org.junit.jupiter.api.Test)

Example 27 with CMLResource

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

the class StandaloneAPITest method canLoadCMLResource.

@Test
public void canLoadCMLResource() {
    // given
    StandaloneContextMapperAPI contextMapper = ContextMapperStandaloneSetup.getStandaloneAPI();
    // when
    CMLResource cml = contextMapper.loadCML("./integ-test-files/standalone/hello-world.cml");
    // then
    assertNotNull(cml);
    assertEquals(1, cml.getContextMappingModel().getBoundedContexts().size());
    assertEquals("HelloWorldContext", cml.getContextMappingModel().getBoundedContexts().get(0).getName());
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) Test(org.junit.jupiter.api.Test)

Example 28 with CMLResource

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

the class CreateMissingBoundedContextQuickFixTest method canCreateBoundedContext4ContextMapContext.

@Test
public void canCreateBoundedContext4ContextMapContext() throws IOException {
    // given
    CMLResource cmlResource = getResourceCopyOfTestCML("create-missing-bounded-context-test-1.cml");
    ContextMappingModel model = cmlResource.getContextMappingModel();
    // when
    new CreateMissingBoundedContextQuickFix("MissingContext").applyQuickfix2EObject(model.getMap());
    // then
    assertEquals(1, model.getBoundedContexts().size());
    assertEquals("MissingContext", model.getBoundedContexts().get(0).getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Test(org.junit.jupiter.api.Test)

Example 29 with CMLResource

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

the class ExtractIDValueObjectQuickFixTest method canExtractValueObjectFromPrimitiveAttributeInModule.

@Test
public void canExtractValueObjectFromPrimitiveAttributeInModule() throws IOException {
    // given
    CMLResource cmlResource = getResourceCopyOfTestCML("extract-vo-for-primitive-id-test-2.cml");
    ContextMappingModel model = cmlResource.getContextMappingModel();
    Attribute idAttr = EcoreUtil2.getAllContentsOfType(model, Attribute.class).stream().filter(a -> a.getName().equals("customerId")).findFirst().get();
    // when
    new ExtractIDValueObjectQuickFix().applyQuickfix(idAttr);
    // then
    SculptorModule module = model.getBoundedContexts().get(0).getModules().get(0);
    assertEquals("TestModule", module.getName());
    assertEquals(2, module.getDomainObjects().size());
    Entity entity = (Entity) module.getDomainObjects().stream().filter(o -> o.getName().equals("Customer")).findFirst().get();
    assertEquals(2, entity.getAttributes().size());
    assertEquals(1, entity.getReferences().size());
    ValueObject vo = (ValueObject) module.getDomainObjects().stream().filter(o -> o.getName().equals("CustomerId")).findFirst().get();
    assertNotNull(vo);
    assertEquals(1, vo.getAttributes().size());
    assertEquals("id", vo.getAttributes().get(0).getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) IOException(java.io.IOException) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) CMLResource(org.contextmapper.dsl.cml.CMLResource) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test)

Example 30 with CMLResource

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

the class ChangePartnershipToUpstreamDownstreamRefactoringTest method canCheck4EqualBoundedContexts.

@Test
void canCheck4EqualBoundedContexts() throws IOException {
    // given
    String boundedContext1 = "TestContext";
    String boundedContext2 = "TestContext";
    CMLResource input = getResourceCopyOfTestCML("change-partnership-to-upstream-downstream-precondition-checks-input.cml");
    // when, then
    Assertions.assertThrows(RefactoringInputException.class, () -> {
        new ChangePartnershipToUpstreamDownstreamRefactoring(boundedContext1, boundedContext2).refactor(input);
    });
}
Also used : CMLResource(org.contextmapper.dsl.cml.CMLResource) 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