Search in sources :

Example 1 with EndpointOperation

use of org.contextmapper.dsl.generator.mdsl.model.EndpointOperation in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreatorTest method canCreateMDSLModelWithoutContextMap.

@Test
void canCreateMDSLModelWithoutContextMap() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("basic-mdsl-model-test-without-contextmap.cml");
    MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
    // when
    List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
    // then
    assertEquals(1, serviceSpecifications.size());
    ServiceSpecification spec = serviceSpecifications.get(0);
    assertEquals("CustomerManagementContextAPI", spec.getName());
    assertEquals(1, spec.getEndpoints().size());
    EndpointContract endpoint = spec.getEndpoints().get(0);
    assertEquals("Customers", endpoint.getName());
    assertEquals(2, endpoint.getOperations().size());
    EndpointOperation operation1 = endpoint.getOperations().get(0);
    assertEquals("updateAddress", operation1.getName());
    EndpointOperation operation2 = endpoint.getOperations().get(1);
    assertEquals("anotherMethod", operation2.getName());
    assertEquals(5, spec.getDataTypes().size());
    DataType dataType1 = spec.getDataTypes().get(0);
    assertEquals("Address", dataType1.getName());
    DataType dataType2 = spec.getDataTypes().get(1);
    assertEquals("Parameter1Type", dataType2.getName());
    DataType dataType3 = spec.getDataTypes().get(2);
    assertEquals("Parameter2Type", dataType3.getName());
    DataType dataType4 = spec.getDataTypes().get(3);
    assertEquals("ReturnType", dataType4.getName());
    DataType dataType5 = spec.getDataTypes().get(4);
    assertEquals("anotherMethodParameter", dataType5.getName());
    assertEquals("Address", operation1.getExpectingPayload().getName());
    assertEquals("ReturnType", operation1.getDeliveringPayload().getName());
    assertEquals("anotherMethodParameter", operation2.getExpectingPayload().getName());
    assertEquals(1, spec.getProviders().size());
    EndpointProvider provider = spec.getProviders().get(0);
    assertEquals("CustomerManagementContextProvider", provider.getName());
    assertEquals(1, provider.getEndpointOffers().size());
    EndpointOffer contractOffered = provider.getEndpointOffers().get(0);
    assertEquals("Customers", contractOffered.getOfferedEndpoint().getName());
    assertEquals("http://localhost:8000", contractOffered.getLocation());
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) CMLResource(org.contextmapper.dsl.cml.CMLResource) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 2 with EndpointOperation

use of org.contextmapper.dsl.generator.mdsl.model.EndpointOperation in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreator method createOperation.

private EndpointOperation createOperation(String operationName, List<Parameter> parameters, ComplexType returnType, ServiceSpecification specification, String docString) {
    EndpointOperation operation = new EndpointOperation();
    operation.setName(mdslEncoder.encodeName(operationName));
    if (parameters.isEmpty()) {
        operation.setExpectingPayload(createVoidReturnType());
    } else if (parameters.size() == 1) {
        Parameter parameter = parameters.get(0);
        operation.setExpectingPayload(dataTypeCreator.createMDSLDataType(parameter.getParameterType()));
        operation.setExpectingCollection(parameter.getParameterType().getCollectionType() != CollectionType.NONE);
    } else {
        operation.setExpectingPayload(dataTypeCreator.createMDSLDataType4ParameterList(operationName, parameters));
    }
    if (returnType != null) {
        operation.setDeliveringPayload(dataTypeCreator.createMDSLDataType(returnType));
        operation.setDeliveringCollection(returnType.getCollectionType() != CollectionType.NONE);
    }
    setOperationResponsibility(operation, docString);
    return operation;
}
Also used : Parameter(org.contextmapper.tactic.dsl.tacticdsl.Parameter) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation)

Example 3 with EndpointOperation

use of org.contextmapper.dsl.generator.mdsl.model.EndpointOperation in project context-mapper-dsl by ContextMapper.

the class MDSLModelCreatorTest method canCreateMDSLModel.

