Search in sources :

Example 1 with ProtectedRegionContextFactory

use of org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory 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 ProtectedRegionContextFactory

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

the class ProtectedRegionContextFactoryTest method canCreateContext4ExistingFileWithoutProtectedSections.

@Test
public void canCreateContext4ExistingFileWithoutProtectedSections() throws IOException {
    // given
    ProtectedRegionContextFactory factory = new ProtectedRegionContextFactory();
    File expectedResultFile = new File(Paths.get("").toAbsolutePath().toString(), "/integ-test-files/mdsl/protected-region-null-test.mdsl");
    String mdslInputFile = FileUtils.readFileToString(expectedResultFile);
    // when
    ProtectedRegionContext context = factory.createProtectedRegionContextForExistingMDSLFile(mdslInputFile);
    // then
    assertNull(context.getProtectedDataTypeRegion());
    assertNull(context.getProtectedEndpointRegion());
    assertNull(context.getProtectedProviderRegion());
    assertNull(context.getProtectedClientRegion());
    assertEquals(0, context.getDataTypeIdentifiers().size());
    assertEquals(0, context.getEndpointIdentifiers().size());
    assertEquals(0, context.getProviderIdentifiers().size());
    assertEquals(0, context.getClientIdentifiers().size());
}
Also used : ProtectedRegionContextFactory(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory) File(java.io.File) ProtectedRegionContext(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContext) Test(org.junit.jupiter.api.Test)

Example 3 with ProtectedRegionContextFactory

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

the class ProtectedRegionContextFactoryTest method canCreateContext4NewMDSLFile.

@Test
public void canCreateContext4NewMDSLFile() {
    // given
    ProtectedRegionContextFactory factory = new ProtectedRegionContextFactory();
    // when
    ProtectedRegionContext context = factory.createProtectedRegionContextForNewMDSLFile();
    // then
    assertEquals("", context.getProtectedDataTypeRegion());
    assertEquals("", context.getProtectedEndpointRegion());
    assertEquals("", context.getProtectedProviderRegion());
    assertEquals("", context.getProtectedClientRegion());
    assertEquals(0, context.getDataTypeIdentifiers().size());
    assertEquals(0, context.getEndpointIdentifiers().size());
    assertEquals(0, context.getProviderIdentifiers().size());
    assertEquals(0, context.getClientIdentifiers().size());
}
Also used : ProtectedRegionContextFactory(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory) ProtectedRegionContext(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContext) Test(org.junit.jupiter.api.Test)

Example 4 with ProtectedRegionContextFactory

use of org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory 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)

Example 5 with ProtectedRegionContextFactory

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

the class ProtectedRegionContextFactoryTest method canCreateContext4ExistingFile.

@Test
public void canCreateContext4ExistingFile() throws IOException {
    // given
    ProtectedRegionContextFactory factory = new ProtectedRegionContextFactory();
    File expectedResultFile = new File(Paths.get("").toAbsolutePath().toString(), "/integ-test-files/mdsl/protected-region-identifier-test.mdsl");
    String mdslInputFile = FileUtils.readFileToString(expectedResultFile);
    // when
    ProtectedRegionContext context = factory.createProtectedRegionContextForExistingMDSLFile(mdslInputFile);
    // then
    assertEquals("data type Address P" + System.lineSeparator() + "data type Parameter1Type P", context.getProtectedDataTypeRegion());
    assertEquals("endpoint type Customers" + System.lineSeparator() + "	exposes" + System.lineSeparator() + "		operation updateAddress" + System.lineSeparator() + "			expecting" + System.lineSeparator() + "				payload Address" + System.lineSeparator() + "			delivering" + System.lineSeparator() + "" + "				payload ReturnType" + System.lineSeparator() + "		operation anotherMethod" + System.lineSeparator() + "			expecting" + System.lineSeparator() + "				payload anotherMethodParameter", context.getProtectedEndpointRegion());
    assertEquals("API provider CustomerManagementContextProvider" + System.lineSeparator() + "	offers Customers" + System.lineSeparator() + "	at endpoint location \"http://localhost:8000\"" + System.lineSeparator() + "		via protocol \"RESTful HTTP\"", context.getProtectedProviderRegion());
    assertEquals("API client ContractManagementContextClient" + System.lineSeparator() + "	consumes Customers", context.getProtectedClientRegion());
    assertEquals(2, context.getDataTypeIdentifiers().size());
    assertEquals(1, context.getEndpointIdentifiers().size());
    assertEquals(1, context.getProviderIdentifiers().size());
    assertEquals(1, context.getClientIdentifiers().size());
}
Also used : ProtectedRegionContextFactory(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContextFactory) File(java.io.File) ProtectedRegionContext(org.contextmapper.dsl.generator.mdsl.ProtectedRegionContext) Test(org.junit.jupiter.api.Test)

Aggregations

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