Commit faa0ed07 authored by Daniel Bluhm's avatar Daniel Bluhm
Browse files

Rearrange dev.annotations to add proxytest module


Signed-off-by: Daniel Bluhm's avatarDaniel Bluhm <bluhmdj@ornl.gov>
parent 7e29d719
<factorypath>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger-compiler/2.16/dagger-compiler-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger/2.16/dagger-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger-producers/2.16/dagger-producers-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/checkerframework/checker-compat-qual/2.3.0/checker-compat-qual-2.3.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/dagger/dagger-spi/2.16/dagger-spi-2.16.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/googlejavaformat/google-java-format/1.4/google-java-format-1.4.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/javac-shaded/9-dev-r4023-3/javac-shaded-9-dev-r4023-3.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/guava/guava/23.3-jre/guava-23.3-jre.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/code/findbugs/jsr305/1.3.9/jsr305-1.3.9.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/errorprone/error_prone_annotations/2.0.18/error_prone_annotations-2.0.18.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/google/j2objc/j2objc-annotations/1.1/j2objc-annotations-1.1.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/org/codehaus/mojo/animal-sniffer-annotations/1.14/animal-sniffer-annotations-1.14.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/com/squareup/javapoet/1.8.0/javapoet-1.8.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/javax/annotation/jsr250-api/1.0/jsr250-api-1.0.jar" enabled="true" runInBatchMode="false"/>
<factorypathentry kind="VARJAR" id="M2_REPO/javax/inject/javax.inject/1/javax.inject-1.jar" enabled="true" runInBatchMode="false"/>
</factorypath>
eclipse.preferences.version=1
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/test/java=UTF-8
encoding//src/test/resources=UTF-8
encoding/<project>=UTF-8
eclipse.preferences.version=1
org.eclipse.jdt.apt.aptEnabled=true
org.eclipse.jdt.apt.genSrcDir=target/generated-sources/annotations
org.eclipse.jdt.apt.genTestSrcDir=target/generated-test-sources/test-annotations
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
org.eclipse.jdt.core.compiler.processAnnotations=enabled
org.eclipse.jdt.core.compiler.release=enabled
org.eclipse.jdt.core.compiler.source=11
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.ice.dev</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<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"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" path="/org.eclipse.ice.dev.annotations"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>org.eclipse.ice.dev.annotations.proxytest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
</natures>
</projectDescription>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.eclipse.ice.dev</groupId>
<artifactId>org.eclipse.ice.dev</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<artifactId>org.eclipse.ice.dev.annotations.proxytest</artifactId>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<release>11</release>
<annotationProcessorPaths>
<path>
<groupId>com.google.dagger</groupId>
<artifactId>dagger-compiler</artifactId>
<version>2.16</version>
</path>
<path>
<groupId>org.eclipse.ice</groupId>
<artifactId>org.eclipse.ice.dev.annotations</artifactId>
<version>3.0.0-SNAPSHOT</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.ice.dev</groupId>
<artifactId>org.eclipse.ice.dev.annotations</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.10.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.10.2</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.6.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.28</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.2</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
package org.eclipse.ice.dev.annotations.proxytest;
import org.eclipse.ice.dev.annotations.DataElement;
import org.eclipse.ice.dev.annotations.DataField;
@DataElement(name = "GeneratedDataElementPOJO")
public class GeneratedDataElementPOJOSpec {
@DataField public TestPOJO testPOJO;
}
package org.eclipse.ice.dev.annotations.proxytest;
import org.eclipse.ice.dev.annotations.DataElement;
import org.eclipse.ice.dev.annotations.DataField;
@DataElement(name = "GeneratedDataElement")
public class GeneratedDataElementSpec {
@DataField public String testField;
}
/*******************************************************************************
* Copyright (c) 2020- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings
*******************************************************************************/
package org.eclipse.ice.dev.annotations.proxytest;
import static org.junit.jupiter.api.Assertions.*;
import org.eclipse.ice.dev.annotations.JavascriptValidator;
import org.junit.jupiter.api.Test;
/**
* This class tests the DataElement class. With the exception of testing for
* serialization to a string, it is sufficient to test this class with T=String.
* For testing serialization, multiple types need to be tested.
*
* @author Jay Jay Billings
* @author Daniel Bluhm
*
*/
class GeneratedDataElementTest {
/**
* This is a helper function for creating GeneratedDataElementImplementation values that are
* used in most of the tests.
*
* @param data the value that should be stored in the element.
* @return the data
*/
private GeneratedDataElement getStringElement(final String data) {
GeneratedDataElement element = new GeneratedDataElementImplementation();
element.setTestField(data);
return element;
}
/**
* Test method for verifying expected defaults are present and modifiable.
*/
@Test
void testDefaultProps() {
// Use a basic string element for this test since it is looking at content on
// the base class.
GeneratedDataElement element = getStringElement("Phutureprimitive");
// Now check the getters
assertEquals(element.getName(), "name");
assertEquals(element.getDescription(), "description");
assertEquals(element.getId(), 0);
assertEquals(element.getComment(), "no comment");
assertEquals(element.getContext(), "default");
// Check the boolean property default values
assertEquals(element.isRequired(), false);
assertEquals(element.isSecret(), false);
// Setup new values for checking setters
String name = "rock";
String description = "round garden rock";
long id = 1L;
String comment = "Brown with a pumpkin next to it";
String context = "garden";
boolean required = true;
boolean secret = true;
// Set all the properties
try {
element.setComment(comment);
element.setContext(context);
element.setId(id);
element.setName(name);
element.setDescription(description);
element.setRequired(required);
element.setSecret(secret);
} catch (Exception e) {
// Complain
e.printStackTrace();
fail();
}
// Check the getters
assertEquals(element.getName(), name);
assertEquals(element.getDescription(), description);
assertEquals(element.getId(), id);
assertEquals(element.getComment(), comment);
assertEquals(element.getContext(), context);
// Check the boolean property default values
assertEquals(element.isRequired(), required);
assertEquals(element.isSecret(), secret);
// Make sure that adding validators works superficially
JavascriptValidator<GeneratedDataElement> validator = new JavascriptValidator<GeneratedDataElement>();
element.setValidator(validator);
assertEquals(element.getValidator(), validator);
// Make sure that the UUID is not null
assertNotNull(element.getUUID());
return;
}
/**
* Test method for accessing generated fields.
*/
@Test
void testDataAccessors() {
// Basic intrinsic class is good for this test
GeneratedDataElement element = getStringElement("Phutureprimitive");
// No properties are configured here. Just want to make sure that the data
// behaves as expected.
// Do the straight check
assertEquals("Phutureprimitive", element.getTestField());
// Make sure that changing the value works round-trip
String data = element.getTestField();
data = "The Glitch Mob";
element.setTestField(data);
assertEquals("The Glitch Mob", element.getTestField());
return;
}
/**
* Test generated DataElement Implementation with POJO as a DataField.
*/
@Test
void testDataAccessorsForPOJOs() {
// Use a test POJO for this that has members
GeneratedDataElementPOJO element = new GeneratedDataElementPOJOImplementation();
element.setTestPOJO(new TestPOJO());
// Do the straight check
TestPOJO pojo = element.getTestPOJO();
assertEquals("foo", pojo.getValue());
assertEquals(2118.0, pojo.getDoubleValue(), 1.0e-15);
// Make sure that changing the value works round-trip
pojo.setDoubleValue(1234.0);
pojo.setValue("bar");
assertEquals("bar", pojo.getValue());
assertEquals(1234.0, pojo.getDoubleValue(), 1.0e-15);
return;
}
/**
* Test generated DataElement Implementation with Intrinsic class as DataField.
*/
@Test
void testStringSerialization() {
// Basic intrinsic class is good for this test
GeneratedDataElement element = getStringElement("Major Lazer & La Roux");
element.setSecret(true);
element.setRequired(true);
element.setValidator(new JavascriptValidator<GeneratedDataElement>());
// Because of the private id changing and being unique, this cannot be checked
// against a reference but can only be checked by inversion.
String output = element.toJSON();
// Change some values then read back in the original to make sure fromString()
// correctly overwrites them.
element.setTestField("Eastern Sun");
System.out.println(output);
GeneratedDataElement element2 = getStringElement("Emancipator");
element2.setValidator(new JavascriptValidator<GeneratedDataElement>());
element2.fromJSON(output);
element.fromJSON(output);
assertEquals(element,element2);
return;
}
/**
* Test method for {@link org.eclipse.ice.renderer.DataElement#toString()} and
* {@link org.eclipse.ice.renderer.DataElement#toString()} for POJOs.
*/
@Test
void testPOJOSerialization() {
// Use a test POJO for this that has members
GeneratedDataElementPOJO element = new GeneratedDataElementPOJOImplementation();
element.setTestPOJO(new TestPOJO());
element.setSecret(true);
element.setRequired(true);
element.setValidator(new JavascriptValidator<GeneratedDataElementPOJO>());
// Because of the private id changing and being unique, this cannot be checked
// against a reference but can only be checked by inversion.
String output = element.toJSON();
// Change some values then read back in the original to make sure fromString()
// correctly overwrites them.
GeneratedDataElementPOJO element2 = new GeneratedDataElementPOJOImplementation();
TestPOJO pojo2 = new TestPOJO();
pojo2.setDoubleValue(1.072);
element2.setValidator(new JavascriptValidator<GeneratedDataElementPOJO>());
element2.setTestPOJO(pojo2);
element2.fromJSON(output);
assertEquals(element,element2);
return;
}
/**
* Test method for
* {@link org.eclipse.ice.renderer.DataElement#matches(DataElement)},
* {@link org.eclipse.ice.renderer.DataElement#equals(java.lang.Object)},
* {@link org.eclipse.ice.renderer.DataElement#hashCode()},
* {@link org.eclipse.ice.renderer.DataElement#copy()}, and
* {@link org.eclipse.ice.renderer.DataElement#clone()}.
*/
@Test
void testEquality() {
// Basic intrinsic class is good for this test
GeneratedDataElement element = getStringElement("Halsey");
GeneratedDataElement element2 = getStringElement("Halsey");
GeneratedDataElement element3 = getStringElement("Billie Eilish");
GeneratedDataElement element4 = getStringElement("Halsey");
// Need a validator for the tests that is shared on the equal elements.
JavascriptValidator<GeneratedDataElement> validator = new JavascriptValidator<GeneratedDataElement>();
element.setValidator(validator);
element2.setValidator(validator);
element4.setValidator(validator);
// Billie needs her own validator
element3.setValidator(new JavascriptValidator<GeneratedDataElement>());
// Data elements must be checked both for matching - a deep inequality except
// the UUID - and for a fully complete match that contains the UUID. Start with
// matching. Check reflexivity first
assertTrue(element.matches(element));
// Check symmetry
assertTrue(element.matches(element2));
assertTrue(element2.matches(element));
// Check transitivity
assertTrue(element.matches(element2));
assertTrue(element2.matches(element4));
assertTrue(element.matches(element4));
// Check a wrong answer
assertFalse(element.matches(element3));
// Check null
assertFalse(element.matches(null));
// Now check equality with a clone - therefore also confirming clone works
GeneratedDataElement elementClone = (GeneratedDataElementImplementation) element.clone();
// Check reflexivity first
assertEquals(element, element);
// Check symmetry
assertEquals(element, elementClone);
assertEquals(elementClone, element);
// This is a sneaky way to use a copy constructor to check transitivity and get
// around the UUID thing
try {
element4 = (GeneratedDataElement) new GeneratedDataElementImplementation(
(GeneratedDataElementImplementation) elementClone
);
} catch (Exception e) {
// Complain
e.printStackTrace();
fail();
}
assertEquals(element4, element);
// Check a wrong answer
assertFalse(element.equals(element3));
// Check null
assertFalse(element.equals(null));
// Check against a string - this should fail
assertFalse(element.equals("Halsey"));
// Check hashCode()
assertEquals(element.hashCode(), elementClone.hashCode());
return;
}
}
package org.eclipse.ice.dev.annotations.proxytest;
import static org.junit.jupiter.api.Assertions.*;
import org.eclipse.ice.dev.annotations.JavascriptValidator;
import org.junit.jupiter.api.Test;
/**
* This class is responsible for testing the ability of the package to do
* Javascript-based validation of data classes.
*
* @author Jay Jay Billings
*
*/
class JavascriptValidatorTest {
/**
* This function tests that Javascript functions can be correctly set on the
* validator and that validation can be run successfully. Since functions are
* simply strings, the first part of the test is a rudimentary accessor test
* only.
*/
@Test