Commit 2c1987ed authored by Greg Cage's avatar Greg Cage

Add file name tests for json schema converter, remove org.eclipse.ice.data.neutrons

Signed-off-by: Greg Cage's avatarGregory Cage <cagege@ornl.gov>
parent 4462dfca
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes"
path="src/main/java">
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src"
output="target/classes" path="src/main/resources">
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true" />
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes"
path="src/test/java">
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
<attribute name="test" value="true" />
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src"
output="target/test-classes" path="src/test/resources">
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true" />
<attribute name="test" value="true" />
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con"
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true" />
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con"
path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true" />
<attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes>
</classpathentry>
<classpathentry kind="con"
path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5" />
<classpathentry kind="src"
path="target/generated-sources/annotations">
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="src" path="target/generated-sources/annotations">
<attributes>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
<attribute name="ignore_optional_problems" value="true" />
<attribute name="m2e-apt" value="true" />
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes"
path="target/generated-test-sources/test-annotations">
<classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
<attributes>
<attribute name="optional" value="true" />
<attribute name="maven.pomderived" value="true" />
<attribute name="ignore_optional_problems" value="true" />
<attribute name="m2e-apt" value="true" />
<attribute name="test" value="true" />
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes" />
<classpathentry kind="output" path="target/classes"/>
</classpath>
......@@ -32,8 +32,7 @@ import org.eclipse.ice.dev.annotations.processors.Field;
* PojoFromJson project accepts
* Pieces of code were derived from Daniel Bluhm's
* org.eclipse.ice.dev.PojoFromJson.
* @author gzi
*
* @author Greg Cage
*/
public class JsonSchemaConverter {
......@@ -99,7 +98,9 @@ public class JsonSchemaConverter {
}
/**
* Parse arguments and continues execution of program.
* Takes in json files specified by command line argument (or json given in
* Standard In if no file parameters are given) and generates DataElements from that
* json.
* @param args command line arguments
*/
public void run(String... args) {
......@@ -108,15 +109,14 @@ public class JsonSchemaConverter {
.build();
jcomm.setProgramName("JsonSchemaConverter");
jcomm.parse(args);
try {
//If no file parameter is passed through command line, read json directly from System.in
if (jsonFiles.isEmpty()) {
handleInputJson(System.in, Path.of(output));
}
//If file parameter is passed through command line, open file and convert it
for (String filePath : jsonFiles) {
try (FileInputStream inputJson =
new FileInputStream(filePath)) {
try (FileInputStream inputJson = new FileInputStream(filePath)) {
handleInputJson(inputJson, Path.of(filePath));
}
}
......@@ -406,7 +406,7 @@ public class JsonSchemaConverter {
*/
public static String formatFileName(String s) throws InvalidFileNameException {
String out = s;
if (out.substring(out.length() - 5).equals(".json")) {
if (out.length() > 5 && out.substring(out.length() - 5).equals(".json")) {
out = out.substring(0, out.length() - 5); //remove .json
}
if (out.contains(".")) {
......
package org.eclipse.ice.dev.jsonschemaconverter;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileInputStream;
......@@ -33,7 +35,7 @@ class JsonSchemaConverterTest {
@BeforeAll
public static void setup() {
jsonResource =JsonSchemaConverterTest.class.getClassLoader().getResource(JSON_FILE).getPath();
jsonResource = JsonSchemaConverterTest.class.getClassLoader().getResource(JSON_FILE).getPath();
destination = Path.of(jsonResource);
}
......@@ -48,10 +50,39 @@ class JsonSchemaConverterTest {
assertTrue(Files.exists(destination.getParent().resolve(GENERATED_IMPLEMENTATION)));
assertTrue(Files.exists(destination.getParent().resolve(GENERATED_PROP_INTERFACE)));
assertTrue(Files.exists(destination.getParent().resolve(GENERATED_PROP_IMPLEMENTATION)));
teardown();
}
@Test
void badFileNameTest() throws InvalidFileNameException {
assertThrows(InvalidFileNameException.class, () -> {
JsonSchemaConverter.formatFileName("Test#.Json.json");
});
assertThrows(InvalidFileNameException.class, () -> {
JsonSchemaConverter.formatFileName("...............");
});
assertThrows(InvalidFileNameException.class, () -> {
JsonSchemaConverter.formatFileName(",IsThisValid.json,");
});
assertThrows(InvalidFileNameException.class, () -> {
JsonSchemaConverter.formatFileName("");
});
assertEquals(JsonSchemaConverter.formatFileName("json.json.json.json"), "jsonjsonjson");
assertEquals(JsonSchemaConverter.formatFileName("valid.json"), "valid");
assertEquals(JsonSchemaConverter.formatFileName("a.json"), "a");
assertEquals(JsonSchemaConverter.formatFileName("a"), "a");
}
@AfterAll
public static void teardown() throws IOException {
Files.delete(destination.getParent().resolve(JSON_RESULT));
Files.delete(destination.getParent().resolve(GENERATED_INTERFACE));
......
......@@ -88,6 +88,8 @@ public class PojoFromJson {
// Write implementation
try (Writer elementImpl = Files.newBufferedWriter(
destination.resolve(data.getImplementationName() + ".java")
)) {
new ImplementationWriter(data).write(elementImpl);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment