use of org.contextmapper.tactic.dsl.tacticdsl.Entity 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.Entity in project context-mapper-dsl by ContextMapper.
the class DeriveSubdomainFromUserRequirementsTest method canDeriveSubdomainFromUserStory.
@ParameterizedTest
@ValueSource(strings = { "derive-subdomain-from-user-story-test-1-input.cml", "derive-subdomain-from-user-story-test-2-input.cml", "derive-subdomain-from-user-story-test-3-input.cml", "derive-subdomain-from-user-story-test-4-input.cml", "derive-subdomain-from-user-story-test-5-input.cml", "derive-subdomain-from-user-story-test-6-input.cml" })
public void canDeriveSubdomainFromUserStory(String inputFile) throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML(inputFile);
// when
Set<String> userStories = Sets.newHashSet(Arrays.asList(new String[] { "US1_Create", "Story_to_be_Ignored", "UseCase_to_be_Ignored" }));
DeriveSubdomainFromUserRequirements ar = new DeriveSubdomainFromUserRequirements("InsuranceDomain", "Customers", userStories);
ar.refactor(input);
ar.persistChanges(serializer);
// then
ContextMappingModel model = reloadResource(input).getContextMappingModel();
assertEquals(1, model.getDomains().size());
assertNotNull(model.getDomains().get(0));
Domain domain = model.getDomains().get(0);
assertEquals(1, domain.getSubdomains().size());
assertNotNull(domain.getSubdomains().get(0));
Subdomain subdomain = domain.getSubdomains().get(0);
Set<String> supportedFeatures = subdomain.getSupportedFeatures().stream().map(f -> f.getName()).collect(Collectors.toSet());
assertTrue(supportedFeatures.contains("US1_Create"));
assertEquals("Customers", subdomain.getName());
assertEquals("Aims at promoting the following benefit for a Insurance Employee: I am able to manage the customer data and offer contracts.", subdomain.getDomainVisionStatement());
assertEquals(1, subdomain.getEntities().size());
assertEquals(1, subdomain.getServices().size());
Entity entity = subdomain.getEntities().get(0);
assertEquals("Customer", entity.getName());
Service service = subdomain.getServices().get(0);
assertEquals("US1_CreateService", service.getName());
assertEquals(1, service.getOperations().size());
ServiceOperation operation = service.getOperations().get(0);
assertEquals("createCustomer", operation.getName());
}
use of org.contextmapper.tactic.dsl.tacticdsl.Entity 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));
}
use of org.contextmapper.tactic.dsl.tacticdsl.Entity in project context-mapper-dsl by ContextMapper.
the class PlantUMLBoundedContextClassDiagramCreatorTest method createsNoteForImplementedSubdomainWithEntities.
@Test
public void createsNoteForImplementedSubdomainWithEntities() {
// given
BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
Subdomain subdomain = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
subdomain.setName("mySubdomain");
boundedContext.setName("myBoundedContext");
boundedContext.getImplementedDomainParts().add(subdomain);
Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
aggregate.setName("testAggregate");
boundedContext.getAggregates().add(aggregate);
aggregate.getDomainObjects().add(TacticdslFactory.eINSTANCE.createSimpleDomainObject());
Entity entity1 = TacticdslFactory.eINSTANCE.createEntity();
Entity entity2 = TacticdslFactory.eINSTANCE.createEntity();
entity1.setName("TestEntity1");
entity2.setName("TestEntity2");
subdomain.getEntities().add(entity1);
subdomain.getEntities().add(entity2);
// when
String plantUML = this.creator.createDiagram(boundedContext);
// then
assertTrue(plantUML.contains("legend left"));
assertTrue(plantUML.contains(" This bounded context implements the subdomain '" + subdomain.getName() + "', which contains the following entities:" + System.lineSeparator()));
assertTrue(plantUML.contains(" - TestEntity1"));
assertTrue(plantUML.contains(" - TestEntity2"));
assertTrue(plantUML.contains("end legend"));
}
use of org.contextmapper.tactic.dsl.tacticdsl.Entity in project context-mapper-dsl by ContextMapper.
the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreatePackageFromModuleWithBasePackage.
@Test
public void canCreatePackageFromModuleWithBasePackage() {
// given
BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
SculptorModule testModule = ContextMappingDSLFactory.eINSTANCE.createSculptorModule();
testModule.setName("mySuperModule");
testModule.setBasePackage("org.contextmapper");
boundedContext.getModules().add(testModule);
Entity testEntity = TacticdslFactory.eINSTANCE.createEntity();
testEntity.setName("TestEntity");
testModule.getDomainObjects().add(testEntity);
// when
String plantUML = this.creator.createDiagram(boundedContext);
// then
assertTrue(plantUML.contains("package org.contextmapper.mySuperModule"));
}
Aggregations