Search in sources :

Example 21 with Subdomain

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

the class DeriveSubdomainFromUserRequirementsTest method canCreateEntityAttributes.

@ParameterizedTest
@ValueSource(strings = { "derive-subdomain-from-user-story-test-7-input.cml", "derive-subdomain-from-user-story-test-8-input.cml" })
public void canCreateEntityAttributes(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);
    ar.persistChanges(serializer);
    // 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);
    Attribute firstNameAttribute = customerEntity.getAttributes().stream().filter(a -> a.getName().equals("firstname")).findFirst().get();
    Attribute lastNameAttribute = customerEntity.getAttributes().stream().filter(a -> a.getName().equals("lastname")).findFirst().get();
    assertNotNull(firstNameAttribute);
    assertNotNull(lastNameAttribute);
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with Subdomain

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

the class DeriveSubdomainFromUserRequirementsTest method canCreateContainmentReference.

@ParameterizedTest
@ValueSource(strings = { "derive-subdomain-from-user-story-test-9-input.cml", "derive-subdomain-from-user-story-test-12-input.cml" })
public void canCreateContainmentReference(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);
    ar.persistChanges(serializer);
    // 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(1, customerEntity.getReferences().size());
    Reference addressReference = customerEntity.getReferences().stream().filter(r -> r.getName().equals("addressList")).findFirst().get();
    assertNotNull(addressReference);
    assertEquals(CollectionType.LIST, addressReference.getCollectionType());
    assertEquals("Address", addressReference.getDomainObjectType().getName());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 23 with Subdomain

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

the class PlantUMLBoundedContextClassDiagramCreatorTest method createsNoteForImplementedDomain.

@Test
public void createsNoteForImplementedDomain() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Subdomain subdomain1 = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
    subdomain1.setName("mySubdomain1");
    Subdomain subdomain2 = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
    subdomain2.setName("mySubdomain2");
    Domain domain = ContextMappingDSLFactory.eINSTANCE.createDomain();
    domain.setName("TestDomain");
    domain.getSubdomains().add(subdomain1);
    domain.getSubdomains().add(subdomain2);
    boundedContext.setName("myBoundedContext");
    boundedContext.getImplementedDomainParts().add(domain);
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    aggregate.getDomainObjects().add(TacticdslFactory.eINSTANCE.createSimpleDomainObject());
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("legend left"));
    assertTrue(plantUML.contains("  This bounded context implements the subdomain '" + subdomain1.getName() + "'." + System.lineSeparator()));
    assertTrue(plantUML.contains("  This bounded context implements the subdomain '" + subdomain2.getName() + "'." + System.lineSeparator()));
    assertTrue(plantUML.contains("end legend"));
}
Also used : Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 24 with Subdomain

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

the class DeriveBoundedContextFromSubdomains method createEntities.

private void createEntities(Subdomain subdomain, Aggregate aggregate) {
    for (Entity sdEntity : subdomain.getEntities()) {
        if (entityAlreadyExistsInOtherContext(sdEntity.getName()))
            throw new ContextMapperApplicationException("Cannot derive Bounded Context. Another context with an Entity of the name \"" + sdEntity.getName() + "\" already exists.");
        Entity bcEntity = createOrGetEntity(aggregate, sdEntity.getName());
        bcEntity.setAggregateRoot(false);
        copyAttributes(sdEntity, bcEntity);
        String idAttributeName = sdEntity.getName().toLowerCase() + "Id";
        if (!bcEntity.getAttributes().stream().filter(a -> idAttributeName.equals(a.getName())).findFirst().isPresent()) {
            Attribute idAttribute = TacticdslFactory.eINSTANCE.createAttribute();
            idAttribute.setName(idAttributeName);
            idAttribute.setType("String");
            idAttribute.setKey(true);
            addElementToEList(bcEntity.getAttributes(), idAttribute);
        }
    }
    for (Entity sdEntity : subdomain.getEntities()) {
        Entity bcEntity = createOrGetEntity(aggregate, sdEntity.getName());
        copyReferences(sdEntity, bcEntity, aggregate.getDomainObjects());
    }
}
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) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute)

Example 25 with Subdomain

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

the class DeriveBoundedContextFromSubdomains method doRefactor.

@Override
protected void doRefactor() {
    Set<Subdomain> selectedSubdomains = collectSubdomains();
    if (selectedSubdomains.isEmpty())
        throw new RefactoringInputException("Please provide at least one subdomain name that can be found in the given CML model.");
    BoundedContext bc = createOrGetBoundedContext(boundedContextName);
    bc.setDomainVisionStatement("This Bounded Context realizes the following subdomains: " + String.join(", ", selectedSubdomains.stream().map(sd -> sd.getName()).collect(Collectors.toList())));
    bc.setType(BoundedContextType.FEATURE);
    for (Subdomain subdomain : selectedSubdomains) {
        addElementToEList(bc.getImplementedDomainParts(), (DomainPart) subdomain);
        createAggregate4Subdomain(subdomain, bc);
    }
}
Also used : Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException)

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