Search in sources :

Example 1 with BoundedContext

use of org.contextmapper.dsl.contextMappingDSL.BoundedContext in project context-mapper-dsl by ContextMapper.

the class ServiceCutterUserRepresentationsExampleGeneratorTest method canCreateUserRepresentationsFile.

@Test
void canCreateUserRepresentationsFile() {
    // given
    ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext.setName("TestContext");
    contextMap.getBoundedContexts().add(boundedContext);
    model.getBoundedContexts().add(boundedContext);
    model.setMap(contextMap);
    // when
    IFileSystemAccess2Mock filesystem = new IFileSystemAccess2Mock();
    this.generator.doGenerate(new ContextMappingModelResourceMock(model, URI.createFileURI(new File(Paths.get("").toAbsolutePath().toString(), dummyInputFilePath).getAbsolutePath())), filesystem, new IGeneratorContextMock());
    // then
    File resultFile = new File(Paths.get("").toAbsolutePath().toString(), resultFiltPath);
    assertTrue(resultFile.exists());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IFileSystemAccess2Mock(org.contextmapper.dsl.generators.mocks.IFileSystemAccess2Mock) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) IGeneratorContextMock(org.contextmapper.dsl.generators.mocks.IGeneratorContextMock) ContextMappingModelResourceMock(org.contextmapper.dsl.generators.mocks.ContextMappingModelResourceMock) File(java.io.File) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) Test(org.junit.jupiter.api.Test)

Example 2 with BoundedContext

use of org.contextmapper.dsl.contextMappingDSL.BoundedContext in project context-mapper-dsl by ContextMapper.

the class SplitAggregateByEntitiesTest method canSplitInModule.

@Test
void canSplitInModule() throws IOException {
    // given
    String inputModelName = "split-agg-by-entities-test-2-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    SplitAggregateByEntitiesRefactoring refactoring = new SplitAggregateByEntitiesRefactoring("Customers");
    // when
    refactoring.refactor(input);
    refactoring.persistChanges(serializer);
    // then
    BoundedContext bc = reloadResource(input).getContextMappingModel().getBoundedContexts().get(0);
    SculptorModule testModule = bc.getModules().get(0);
    assertEquals(2, testModule.getAggregates().size());
    for (Aggregate aggregate : testModule.getAggregates()) {
        assertEquals(1, aggregate.getDomainObjects().size());
    }
    List<String> aggregateNames = testModule.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
    assertTrue(aggregateNames.contains("Customers"));
    assertTrue(aggregateNames.contains("Account"));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) 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) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 3 with BoundedContext

use of org.contextmapper.dsl.contextMappingDSL.BoundedContext in project context-mapper-dsl by ContextMapper.

the class SplitAggregateByEntitiesTest method canSplitWithTwoAggregates.

@Test
void canSplitWithTwoAggregates() throws IOException {
    // given
    String inputModelName = "split-agg-by-entities-test-1-input.cml";
    CMLResource input = getResourceCopyOfTestCML(inputModelName);
    SplitAggregateByEntitiesRefactoring refactoring = new SplitAggregateByEntitiesRefactoring("Customers");
    // when
    refactoring.refactor(input);
    refactoring.persistChanges(serializer);
    // then
    BoundedContext bc = reloadResource(input).getContextMappingModel().getBoundedContexts().get(0);
    assertEquals(2, bc.getAggregates().size());
    for (Aggregate aggregate : bc.getAggregates()) {
        assertEquals(1, aggregate.getDomainObjects().size());
    }
    List<String> aggregateNames = bc.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
    assertTrue(aggregateNames.contains("Customers"));
    assertTrue(aggregateNames.contains("Account"));
    for (Aggregate aggregate : bc.getAggregates()) {
        SimpleDomainObject obj = aggregate.getDomainObjects().get(0);
        if (obj instanceof DomainObject)
            assertTrue(((DomainObject) obj).isAggregateRoot());
    }
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Test(org.junit.jupiter.api.Test) List(java.util.List) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) 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) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CMLResource(org.contextmapper.dsl.cml.CMLResource) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 4 with BoundedContext

use of org.contextmapper.dsl.contextMappingDSL.BoundedContext 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 5 with BoundedContext

use of org.contextmapper.dsl.contextMappingDSL.BoundedContext in project context-mapper-dsl by ContextMapper.

the class DeriveBoundedContextFromSubdomainsTest method canCopyAndEnhanceServices.

@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-1-input.cml", "derive-bc-from-subdomain-test-6-input.cml", "derive-bc-from-subdomain-test-7-input.cml" })
public void canCopyAndEnhanceServices(String inputFile) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    Set<String> subdomains = Sets.newHashSet(Arrays.asList(new String[] { "CustomerDomain" }));
    DeriveBoundedContextFromSubdomains ar = new DeriveBoundedContextFromSubdomains("NewTestBC", subdomains);
    ar.refactor(input);
    ar.persistChanges(serializer);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    assertEquals(1, model.getBoundedContexts().size());
    assertNotNull(model.getBoundedContexts().get(0));
    BoundedContext bc = model.getBoundedContexts().get(0);
    assertEquals("NewTestBC", bc.getName());
    assertEquals(BoundedContextType.FEATURE, bc.getType());
    assertEquals(1, bc.getAggregates().size());
    assertNotNull(bc.getAggregates().get(0));
    Aggregate aggregate = bc.getAggregates().get(0);
    assertEquals(1, aggregate.getServices().size());
    Service service = aggregate.getServices().get(0);
    assertEquals("CustomerService", service.getName());
    assertEquals(2, service.getOperations().size());
    ServiceOperation operation = service.getOperations().stream().filter(o -> o.getName().equals("createCustomer")).findFirst().get();
    assertEquals("createCustomer", operation.getName());
    assertEquals("boolean", operation.getReturnType().getType());
    assertEquals(1, operation.getParameters().size());
    Parameter parameter = operation.getParameters().get(0);
    assertEquals("createCustomerInput", parameter.getName());
    assertEquals("CreateCustomerInput", parameter.getParameterType().getType());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)192 Test (org.junit.jupiter.api.Test)106 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)77 CMLResource (org.contextmapper.dsl.cml.CMLResource)70 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)65 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)62 Collectors (java.util.stream.Collectors)51 List (java.util.List)50 UpstreamDownstreamRelationship (org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship)42 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)39 Optional (java.util.Optional)34 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)28 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)27 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)26 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)24 Assertions.assertTrue (org.junit.jupiter.api.Assertions.assertTrue)24 Lists (com.google.common.collect.Lists)20 IOException (java.io.IOException)19 Set (java.util.Set)19 BoundedContextType (org.contextmapper.dsl.contextMappingDSL.BoundedContextType)18