Search in sources :

Example 1 with ValueObject

use of org.contextmapper.tactic.dsl.tacticdsl.ValueObject 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());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) IOException(java.io.IOException) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) EcoreUtil2(org.eclipse.xtext.EcoreUtil2) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) CMLResource(org.contextmapper.dsl.cml.CMLResource) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) SculptorModule(org.contextmapper.dsl.contextMappingDSL.SculptorModule) CMLResource(org.contextmapper.dsl.cml.CMLResource) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Test(org.junit.jupiter.api.Test)

Example 2 with ValueObject

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

the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreateInheritance4VO.

@Test
public void canCreateInheritance4VO() {
    // given
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    ValueObject vo1 = TacticdslFactory.eINSTANCE.createValueObject();
    vo1.setName("Customer");
    ValueObject vo2 = TacticdslFactory.eINSTANCE.createValueObject();
    vo2.setName("AbstractVO");
    vo1.setExtends(vo2);
    aggregate.getDomainObjects().add(vo1);
    aggregate.getDomainObjects().add(vo2);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("	class Customer <<(V,DarkSeaGreen) Value Object>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("	class AbstractVO <<(V,DarkSeaGreen) Value Object>> {" + System.lineSeparator() + "	}" + System.lineSeparator()));
    assertTrue(plantUML.contains("Customer --|> AbstractVO" + System.lineSeparator()));
}
Also used : BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 3 with ValueObject

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

the class ExtractIDValueObjectQuickFix method applyQuickfix.

@Override
public void applyQuickfix(Attribute attribute) {
    if (!(attribute.eContainer() instanceof DomainObject))
        throw new ContextMapperApplicationException("This Quickfix is not applicable on the selected object.");
    DomainObject parentObject = (DomainObject) attribute.eContainer();
    ValueObject vo = createValueObject(attribute);
    addVOToContainer(parentObject, vo);
    fixReference(attribute, parentObject, vo);
}
Also used : ContextMapperApplicationException(org.contextmapper.dsl.exception.ContextMapperApplicationException) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject)

Example 4 with ValueObject

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

the class ExtractIDValueObjectQuickFix method createValueObject.

private ValueObject createValueObject(Attribute attribute) {
    ValueObject vo = TacticdslFactory.eINSTANCE.createValueObject();
    String voName = attribute.getName().substring(0, 1).toUpperCase() + attribute.getName().substring(1);
    vo.setName(voName);
    Attribute idAttribute = TacticdslFactory.eINSTANCE.createAttribute();
    idAttribute.setName("id");
    idAttribute.setType(attribute.getType());
    vo.getAttributes().add(idAttribute);
    return vo;
}
Also used : Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject)

Example 5 with ValueObject

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

the class ContextMappingModelToServiceCutterERDConverterTest method canCreateEntity4ValueObject.

@Test
public void canCreateEntity4ValueObject() {
    // given
    ContextMappingModel model = ContextMappingDSLFactory.eINSTANCE.createContextMappingModel();
    ContextMap contextMap = ContextMappingDSLFactory.eINSTANCE.createContextMap();
    BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
    boundedContext.setName("testBC");
    contextMap.getBoundedContexts().add(boundedContext);
    model.getBoundedContexts().add(boundedContext);
    Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
    aggregate.setName("testAggregate");
    boundedContext.getAggregates().add(aggregate);
    ValueObject valueObject = TacticdslFactory.eINSTANCE.createValueObject();
    valueObject.setName("TestValueObject");
    Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
    attribute.setName("attribute1");
    aggregate.getDomainObjects().add(valueObject);
    valueObject.getAttributes().add(attribute);
    model.setMap(contextMap);
    // when
    EntityRelationDiagram scDiagram = this.converter.convert("TestModel", model);
    // then
    List<String> entityNames = scDiagram.getEntities().stream().map(e -> e.getName()).collect(Collectors.toList());
    assertTrue(entityNames.contains("TestValueObject"));
    ch.hsr.servicecutter.api.model.Entity scEntity = getEntity(scDiagram.getEntities(), "TestValueObject");
    assertEquals(1, scEntity.getNanoentities().size());
    assertEquals("attribute1", scEntity.getNanoentities().get(0));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) RelationType(ch.hsr.servicecutter.api.model.EntityRelation.RelationType) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Collectors(java.util.stream.Collectors) ContextMappingModelToServiceCutterERDConverter(org.contextmapper.dsl.generator.servicecutter.input.converter.ContextMappingModelToServiceCutterERDConverter) Test(org.junit.jupiter.api.Test) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) List(java.util.List) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) ContextMappingDSLFactory(org.contextmapper.dsl.contextMappingDSL.ContextMappingDSLFactory) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) BeforeEach(org.junit.jupiter.api.BeforeEach) ContextMap(org.contextmapper.dsl.contextMappingDSL.ContextMap) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) EntityRelationDiagram(ch.hsr.servicecutter.api.model.EntityRelationDiagram) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ValueObject(org.contextmapper.tactic.dsl.tacticdsl.ValueObject) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Aggregations

ValueObject (org.contextmapper.tactic.dsl.tacticdsl.ValueObject)8 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)5 Test (org.junit.jupiter.api.Test)5 Attribute (org.contextmapper.tactic.dsl.tacticdsl.Attribute)4 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)3 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)3 ContextMapperApplicationException (org.contextmapper.dsl.exception.ContextMapperApplicationException)3 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)3 TacticdslFactory (org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory)3 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)3 IOException (java.io.IOException)2 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)2 CMLResource (org.contextmapper.dsl.cml.CMLResource)2 SculptorModule (org.contextmapper.dsl.contextMappingDSL.SculptorModule)2 ExtractIDValueObjectQuickFix (org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix)2 DomainEvent (org.contextmapper.tactic.dsl.tacticdsl.DomainEvent)2 DomainObject (org.contextmapper.tactic.dsl.tacticdsl.DomainObject)2 EcoreUtil2 (org.eclipse.xtext.EcoreUtil2)2 Assertions.assertNotNull (org.junit.jupiter.api.Assertions.assertNotNull)2 Assertions.assertThrows (org.junit.jupiter.api.Assertions.assertThrows)2