Consistent returns on Service Template gets
[policy/models.git] / models-base / src / test / java / org / onap / policy / models / base / PfKeyUseTest.java
index 7dbde74..46a0066 100644 (file)
@@ -1,6 +1,7 @@
-/*
+/*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,6 +21,7 @@
 
 package org.onap.policy.models.base;
 
+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.assertNotEquals;
@@ -28,23 +30,33 @@ import static org.junit.Assert.assertTrue;
 
 import org.junit.Test;
 import org.onap.policy.models.base.PfKey.Compatibility;
+import org.onap.policy.models.base.testconcepts.DummyPfConceptKeySub;
 
 public class PfKeyUseTest {
 
+    private static final String OTHER_KEY_IS_NULL = "^otherKey is marked .*on.*ull but is null$";
+
     @Test
-    public void test() {
+    public void testKeyUse() {
         assertNotNull(new PfKeyUse());
         assertNotNull(new PfKeyUse(new PfConceptKey()));
         assertNotNull(new PfKeyUse(new PfReferenceKey()));
 
+        assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null))
+            .hasMessageMatching("^copyConcept is marked .*on.*ull but is null$");
+
         PfConceptKey key = new PfConceptKey("Key", "0.0.1");
         PfKeyUse keyUse = new PfKeyUse();
         keyUse.setKey(key);
         assertEquals(key, keyUse.getKey());
         assertEquals("Key:0.0.1", keyUse.getId());
         assertEquals(key, keyUse.getKeys().get(0));
+        assertFalse(keyUse.isNullKey());
 
         assertEquals(Compatibility.IDENTICAL, keyUse.getCompatibility(key));
+
+        assertThatThrownBy(() -> key.getCompatibility(null)).hasMessageMatching(OTHER_KEY_IS_NULL);
+
         assertTrue(keyUse.isCompatible(key));
 
         keyUse.clean();
@@ -74,5 +86,27 @@ public class PfKeyUseTest {
         PfKeyUse keyUseNull = new PfKeyUse(PfConceptKey.getNullKey());
         PfValidationResult resultNull = new PfValidationResult();
         assertEquals(false, keyUseNull.validate(resultNull).isValid());
+
+        assertThatThrownBy(() -> keyUse.setKey(null)).hasMessageMatching("^key is marked .*on.*ull but is null$");
+
+        assertThatThrownBy(() -> keyUse.getCompatibility(null)).hasMessageMatching(OTHER_KEY_IS_NULL);
+
+        assertThatThrownBy(() -> keyUse.isCompatible(null)).hasMessageMatching(OTHER_KEY_IS_NULL);
+
+        assertThatThrownBy(() -> keyUse.validate(null)).hasMessageMatching("^result is marked .*on.*ull but is null$");
+
+        PfKeyUse testKeyUse = new PfKeyUse(new DummyPfConceptKeySub(new PfConceptKey()));
+        assertEquals(testKeyUse, new PfKeyUse(testKeyUse));
+
+        assertThatThrownBy(() -> new PfKeyUse((PfKeyUse) null)).isInstanceOf(NullPointerException.class);
+
+        assertThatThrownBy(() -> keyUse.isNewerThan(null)).hasMessageMatching(OTHER_KEY_IS_NULL);
+
+        assertEquals(false, testKeyUse.isNewerThan(keyUse));
+        assertEquals(false, testKeyUse.isNewerThan(testKeyUse));
+
+        assertEquals(0, testKeyUse.getMajorVersion());
+        assertEquals(0, testKeyUse.getMinorVersion());
+        assertEquals(0, testKeyUse.getPatchVersion());
     }
 }