use of com.devonfw.cobigen.api.extension.InputReader in project cobigen by devonfw.
the class TypeScriptInputReaderTest method testIsMostProbablyReadable.
/**
* Sends a fileEto containing only the path of the file that needs to be parsed. Checks whether the file is most
* likely readable.
*
* @test fails
*/
@Test
public void testIsMostProbablyReadable() {
// arrange
InputReader tsInputReader = this.activator.bindTriggerInterpreter().stream().map(e -> e.getInputReader()).findFirst().get();
File baseFile = new File(testFileRootPath + "baseFile.ts");
boolean isReadable = tsInputReader.isMostLikelyReadable(baseFile.toPath());
assertTrue(isReadable);
}
use of com.devonfw.cobigen.api.extension.InputReader in project cobigen by devonfw.
the class TypeScriptInputReaderTest method testValidInputObjectString.
/**
* Sends an Object containing only the path of the file that needs to be parsed. Checks whether it is a valid input.
*
* @test fails
*/
@Test
public void testValidInputObjectString() {
// arrange
InputReader tsInputReader = this.activator.bindTriggerInterpreter().stream().map(e -> e.getInputReader()).findFirst().get();
File baseFile = new File(testFileRootPath + "baseFile.ts");
Map<String, Object> inputModel = (Map<String, Object>) tsInputReader.read(baseFile.getAbsoluteFile().toPath(), Charset.defaultCharset());
boolean isValidInput = tsInputReader.isValidInput(inputModel);
assertTrue(isValidInput);
}
use of com.devonfw.cobigen.api.extension.InputReader in project cobigen by devonfw.
the class TypeScriptInputReaderTest method readingInput.
/**
* Sends the path of a file to be parsed by the external process. Should return a valid JSON model.
*
* @param filePath the path that is going to get sent to the external process.
* @return The output from the server (in this case will be a JSON model of the input file).
*
* @test fails
*/
public String readingInput(Path filePath) {
// arrange
InputReader tsInputReader = this.activator.bindTriggerInterpreter().stream().map(e -> e.getInputReader()).findFirst().get();
// act
String inputModel = (String) tsInputReader.read(filePath, Charset.defaultCharset());
assertThat(inputModel).contains("\"identifier\":\"aProperty\"");
assertThat(inputModel).contains("\"identifier\":\"aMethod\"");
assertThat(inputModel).contains("\"module\":\"b\"");
return inputModel;
}
use of com.devonfw.cobigen.api.extension.InputReader in project cobigen by devonfw.
the class TypeScriptInputReaderTest method testCreatingModel.
/**
* Sends the path of a file to be parsed by the external process. Should return a valid JSON model. The validity of
* the generated model is then checked.
*
* @test fails
*/
@Test
public void testCreatingModel() {
// arrange
InputReader tsInputReader = this.activator.bindTriggerInterpreter().stream().map(e -> e.getInputReader()).findFirst().get();
File baseFile = new File(testFileRootPath + "baseFile.ts");
Map<String, Object> mapModel = (Map<String, Object>) tsInputReader.read(baseFile.getAbsoluteFile().toPath(), Charset.defaultCharset());
mapModel = (Map<String, Object>) mapModel.get("model");
// Checking imports
ArrayList<Object> importDeclarations = castToList(mapModel, "importDeclarations");
assertEquals(importDeclarations.size(), 2);
String[] modules = { "b", "d" };
String[] importedEntities = { "a", "c" };
for (int i = 0; i < modules.length; i++) {
LinkedHashMap<String, Object> currentImport = (LinkedHashMap<String, Object>) importDeclarations.get(i);
assertEquals(currentImport.get("module"), modules[i]);
ArrayList<String> currentEntities = (ArrayList<String>) currentImport.get("named");
assertEquals(currentEntities.get(0), importedEntities[i]);
}
// Checking exports
ArrayList<Object> exportDeclarations = castToList(mapModel, "exportDeclarations");
assertEquals(exportDeclarations.size(), 1);
LinkedHashMap<String, Object> currentExport = (LinkedHashMap<String, Object>) exportDeclarations.get(0);
assertEquals(currentExport.get("module"), "f");
ArrayList<String> currentEntities = (ArrayList<String>) currentExport.get("named");
assertEquals(currentEntities.get(0), "e");
// Checking classes
ArrayList<Object> classes = castToList(mapModel, "classes");
assertEquals(classes.size(), 1);
// Checking interfaces
ArrayList<Object> interfaces = castToList(mapModel, "interfaces");
assertEquals(interfaces.size(), 1);
}
use of com.devonfw.cobigen.api.extension.InputReader in project cobigen by devonfw.
the class TypeScriptInputReaderTest method testIsValidInputAfterReading.
/**
* Testing whether a file is valid, after it has been read.
*
* @test fails
*/
@Test
public void testIsValidInputAfterReading() {
// arrange
InputReader tsInputReader = this.activator.bindTriggerInterpreter().stream().map(e -> e.getInputReader()).findFirst().get();
File baseFile = new File(testFileRootPath + "baseFile.ts");
// parsing
tsInputReader.read(baseFile.toPath(), Charset.defaultCharset());
// Now checking whether the input is valid
boolean isValid = tsInputReader.isValidInput(baseFile.toPath());
assertTrue(isValid);
}
Aggregations