use of org.contextmapper.dsl.contextMappingDSL.Subdomain 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);
}
use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.
the class DeriveSubdomainFromUserRequirementsTest method canCreateContainmentReference.
@ParameterizedTest
@ValueSource(strings = { "derive-subdomain-from-user-story-test-9-input.cml", "derive-subdomain-from-user-story-test-12-input.cml" })
public void canCreateContainmentReference(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);
assertEquals(1, customerEntity.getReferences().size());
Reference addressReference = customerEntity.getReferences().stream().filter(r -> r.getName().equals("addressList")).findFirst().get();
assertNotNull(addressReference);
assertEquals(CollectionType.LIST, addressReference.getCollectionType());
assertEquals("Address", addressReference.getDomainObjectType().getName());
}
use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.
the class PlantUMLBoundedContextClassDiagramCreatorTest method createsNoteForImplementedDomain.
@Test
public void createsNoteForImplementedDomain() {
// given
BoundedContext boundedContext = ContextMappingDSLFactory.eINSTANCE.createBoundedContext();
Subdomain subdomain1 = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
subdomain1.setName("mySubdomain1");
Subdomain subdomain2 = ContextMappingDSLFactory.eINSTANCE.createSubdomain();
subdomain2.setName("mySubdomain2");
Domain domain = ContextMappingDSLFactory.eINSTANCE.createDomain();
domain.setName("TestDomain");
domain.getSubdomains().add(subdomain1);
domain.getSubdomains().add(subdomain2);
boundedContext.setName("myBoundedContext");
boundedContext.getImplementedDomainParts().add(domain);
Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
aggregate.setName("testAggregate");
boundedContext.getAggregates().add(aggregate);
aggregate.getDomainObjects().add(TacticdslFactory.eINSTANCE.createSimpleDomainObject());
// when
String plantUML = this.creator.createDiagram(boundedContext);
// then
assertTrue(plantUML.contains("legend left"));
assertTrue(plantUML.contains(" This bounded context implements the subdomain '" + subdomain1.getName() + "'." + System.lineSeparator()));
assertTrue(plantUML.contains(" This bounded context implements the subdomain '" + subdomain2.getName() + "'." + System.lineSeparator()));
assertTrue(plantUML.contains("end legend"));
}
use of org.contextmapper.dsl.contextMappingDSL.Subdomain 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());
}
}
use of org.contextmapper.dsl.contextMappingDSL.Subdomain in project context-mapper-dsl by ContextMapper.
the class DeriveBoundedContextFromSubdomains method doRefactor.
@Override
protected void doRefactor() {
Set<Subdomain> selectedSubdomains = collectSubdomains();
if (selectedSubdomains.isEmpty())
throw new RefactoringInputException("Please provide at least one subdomain name that can be found in the given CML model.");
BoundedContext bc = createOrGetBoundedContext(boundedContextName);
bc.setDomainVisionStatement("This Bounded Context realizes the following subdomains: " + String.join(", ", selectedSubdomains.stream().map(sd -> sd.getName()).collect(Collectors.toList())));
bc.setType(BoundedContextType.FEATURE);
for (Subdomain subdomain : selectedSubdomains) {
addElementToEList(bc.getImplementedDomainParts(), (DomainPart) subdomain);
createAggregate4Subdomain(subdomain, bc);
}
}
Aggregations