Merge "Convert models to JUnit 5"
[policy/models.git] / models-interactions / model-actors / actor.test / src / main / java / org / onap / policy / controlloop / actor / test / BasicBidirectionalTopicOperation.java
index 215286e..3f339d0 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023-2024 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -20,8 +21,9 @@
 
 package org.onap.policy.controlloop.actor.test;
 
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.when;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.fail;
+import static org.mockito.Mockito.lenient;
 
 import java.util.List;
 import java.util.function.BiConsumer;
@@ -44,7 +46,6 @@ import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopic
 import org.onap.policy.controlloop.actorserviceprovider.topic.BidirectionalTopicManager;
 import org.onap.policy.controlloop.actorserviceprovider.topic.Forwarder;
 import org.onap.policy.simulators.TopicServer;
-import org.onap.policy.simulators.Util;
 
 /**
  * Superclass for various BidirectionalTopicOperation tests.
@@ -96,20 +97,17 @@ public abstract class BasicBidirectionalTopicOperation<Q> extends BasicOperation
     /**
      * Starts the topic.
      *
-     * @throws InterruptedException if interrupted
      * @throws BidirectionalTopicClientException if the client cannot be built
      */
     protected static void initBeforeClass(String sinkTopic, String sourceTopic)
-                    throws InterruptedException, BidirectionalTopicClientException {
-
-        Util.buildDmaapSim();
+                    throws BidirectionalTopicClientException {
 
         // note: the sink and source names are swapped for the simulator
         var ptopic = new TopicParameters();
         ptopic.setTopic(sourceTopic);
         ptopic.setManaged(true);
         ptopic.setServers(List.of("localhost"));
-        ptopic.setTopicCommInfrastructure("dmaap");
+        ptopic.setTopicCommInfrastructure("NOOP");
         ptopic.setFetchTimeout(500);
         serverSink = TopicEndpointManager.getManager().addTopicSinks(List.of(ptopic)).get(0);
 
@@ -153,8 +151,16 @@ public abstract class BasicBidirectionalTopicOperation<Q> extends BasicOperation
         initConfig();
     }
 
+    /**
+     * Finish all topic servers and mocks.
+     */
     public void tearDownBasic() {
         topicServer.shutdown();
+        try {
+            closeable.close();
+        } catch (Exception e) {
+            fail(e.getMessage());
+        }
     }
 
     /**
@@ -170,9 +176,9 @@ public abstract class BasicBidirectionalTopicOperation<Q> extends BasicOperation
      * Initializes a configuration.
      */
     protected void initConfig() {
-        when(config.getTopicHandler()).thenReturn(topicHandler);
-        when(config.getForwarder()).thenReturn(forwarder);
-        when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS);
+        lenient().when(config.getTopicHandler()).thenReturn(topicHandler);
+        lenient().when(config.getForwarder()).thenReturn(forwarder);
+        lenient().when(config.getTimeoutMs()).thenReturn(TIMEOUT_MS);
     }
 
     /**