summaryrefslogtreecommitdiffstats
path: root/models-tosca/src/test
diff options
context:
space:
mode:
authorJim Hahn <jrh3@att.com>2019-04-11 21:58:12 -0400
committerJim Hahn <jrh3@att.com>2019-04-12 11:37:46 -0400
commit92d9b661cc32b8dcc90e813aa220e26ef6f83b17 (patch)
treec1e2afa2a2294377aa5364e8234713c44b62bfeb /models-tosca/src/test
parent8a26f57269caf7a559deb46077050048da92dca8 (diff)
Add validation methods for PAP REST API
Also made the identifier classes comparable. Stupid tabs. Change-Id: I54c0595c6a2c61a1b72b58fe1d667657f9d5d71e Issue-ID: POLICY-1542 Signed-off-by: Jim Hahn <jrh3@att.com>
Diffstat (limited to 'models-tosca/src/test')
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaIdentifierTestBase.java45
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java9
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java37
-rw-r--r--models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java36
4 files changed, 112 insertions, 15 deletions
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaIdentifierTestBase.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaIdentifierTestBase.java
index 5c935394b..d7bca2808 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaIdentifierTestBase.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaIdentifierTestBase.java
@@ -20,6 +20,9 @@
package org.onap.policy.models.tosca.authorative.concepts;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import org.onap.policy.common.utils.coder.Coder;
import org.onap.policy.common.utils.coder.CoderException;
import org.onap.policy.common.utils.coder.StandardCoder;
@@ -29,19 +32,49 @@ import org.onap.policy.common.utils.coder.StandardCoder;
*
* @param <T> type of key being tested
*/
-public class ToscaIdentifierTestBase<T> {
+public class ToscaIdentifierTestBase<T extends Comparable<T>> {
+ public static final String NAME = "my-name";
+ public static final String VERSION = "1.2.3";
private static final Coder coder = new StandardCoder();
private final Class<T> clazz;
+ private final String nameField;
+ private final String versionField;
/**
* Constructs the object.
+ *
* @param clazz the type of class being tested
+ * @param nameField name of the field containing the "name"
+ * @param versionField name of the field containing the "version"
*/
- public ToscaIdentifierTestBase(Class<T> clazz) {
+ public ToscaIdentifierTestBase(Class<T> clazz, String nameField, String versionField) {
this.clazz = clazz;
+ this.nameField = nameField;
+ this.versionField = versionField;
+ }
+
+ /**
+ * Tests the compareTo() method.
+ *
+ * @throws Exception if an error occurs
+ */
+ public void testCompareTo() throws Exception {
+ T ident = makeIdent(NAME, VERSION);
+ assertEquals(0, ident.compareTo(ident));
+
+ assertTrue(ident.compareTo(null) > 0);
+
+ assertTrue(ident.compareTo(makeIdent(NAME, VERSION)) == 0);
+ assertTrue(ident.compareTo(makeIdent(NAME, null)) > 0);
+ assertTrue(ident.compareTo(makeIdent(null, VERSION)) > 0);
+ assertTrue(ident.compareTo(makeIdent(NAME, VERSION + "a")) < 0);
+ assertTrue(ident.compareTo(makeIdent(NAME + "a", VERSION)) < 0);
+
+ // name takes precedence over version
+ assertTrue(makeIdent(NAME, VERSION + "a").compareTo(makeIdent(NAME + "a", VERSION)) < 0);
}
/**
@@ -57,7 +90,9 @@ public class ToscaIdentifierTestBase<T> {
bldr.append("{");
if (name != null) {
- bldr.append("'name':'");
+ bldr.append("'");
+ bldr.append(nameField);
+ bldr.append("':'");
bldr.append(name);
bldr.append("'");
}
@@ -67,7 +102,9 @@ public class ToscaIdentifierTestBase<T> {
bldr.append(',');
}
- bldr.append("'version':'");
+ bldr.append("'");
+ bldr.append(versionField);
+ bldr.append("':'");
bldr.append(version);
bldr.append("'");
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
index 561b4fb21..3f0a7b09c 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierOptVersionTest.java
@@ -31,11 +31,9 @@ import org.junit.Test;
* Test the other constructors, as {@link PojosTest} tests the other methods.
*/
public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase<ToscaPolicyIdentifierOptVersion> {
- private static final String NAME = "my-name";
- private static final String VERSION = "1.2.3";
public ToscaPolicyIdentifierOptVersionTest() {
- super(ToscaPolicyIdentifierOptVersion.class);
+ super(ToscaPolicyIdentifierOptVersion.class, "policy-id", "policy-version");
}
@Test
@@ -68,4 +66,9 @@ public class ToscaPolicyIdentifierOptVersionTest extends ToscaIdentifierTestBase
orig = makeIdent(NAME, VERSION);
assertEquals(orig.toString(), new ToscaPolicyIdentifierOptVersion(orig).toString());
}
+
+ @Test
+ public void testCompareTo() throws Exception {
+ super.testCompareTo();
+ }
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java
index a53af7b1f..f31abf837 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyIdentifierTest.java
@@ -22,18 +22,21 @@ package org.onap.policy.models.tosca.authorative.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.onap.policy.common.parameters.ValidationResult;
/**
- * Test the other constructors, as {@link PojosTest} tests the other methods.
+ * Test methods not tested by {@link PojosTest}.
*/
public class ToscaPolicyIdentifierTest extends ToscaIdentifierTestBase<ToscaPolicyIdentifier> {
- private static final String NAME = "my-name";
- private static final String VERSION = "1.2.3";
public ToscaPolicyIdentifierTest() {
- super(ToscaPolicyIdentifier.class);
+ super(ToscaPolicyIdentifier.class, "name", "version");
}
@Test
@@ -59,4 +62,30 @@ public class ToscaPolicyIdentifierTest extends ToscaIdentifierTestBase<ToscaPoli
orig = new ToscaPolicyIdentifier(NAME, VERSION);
assertEquals(orig.toString(), new ToscaPolicyIdentifier(orig).toString());
}
+
+ @Test
+ public void testValidatePapRest() throws Exception {
+ ToscaPolicyIdentifier ident = new ToscaPolicyIdentifier(NAME, VERSION);
+ ValidationResult result = ident.validatePapRest();
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertNull(result.getResult());
+
+ ident = makeIdent(NAME, null);
+ result = ident.validatePapRest();
+ assertNotNull(result);
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+
+ ident = makeIdent(null, VERSION);
+ result = ident.validatePapRest();
+ assertNotNull(result);
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+ }
+
+ @Test
+ public void testCompareTo() throws Exception {
+ super.testCompareTo();
+ }
}
diff --git a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java
index 8388f1061..e440dd6da 100644
--- a/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java
+++ b/models-tosca/src/test/java/org/onap/policy/models/tosca/authorative/concepts/ToscaPolicyTypeIdentifierTest.java
@@ -22,18 +22,21 @@ package org.onap.policy.models.tosca.authorative.concepts;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import org.junit.Test;
+import org.onap.policy.common.parameters.ValidationResult;
/**
- * Test the other constructors, as {@link PojosTest} tests the other methods.
+ * Test methods not tested by {@link PojosTest}.
*/
public class ToscaPolicyTypeIdentifierTest extends ToscaIdentifierTestBase<ToscaPolicyTypeIdentifier> {
- private static final String NAME = "my-name";
- private static final String VERSION = "1.2.3";
public ToscaPolicyTypeIdentifierTest() {
- super(ToscaPolicyTypeIdentifier.class);
+ super(ToscaPolicyTypeIdentifier.class, "name", "version");
}
@Test
@@ -60,4 +63,29 @@ public class ToscaPolicyTypeIdentifierTest extends ToscaIdentifierTestBase<Tosca
assertEquals(orig.toString(), new ToscaPolicyTypeIdentifier(orig).toString());
}
+ @Test
+ public void testValidatePapRest() throws Exception {
+ ToscaPolicyTypeIdentifier ident = new ToscaPolicyTypeIdentifier(NAME, VERSION);
+ ValidationResult result = ident.validatePapRest();
+ assertNotNull(result);
+ assertTrue(result.isValid());
+ assertNull(result.getResult());
+
+ ident = makeIdent(NAME, null);
+ result = ident.validatePapRest();
+ assertNotNull(result);
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+
+ ident = makeIdent(null, VERSION);
+ result = ident.validatePapRest();
+ assertNotNull(result);
+ assertFalse(result.isValid());
+ assertNotNull(result.getResult());
+ }
+
+ @Test
+ public void testCompareTo() throws Exception {
+ super.testCompareTo();
+ }
}