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());
}
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()));
}
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);
}
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;
}
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));
}
Aggregations