Search in sources :

Example 1 with ProtectedRegionContext

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

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

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

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

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