@Test
void canCreateMDSLModel() throws IOException {
    // given
    CMLResource input = getResourceCopyOfTestCML("basic-mdsl-model-test.cml");
    MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
    // when
    List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
    // then
    assertEquals(1, serviceSpecifications.size());
    ServiceSpecification spec = serviceSpecifications.get(0);
    assertEquals("CustomerManagementContextAPI", spec.getName());
    assertEquals(1, spec.getEndpoints().size());
    EndpointContract endpoint = spec.getEndpoints().get(0);
    assertEquals("Customers", endpoint.getName());
    assertEquals(2, endpoint.getOperations().size());
    EndpointOperation operation1 = endpoint.getOperations().get(0);
    assertEquals("updateAddress", operation1.getName());
    EndpointOperation operation2 = endpoint.getOperations().get(1);
    assertEquals("anotherMethod", operation2.getName());
    assertEquals(5, spec.getDataTypes().size());
    DataType dataType1 = spec.getDataTypes().get(0);
    assertEquals("Address", dataType1.getName());
    DataType dataType2 = spec.getDataTypes().get(1);
    assertEquals("Parameter1Type", dataType2.getName());
    DataType dataType3 = spec.getDataTypes().get(2);
    assertEquals("Parameter2Type", dataType3.getName());
    DataType dataType4 = spec.getDataTypes().get(3);
    assertEquals("ReturnType", dataType4.getName());
    DataType dataType5 = spec.getDataTypes().get(4);
    assertEquals("anotherMethodParameter", dataType5.getName());
    assertEquals("Address", operation1.getExpectingPayload().getName());
    assertEquals("ReturnType", operation1.getDeliveringPayload().getName());
    assertEquals("anotherMethodParameter", operation2.getExpectingPayload().getName());
    assertEquals(1, spec.getProviders().size());
    EndpointProvider provider = spec.getProviders().get(0);
    assertEquals("CustomerManagementContextProvider", provider.getName());
    assertEquals(1, provider.getEndpointOffers().size());
    EndpointOffer contractOffered = provider.getEndpointOffers().get(0);
    assertEquals("Customers", contractOffered.getOfferedEndpoint().getName());
    assertEquals("http://localhost:8000", contractOffered.getLocation());
    assertEquals("RESTful HTTP", contractOffered.getProtocol());
    assertEquals(1, spec.getClients().size());
    EndpointClient client = spec.getClients().get(0);
    assertEquals("ContractManagementContextClient", client.getName());
    assertEquals(1, client.getConsumedOfferNames().size());
    assertEquals("Customers", client.getConsumedOfferNames().get(0));
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) EndpointContract(org.contextmapper.dsl.generator.mdsl.model.EndpointContract) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) EndpointProvider(org.contextmapper.dsl.generator.mdsl.model.EndpointProvider) CMLResource(org.contextmapper.dsl.cml.CMLResource) DataType(org.contextmapper.dsl.generator.mdsl.model.DataType) EndpointOffer(org.contextmapper.dsl.generator.mdsl.model.EndpointOffer) EndpointOperation(org.contextmapper.dsl.generator.mdsl.model.EndpointOperation) EndpointClient(org.contextmapper.dsl.generator.mdsl.model.EndpointClient) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Aggregations

EndpointOperation (org.contextmapper.dsl.generator.mdsl.model.EndpointOperation)3 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)2 CMLResource (org.contextmapper.dsl.cml.CMLResource)2 MDSLModelCreator (org.contextmapper.dsl.generator.mdsl.MDSLModelCreator)2 DataType (org.contextmapper.dsl.generator.mdsl.model.DataType)2 EndpointContract (org.contextmapper.dsl.generator.mdsl.model.EndpointContract)2 EndpointOffer (org.contextmapper.dsl.generator.mdsl.model.EndpointOffer)2 EndpointProvider (org.contextmapper.dsl.generator.mdsl.model.EndpointProvider)2 ServiceSpecification (org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification)2 Test (org.junit.jupiter.api.Test)2 EndpointClient (org.contextmapper.dsl.generator.mdsl.model.EndpointClient)1 Parameter (org.contextmapper.tactic.dsl.tacticdsl.Parameter)1