policy/pap jdk11 upgrades
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / comm / msgdata / UpdateReqTest.java
index 4aa8075..db95515 100644 (file)
@@ -2,7 +2,7 @@
  * ============LICENSE_START=======================================================
  * ONAP PAP
  * ================================================================================
- * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2019-2020 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.
@@ -25,13 +25,15 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.Set;
+import java.util.TreeSet;
 import java.util.stream.Collectors;
 import org.junit.Before;
 import org.junit.Test;
@@ -79,12 +81,14 @@ public class UpdateReqTest extends CommonRequestBase {
     @Test
     public void testCheckResponse() {
         assertNull(data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
         verifyResponse();
 
         // both policy lists null
         update.setPolicies(null);
         response.setPolicies(null);
         assertNull(data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
     }
 
     @Test
@@ -92,6 +96,7 @@ public class UpdateReqTest extends CommonRequestBase {
         response.setName(null);
 
         assertEquals("null PDP name", data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
         verifyNoResponse();
     }
 
@@ -100,6 +105,7 @@ public class UpdateReqTest extends CommonRequestBase {
         update.setName(null);
 
         assertEquals(null, data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
         verifyResponse();
     }
 
@@ -108,6 +114,7 @@ public class UpdateReqTest extends CommonRequestBase {
         response.setPdpGroup(DIFFERENT);
 
         assertEquals("group does not match", data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
         verifyResponse();
     }
 
@@ -116,6 +123,20 @@ public class UpdateReqTest extends CommonRequestBase {
         response.setPdpSubgroup(DIFFERENT);
 
         assertEquals("subgroup does not match", data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
+        verifyResponse();
+    }
+
+    @Test
+    public void testCheckResponse_NullSubGroup() {
+        update.setPdpSubgroup(null);
+        response.setPdpSubgroup(null);
+
+        // different policy list - should have no impact
+        response.setPolicies(Collections.emptyList());
+
+        assertEquals(null, data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
         verifyResponse();
     }
 
@@ -128,6 +149,10 @@ public class UpdateReqTest extends CommonRequestBase {
 
         assertEquals("policies do not match", data.checkResponse(response));
         verifyResponse();
+
+        // the first policy from the original update is all that should be undeployed
+        assertEquals(Collections.singleton(update.getPolicies().get(0).getIdentifier()).toString(),
+                        data.getUndeployPolicies().toString());
     }
 
     @Test
@@ -135,6 +160,7 @@ public class UpdateReqTest extends CommonRequestBase {
         update.setPolicies(null);
 
         assertEquals("policies do not match", data.checkResponse(response));
+        assertTrue(data.getUndeployPolicies().isEmpty());
         verifyResponse();
     }
 
@@ -144,6 +170,10 @@ public class UpdateReqTest extends CommonRequestBase {
 
         assertEquals("policies do not match", data.checkResponse(response));
         verifyResponse();
+
+        // all policies in the update should be undeployed
+        assertEquals(update.getPolicies().stream().map(ToscaPolicy::getIdentifier).collect(Collectors.toList())
+                        .toString(), new TreeSet<>(data.getUndeployPolicies()).toString());
     }
 
     @Test
@@ -164,7 +194,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent() {
+    public void testIsSameContent() {
         PdpUpdate msg2 = new PdpUpdate(update);
         msg2.setName("world");
         assertTrue(data.isSameContent(msg2));
@@ -176,7 +206,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent_BothGroupNamesNull() {
+    public void testIsSameContent_BothGroupNamesNull() {
         PdpUpdate msg2 = new PdpUpdate(update);
         msg2.setPdpGroup(null);
         update.setPdpGroup(null);
@@ -184,7 +214,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent_BothSubGroupNamesNull() {
+    public void testIsSameContent_BothSubGroupNamesNull() {
         PdpUpdate msg2 = new PdpUpdate(update);
         msg2.setPdpSubgroup(null);
         update.setPdpSubgroup(null);
@@ -192,7 +222,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent_DiffGroup() {
+    public void testIsSameContent_DiffGroup() {
         PdpUpdate msg2 = new PdpUpdate(update);
         msg2.setPdpGroup(null);
         assertFalse(data.isSameContent(msg2));
@@ -205,7 +235,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent_DiffSubGroup() {
+    public void testIsSameContent_DiffSubGroup() {
         PdpUpdate msg2 = new PdpUpdate(update);
         msg2.setPdpSubgroup(null);
         assertFalse(data.isSameContent(msg2));
@@ -218,7 +248,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent_DiffPolicies() {
+    public void testIsSameContent_DiffPolicies() {
         PdpUpdate msg2 = new PdpUpdate(update);
 
         ArrayList<ToscaPolicy> policies = new ArrayList<>(update.getPolicies());
@@ -229,7 +259,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent_DiffPolicies_NotNull_Null() {
+    public void testIsSameContent_DiffPolicies_NotNull_Null() {
         PdpUpdate msg2 = new PdpUpdate(update);
         msg2.setPolicies(null);
 
@@ -237,7 +267,7 @@ public class UpdateReqTest extends CommonRequestBase {
     }
 
     @Test
-    public void isSameContent_DiffPolicies_Null_NotNull() {
+    public void testIsSameContent_DiffPolicies_Null_NotNull() {
         PdpUpdate msg2 = new PdpUpdate(update);
 
         update.setPolicies(null);