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