Make feature-pooling-dmaap work without filtering
[policy/drools-pdp.git] / feature-pooling-dmaap / src / test / java / org / onap / policy / drools / pooling / PoolingFeatureTest.java
index f9878a9..02a4db5 100644 (file)
@@ -2,14 +2,15 @@
  * ============LICENSE_START=======================================================
  * ONAP
  * ================================================================================
- * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright (C) 2018, 2020 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2020 Nordix Foundation
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * 
+ *
  *      http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -38,6 +39,7 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Properties;
 import java.util.concurrent.CountDownLatch;
+import org.apache.commons.lang3.tuple.Pair;
 import org.junit.Before;
 import org.junit.Test;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
@@ -46,7 +48,6 @@ import org.onap.policy.common.endpoints.event.comm.TopicSource;
 import org.onap.policy.drools.controller.DroolsController;
 import org.onap.policy.drools.system.PolicyController;
 import org.onap.policy.drools.system.PolicyEngine;
-import org.onap.policy.drools.utils.Pair;
 
 public class PoolingFeatureTest {
 
@@ -83,7 +84,7 @@ public class PoolingFeatureTest {
 
     /**
      * Setup.
-     * 
+     *
      * @throws Exception exception
      */
     @Before
@@ -113,8 +114,8 @@ public class PoolingFeatureTest {
         pool.afterCreate(controller1);
         pool.afterCreate(controller2);
 
-        mgr1 = managers.get(0).first();
-        mgr2 = managers.get(1).first();
+        mgr1 = managers.get(0).getLeft();
+        mgr2 = managers.get(1).getLeft();
     }
 
     @Test
@@ -245,7 +246,7 @@ public class PoolingFeatureTest {
         verify(mgr1).afterStop();
 
         assertFalse(pool.afterStop(controllerDisabled));
-        
+
         // count should be unchanged
         verify(mgr1).afterStop();
     }
@@ -254,7 +255,7 @@ public class PoolingFeatureTest {
     public void testAfterHalt() {
         assertFalse(pool.afterHalt(controller1));
         assertFalse(pool.afterHalt(controller1));
-        
+
         verify(mgr1, never()).afterStop();
 
         assertFalse(pool.afterStop(controllerDisabled));
@@ -264,7 +265,7 @@ public class PoolingFeatureTest {
     public void testAfterShutdown() {
         assertFalse(pool.afterShutdown(controller1));
         assertFalse(pool.afterShutdown(controller1));
-        
+
         verify(mgr1, never()).afterStop();
 
         assertFalse(pool.afterStop(controllerDisabled));
@@ -297,20 +298,20 @@ public class PoolingFeatureTest {
     @Test
     public void testBeforeOffer() {
         assertFalse(pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC1, EVENT1));
-        verify(mgr1).beforeOffer(CommInfrastructure.UEB, TOPIC1, EVENT1);
+        verify(mgr1).beforeOffer(TOPIC1, EVENT1);
 
         // ensure that the args were captured
         pool.beforeInsert(drools1, OBJECT1);
-        verify(mgr1).beforeInsert(CommInfrastructure.UEB, TOPIC1, EVENT1, OBJECT1);
+        verify(mgr1).beforeInsert(TOPIC1, OBJECT1);
 
 
         // ensure it's still in the map by re-invoking
         assertFalse(pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC2, EVENT2));
-        verify(mgr1).beforeOffer(CommInfrastructure.UEB, TOPIC2, EVENT2);
+        verify(mgr1).beforeOffer(TOPIC2, EVENT2);
 
         // ensure that the new args were captured
         pool.beforeInsert(drools1, OBJECT2);
-        verify(mgr1).beforeInsert(CommInfrastructure.UEB, TOPIC2, EVENT2, OBJECT2);
+        verify(mgr1).beforeInsert(TOPIC2, OBJECT2);
 
 
         assertFalse(pool.beforeOffer(controllerDisabled, CommInfrastructure.UEB, TOPIC1, EVENT1));
@@ -325,14 +326,14 @@ public class PoolingFeatureTest {
     public void testBeforeOffer_MgrTrue() {
 
         // manager will return true
-        when(mgr1.beforeOffer(any(), any(), any())).thenReturn(true);
+        when(mgr1.beforeOffer(any(), any())).thenReturn(true);
 
         assertTrue(pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC1, EVENT1));
-        verify(mgr1).beforeOffer(CommInfrastructure.UEB, TOPIC1, EVENT1);
+        verify(mgr1).beforeOffer(TOPIC1, EVENT1);
 
         // ensure it's still in the map by re-invoking
         assertTrue(pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC2, EVENT2));
-        verify(mgr1).beforeOffer(CommInfrastructure.UEB, TOPIC2, EVENT2);
+        verify(mgr1).beforeOffer(TOPIC2, EVENT2);
 
         assertFalse(pool.beforeOffer(controllerDisabled, CommInfrastructure.UEB, TOPIC1, EVENT1));
     }
@@ -341,12 +342,12 @@ public class PoolingFeatureTest {
     public void testBeforeInsert() {
         pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC1, EVENT1);
         assertFalse(pool.beforeInsert(drools1, OBJECT1));
-        verify(mgr1).beforeInsert(CommInfrastructure.UEB, TOPIC1, EVENT1, OBJECT1);
+        verify(mgr1).beforeInsert(TOPIC1, OBJECT1);
 
         // ensure it's still in the map by re-invoking
         pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC2, EVENT2);
         assertFalse(pool.beforeInsert(drools1, OBJECT2));
-        verify(mgr1).beforeInsert(CommInfrastructure.UEB, TOPIC2, EVENT2, OBJECT2);
+        verify(mgr1).beforeInsert(TOPIC2, OBJECT2);
 
         pool.beforeOffer(controllerDisabled, CommInfrastructure.UEB, TOPIC2, EVENT2);
         assertFalse(pool.beforeInsert(droolsDisabled, OBJECT1));
@@ -357,10 +358,10 @@ public class PoolingFeatureTest {
 
         // call beforeInsert without beforeOffer
         assertFalse(pool.beforeInsert(drools1, OBJECT1));
-        verify(mgr1, never()).beforeInsert(any(), any(), any(), any());
+        verify(mgr1, never()).beforeInsert(any(), any());
 
         assertFalse(pool.beforeInsert(droolsDisabled, OBJECT1));
-        verify(mgr1, never()).beforeInsert(any(), any(), any(), any());
+        verify(mgr1, never()).beforeInsert(any(), any());
     }
 
     @Test
@@ -375,7 +376,7 @@ public class PoolingFeatureTest {
 
         pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC1, EVENT1);
         assertFalse(pool.beforeInsert(drools1, OBJECT1));
-        verify(mgr1, never()).beforeInsert(any(), any(), any(), any());
+        verify(mgr1, never()).beforeInsert(any(), any());
     }
 
     @Test
@@ -390,7 +391,7 @@ public class PoolingFeatureTest {
 
         pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC1, EVENT1);
         assertFalse(pool.beforeInsert(drools1, OBJECT1));
-        verify(mgr1, never()).beforeInsert(any(), any(), any(), any());
+        verify(mgr1, never()).beforeInsert(any(), any());
     }
 
     @Test
@@ -406,7 +407,7 @@ public class PoolingFeatureTest {
 
         pool.beforeOffer(controller1, CommInfrastructure.UEB, TOPIC1, EVENT1);
         assertFalse(pool.beforeInsert(drools1, OBJECT1));
-        verify(mgr1, never()).beforeInsert(any(), any(), any(), any());
+        verify(mgr1, never()).beforeInsert(any(), any());
     }
 
     @Test
@@ -425,7 +426,7 @@ public class PoolingFeatureTest {
         assertFalse(pool.afterOffer(controller1, CommInfrastructure.UEB, TOPIC2, EVENT2, true));
 
         assertFalse(pool.beforeInsert(drools1, OBJECT1));
-        verify(mgr1, never()).beforeInsert(any(), any(), any(), any());
+        verify(mgr1, never()).beforeInsert(any(), any());
 
 
         assertFalse(pool.beforeInsert(droolsDisabled, OBJECT1));
@@ -515,7 +516,7 @@ public class PoolingFeatureTest {
 
             PoolingManagerImpl mgr = mock(PoolingManagerImpl.class);
 
-            managers.add(new Pair<>(mgr, props));
+            managers.add(Pair.of(mgr, props));
 
             return mgr;
         }