use of org.contextmapper.dsl.generator.mdsl.model.EndpointProvider 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());
}
use of org.contextmapper.dsl.generator.mdsl.model.EndpointProvider in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreator method createProvider.
private EndpointProvider createProvider(UpstreamAPIContext context, List<EndpointContract> endpointContracts) {
EndpointProvider provider = new EndpointProvider();
String implementationTechnology = context.getJoinedImplementationTechnologies();
provider.setName(mdslEncoder.encodeName(context.getUpstreamContext().getName() + PROVIDER_NAME_EXTENSION));
for (EndpointContract contract : endpointContracts) {
EndpointOffer offer = new EndpointOffer();
offer.setOfferedEndpoint(contract);
offer.setLocation(ENDPOINT_LOCATION + (initialPort++));
offer.setProtocol(!"".equals(implementationTechnology) ? implementationTechnology : PROTOCOL_STRING_IF_NOT_DEFINED);
offer.setProtocolComment(!"".equals(implementationTechnology) ? "" : PROTOCOL_NOT_DEFINED_COMMENT);
provider.addEndpointOffer(offer);
}
if (!context.getUpstreamRoles().isEmpty()) {
String roles = String.join(" and ", context.getUpstreamRoles().stream().map(ur -> ur.getName() + " (" + ur.getLiteral() + ")").collect(Collectors.toList()));
provider.addComment("Generated from DDD upstream Bounded Context '" + context.getUpstreamContext().getName() + "' implementing " + roles + ".");
}
if (context.getUpstreamContext().getDomainVisionStatement() != null && !"".equals(context.getUpstreamContext().getDomainVisionStatement()))
provider.setDomainVisionStatement(context.getUpstreamContext().getDomainVisionStatement());
return provider;
}
use of org.contextmapper.dsl.generator.mdsl.model.EndpointProvider 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));
}
Aggregations