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"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/classes" <classpathentry kind="src" output="target/classes" path="src/main/java">
path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true" /> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" <classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
output="target/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" <classpathentry kind="src" output="target/test-classes" path="src/test/java">
path="src/test/java">
<attributes> <attributes>
<attribute name="optional" value="true" /> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true" /> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
output="target/test-classes" path="src/test/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true" /> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" <classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5" /> <classpathentry kind="src" path="target/generated-sources/annotations">
<classpathentry kind="src"
path="target/generated-sources/annotations">
<attributes> <attributes>
<attribute name="optional" value="true" /> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true" /> <attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true" /> <attribute name="m2e-apt" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" output="target/test-classes" <classpathentry kind="src" output="target/test-classes" path="target/generated-test-sources/test-annotations">
path="target/generated-test-sources/test-annotations">
<attributes> <attributes>
<attribute name="optional" value="true" /> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true" /> <attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true" /> <attribute name="ignore_optional_problems" value="true"/>
<attribute name="m2e-apt" value="true" /> <attribute name="m2e-apt" value="true"/>
<attribute name="test" value="true" /> <attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/classes" /> <classpathentry kind="output" path="target/classes"/>
</classpath> </classpath>
...@@ -32,8 +32,7 @@ import org.eclipse.ice.dev.annotations.processors.Field; ...@@ -32,8 +32,7 @@ import org.eclipse.ice.dev.annotations.processors.Field;
* PojoFromJson project accepts * PojoFromJson project accepts
* Pieces of code were derived from Daniel Bluhm's * Pieces of code were derived from Daniel Bluhm's
* org.eclipse.ice.dev.PojoFromJson. * org.eclipse.ice.dev.PojoFromJson.
* @author gzi * @author Greg Cage
*
*/ */
public class JsonSchemaConverter { public class JsonSchemaConverter {
...@@ -99,7 +98,9 @@ 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 * @param args command line arguments
*/ */
public void run(String... args) { public void run(String... args) {
...@@ -108,15 +109,14 @@ public class JsonSchemaConverter { ...@@ -108,15 +109,14 @@ public class JsonSchemaConverter {
.build(); .build();
jcomm.setProgramName("JsonSchemaConverter"); jcomm.setProgramName("JsonSchemaConverter");
jcomm.parse(args); jcomm.parse(args);
try { try {
//If no file parameter is passed through command line, read json directly from System.in
if (jsonFiles.isEmpty()) { if (jsonFiles.isEmpty()) {
handleInputJson(System.in, Path.of(output)); handleInputJson(System.in, Path.of(output));
} }
//If file parameter is passed through command line, open file and convert it
for (String filePath : jsonFiles) { for (String filePath : jsonFiles) {
try (FileInputStream inputJson = new FileInputStream(filePath)) {
try (FileInputStream inputJson =
new FileInputStream(filePath)) {
handleInputJson(inputJson, Path.of(filePath)); handleInputJson(inputJson, Path.of(filePath));
} }
} }
...@@ -406,7 +406,7 @@ public class JsonSchemaConverter { ...@@ -406,7 +406,7 @@ public class JsonSchemaConverter {
*/ */
public static String formatFileName(String s) throws InvalidFileNameException { public static String formatFileName(String s) throws InvalidFileNameException {
String out = s; 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 out = out.substring(0, out.length() - 5); //remove .json
} }
if (out.contains(".")) { if (out.contains(".")) {
......
package org.eclipse.ice.dev.jsonschemaconverter; 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 static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.FileInputStream; import java.io.FileInputStream;
...@@ -33,7 +35,7 @@ class JsonSchemaConverterTest { ...@@ -33,7 +35,7 @@ class JsonSchemaConverterTest {
@BeforeAll @BeforeAll
public static void setup() { public static void setup() {
jsonResource =JsonSchemaConverterTest.class.getClassLoader().getResource(JSON_FILE).getPath(); jsonResource = JsonSchemaConverterTest.class.getClassLoader().getResource(JSON_FILE).getPath();
destination = Path.of(jsonResource); destination = Path.of(jsonResource);
} }
...@@ -48,10 +50,39 @@ class JsonSchemaConverterTest { ...@@ -48,10 +50,39 @@ class JsonSchemaConverterTest {
assertTrue(Files.exists(destination.getParent().resolve(GENERATED_IMPLEMENTATION))); 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_INTERFACE)));
assertTrue(Files.exists(destination.getParent().resolve(GENERATED_PROP_IMPLEMENTATION))); 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 { public static void teardown() throws IOException {
Files.delete(destination.getParent().resolve(JSON_RESULT)); Files.delete(destination.getParent().resolve(JSON_RESULT));
Files.delete(destination.getParent().resolve(GENERATED_INTERFACE)); Files.delete(destination.getParent().resolve(GENERATED_INTERFACE));
......
...@@ -88,6 +88,8 @@ public class PojoFromJson { ...@@ -88,6 +88,8 @@ public class PojoFromJson {
// Write implementation // Write implementation
try (Writer elementImpl = Files.newBufferedWriter( try (Writer elementImpl = Files.newBufferedWriter(
destination.resolve(data.getImplementationName() + ".java")
)) {
new ImplementationWriter(data).write(elementImpl); 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