Search in sources :

Example 1 with MDSLAPIDescriptionCreator

use of org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator 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);
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) MDSLAPIDescriptionCreator(org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) CMLResource(org.contextmapper.dsl.cml.CMLResource) ProtectedRegionContextFactory(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory) File(java.io.File) AbstractCMLInputFileTest(org.contextmapper.dsl.AbstractCMLInputFileTest) Test(org.junit.jupiter.api.Test)

Example 2 with MDSLAPIDescriptionCreator

use of org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator 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));
    }
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) MDSLAPIDescriptionCreator(org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) ProtectedRegionContext(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContext)

Example 3 with MDSLAPIDescriptionCreator

use of org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator 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);
}
Also used : ServiceSpecification(org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification) MDSLAPIDescriptionCreator(org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator) MDSLModelCreator(org.contextmapper.dsl.generator.mdsl.MDSLModelCreator) CMLResource(org.contextmapper.dsl.cml.CMLResource) File(java.io.File) ProtectedRegionContextFactory(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory)

Aggregations

MDSLAPIDescriptionCreator (org.contextmapper.dsl.generator.mdsl.MDSLAPIDescriptionCreator)3 MDSLModelCreator (org.contextmapper.dsl.generator.mdsl.MDSLModelCreator)3 ServiceSpecification (org.contextmapper.dsl.generator.mdsl.model.ServiceSpecification)3 File (java.io.File)2 CMLResource (org.contextmapper.dsl.cml.CMLResource)2 ProtectedRegionContextFactory (org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory)2 AbstractCMLInputFileTest (org.contextmapper.dsl.AbstractCMLInputFileTest)1 ProtectedRegionContext (org.contextmapper.dsl.generator.mdsl.ProtectedRegionContext)1 Test (org.junit.jupiter.api.Test)1