use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class SplitAggregateByEntitiesTest method canSplitInModule.
@Test
void canSplitInModule() throws IOException {
// given
String inputModelName = "split-agg-by-entities-test-2-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);
SculptorModule testModule = bc.getModules().get(0);
assertEquals(2, testModule.getAggregates().size());
for (Aggregate aggregate : testModule.getAggregates()) {
assertEquals(1, aggregate.getDomainObjects().size());
}
List<String> aggregateNames = testModule.getAggregates().stream().map(a -> a.getName()).collect(Collectors.toList());
assertTrue(aggregateNames.contains("Customers"));
assertTrue(aggregateNames.contains("Account"));
}
use of org.contextmapper.dsl.contextMappingDSL.Aggregate 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.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class DeriveBoundedContextFromSubdomainsTest method canCopyAndEnhanceServices.
@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-1-input.cml", "derive-bc-from-subdomain-test-6-input.cml", "derive-bc-from-subdomain-test-7-input.cml" })
public void canCopyAndEnhanceServices(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(1, aggregate.getServices().size());
Service service = aggregate.getServices().get(0);
assertEquals("CustomerService", service.getName());
assertEquals(2, service.getOperations().size());
ServiceOperation operation = service.getOperations().stream().filter(o -> o.getName().equals("createCustomer")).findFirst().get();
assertEquals("createCustomer", operation.getName());
assertEquals("boolean", operation.getReturnType().getType());
assertEquals(1, operation.getParameters().size());
Parameter parameter = operation.getParameters().get(0);
assertEquals("createCustomerInput", parameter.getName());
assertEquals("CreateCustomerInput", parameter.getParameterType().getType());
}
use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class DeriveBoundedContextFromSubdomainsTest method canCreateServiceOperationParametersFromFeaturesInModule.
@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-10-input.cml" })
public void canCreateServiceOperationParametersFromFeaturesInModule(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.getModules().get(0).getAggregates().size());
assertNotNull(bc.getModules().get(0).getAggregates().get(0));
Aggregate aggregate = bc.getModules().get(0).getAggregates().get(0);
assertEquals(1, aggregate.getServices().size());
Service service = aggregate.getServices().get(0);
assertEquals("CustomerService", service.getName());
assertEquals(2, service.getOperations().size());
ServiceOperation createOperation = service.getOperations().stream().filter(o -> o.getName().equals("createCustomer")).findFirst().get();
assertEquals("createCustomer", createOperation.getName());
assertEquals("String", createOperation.getReturnType().getType());
assertEquals(1, createOperation.getParameters().size());
Parameter parameter = createOperation.getParameters().get(0);
assertEquals("customer", parameter.getName());
assertEquals("Customer", parameter.getParameterType().getDomainObjectType().getName());
ServiceOperation readOperation = service.getOperations().stream().filter(o -> o.getName().equals("readCustomer")).findFirst().get();
assertEquals("readCustomer", readOperation.getName());
assertEquals("Customer", readOperation.getReturnType().getDomainObjectType().getName());
assertEquals(1, readOperation.getParameters().size());
parameter = readOperation.getParameters().get(0);
assertEquals("id", parameter.getName());
assertEquals("String", parameter.getParameterType().getType());
}
use of org.contextmapper.dsl.contextMappingDSL.Aggregate in project context-mapper-dsl by ContextMapper.
the class DeriveBoundedContextFromSubdomainsTest method canCreateServiceOperationParametersFromFeatures.
@ParameterizedTest
@ValueSource(strings = { "derive-bc-from-subdomain-test-9-input.cml" })
public void canCreateServiceOperationParametersFromFeatures(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(1, aggregate.getServices().size());
Service service = aggregate.getServices().get(0);
assertEquals("CustomerService", service.getName());
assertEquals(2, service.getOperations().size());
ServiceOperation createOperation = service.getOperations().stream().filter(o -> o.getName().equals("createCustomer")).findFirst().get();
assertEquals("createCustomer", createOperation.getName());
assertEquals("String", createOperation.getReturnType().getType());
assertEquals(1, createOperation.getParameters().size());
Parameter parameter = createOperation.getParameters().get(0);
assertEquals("customer", parameter.getName());
assertEquals("Customer", parameter.getParameterType().getDomainObjectType().getName());
ServiceOperation readOperation = service.getOperations().stream().filter(o -> o.getName().equals("readCustomer")).findFirst().get();
assertEquals("readCustomer", readOperation.getName());
assertEquals("Customer", readOperation.getReturnType().getDomainObjectType().getName());
assertEquals(1, readOperation.getParameters().size());
parameter = readOperation.getParameters().get(0);
assertEquals("id", parameter.getName());
assertEquals("String", parameter.getParameterType().getType());
}
Aggregations