Replace copyTo methods with copy constructors
[policy/models.git] / models-tosca / src / test / java / org / onap / policy / models / tosca / simple / concepts / JpaToscaPolicyTest.java
index ae38ab9..73e5066 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.
@@ -45,6 +46,9 @@ import org.onap.policy.models.tosca.simple.concepts.JpaToscaPolicy;
  */
 public class JpaToscaPolicyTest {
 
+    private static final String KEY_IS_NULL = "key is marked @NonNull but is null";
+    private static final String VERSION_001 = "0.0.1";
+
     @Test
     public void testPolicyPojo() {
         assertNotNull(new JpaToscaPolicy());
@@ -58,11 +62,11 @@ public class JpaToscaPolicyTest {
 
         assertThatThrownBy(() -> {
             new JpaToscaPolicy((PfConceptKey) null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessage(KEY_IS_NULL);
 
         assertThatThrownBy(() -> {
             new JpaToscaPolicy(null, null);
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessage(KEY_IS_NULL);
 
         assertThatThrownBy(() -> {
             new JpaToscaPolicy(new PfConceptKey(), null);
@@ -70,14 +74,13 @@ public class JpaToscaPolicyTest {
 
         assertThatThrownBy(() -> {
             new JpaToscaPolicy(null, new PfConceptKey());
-        }).hasMessage("key is marked @NonNull but is null");
+        }).hasMessage(KEY_IS_NULL);
 
-        assertThatThrownBy(() -> {
-            new JpaToscaPolicy((JpaToscaPolicy) null);
-        }).hasMessage("copyConcept is marked @NonNull but is null");
+        assertThatThrownBy(() -> new JpaToscaPolicy((JpaToscaPolicy) null))
+                        .isInstanceOf(NullPointerException.class);
 
-        PfConceptKey tpKey = new PfConceptKey("tdt", "0.0.1");
-        PfConceptKey ptKey = new PfConceptKey("policyType", "0.0.1");
+        PfConceptKey tpKey = new PfConceptKey("tdt", VERSION_001);
+        PfConceptKey ptKey = new PfConceptKey("policyType", VERSION_001);
         JpaToscaPolicy tp = new JpaToscaPolicy(tpKey, ptKey);
 
         Map<String, String> propertyMap = new HashMap<>();
@@ -86,7 +89,7 @@ public class JpaToscaPolicyTest {
         assertEquals(propertyMap, tp.getProperties());
 
         List<PfConceptKey> targets = new ArrayList<>();
-        PfConceptKey target = new PfConceptKey("target", "0.0.1");
+        PfConceptKey target = new PfConceptKey("target", VERSION_001);
         targets.add(target);
         tp.setTargets(targets);
         assertEquals(targets, tp.getTargets());
@@ -95,8 +98,7 @@ public class JpaToscaPolicyTest {
         assertEquals(tp, tdtClone0);
         assertEquals(0, tp.compareTo(tdtClone0));
 
-        JpaToscaPolicy tdtClone1 = new JpaToscaPolicy();
-        tp.copyTo(tdtClone1);
+        JpaToscaPolicy tdtClone1 = new JpaToscaPolicy(tp);
         assertEquals(tp, tdtClone1);
         assertEquals(0, tp.compareTo(tdtClone1));
 
@@ -104,7 +106,7 @@ public class JpaToscaPolicyTest {
         assertEquals(0, tp.compareTo(tp));
         assertFalse(tp.compareTo(tp.getKey()) == 0);
 
-        PfConceptKey otherDtKey = new PfConceptKey("otherDt", "0.0.1");
+        PfConceptKey otherDtKey = new PfConceptKey("otherDt", VERSION_001);
         JpaToscaPolicy otherDt = new JpaToscaPolicy(otherDtKey);
 
         assertFalse(tp.compareTo(otherDt) == 0);
@@ -117,10 +119,6 @@ public class JpaToscaPolicyTest {
         otherDt.setTargets(targets);
         assertEquals(0, tp.compareTo(otherDt));
 
-        assertThatThrownBy(() -> {
-            tp.copyTo(null);
-        }).hasMessage("target is marked @NonNull but is null");
-
         assertEquals(3, tp.getKeys().size());
         assertEquals(2, new JpaToscaPolicy().getKeys().size());
 
@@ -129,7 +127,6 @@ public class JpaToscaPolicyTest {
         assertEquals(tdtClone0, tp);
 
         assertFalse(new JpaToscaPolicy().validate(new PfValidationResult()).isValid());
-        System.err.println(tp.validate(new PfValidationResult()));
         assertTrue(tp.validate(new PfValidationResult()).isValid());
 
         tp.getProperties().put(null, null);