Search in sources :

Example 21 with Attribute

use of org.contextmapper.tactic.dsl.tacticdsl.Attribute in project context-mapper-dsl by ContextMapper.

the class DeriveBoundedContextFromSubdomainsTest method canDeriveBoundedContextFromSubdomain.

@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-1-input.cml", "derive-bc-from-subdomain-test-2-input.cml", "derive-bc-from-subdomain-test-3-input.cml", "derive-bc-from-subdomain-test-4-input.cml", "derive-bc-from-subdomain-test-5-input.cml" })
public void canDeriveBoundedContextFromSubdomain(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("CustomerDomainAggregate", aggregate.getName());
    assertEquals(1, aggregate.getDomainObjects().size());
    assertNotNull(aggregate.getDomainObjects().get(0));
    assertTrue(aggregate.getDomainObjects().get(0) instanceof Entity);
    Entity entity = (Entity) aggregate.getDomainObjects().get(0);
    assertEquals("Customer", entity.getName());
    assertFalse(entity.isAggregateRoot());
    assertEquals(1, entity.getAttributes().size());
    Attribute idAttr = entity.getAttributes().get(0);
    assertNotNull(idAttr);
    assertEquals("customerId", idAttr.getName());
    assertEquals("String", idAttr.getType());
    assertTrue(idAttr.isKey());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) CMLResource(org.contextmapper.dsl.cml.CMLResource) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 22 with Attribute

use of org.contextmapper.tactic.dsl.tacticdsl.Attribute 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 23 with Attribute

use of org.contextmapper.tactic.dsl.tacticdsl.Attribute in project context-mapper-dsl by ContextMapper.

the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreateClassFromEntity.

@Test
public void canCreateClassFromEntity() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    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);
    aggregate.getDomainObjects().add(entity);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // 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) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 24 with Attribute

use of org.contextmapper.tactic.dsl.tacticdsl.Attribute in project context-mapper-dsl by ContextMapper.

the class PlantUMLAggregateClassDiagramCreatorTest method canCreateClassFromEntity.

@Test
public void canCreateClassFromEntity() {
    // given
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    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);
    aggregate.getDomainObjects().add(entity);
    // when
    String plantUML = this.creator.createDiagram(aggregate);
    // 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) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest)

Example 25 with Attribute

use of org.contextmapper.tactic.dsl.tacticdsl.Attribute 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)

Aggregations

Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)25 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)16 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)13 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)11 Test (org.junit.jupiter.api.Test)11 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)8 Reference (org.contextmapper.tactic.dsl.tacticdsl.Reference)8 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)8 ValueObject (org.contextmapper.tactic.dsl.tacticdsl.ValueObject)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 ContextMappingDSLFactory (org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory)6 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)5 ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)5 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)5 CMLResource (org.contextmapper.dsl.cml.CMLResource)4 ContextMap (org.contextmapper.dsl.contextMappingDSL.ContextMap)4 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)4 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)4 RelationType (ch.hsr.servicecutter.api.model.EntityRelation.RelationType)3