Changes for Checkstyle 8.32
[policy/models.git] / models-pdp / src / test / java / org / onap / policy / models / pdp / persistence / concepts / JpaPdpSubGroupTest.java
index d066d9b..7f8752d 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2019 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.
@@ -31,10 +32,10 @@ import static org.junit.Assert.assertTrue;
 import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
-
 import org.junit.Test;
 import org.onap.policy.models.base.PfConceptKey;
 import org.onap.policy.models.base.PfReferenceKey;
+import org.onap.policy.models.base.PfSearchableKey;
 import org.onap.policy.models.base.PfValidationResult;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
 import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild;
@@ -46,97 +47,98 @@ import org.onap.policy.models.pdp.testconcepts.DummyJpaPdpSubgroupChild;
  */
 public class JpaPdpSubGroupTest {
 
+    private static final String NULL_KEY_ERROR = "key is marked .*ull but is null";
+    private static final String PDP_A = "PDP-A";
+
     @Test
     public void testJpaPdpSubGroup() {
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup((JpaPdpSubGroup) null);
-        }).hasMessage("copyConcept is marked @NonNull but is null");
+        }).hasMessageMatching("copyConcept is marked .*ull but is null");
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup((PfReferenceKey) null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup((PdpSubGroup) null);
-        }).hasMessage("authorativeConcept is marked @NonNull but is null");
+        }).hasMessageMatching("authorativeConcept is marked .*ull but is null");
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, null, null, null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(new PfReferenceKey(), null, null, null);
-        }).hasMessage("supportedPolicyTypes is marked @NonNull but is null");
+        }).hasMessageMatching("supportedPolicyTypes is marked .*ull but is null");
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(new PfReferenceKey(), new ArrayList<>(), null, null);
-        }).hasMessage("policies is marked @NonNull but is null");
+        }).hasMessageMatching("policies is marked .*ull but is null");
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, new ArrayList<>(), null, null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, new ArrayList<>(), new ArrayList<>(), null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, null, new ArrayList<>(), null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, null, null, new ArrayList<>());
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(new PfReferenceKey(), null, null, new ArrayList<>());
-        }).hasMessage("supportedPolicyTypes is marked @NonNull but is null");
+        }).hasMessageMatching("supportedPolicyTypes is marked .*ull but is null");
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(new PfReferenceKey(), new ArrayList<>(), null, new ArrayList<>());
-        }).hasMessage("policies is marked @NonNull but is null");
+        }).hasMessageMatching("policies is marked .*ull but is null");
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, new ArrayList<>(), null, new ArrayList<>());
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, new ArrayList<>(), new ArrayList<>(), new ArrayList<>());
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertThatThrownBy(() -> {
             new JpaPdpSubGroup(null, null, new ArrayList<>(), null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessageMatching(NULL_KEY_ERROR);
 
         assertNotNull(new JpaPdpSubGroup((new PfReferenceKey())));
 
         PdpSubGroup testPdpSubgroup = new PdpSubGroup();
-        testPdpSubgroup.setPdpType("PDP-A");
+        testPdpSubgroup.setPdpType(PDP_A);
         JpaPdpSubGroup testJpaPdpSubGroup = new JpaPdpSubGroup();
         testJpaPdpSubGroup.setKey(null);
         testJpaPdpSubGroup.fromAuthorative(testPdpSubgroup);
-        assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName());
+        assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName());
         testJpaPdpSubGroup.setKey(PfReferenceKey.getNullKey());
         testJpaPdpSubGroup.fromAuthorative(testPdpSubgroup);
 
         assertThatThrownBy(() -> {
             testJpaPdpSubGroup.fromAuthorative(null);
-        }).hasMessage("pdpSubgroup is marked @NonNull but is null");
+        }).hasMessageMatching("pdpSubgroup is marked .*ull but is null");
 
-        assertThatThrownBy(() -> {
-            testJpaPdpSubGroup.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaPdpSubGroup((JpaPdpSubGroup) null)).isInstanceOf(NullPointerException.class);
 
-        assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName());
-        assertEquals("PDP-A", new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName());
-        assertEquals("PDP-A", ((PfReferenceKey) new JpaPdpSubGroup(testPdpSubgroup).getKeys().get(0)).getLocalName());
+        assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName());
+        assertEquals(PDP_A, new JpaPdpSubGroup(testPdpSubgroup).getKey().getLocalName());
+        assertEquals(PDP_A, ((PfReferenceKey) new JpaPdpSubGroup(testPdpSubgroup).getKeys().get(0)).getLocalName());
 
         testJpaPdpSubGroup.clean();
-        assertEquals("PDP-A", testJpaPdpSubGroup.getKey().getLocalName());
+        assertEquals(PDP_A, testJpaPdpSubGroup.getKey().getLocalName());
 
         assertThatThrownBy(() -> {
             testJpaPdpSubGroup.validate(null);
-        }).hasMessage("resultIn is marked @NonNull but is null");
+        }).hasMessageMatching("resultIn is marked .*ull but is null");
 
         assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
         assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
@@ -150,7 +152,7 @@ public class JpaPdpSubGroupTest {
                 .contains("INVALID:a PDP subgroup must support at least one policy type"));
 
         testJpaPdpSubGroup.setSupportedPolicyTypes(new ArrayList<>());
-        testJpaPdpSubGroup.getSupportedPolicyTypes().add(new PfConceptKey("APolicyType:1.0.0"));
+        testJpaPdpSubGroup.getSupportedPolicyTypes().add(new PfSearchableKey("APolicyType:1.0.0"));
         assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
         assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).toString()
                 .contains("INVALID:a PDP subgroup must support at least one policy type"));
@@ -186,7 +188,7 @@ public class JpaPdpSubGroupTest {
         testJpaPdpSubGroup.setProperties(null);
         assertTrue(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
 
-        List<PfConceptKey> supportedPolicyTypes = testJpaPdpSubGroup.getSupportedPolicyTypes();
+        List<PfSearchableKey> supportedPolicyTypes = testJpaPdpSubGroup.getSupportedPolicyTypes();
         assertNotNull(supportedPolicyTypes);
         testJpaPdpSubGroup.setSupportedPolicyTypes(null);
         assertFalse(testJpaPdpSubGroup.validate(new PfValidationResult()).isOk());
@@ -234,7 +236,7 @@ public class JpaPdpSubGroupTest {
         testJpaPdpSubGroup.setDesiredInstanceCount(0);
         assertEquals(0, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
 
-        PfConceptKey anotherPolicyType = new PfConceptKey("AnotherPolicyType", "1.0.0");
+        PfSearchableKey anotherPolicyType = new PfSearchableKey("AnotherPolicyType.*", "1.0.0");
         testJpaPdpSubGroup.getSupportedPolicyTypes().add(anotherPolicyType);
         assertNotEquals(0, testJpaPdpSubGroup.compareTo(otherJpaPdpSubGroup));
         testJpaPdpSubGroup.getSupportedPolicyTypes().remove(anotherPolicyType);
@@ -275,5 +277,7 @@ public class JpaPdpSubGroupTest {
         assertEquals("Prop Value", testJpaPdpSubGroup.getProperties().get("PropKey"));
 
         assertEquals(4, testJpaPdpSubGroup.getKeys().size());
+
+        assertEquals(testJpaPdpSubGroup, new JpaPdpSubGroup(testJpaPdpSubGroup));
     }
 }