use of org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation 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.tactic.dsl.tacticdsl.ServiceOperation 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.tactic.dsl.tacticdsl.ServiceOperation 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());
}
use of org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation 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.ServiceOperation 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.");
}
Aggregations