Search in sources :

Example 1 with InputReader

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);
}
Also used : InputReader(com.devonfw.cobigen.api.extension.InputReader) File(java.io.File) Test(org.junit.Test)

Example 2 with InputReader

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);
}
Also used : InputReader(com.devonfw.cobigen.api.extension.InputReader) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with InputReader

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;
}
Also used : InputReader(com.devonfw.cobigen.api.extension.InputReader)

Example 4 with InputReader

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);
}
Also used : ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) InputReader(com.devonfw.cobigen.api.extension.InputReader) File(java.io.File) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with InputReader

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);
}
Also used : InputReader(com.devonfw.cobigen.api.extension.InputReader) File(java.io.File) Test(org.junit.Test)

Aggregations

InputReader (com.devonfw.cobigen.api.extension.InputReader)22 File (java.io.File)17 Test (org.junit.Test)16 TriggerInterpreter (com.devonfw.cobigen.api.extension.TriggerInterpreter)14 GeneratorPluginActivator (com.devonfw.cobigen.api.extension.GeneratorPluginActivator)13 MatcherInterpreter (com.devonfw.cobigen.api.extension.MatcherInterpreter)13 MatcherToMatcher (com.devonfw.cobigen.api.matchers.MatcherToMatcher)13 CobiGen (com.devonfw.cobigen.api.CobiGen)10 AbstractApiTest (com.devonfw.cobigen.systemtest.common.AbstractApiTest)10 VariableAssignmentToMatcher (com.devonfw.cobigen.api.matchers.VariableAssignmentToMatcher)3 GenerationReportTo (com.devonfw.cobigen.api.to.GenerationReportTo)3 MatcherTo (com.devonfw.cobigen.api.to.MatcherTo)3 Charset (java.nio.charset.Charset)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 TemplateTo (com.devonfw.cobigen.api.to.TemplateTo)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Cached (com.devonfw.cobigen.api.annotation.Cached)1