Search in sources :

Example 16 with Subdomain

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

the class DeriveBoundedContextFromSubdomains method collectSubdomains.

private Set<Subdomain> collectSubdomains() {
    Set<Subdomain> allSubdomains = Sets.newHashSet();
    for (Domain domain : getAllDomains()) {
        allSubdomains.addAll(domain.getSubdomains());
    }
    Set<Subdomain> subdomains = Sets.newHashSet();
    for (String subdomainId : subdomainIds) {
        Optional<Subdomain> optSubdomain = allSubdomains.stream().filter(sd -> subdomainId.equals(sd.getName())).findFirst();
        if (optSubdomain.isPresent())
            subdomains.add(optSubdomain.get());
    }
    return subdomains;
}
Also used : Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) BoundedContextType(org.contextmapper.dsl.contextMappingDSL.BoundedContextType) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Feature(org.contextmapper.dsl.contextMappingDSL.Feature) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Set(java.util.Set) ComplexType(org.contextmapper.tactic.dsl.tacticdsl.ComplexType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) IteratorExtensions(org.eclipse.xtext.xbase.lib.IteratorExtensions) CMLModelObjectsResolvingHelper(org.contextmapper.dsl.cml.CMLModelObjectsResolvingHelper) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) List(java.util.List) DomainPart(org.contextmapper.dsl.contextMappingDSL.DomainPart) Optional(java.util.Optional) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Domain(org.contextmapper.dsl.contextMappingDSL.Domain)

Example 17 with Subdomain

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

the class DeriveSubdomainFromUserRequirementsTest method canIgnoreEmptyReferences.

@ParameterizedTest
@ValueSource(strings = { "derive-subdomain-from-user-story-test-10-input.cml", "derive-subdomain-from-user-story-test-11-input.cml" })
public void canIgnoreEmptyReferences(String inputFile) throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML(inputFile);
    // when
    Set<String> userStories = Sets.newHashSet(Arrays.asList(new String[] { "US1_Create" }));
    DeriveSubdomainFromUserRequirements ar = new DeriveSubdomainFromUserRequirements("InsuranceDomain", "Customers", userStories);
    ar.refactor(input);
    // then
    ContextMappingModel model = reloadResource(input).getContextMappingModel();
    Subdomain subdomain = model.getDomains().get(0).getSubdomains().get(0);
    assertNotNull(subdomain);
    Entity customerEntity = subdomain.getEntities().stream().filter(e -> e.getName().equals("Customer")).findFirst().get();
    assertNotNull(customerEntity);
    assertEquals(0, customerEntity.getReferences().size());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 18 with Subdomain

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

the class PlantUMLSubdomainClassDiagramCreatorTest method canCreateClasses4Entities.

@Test
public void canCreateClasses4Entities() {
    // given
    Subdomain subdomain = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
    subdomain.setName("MyTestSubdomain");
    Entity entity = TacticdslFactory.eINSTANCE.createEntity();
    entity.setName("Test");
    Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
    attribute.setType("int");
    attribute.setName("amount");
    entity.getAttributes().add(attribute);
    Attribute listAttribute = TacticdslFactory.eINSTANCE.createAttribute();
    listAttribute.setCollectionType(CollectionType.LIST);
    listAttribute.setName("myList");
    listAttribute.setType("String");
    entity.getAttributes().add(listAttribute);
    subdomain.getEntities().add(entity);
    // when
    String plantUML = this.creator.createDiagram(subdomain);
    // then
    assertTrue(plantUML.contains("	class Test <<(E,DarkSeaGreen) Entity>> {" + System.lineSeparator() + "		int amount" + System.lineSeparator() + "		List<String> myList" + System.lineSeparator() + "	}" + System.lineSeparator()));
}
Also used : Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) Test(org.junit.jupiter.api.Test) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest)

Example 19 with Subdomain

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

the class PlantUMLGeneratorTest method canCreatePlantUMLDiagramFiles.

@Test
void canCreatePlantUMLDiagramFiles() {
    // given
    ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Domain domain = ContextMappingDSLFactory.eINSTANCE.createDomain();
    Subdomain subdomain = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
    domain.setName("TestDomain");
    subdomain.setName("TestSubdomain");
    domain.getSubdomains().add(subdomain);
    boundedContext.setName("TestContext");
    model.getBoundedContexts().add(boundedContext);
    contextMap.getBoundedContexts().add(boundedContext);
    model.setMap(contextMap);
    model.getDomains().add(domain);
    // when
    IFileSystemAccess2Mock filesystem = new IFileSystemAccess2Mock();
    this.generator.doGenerate(new ContextMappingModelResourceMock(model, "testmodel", "cml"), filesystem, new IGeneratorContextMock());
    // then
    assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_ContextMap.puml"));
    assertTrue(filesystem.getGeneratedFilesSet().contains("testmodel_BC_TestContext.puml"));
    assertFalse(filesystem.getGeneratedFilesSet().contains("testmodel_SD_TestSubdomain.puml"));
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) IFileSystemAccess2Mock(org.contextmapper.dsl.generators.mocks.IFileSystemAccess2Mock) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) IGeneratorContextMock(org.contextmapper.dsl.generators.mocks.IGeneratorContextMock) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) ContextMappingModelResourceMock(org.contextmapper.dsl.generators.mocks.ContextMappingModelResourceMock) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 20 with Subdomain

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

the class PlantUMLBoundedContextClassDiagramCreator method printLegend.

private void printLegend(BoundedContext boundedContext) {
    List<Subdomain> subdomains = getSubdomains(boundedContext.getImplementedDomainParts());
    if (subdomains.isEmpty() && boundedContext.getRefinedBoundedContext() == null)
        return;
    sb.append("legend left");
    linebreak();
    if (boundedContext.getRefinedBoundedContext() != null) {
        sb.append("  ").append("This Bounded Context '").append(boundedContext.getName()).append("' refines the '").append(boundedContext.getRefinedBoundedContext().getName()).append("' Bounded Context.");
        linebreak();
    }
    for (Subdomain subdomain : subdomains) {
        if (subdomain.getEntities().isEmpty()) {
            sb.append("  ").append("This bounded context implements the subdomain '" + subdomain.getName() + "'.");
        } else {
            sb.append("  ").append("This bounded context implements the subdomain '" + subdomain.getName() + "', which contains the following entities:");
        }
        linebreak();
        for (Entity entity : subdomain.getEntities()) {
            sb.append("  ").append(" - ").append(entity.getName());
            linebreak();
        }
    }
    sb.append("end legend");
    linebreak();
}
Also used : Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain)

Aggregations

Subdomain (org.contextmapper.dsl.contextMappingDSL.Subdomain)26 Domain (org.contextmapper.dsl.contextMappingDSL.Domain)14 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)13 Test (org.junit.jupiter.api.Test)10 Collectors (java.util.stream.Collectors)9 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)9 RefactoringInputException (org.contextmapper.dsl.refactoring.exception.RefactoringInputException)9 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)9 List (java.util.List)8 Optional (java.util.Optional)8 Set (java.util.Set)8 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)8 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)8 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)8 Sets (com.google.common.collect.Sets)7 CollectionType (org.contextmapper.tactic.dsl.tacticdsl.CollectionType)7 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)7 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)7 CMLResource (org.contextmapper.dsl.cml.CMLResource)6 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)6