Commit 871ffac6 authored by Greg Cage's avatar Greg Cage

Merge branch 'e2e-test' of code.ornl.gov:rse-ice/ice into next

parents 13017447 b04d2bc5
......@@ -13,12 +13,16 @@ import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
......@@ -28,7 +32,9 @@ import lombok.Setter;
* This is an implementation of $interface that satisfies the dependencies of
* the @DataElement Annotation and was auto-generated by the ICE Framework.
*/
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -37,12 +43,22 @@ import lombok.Setter;
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = ${class}.${class}Builder.class)
public class ${class} implements ${interface}, Serializable {
/**
* Logging tool
*/
private static final Logger logger = LoggerFactory.getLogger(${class}.class);
/**
* Deserialization helpers.
*/
@JsonPOJOBuilder(withPrefix = "")
public static class ${class}Builder implements ${class}BuilderMeta {
}
private interface ${class}BuilderMeta {
}
#foreach($field in $fields)
#fielddoc
......@@ -53,7 +69,7 @@ public class ${class} implements ${interface}, Serializable {
#if(!${field.Setter} || ${field.VarNameDifferent})
@Setter(AccessLevel.NONE)
#end
#fielddecl
#fielddecl(true)
#end
#foreach($field in ${fields.Constants})
......@@ -82,25 +98,6 @@ public class ${class} implements ${interface}, Serializable {
#end
#end
/**
* All args constructor for $class.
*
* Used in JSON Deserialization.
#foreach($field in $fields)
* @param ${field.VarName} {@code #fieldtype} for field ${field.VarName}
#end
*/
@JsonCreator
public $class(
#foreach($field in $fields)
@JsonProperty("${field.VarName}") #fieldparametertype ${field.VarName}#if($foreach.hasNext),#end
#end
) {
#foreach($field in $fields)
this.${field.VarName} = ${field.VarName};
#end
}
/**
* Copy constructor for $class.
* @param other Instance of $class to copy
......
......@@ -50,9 +50,9 @@
#macro(fieldparametertype)#nonnull("", " ")#fieldtype#end
## Get field declaration
#macro(fielddecl)
#macro(fielddecl $mutable)
#@settab(1)
#join(" ", ${field.Annotations})#join(" ", ${field.Modifiers})#fieldtype() ${field.VarName}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end;
#if(${field.DefaultValue} && $mutable) @Builder.Default #end#join(" ", ${field.Annotations})#join(" ", ${field.Modifiers})#fieldtype() ${field.VarName}#if(${field.DefaultValue}) = #evaluate(${field.DefaultValue})#end;
#end
#end
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,6 +9,7 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
public int shouldBePublic;
protected int shouldBeProtected;
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,6 +9,7 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
public int testInt = 42;
@Builder.Default public int testInt = 42;
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,6 +9,7 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull public String test = "A String Value";
@NonNull @Builder.Default public String test = "A String Value";
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,17 +9,18 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull
@Getter(AccessLevel.NONE)
@Setter(AccessLevel.NONE)
protected UUID privateId = UUID.randomUUID();
protected long id = 0L;
@NonNull protected String name = "name";
@NonNull protected String description = "description";
@NonNull protected String comment = "no comment";
@NonNull protected String context = "default";
protected boolean required = false;
protected boolean secret = false;
@Builder.Default protected UUID privateId = UUID.randomUUID();
@Builder.Default protected long id = 0L;
@NonNull @Builder.Default protected String name = "name";
@NonNull @Builder.Default protected String description = "description";
@NonNull @Builder.Default protected String comment = "no comment";
@NonNull @Builder.Default protected String context = "default";
@Builder.Default protected boolean required = false;
@Builder.Default protected boolean secret = false;
protected JavascriptValidator<Test> validator;
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,6 +9,7 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
public byte testByte;
public short testShort;
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,6 +9,7 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull public UUID testUuid;
@NonNull public String testString;
......
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,6 +9,7 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
public int testInt;
}
\ No newline at end of file
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonAutoDetect(
fieldVisibility = Visibility.ANY,
......@@ -7,6 +9,7 @@
setterVisibility = Visibility.NONE
)
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonDeserialize(builder = TestImplementation.TestImplementationBuilder.class)
public class TestImplementation implements Test, Serializable {
@NonNull public UUID testUuid;
}
\ No newline at end of file
......@@ -6,9 +6,10 @@
<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/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="ignore_optional_problems" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
......@@ -18,17 +19,15 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="test" 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.jdt.launching.JRE_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.ice.tests.data</name>
<name>org.eclipse.ice.tests.util.data</name>
<comment></comment>
<projects>
</projects>
......
......@@ -55,20 +55,13 @@ public class TestConfig extends Properties {
*/
public void load(String propertyFilename) {
Path propPath = dataPath.resolve(propertyFilename);
if (dataPath.exists(propPath)) {
try(InputStream propStream = dataPath.input(propPath)) {
super.load(propStream);
} catch (IOException e) {
logger.warn(
"Could not load properties from {}: {}",
propPath.toString(),
e.getMessage()
);
}
} else {
try(InputStream propStream = dataPath.input(propPath)) {
super.load(propStream);
} catch (IOException e) {
logger.warn(
"Could not find properties file {} in test data directory",
propPath.toString()
"Could not load properties from {}:",
propPath,
e
);
}
}
......
......@@ -58,7 +58,7 @@ public class TestDataPath {
* No args constructor.
*/
public TestDataPath() {
fs = FileSystems.getDefault();
this.fs = FileSystems.getDefault();
this.testDataDir = determineTestDataDirectory(System.getenv());
}
......@@ -87,6 +87,22 @@ public class TestDataPath {
}
}
/**
* Return the testDataDirectory as string.
*/
@Override
public String toString() {
return this.testDataDir.toString();
}
/**
* Get the test data directory.
* @return test data directory
*/
public Path getTestDataDirectory() {
return this.testDataDir;
}
/**
* Create the test data directory if it doesn't already exist.
* @throws IOException on file errors
......
......@@ -38,11 +38,36 @@ class TestConfigTest {
@Test
void testLoadAndAccess() throws IOException {
TestDataPath dataPath = TestDataPathTest.inMemTestDataPath(null);
TestDataPath dataPath = TestDataPathTest.inMemTestDataPath();
TestConfig config = new TestConfig(dataPath);
setupPropFile(dataPath);
config.load(PROP_FILENAME);
String test = config.getProperty("test");
assertEquals("abcd1234", test);
assertEquals("abcd1234", config.getProperty("test"));
}
@Test
void testExceptionNotThrownOnFileNotExist() throws IOException {
TestDataPath dataPath = TestDataPathTest.inMemTestDataPath();
TestConfig config = new TestConfig(dataPath);
config.load(PROP_FILENAME);
assertEquals("default", config.getProperty("test", "default"));
}
@Test
void testExceptionNotThrownOnBadPropFile() throws IOException {
TestDataPath dataPath = TestDataPathTest.inMemTestDataPath();
TestConfig config = new TestConfig(dataPath);
dataPath.create();
try(PrintWriter writer = new PrintWriter(dataPath.writer(PROP_FILENAME))) {
writer.println("Not valid property contents");
}
config.load(PROP_FILENAME);
assertEquals("default", config.getProperty("test", "default"));
}
@Test
void testFrom() {
TestConfig config = TestConfig.from("");
assertEquals("default", config.getProperty("test", "default"));
}
}
......@@ -33,18 +33,20 @@ import com.google.common.jimfs.Jimfs;
*/
class TestDataPathTest {
private static final String TEST_DATA_PATH = "/home/test/test_data";
private static final Map<String, String> ALTERNATE_ENVIRONMENT = Map.of(
TestDataPath.TEST_DATA_PATH_ENV_VAR, TEST_DATA_PATH
);
public static TestDataPath inMemTestDataPath(
Map<String, String> env, String... dirs
String... dirs
) throws IOException {
FileSystem fs = Jimfs.newFileSystem(Configuration.unix());
for (String dir : dirs) {
Path toMake = fs.getPath(dir);
Files.createDirectories(toMake);
}
if (env == null) {
env = Collections.emptyMap();
}
return new TestDataPath(fs, env);
return new TestDataPath(fs, ALTERNATE_ENVIRONMENT);
}
@Test
......@@ -57,29 +59,35 @@ class TestDataPathTest {
}
@Test
void testResolve() throws IOException {
TestDataPath data = inMemTestDataPath(null);
void testDefaultInPlaceWhenNoOverrideGiven() throws IOException {
TestDataPath data = new TestDataPath();
assertEquals(
TestDataPath.DEFAULT_TEST_DATA_DIR.resolve("test").toString(),
data.resolve("test").toString()
TestDataPath.DEFAULT_TEST_DATA_DIR,
data.getTestDataDirectory()
);
}
@Test
void testResolveWithOverridenDefault() throws IOException {
final Path alt = Path.of("/home/test/test_data");
TestDataPath data = inMemTestDataPath(
Map.of(TestDataPath.TEST_DATA_PATH_ENV_VAR, alt.toString())
void testOverridenDefault() throws IOException {
TestDataPath data = inMemTestDataPath();
assertEquals(
TEST_DATA_PATH,
data.toString()
);
}
@Test
void testResolve() throws IOException {
TestDataPath data = inMemTestDataPath();
assertEquals(
alt.resolve("test").toString(),
TEST_DATA_PATH + "/test",
data.resolve("test").toString()
);
}
@Test
void testCreate() throws IOException {
TestDataPath data = inMemTestDataPath(null);
TestDataPath data = inMemTestDataPath();
data.create();
assertTrue(Files.exists(data.resolve("")));
}
......@@ -87,14 +95,14 @@ class TestDataPathTest {
@Test
void testCreateDirString() throws IOException {
final String test = "test";
TestDataPath data = inMemTestDataPath(null);
TestDataPath data = inMemTestDataPath();
data.createDir(test);
assertTrue(Files.exists(data.resolve(test)));
}
@Test
void testCreateDirPath() throws IOException {
TestDataPath data = inMemTestDataPath(null);
TestDataPath data = inMemTestDataPath();
final Path test = data.resolve("test");
data.createDir(test);
assertTrue(Files.exists(test));
......@@ -102,56 +110,54 @@ class TestDataPathTest {
@Test
void testExists() throws IOException {
TestDataPath data = inMemTestDataPath(
null, TestDataPath.DEFAULT_TEST_DATA_DIR.toString()
);
TestDataPath data = inMemTestDataPath();
assertFalse(data.exists());
Files.createDirectories(data.getTestDataDirectory());
assertTrue(data.exists());
}
@Test
void testExistsString() throws IOException {
TestDataPath data = inMemTestDataPath(
null,
TestDataPath.DEFAULT_TEST_DATA_DIR.resolve("test").toString()
);
TestDataPath data = inMemTestDataPath();
assertFalse(data.exists("test"));
Files.createDirectories(data.getTestDataDirectory().resolve("test"));
assertTrue(data.exists("test"));
}
@Test
void testExistsPath() throws IOException {
TestDataPath data = inMemTestDataPath(
null,
TestDataPath.DEFAULT_TEST_DATA_DIR.resolve("test").toString()
);
TestDataPath data = inMemTestDataPath();
final Path test = data.resolve("test");
assertFalse(data.exists(test));
Files.createDirectories(data.getTestDataDirectory().resolve(test));
assertTrue(data.exists(test));
}
@Test
void testInputString() throws IOException {
TestDataPath data = inMemTestDataPath(null);
TestDataPath data = inMemTestDataPath();
assertThrows(IOException.class, () -> {data.input("test");});
data.create();
Files.createFile(data.resolve("test"));
Files.createFile(data.getTestDataDirectory().resolve("test"));
InputStream input = data.input("test");
assertEquals(0, input.available());
}
@Test
void testInputPath() throws IOException {
TestDataPath data = inMemTestDataPath(null);
TestDataPath data = inMemTestDataPath();
assertThrows(IOException.class, () -> {
data.input(data.resolve("test"));
data.input(data.getTestDataDirectory().resolve("test"));
});
data.create();
Files.createFile(data.resolve("test"));
InputStream input = data.input(data.resolve("test"));
Files.createFile(data.getTestDataDirectory().resolve("test"));
InputStream input = data.input(data.getTestDataDirectory().resolve("test"));
assertEquals(0, input.available());
}
@Test
void testOutputString() throws IOException {
TestDataPath data = inMemTestDataPath(null);
TestDataPath data = inMemTestDataPath();
assertThrows(IOException.class, () -> {
data.output("test");
});
......@@ -162,40 +168,40 @@ class TestDataPathTest {
@Test
void testOutputPath() throws IOException {
TestDataPath data = inMemTestDataPath(null);
TestDataPath data = inMemTestDataPath();
assertThrows(IOException.class, () -> {
data.output(data.resolve("test"));
data.output(data.getTestDataDirectory().resolve("test"));
});
data.create();