use of org.contextmapper.tactic.dsl.tacticdsl.Attribute in project context-mapper-dsl by ContextMapper.
the class DeriveBoundedContextFromSubdomainsTest method canDeriveBoundedContextFromSubdomain.
@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-1-input.cml", "derive-bc-from-subdomain-test-2-input.cml", "derive-bc-from-subdomain-test-3-input.cml", "derive-bc-from-subdomain-test-4-input.cml", "derive-bc-from-subdomain-test-5-input.cml" })
public void canDeriveBoundedContextFromSubdomain(String inputFile) throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML(inputFile);
// when
Set<String> subdomains = Sets.newHashSet(Arrays.asList(new String[] { "CustomerDomain" }));
DeriveBoundedContextFromSubdomains ar = new DeriveBoundedContextFromSubdomains("NewTestBC", subdomains);
ar.refactor(input);
ar.persistChanges(serializer);
// then
ContextMappingModel model = reloadResource(input).getContextMappingModel();
assertEquals(1, model.getBoundedContexts().size());
assertNotNull(model.getBoundedContexts().get(0));
BoundedContext bc = model.getBoundedContexts().get(0);
assertEquals("NewTestBC", bc.getName());
assertEquals(BoundedContextType.FEATURE, bc.getType());
assertEquals(1, bc.getAggregates().size());
assertNotNull(bc.getAggregates().get(0));
Aggregate aggregate = bc.getAggregates().get(0);
assertEquals("CustomerDomainAggregate", aggregate.getName());
assertEquals(1, aggregate.getDomainObjects().size());
assertNotNull(aggregate.getDomainObjects().get(0));
assertTrue(aggregate.getDomainObjects().get(0) instanceof Entity);
Entity entity = (Entity) aggregate.getDomainObjects().get(0);
assertEquals("Customer", entity.getName());
assertFalse(entity.isAggregateRoot());
assertEquals(1, entity.getAttributes().size());
Attribute idAttr = entity.getAttributes().get(0);
assertNotNull(idAttr);
assertEquals("customerId", idAttr.getName());
assertEquals("String", idAttr.getType());
assertTrue(idAttr.isKey());
}
use of org.contextmapper.tactic.dsl.tacticdsl.Attribute 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.tactic.dsl.tacticdsl.Attribute in project context-mapper-dsl by ContextMapper.
the class PlantUMLBoundedContextClassDiagramCreatorTest method canCreateClassFromEntity.
@Test
public void canCreateClassFromEntity() {
// 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");
entity.getAttributes().add(attribute);
Attribute listAttribute = TacticdslFactory.eINSTANCE.createAttribute();
listAttribute.setCollectionType(CollectionType.LIST);
listAttribute.setName("myList");
listAttribute.setType("String");
entity.getAttributes().add(listAttribute);
aggregate.getDomainObjects().add(entity);
// when
String plantUML = this.creator.createDiagram(boundedContext);
// then
assertTrue(plantUML.contains(" class Test <<(E,DarkSeaGreen) Entity>> {" + System.lineSeparator() + " int amount" + System.lineSeparator() + " List<String> myList" + System.lineSeparator() + " }" + System.lineSeparator()));
}
use of org.contextmapper.tactic.dsl.tacticdsl.Attribute in project context-mapper-dsl by ContextMapper.
the class PlantUMLAggregateClassDiagramCreatorTest method canCreateClassFromEntity.
@Test
public void canCreateClassFromEntity() {
// given
Aggregate aggregate = ContextMappingDSLFactory.eINSTANCE.createAggregate();
aggregate.setName("testAggregate");
Entity entity = TacticdslFactory.eINSTANCE.createEntity();
entity.setName("Test");
Attribute attribute = TacticdslFactory.eINSTANCE.createAttribute();
attribute.setType("int");
attribute.setName("amount");
entity.getAttributes().add(attribute);
Attribute listAttribute = TacticdslFactory.eINSTANCE.createAttribute();
listAttribute.setCollectionType(CollectionType.LIST);
listAttribute.setName("myList");
listAttribute.setType("String");
entity.getAttributes().add(listAttribute);
aggregate.getDomainObjects().add(entity);
// when
String plantUML = this.creator.createDiagram(aggregate);
// then
assertTrue(plantUML.contains(" class Test <<(E,DarkSeaGreen) Entity>> {" + System.lineSeparator() + " int amount" + System.lineSeparator() + " List<String> myList" + System.lineSeparator() + " }" + System.lineSeparator()));
}
use of org.contextmapper.tactic.dsl.tacticdsl.Attribute 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());
}
}
Aggregations