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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations