use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.
the class SplitAggregateByEntitiesTest method canSplitWithTwoAggregates.
@Test
void canSplitWithTwoAggregates() throws IOException {
// given
String inputModelName = "split-agg-by-entities-test-1-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
SplitAggregateByEntitiesRefactoring refactoring = new SplitAggregateByEntitiesRefactoring("Customers");
// when
refactoring.refactor(input);
refactoring.persistChanges(serializer);
// then
BoundedContext bc = reloadResource(input).getContextMappingModel().getBoundedContexts().get(0);
assertEquals(2, bc.getAggregates().size());
for (Aggregate aggregate : bc.getAggregates()) {
assertEquals(1, aggregate.getDomainObjects().size());
}
List<String> aggregateNames = bc.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
assertTrue(aggregateNames.contains("Customers"));
assertTrue(aggregateNames.contains("Account"));
for (Aggregate aggregate : bc.getAggregates()) {
SimpleDomainObject obj = aggregate.getDomainObjects().get(0);
if (obj instanceof DomainObject)
assertTrue(((DomainObject) obj).isAggregateRoot());
}
}
use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.
the class MergeAggregatesTest method canHandleAggregateRoots.
@Test
void canHandleAggregateRoots() throws IOException {
// given
String inputModelName = "merge-aggregates-test-6-input.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
MergeAggregatesRefactoring refactoring = new MergeAggregatesRefactoring("agg1", "agg2", true);
// when
refactoring.refactor(input);
// then
ContextMappingModel model = input.getContextMappingModel();
assertEquals(1, model.getBoundedContexts().size());
BoundedContext bc = model.getBoundedContexts().get(0);
assertEquals(1, bc.getAggregates().size());
Aggregate aggregate = bc.getAggregates().get(0);
List<DomainObject> aggregateRoots = aggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).collect(Collectors.toList());
assertEquals(1, aggregateRoots.size());
}
use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.
the class MDSLDataTypeCreator method getDomainObjectAttributes.
private List<Attribute> getDomainObjectAttributes(DomainObject domainObject) {
List<Attribute> attributes = new ArrayList<>();
DomainObject extendsType = getExtendsType(domainObject);
while (extendsType != null) {
attributes.addAll(extendsType.getAttributes());
extendsType = getExtendsType(extendsType);
}
attributes.addAll(domainObject.getAttributes());
return attributes;
}
use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method checkPreconditions.
private void checkPreconditions() {
Map<String, UpstreamAPIContext> upstreamContexts = collectUpstreamContexts();
List<Aggregate> exposedAggregates = Lists.newArrayList();
List<Application> applications = Lists.newArrayList();
for (UpstreamAPIContext context : upstreamContexts.values()) {
exposedAggregates.addAll(context.getExposedAggregates());
if (context.getApplicationLayer() != null)
applications.add(context.getApplicationLayer());
}
if (exposedAggregates.isEmpty() && applications.isEmpty())
throw new GeneratorInputException("None of your upstream-downstream relationships exposes any Aggregates or application layers. Therefore there is nothing to generate. Use the 'exposedAggregates' attribute on your upstream-downstream relationships to specify which Aggregates are exposed by the upstream or model an 'Application' in your upstream.");
boolean atLeastOneAggregateWithAnOperation = false;
for (Aggregate exposedAggregate : exposedAggregates) {
Optional<DomainObject> aggregateRoot = exposedAggregate.getDomainObjects().stream().filter(o -> o instanceof DomainObject).map(o -> (DomainObject) o).filter(o -> o.isAggregateRoot()).findFirst();
if (aggregateRoot.isPresent() && !aggregateRoot.get().getOperations().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = exposedAggregate.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
for (Application application : applications) {
if (!application.getCommands().isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
List<ServiceOperation> serviceOperations = application.getServices().stream().flatMap(s -> s.getOperations().stream()).collect(Collectors.toList());
if (!serviceOperations.isEmpty()) {
atLeastOneAggregateWithAnOperation = true;
break;
}
}
if (!atLeastOneAggregateWithAnOperation)
throw new GeneratorInputException("None of your exposed Aggregates contains either Service or 'Aggregate Root' operations/methods. Therefore there is nothing to generate. Add at least one operation/method to the 'Aggregate Root' or to a Service in one of your exposed Aggregates to get a result.");
}
use of org.contextmapper.tactic.dsl.tacticdsl.DomainObject in project context-mapper-dsl by ContextMapper.
the class CMLModelObjectsResolvingHelperTest method canReturnNullInCaseDomainObjectIsNotPartOfBC.
@Test
public void canReturnNullInCaseDomainObjectIsNotPartOfBC() throws IOException {
// given
CMLResource input = getResourceCopyOfTestCML("bc-resolving-test-1.cml");
DomainObject domainObject = EcoreUtil2.eAllOfType(input.getContextMappingModel(), DomainObject.class).stream().filter(o -> o.getName().equals("TestEntity3")).findFirst().get();
// when
CMLModelObjectsResolvingHelper helper = new CMLModelObjectsResolvingHelper(input.getContextMappingModel());
BoundedContext bc = helper.resolveBoundedContext(domainObject);
// then
assertNull(bc);
}
Aggregations