diff options
author | liamfallon <liam.fallon@est.tech> | 2019-03-26 22:31:43 +0000 |
---|---|---|
committer | liamfallon <liam.fallon@est.tech> | 2019-03-26 22:31:43 +0000 |
commit | cee84a9344f35356f86384b0d48127f5a83e3776 (patch) | |
tree | c2a796218273fa4553f07d1328adac3882ab4711 /models-base/src/test/java/org/onap | |
parent | 38e3ea9ff6a0a1534a30655e22082cf4c8d887d0 (diff) |
Add Legacy Op Policy Persistence
Legacy operational policies now fully supported for
serialization and persistence from provider through to
database and back. Unit test coverage completed
also
Issue-ID: POLICY-1095
Change-Id: I65755859c94b50edee537d2685f51a7838c6541f
Signed-off-by: liamfallon <liam.fallon@est.tech>
Diffstat (limited to 'models-base/src/test/java/org/onap')
5 files changed, 156 insertions, 22 deletions
diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java index 848889cc3..a4c504788 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyTest.java @@ -42,9 +42,10 @@ public class PfKeyTest { new PfConceptKey("some bad key id"); fail("This test should throw an exception"); } catch (IllegalArgumentException e) { - assertEquals("parameter \"id\": value \"some bad key id\", " + assertEquals( + "parameter \"id\": value \"some bad key id\", " + "does not match regular expression \"[A-Za-z0-9\\-_\\.]+:[0-9].[0-9].[0-9]\"", - e.getMessage()); + e.getMessage()); } PfConceptKey someKey0 = new PfConceptKey(); @@ -110,19 +111,19 @@ public class PfKeyTest { assertFalse(someKey1.isCompatible(new DummyPfKey())); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey0.validate(new PfValidationResult()).getValidationResult()); + someKey0.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey1.validate(new PfValidationResult()).getValidationResult()); + someKey1.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey2.validate(new PfValidationResult()).getValidationResult()); + someKey2.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey3.validate(new PfValidationResult()).getValidationResult()); + someKey3.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey4.validate(new PfValidationResult()).getValidationResult()); + someKey4.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey5.validate(new PfValidationResult()).getValidationResult()); + someKey5.validate(new PfValidationResult()).getValidationResult()); assertEquals(PfValidationResult.ValidationResult.VALID, - someKey6.validate(new PfValidationResult()).getValidationResult()); + someKey6.validate(new PfValidationResult()).getValidationResult()); someKey0.clean(); assertNotNull(someKey0.toString()); @@ -150,14 +151,14 @@ public class PfKeyTest { @Test public void testNullArguments() { try { - new PfConceptKey((String)null); + new PfConceptKey((String) null); fail("test should throw an exception here"); } catch (Exception exc) { assertEquals("id is marked @NonNull but is null", exc.getMessage()); } try { - new PfConceptKey((PfConceptKey)null); + new PfConceptKey((PfConceptKey) null); fail("id is marked @NonNull but is null"); } catch (Exception exc) { assertEquals("copyConcept is marked @NonNull but is null", exc.getMessage()); @@ -207,9 +208,9 @@ public class PfKeyTest { nameField.set(testKey, "TheKey"); nameField.setAccessible(false); assertEquals( - "name invalid-parameter name with value Key Name " - + "does not match regular expression [A-Za-z0-9\\-_\\.]+", - validationResult.getMessageList().get(0).getMessage()); + "name invalid-parameter name with value Key Name " + + "does not match regular expression [A-Za-z0-9\\-_\\.]+", + validationResult.getMessageList().get(0).getMessage()); } catch (Exception validationException) { fail("test should not throw an exception"); } @@ -223,11 +224,105 @@ public class PfKeyTest { versionField.set(testKey, "0.0.1"); versionField.setAccessible(false); assertEquals( - "version invalid-parameter version with value Key Version " - + "does not match regular expression [A-Za-z0-9.]+", - validationResult.getMessageList().get(0).getMessage()); + "version invalid-parameter version with value Key Version " + + "does not match regular expression [A-Za-z0-9.]+", + validationResult.getMessageList().get(0).getMessage()); } catch (Exception validationException) { fail("test should not throw an exception"); } } + + @Test + public void testkeynewerThan() { + PfConceptKey key1 = new PfConceptKey("Key1", "1.2.3"); + + try { + key1.isNewerThan(null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); + } + + try { + key1.isNewerThan(new PfReferenceKey()); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("org.onap.policy.models.base.PfReferenceKey is not " + + "an instance of org.onap.policy.models.base.PfConceptKey", exc.getMessage()); + } + + assertFalse(key1.isNewerThan(key1)); + + PfConceptKey key1a = new PfConceptKey("Key1a", "1.2.3"); + assertFalse(key1.isNewerThan(key1a)); + + PfConceptKey key1b = new PfConceptKey("Key0", "1.2.3"); + assertTrue(key1.isNewerThan(key1b)); + + key1a.setName("Key1"); + assertFalse(key1.isNewerThan(key1a)); + + key1a.setVersion("0.2.3"); + assertTrue(key1.isNewerThan(key1a)); + key1a.setVersion("2.2.3"); + assertFalse(key1.isNewerThan(key1a)); + key1a.setVersion("1.2.3"); + assertFalse(key1.isNewerThan(key1a)); + + key1a.setVersion("1.1.3"); + assertTrue(key1.isNewerThan(key1a)); + key1a.setVersion("1.3.3"); + assertFalse(key1.isNewerThan(key1a)); + key1a.setVersion("1.2.3"); + assertFalse(key1.isNewerThan(key1a)); + + key1a.setVersion("1.2.2"); + assertTrue(key1.isNewerThan(key1a)); + key1a.setVersion("1.2.4"); + assertFalse(key1.isNewerThan(key1a)); + key1a.setVersion("1.2.3"); + assertFalse(key1.isNewerThan(key1a)); + + key1.setVersion("1"); + assertFalse(key1.isNewerThan(key1a)); + key1a.setVersion("1"); + assertFalse(key1.isNewerThan(key1a)); + + PfReferenceKey refKey = new PfReferenceKey(); + + try { + refKey.isNewerThan(null); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); + } + + try { + refKey.isNewerThan(new PfConceptKey()); + fail("test should throw an exception"); + } catch (Exception exc) { + assertEquals("org.onap.policy.models.base.PfConceptKey is not " + + "an instance of org.onap.policy.models.base.PfReferenceKey", exc.getMessage()); + } + + assertFalse(refKey.isNewerThan(refKey)); + } + + @Test + public void testmajorMinorPatch() { + PfConceptKey key = new PfConceptKey("Key", "1"); + assertEquals(1, key.getMajorVersion()); + assertEquals(0, key.getMinorVersion()); + assertEquals(0, key.getPatchVersion()); + + key = new PfConceptKey("Key", "1.2"); + assertEquals(1, key.getMajorVersion()); + assertEquals(2, key.getMinorVersion()); + assertEquals(0, key.getPatchVersion()); + + key = new PfConceptKey("Key", "1.2.3"); + assertEquals(1, key.getMajorVersion()); + assertEquals(2, key.getMinorVersion()); + assertEquals(3, key.getPatchVersion()); + } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java index ccdc72dcd..72df28f04 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfKeyUseTest.java @@ -131,5 +131,9 @@ public class PfKeyUseTest { } catch (Exception exc) { assertEquals("error copying concept key: Some error message", exc.getMessage()); } + + assertEquals(0, testKeyUse.getMajorVersion()); + assertEquals(0, testKeyUse.getMinorVersion()); + assertEquals(0, testKeyUse.getPatchVersion()); } } diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java index 64d4bc6b8..edf4466f8 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfReferenceKeyTest.java @@ -58,6 +58,10 @@ public class PfReferenceKeyTest { testReferenceKey.setParentConceptKey(new PfConceptKey("PN", "0.0.1")); assertEquals("PN:0.0.1", testReferenceKey.getParentConceptKey().getId()); + assertEquals(0, testReferenceKey.getMajorVersion()); + assertEquals(0, testReferenceKey.getMinorVersion()); + assertEquals(1, testReferenceKey.getPatchVersion()); + assertEquals(1, testReferenceKey.getKeys().size()); assertFalse(testReferenceKey.isNullKey()); @@ -76,6 +80,13 @@ public class PfReferenceKeyTest { testReferenceKey.setLocalName("NLN"); assertEquals("NLN", testReferenceKey.getLocalName()); + try { + testReferenceKey.isCompatible(null); + fail("test should throw an exception here"); + } catch (Exception exc) { + assertEquals("otherKey is marked @NonNull but is null", exc.getMessage()); + } + assertFalse(testReferenceKey.isCompatible(PfConceptKey.getNullKey())); assertFalse(testReferenceKey.isCompatible(PfReferenceKey.getNullKey())); assertTrue(testReferenceKey.isCompatible(testReferenceKey)); diff --git a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java index bdbab5c36..11ddf3132 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java +++ b/models-base/src/test/java/org/onap/policy/models/base/PfUtilsTest.java @@ -1,4 +1,4 @@ -/* +/*- * ============LICENSE_START======================================================= * Copyright (C) 2019 Nordix Foundation. * Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. @@ -23,7 +23,7 @@ package org.onap.policy.models.base; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import java.util.Arrays; import java.util.List; @@ -47,9 +47,10 @@ public class PfUtilsTest { @Test public void testMapList() { - assertNull(PfUtils.mapList(null, item -> { + List<Object> resultList = PfUtils.mapList(null, item -> { throw new RuntimeException("should not be invoked"); - })); + }); + assertTrue(resultList.isEmpty()); List<String> origList = Arrays.asList("abc", "def"); List<String> newList = PfUtils.mapList(origList, text -> text + "X"); diff --git a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java index 6cf41e60c..f485b0d0f 100644 --- a/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java +++ b/models-base/src/test/java/org/onap/policy/models/base/testconcepts/DummyPfKey.java @@ -23,11 +23,13 @@ package org.onap.policy.models.base.testconcepts; import java.util.Arrays; import java.util.List; +import lombok.NonNull; + import org.onap.policy.models.base.PfConcept; import org.onap.policy.models.base.PfKey; import org.onap.policy.models.base.PfValidationResult; -public class DummyPfKey extends PfKey { +public class DummyPfKey extends PfKey { private static final long serialVersionUID = 1L; @Override @@ -94,4 +96,25 @@ public class DummyPfKey extends PfKey { public PfConcept copyTo(PfConcept target) { return null; } + + @Override + public boolean isNewerThan(@NonNull PfKey otherKey) { + // TODO Auto-generated method stub + return false; + } + + @Override + public int getMajorVersion() { + return 0; + } + + @Override + public int getMinorVersion() { + return 0; + } + + @Override + public int getPatchVersion() { + return 0; + } } |