Search in sources :

Example 1 with Parameter

use of org.contextmapper.tactic.dsl.tacticdsl.Parameter 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 Parameter

use of org.contextmapper.tactic.dsl.tacticdsl.Parameter 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 Parameter

use of org.contextmapper.tactic.dsl.tacticdsl.Parameter 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 Parameter

use of org.contextmapper.tactic.dsl.tacticdsl.Parameter in project context-mapper-dsl by ContextMapper.

the class MDSLDataTypeCreator method createAttributes4ParameterList.

private List<DataTypeAttribute> createAttributes4ParameterList(List<Parameter> parameters) {
    List<DataTypeAttribute> mdslAttributes = Lists.newArrayList();
    for (Parameter parameter : parameters) {
        DataType referencedType = createMDSLDataType(parameter.getParameterType());
        mdslAttributes.add(createAttribute(parameter.getName(), referencedType.getName(), isCollection(parameter.getParameterType().getCollectionType()), false));
    }
    return mdslAttributes;
}
Also used : DataTypeAttribute(org.contextmapper.dsl.generator.mdsl.model.DataTypeAttribute) Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType)

Example 5 with Parameter

use of org.contextmapper.tactic.dsl.tacticdsl.Parameter in project context-mapper-dsl by ContextMapper.

the class DeriveBoundedContextFromSubdomains method createParameter.

private Parameter createParameter(String name, ComplexType type) {
    Parameter parameter = TacticdslFactory.eINSTANCE.createParameter();
    parameter.setName(name);
    parameter.setParameterType(type);
    return parameter;
}
Also used : Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter)

Aggregations

Parameter (org.contextmapper.tactic.dsl.tacticdsl.Parameter)9 Aggregate (org.contextmapper.dsl.contextMappingDSL.Aggregate)4 BoundedContext (org.contextmapper.dsl.contextMappingDSL.BoundedContext)4 CMLResource (org.contextmapper.dsl.cml.CMLResource)3 ContextMappingModel (org.contextmapper.dsl.contextMappingDSL.ContextMappingModel)3 Service (org.contextmapper.tactic.dsl.tacticdsl.Service)3 ServiceOperation (org.contextmapper.tactic.dsl.tacticdsl.ServiceOperation)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 ValueSource (org.junit.jupiter.params.provider.ValueSource)3 ComplexType (org.contextmapper.tactic.dsl.tacticdsl.ComplexType)2 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)1 DataType (org.contextmapper.dsl.generator.mdsl.model.DataType)1 DataTypeAttribute (org.contextmapper.dsl.generator.mdsl.model.DataTypeAttribute)1 EndpointOperation (org.contextmapper.dsl.generator.mdsl.model.EndpointOperation)1 DomainObjectOperation (org.contextmapper.tactic.dsl.tacticdsl.DomainObjectOperation)1 Entity (org.contextmapper.tactic.dsl.tacticdsl.Entity)1 Test (org.junit.jupiter.api.Test)1