Search in sources :

Example 1 with Attribute

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

the class ExtractIDValueObjectQuickFixTest method canCheckThatAttributeIsContainedInDomainObject.

@Test
public void canCheckThatAttributeIsContainedInDomainObject() {
    // given
    Attribute attr = TacticdslFactory.eINSTANCE.createAttribute();
    attr.setName("singleAttr");
    // when, then
    assertThrows(ContextMapperApplicationException.class, () -> {
        new ExtractIDValueObjectQuickFix().applyQuickfix(attr);
    });
}
Also used : Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ExtractIDValueObjectQuickFix(org.contextmapper.dsl.quickfixes.tactic.ExtractIDValueObjectQuickFix) Test(org.junit.jupiter.api.Test)

Example 2 with Attribute

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

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

the class ContextMappingModelToServiceCutterERDConverterTest method canCreateEntity4DomainEvent.

@Test
public void canCreateEntity4DomainEvent() {
    // 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);
    DomainEvent domainEvent = TacticdslFactory.eINSTANCE.createDomainEvent();
    domainEvent.setName("TestDomainEvent");
    Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
    attribute.setName("attribute1");
    aggregate.getDomainObjects().add(domainEvent);
    domainEvent.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("TestDomainEvent"));
    ch.hsr.servicecutter.api.model.Entity scEntity = getEntity(scDiagram.getEntities(), "TestDomainEvent");
    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) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) 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) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 4 with Attribute

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

the class ContextMappingModelToServiceCutterERDConverterTest method canCreateEntity4Entity.

@Test
public void canCreateEntity4Entity() {
    // 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);
    Entity entity = TacticdslFactory.eINSTANCE.createEntity();
    entity.setName("TestEntity");
    Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
    attribute.setName("attribute1");
    aggregate.getDomainObjects().add(entity);
    entity.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("TestEntity"));
    ch.hsr.servicecutter.api.model.Entity scEntity = getEntity(scDiagram.getEntities(), "TestEntity");
    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) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) 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) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Test(org.junit.jupiter.api.Test)

Example 5 with Attribute

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

the class PlantUMLBoundedContextClassDiagramCreatorTest method respectNullableOnAttributes.

@Test
public void respectNullableOnAttributes() {
    // 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");
    attribute.setNullable(true);
    entity.getAttributes().add(attribute);
    aggregate.getDomainObjects().add(entity);
    // when
    String plantUML = this.creator.createDiagram(boundedContext);
    // then
    assertTrue(plantUML.contains("	class Test <<(E,DarkSeaGreen) Entity>> {" + System.lineSeparator() + "		int[0..1] amount" + 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)

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