use of org.contextmapper.dsl.generator.mdsl.MDSLModelCreator in project context-mapper-dsl by ContextMapper.
the class MDSLAPIDescriptionCreatorTest method canCreateCommentInCaseThereIsNoOperationInAnAPI.
@Test
void canCreateCommentInCaseThereIsNoOperationInAnAPI() throws IOException {
// given
String baseFilename = "mdsl-no-operation-in-one-api";
String inputModelName = baseFilename + ".cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
// when
List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
MDSLAPIDescriptionCreator dslTextCreator = new TestMDSLAPIDescriptionCreator(new ProtectedRegionContextFactory().createProtectedRegionContextForNewMDSLFile(), input.getURI().toFileString());
ServiceSpecification spec = serviceSpecifications.stream().filter(s -> s.getName().equals("MyBoundedContextAPI")).findFirst().get();
String dslText = dslTextCreator.createText(spec);
// then
File expectedResultFile = new File(Paths.get("").toAbsolutePath().toString(), "/integ-test-files/mdsl/" + baseFilename + ".mdsl");
String expectedResult = FileUtils.readFileToString(expectedResultFile, Charset.forName("UTF-8"));
assertEquals(expectedResult, dslText);
}
use of org.contextmapper.dsl.generator.mdsl.MDSLModelCreator in project context-mapper-dsl by ContextMapper.
the class MDSLModelCreatorTest method canHandleMDSLKeywords.
@Test
void canHandleMDSLKeywords() throws IOException {
// given
String inputModelName = "mdsl-can-handle-keyword-clashes.cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
// when
List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
// then
assertEquals(1, serviceSpecifications.size());
ServiceSpecification spec = serviceSpecifications.get(0);
assertEquals(2, spec.getDataTypes().size());
DataType dataType1 = spec.getDataTypes().get(0);
DataType dataType2 = spec.getDataTypes().get(1);
assertEquals("ReturnType", dataType1.getName());
assertEquals("^Link", dataType2.getName());
}
use of org.contextmapper.dsl.generator.mdsl.MDSLModelCreator 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.MDSLModelCreator in project context-mapper-dsl by ContextMapper.
the class MDSLContractsGenerator method generateFromContextMappingModel.
@Override
protected void generateFromContextMappingModel(ContextMappingModel model, IFileSystemAccess2 fsa, URI inputFileURI) {
MDSLModelCreator mdslModelCreator = new MDSLModelCreator(model);
for (ServiceSpecification serviceSpecification : mdslModelCreator.createServiceSpecifications()) {
String mdslFileName = inputFileURI.trimFileExtension().lastSegment() + "_" + serviceSpecification.getName() + "." + MDSL_FILE_EXT;
ProtectedRegionContext protectedRegionContext = createProtectedRegionContext(mdslFileName, fsa);
MDSLAPIDescriptionCreator dslCreator = new MDSLAPIDescriptionCreator(protectedRegionContext, inputFileURI.lastSegment());
fsa.generateFile(mdslFileName, dslCreator.createText(serviceSpecification));
}
}
use of org.contextmapper.dsl.generator.mdsl.MDSLModelCreator in project context-mapper-dsl by ContextMapper.
the class MDSLAPIDescriptionCreatorTest method testCMLInputAndMDSLOutputFiles.
private void testCMLInputAndMDSLOutputFiles(String baseFilename, boolean overwriteExistingFile) throws IOException {
// given
String inputModelName = baseFilename + ".cml";
CMLResource input = getResourceCopyOfTestCML(inputModelName);
EcoreUtil2.resolveAll(input);
MDSLModelCreator mdslCreator = new MDSLModelCreator(input.getContextMappingModel());
// when
List<ServiceSpecification> serviceSpecifications = mdslCreator.createServiceSpecifications();
MDSLAPIDescriptionCreator dslTextCreator;
if (overwriteExistingFile) {
File existingFile = new File(Paths.get("").toAbsolutePath().toString(), "/integ-test-files/mdsl/" + baseFilename + "-existing.mdsl");
String existingFileContent = FileUtils.readFileToString(existingFile, Charset.forName("UTF-8"));
dslTextCreator = new TestMDSLAPIDescriptionCreator(new ProtectedRegionContextFactory().createProtectedRegionContextForExistingMDSLFile(existingFileContent), input.getURI().toFileString());
} else {
dslTextCreator = new TestMDSLAPIDescriptionCreator(new ProtectedRegionContextFactory().createProtectedRegionContextForNewMDSLFile(), input.getURI().toFileString());
}
String dslText = dslTextCreator.createText(serviceSpecifications.get(0));
// then
File expectedResultFile = new File(Paths.get("").toAbsolutePath().toString(), "/integ-test-files/mdsl/" + baseFilename + ".mdsl");
String expectedResult = FileUtils.readFileToString(expectedResultFile, Charset.forName("UTF-8"));
assertEquals(expectedResult, dslText);
}
Aggregations