Search in sources :

Example 1 with ServiceOperation

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());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with ServiceOperation

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());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with ServiceOperation

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());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with ServiceOperation

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());
}
Also used : ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) ValueSource(org.junit.jupiter.params.provider.ValueSource) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) Arrays(java.util.Arrays) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Set(java.util.Set) IOException(java.io.IOException) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) Test(org.junit.jupiter.api.Test) RefactoringInputException(org.contextmapper.dsl.refactoring.exception.RefactoringInputException) Attribute(org.contextmapper.tactic.dsl.tacticdsl.Attribute) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) Reference(org.contextmapper.tactic.dsl.tacticdsl.Reference) NullSource(org.junit.jupiter.params.provider.NullSource) CMLResource(org.contextmapper.dsl.cml.CMLResource) Entity(org.contextmapper.tactic.dsl.tacticdsl.Entity) Subdomain(org.contextmapper.dsl.contextMappingDSL.Subdomain) CMLResource(org.contextmapper.dsl.cml.CMLResource) Service(org.contextmapper.tactic.dsl.tacticdsl.Service) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) Domain(org.contextmapper.dsl.contextMappingDSL.Domain) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with ServiceOperation

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.");
}
Also used : EndpointClient(org.contextmapper.dsl.generator.mdsl.model.EndpointClient) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) ContextMappingModel(org.contextmapper.dsl.contextMappingDSL.ContextMappingModel) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) UpstreamRole(org.contextmapper.dsl.contextMappingDSL.UpstreamRole) EitherCommandOrOperationInvokation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperationInvokation) ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) CollectionType(org.contextmapper.tactic.dsl.tacticdsl.CollectionType) StringUtils(org.apache.commons.lang3.StringUtils) SingleEventProduction(org.contextmapper.dsl.contextMappingDSL.SingleEventProduction) UpstreamDownstreamRelationship(org.contextmapper.dsl.contextMappingDSL.UpstreamDownstreamRelationship) InvalidParameterException(java.security.InvalidParameterException) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) Map(java.util.Map) DomainObjectOperation(org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation) CommandInvokationStep(org.contextmapper.dsl.contextMappingDSL.CommandInvokationStep) ConcurrentCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ConcurrentCommandInvokation) SingleCommandInvokation(org.contextmapper.dsl.contextMappingDSL.SingleCommandInvokation) EventProduction(org.contextmapper.dsl.contextMappingDSL.EventProduction) DomainEvent(org.contextmapper.tactic.dsl.tacticdsl.DomainEvent) MultipleEventProduction(org.contextmapper.dsl.contextMappingDSL.MultipleEventProduction) DownstreamContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.DownstreamContext) Collectors(java.util.stream.Collectors) List(java.util.List) ExclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeCommandInvokation) APIUsageContext(org.contextmapper.dsl.generator.mdsl.model.APIUsageContext) Optional(java.util.Optional) TacticdslFactory(org.contextmapper.tactic.dsl.tacticdsl.TacticdslFactory) BoundedContext(org.contextmapper.dsl.contextMappingDSL.BoundedContext) InclusiveAlternativeCommandInvokation(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeCommandInvokation) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) EitherCommandOrOperation(org.contextmapper.dsl.contextMappingDSL.EitherCommandOrOperation) CommandEvent(org.contextmapper.tactic.dsl.tacticdsl.CommandEvent) Visibility(org.contextmapper.tactic.dsl.tacticdsl.Visibility) Lists(com.google.common.collect.Lists) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) Application(org.contextmapper.dsl.contextMappingDSL.Application) ExclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.ExclusiveAlternativeEventProduction) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) ComplexType(org.contextmapper.tactic.dsl.tacticdsl.ComplexType) Maps(com.google.common.collect.Maps) EList(org.eclipse.emf.common.util.EList) FlowStep(org.contextmapper.dsl.contextMappingDSL.FlowStep) OrchestrationFlow(org.contextmapper.dsl.generator.mdsl.model.OrchestrationFlow) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) InclusiveAlternativeEventProduction(org.contextmapper.dsl.contextMappingDSL.InclusiveAlternativeEventProduction) DomainEventProductionStep(org.contextmapper.dsl.contextMappingDSL.DomainEventProductionStep) Flow(org.contextmapper.dsl.contextMappingDSL.Flow) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) GeneratorInputException(org.contextmapper.dsl.generator.exception.GeneratorInputException) ServiceOperation(org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation) UpstreamAPIContext(org.contextmapper.dsl.generator.mdsl.generatorcontext.UpstreamAPIContext) SimpleDomainObject(org.contextmapper.tactic.dsl.tacticdsl.SimpleDomainObject) DomainObject(org.contextmapper.tactic.dsl.tacticdsl.DomainObject) Aggregate(org.contextmapper.dsl.contextMappingDSL.Aggregate) Application(org.contextmapper.dsl.contextMappingDSL.Application)

Aggregations

ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)12 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)8 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)8 Collectors (java.util.stream.Collectors)7 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)7 List (java.util.List)6 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)6 Optional (java.util.Optional)5 Parameter (org.contextmapper.tactic.dsl.tacticdsl.Parameter)5 Lists (com.google.common.collect.Lists)4 CMLResource (org.contextmapper.dsl.cml.CMLResource)4 CollectionType (org.contextmapper.tactic.dsl.tacticdsl.CollectionType)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 ValueSource (org.junit.jupiter.params.provider.ValueSource)4 Maps (com.google.common.collect.Maps)3 Sets (com.google.common.collect.Sets)3 InvalidParameterException (java.security.InvalidParameterException)3 Map (java.util.Map)3 Set (java.util.Set)3 StringUtils (org.apache.commons.lang3.StringUtils)3