Topic names in PAP should be configurable from application.yaml 66/132266/2
authoradheli.tavares <adheli.tavares@est.tech>
Wed, 16 Nov 2022 14:12:22 +0000 (14:12 +0000)
committerAdheli Tavares <adheli.tavares@est.tech>
Thu, 17 Nov 2022 13:01:39 +0000 (13:01 +0000)
- for using Kafka instead of dmaap, topics names need to be lowercase
- fix for unit/integration tests using default names and changed names
for topics and group
- fix for sonar lints found along the way

Issue-ID: POLICY-4455
Change-Id: I89e9e6f7dbb07462f1ae497755965cb5a3f223a3
Signed-off-by: adheli.tavares <adheli.tavares@est.tech>
35 files changed:
main/src/main/java/org/onap/policy/pap/main/PapConstants.java
main/src/main/java/org/onap/policy/pap/main/comm/PdpMessageGenerator.java
main/src/main/java/org/onap/policy/pap/main/config/WebConfig.java
main/src/main/java/org/onap/policy/pap/main/rest/PolicyComponentsHealthCheckProvider.java
main/src/main/java/org/onap/policy/pap/main/rest/SessionData.java
main/src/main/java/org/onap/policy/pap/main/startstop/PapActivator.java
main/src/main/resources/application.yaml
main/src/test/java/org/onap/policy/pap/main/comm/CommonRequestBase.java
main/src/test/java/org/onap/policy/pap/main/comm/PublisherTest.java
main/src/test/java/org/onap/policy/pap/main/rest/TestHealthCheckRestControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupCreateOrUpdateControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeleteControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupDeployControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupHealthCheckControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupQueryControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPdpGroupStateChangeControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyAuditControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyComponentsHealthCheckProvider.java
main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/TestStatisticsRestControllerV1.java
main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java
main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java
main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java
main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java
main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java
main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java
main/src/test/java/org/onap/policy/pap/main/service/PdpGroupServiceTest.java
main/src/test/java/org/onap/policy/pap/main/service/PdpStatisticsServiceTest.java
main/src/test/java/org/onap/policy/pap/main/service/PolicyAuditServiceTest.java
main/src/test/java/org/onap/policy/pap/main/service/PolicyStatusServiceTest.java
main/src/test/java/org/onap/policy/pap/main/startstop/TestPapActivator.java
main/src/test/resources/application-test-e2e.yaml [new file with mode: 0644]
main/src/test/resources/application-test.yaml [moved from main/src/test/resources/config/application.yaml with 83% similarity]
main/src/test/resources/e2e/PapConfigParameters.json

index 36d5eeb..98859f1 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -35,14 +36,7 @@ public final class PapConstants {
     public static final String REG_PDP_MODIFY_MAP = "object:pdp/modify/map";
     public static final String REG_METER_REGISTRY = "object:meter/registry";
 
-    // topic names
-    public static final String TOPIC_POLICY_PDP_PAP = "POLICY-PDP-PAP";
-    public static final String TOPIC_POLICY_NOTIFICATION = "POLICY-NOTIFICATION";
-    public static final String TOPIC_POLICY_HEARTBEAT = "POLICY-HEARTBEAT";
-
     // policy components names
-    public static final String POLICY_API = "api";
-    public static final String POLICY_DISTRIBUTION = "distribution";
     public static final String POLICY_PAP = "pap";
     public static final String POLICY_PDPS = "pdps";
 
index 255b93e..7bf6b80 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
  * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,6 +24,7 @@ package org.onap.policy.pap.main.comm;
 
 import java.util.LinkedList;
 import java.util.List;
+import lombok.Getter;
 import org.onap.policy.common.parameters.ParameterService;
 import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.models.base.PfModelException;
@@ -43,6 +44,7 @@ import org.onap.policy.pap.main.service.ToscaServiceTemplateService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.boot.context.event.ApplicationReadyEvent;
 import org.springframework.context.event.EventListener;
 
@@ -53,9 +55,7 @@ import org.springframework.context.event.EventListener;
 public class PdpMessageGenerator {
     private static final Logger LOGGER = LoggerFactory.getLogger(PdpMessageGenerator.class);
 
-    private static final String PAP_GROUP_PARAMS_NAME = "PapGroup";
-
-    private boolean includeHeartBeat;
+    private final boolean includeHeartBeat;
     /**
      * Lock used when updating PDPs.
      */
@@ -80,6 +80,10 @@ public class PdpMessageGenerator {
     @Autowired
     private PolicyNotifier policyNotifier;
 
+    @Getter
+    @Value("${pap.name}")
+    private String papGroupParamName = "PapGroup";
+
     /**
      * Constructs the object.
      *
@@ -99,7 +103,7 @@ public class PdpMessageGenerator {
         requestMap = Registry.get(PapConstants.REG_PDP_MODIFY_MAP, PdpModifyRequestMap.class);
 
         if (includeHeartBeat) {
-            PapParameterGroup params = ParameterService.get(PAP_GROUP_PARAMS_NAME);
+            PapParameterGroup params = ParameterService.get(papGroupParamName);
             heartBeatMs = params.getPdpParameters().getHeartBeatMs();
 
         } else {
@@ -130,8 +134,8 @@ public class PdpMessageGenerator {
      * Method to return a list of policies.
      *
      * @param subGroup PdpSubGroup to retrieve policies from
+     * @return a list of ToscaPolicy
      * @throws PfModelException the exception
-     * @returns a list of ToscaPolicy
      **/
     public List<ToscaPolicy> getToscaPolicies(final PdpSubGroup subGroup) throws PfModelException {
 
@@ -167,7 +171,6 @@ public class PdpMessageGenerator {
      * @param pdpInstanceId the pdp instance
      * @param pdpState the new state as per the PDP_STATE_CHANGE change message
      * @param policies list of policies as per the PDP_UPDATE message
-     * @throws PfModelException the exception
      */
     protected void updateDeploymentStatus(final String pdpGroupName, final String pdpType, final String pdpInstanceId,
         PdpState pdpState, List<ToscaPolicy> policies) {
index d8aee3a..a6cfdf6 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2022 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,7 +21,6 @@
 
 package org.onap.policy.pap.main.config;
 
-import java.util.Arrays;
 import java.util.List;
 import org.onap.policy.common.spring.utils.YamlHttpMessageConverter;
 import org.springframework.context.annotation.Configuration;
@@ -37,7 +37,7 @@ public class WebConfig implements WebMvcConfigurer {
     @Override
     public void extendMessageConverters(List<HttpMessageConverter<?>> converters) {
         var yamlConverter = new YamlHttpMessageConverter();
-        yamlConverter.setSupportedMediaTypes(Arrays.asList(MediaType.parseMediaType("application/yaml")));
+        yamlConverter.setSupportedMediaTypes(List.of(MediaType.parseMediaType("application/yaml")));
         converters.add(yamlConverter);
     }
 }
\ No newline at end of file
index 53f05a1..4da802d 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2020, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
  *  Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
  * ================================================================================
@@ -88,6 +88,9 @@ public class PolicyComponentsHealthCheckProvider {
     @Value("${server.port}")
     private int port;
 
+    @Value("${pap.topic.pdp-pap.name:POLICY-PDP-PAP}")
+    private String topicPolicyPdpPap;
+
     /**
      * This method is used to initialize clients and executor.
      */
@@ -244,8 +247,8 @@ public class PolicyComponentsHealthCheckProvider {
     private HealthCheckReport verifyDmaapClient(HttpClient httpClient, Response resp) {
         DmaapGetTopicResponse dmaapResponse = resp.readEntity(DmaapGetTopicResponse.class);
         var topicVerificationStatus = (dmaapResponse.getTopics() != null
-                        && dmaapResponse.getTopics().contains(PapConstants.TOPIC_POLICY_PDP_PAP));
-        String message = (topicVerificationStatus ? "PAP to DMaaP connection check is successfull"
+                        && dmaapResponse.getTopics().contains(topicPolicyPdpPap));
+        String message = (topicVerificationStatus ? "PAP to DMaaP connection check is successful"
                         : "PAP to DMaaP connection check failed");
         int code = (topicVerificationStatus ? resp.getStatus() : 503);
         return createHealthCheckReport(httpClient.getName(), httpClient.getBaseUrl(), code,
index 2abce9b..4cea257 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
  * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -96,12 +96,12 @@ public class SessionData {
     /**
      * Map's a policy's identifier to the policies for deployment.
      */
-    private Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployed = new HashMap<>();
+    private final Map<ToscaConceptIdentifier, ToscaPolicy> policiesToBeDeployed = new HashMap<>();
 
     /**
      * Set of policies to be undeployed.
      */
-    private Set<ToscaConceptIdentifier> policiesToBeUndeployed = new HashSet<>();
+    private final Set<ToscaConceptIdentifier> policiesToBeUndeployed = new HashSet<>();
 
     /**
      * User starting requests.
@@ -114,11 +114,11 @@ public class SessionData {
      */
     private final DeploymentStatus deployStatus;
 
-    private PolicyAuditManager auditManager;
+    private final PolicyAuditManager auditManager;
 
-    private ToscaServiceTemplateService toscaService;
+    private final ToscaServiceTemplateService toscaService;
 
-    private PdpGroupService pdpGroupService;
+    private final PdpGroupService pdpGroupService;
 
     /**
      * Constructs the object.
@@ -368,9 +368,8 @@ public class SessionData {
      *
      * @param type desired policy type
      * @return the active groups supporting the given policy
-     * @throws PfModelException if an error occurred
      */
-    public List<PdpGroup> getActivePdpGroupsByPolicyType(ToscaConceptIdentifier type) throws PfModelException {
+    public List<PdpGroup> getActivePdpGroupsByPolicyType(ToscaConceptIdentifier type) {
         /*
          * Cannot use computeIfAbsent() because the enclosed code throws an unchecked exception and handling that would
          * obfuscate the code too much, thus disabling the sonar.
@@ -392,7 +391,7 @@ public class SessionData {
     /**
      * Gets the list of policies to be deployed to the PDPs.
      *
-     * @returns a list of policies to be deployed
+     * @return a list of policies to be deployed
      */
     public List<ToscaPolicy> getPoliciesToBeDeployed() {
         return new LinkedList<>(this.policiesToBeDeployed.values());
@@ -401,7 +400,7 @@ public class SessionData {
     /**
      * Gets the list of policies to be undeployed from the PDPs.
      *
-     * @returns a list of policies to be undeployed
+     * @return a list of policies to be undeployed
      */
     public List<ToscaConceptIdentifier> getPoliciesToBeUndeployed() {
         return new LinkedList<>(this.policiesToBeUndeployed);
index f8c4fb3..19b3c67 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2021 AT&T Intellectual Property.
  *  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
@@ -28,6 +28,7 @@ import java.util.concurrent.Executors;
 import java.util.concurrent.ScheduledExecutorService;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
+import lombok.Getter;
 import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
 import org.onap.policy.common.endpoints.event.comm.TopicListener;
 import org.onap.policy.common.endpoints.event.comm.TopicSource;
@@ -50,6 +51,7 @@ import org.onap.policy.pap.main.notification.PolicyNotifier;
 import org.onap.policy.pap.main.parameters.PapParameterGroup;
 import org.onap.policy.pap.main.parameters.PdpModifyRequestMapParams;
 import org.onap.policy.pap.main.rest.PapStatisticsManager;
+import org.springframework.beans.factory.annotation.Value;
 import org.springframework.context.event.ContextClosedEvent;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.context.event.EventListener;
@@ -63,15 +65,29 @@ import org.springframework.stereotype.Component;
  */
 @Component
 public class PapActivator extends ServiceManagerContainer {
+
+    // topic names
+    @Getter
+    @Value("${pap.topic.pdp-pap.name}")
+    private String topicPolicyPdpPap = "POLICY-PDP-PAP";
+
+    @Getter
+    @Value("${pap.topic.notification.name}")
+    private String topicPolicyNotification = "POLICY-NOTIFICATION";
+
+    @Getter
+    @Value("${pap.topic.heartbeat.name}")
+    private String topicPolicyHeartbeat = "POLICY-HEARTBEAT";
+
     private static final String[] MSG_TYPE_NAMES = { "messageName" };
     private static final String[] REQ_ID_NAMES = { "response", "responseTo" };
 
     /**
-     * Max number of heat beats that can be missed before PAP removes a PDP.
+     * Max number of heart beats that can be missed before PAP removes a PDP.
      */
     private static final int MAX_MISSED_HEARTBEATS = 3;
 
-    private PapParameterGroup papParameterGroup;
+    private final PapParameterGroup papParameterGroup;
 
     /**
      * Listens for messages on the topic, decodes them into a {@link PdpStatus} message, and then dispatches them to
@@ -142,12 +158,12 @@ public class PapActivator extends ServiceManagerContainer {
             () -> heartbeatMsgDispatcher.unregister(PdpMessageType.PDP_STATUS.name()));
 
         addAction("Response Message Dispatcher",
-            () -> registerMsgDispatcher(responseMsgDispatcher, PapConstants.TOPIC_POLICY_PDP_PAP),
-            () -> unregisterMsgDispatcher(responseMsgDispatcher, PapConstants.TOPIC_POLICY_PDP_PAP));
+            () -> registerMsgDispatcher(responseMsgDispatcher, topicPolicyPdpPap),
+            () -> unregisterMsgDispatcher(responseMsgDispatcher, topicPolicyPdpPap));
 
         addAction("Heartbeat Message Dispatcher",
-            () -> registerMsgDispatcher(heartbeatMsgDispatcher, PapConstants.TOPIC_POLICY_HEARTBEAT),
-            () -> unregisterMsgDispatcher(heartbeatMsgDispatcher, PapConstants.TOPIC_POLICY_HEARTBEAT));
+            () -> registerMsgDispatcher(heartbeatMsgDispatcher, topicPolicyHeartbeat),
+            () -> unregisterMsgDispatcher(heartbeatMsgDispatcher, topicPolicyHeartbeat));
 
         addAction("topics",
             TopicEndpointManager.getManager()::start,
@@ -163,14 +179,14 @@ public class PapActivator extends ServiceManagerContainer {
 
         addAction("PDP publisher",
             () -> {
-                pdpPub.set(new Publisher<>(PapConstants.TOPIC_POLICY_PDP_PAP));
+                pdpPub.set(new Publisher<>(topicPolicyPdpPap));
                 startThread(pdpPub.get());
             },
             () -> pdpPub.get().stop());
 
         addAction("Policy Notification publisher",
             () -> {
-                notifyPub.set(new Publisher<>(PapConstants.TOPIC_POLICY_NOTIFICATION));
+                notifyPub.set(new Publisher<>(topicPolicyNotification));
                 startThread(notifyPub.get());
                 policyNotifier.setPublisher(notifyPub.get());
             },
index ebe94b8..2711e2d 100644 (file)
@@ -27,6 +27,10 @@ server:
 pap:
   name: PapGroup
   aaf: false
+  topic:
+    pdp-pap.name: POLICY-PDP-PAP
+    notification.name: POLICY-NOTIFICATION
+    heartbeat.name: POLICY-HEARTBEAT
   pdpParameters:
     heartBeatMs: 120000
     updateParameters:
@@ -38,24 +42,24 @@ pap:
   savePdpStatisticsInDb: true
   topicParameterGroup:
     topicSources:
-    - topic: POLICY-PDP-PAP
+    - topic: ${pap.topic.pdp-pap.name}
       servers:
       - message-router
       topicCommInfrastructure: dmaap
       fetchTimeout: 15000
-    - topic: POLICY-HEARTBEAT
-      effectiveTopic: POLICY-PDP-PAP
+    - topic: ${pap.topic.heartbeat.name}
+      effectiveTopic: ${pap.topic.pdp-pap.name}
       consumerGroup: policy-pap
       servers:
       - message-router
       topicCommInfrastructure: dmaap
       fetchTimeout: 15000
     topicSinks:
-    - topic: POLICY-PDP-PAP
+    - topic: ${pap.topic.pdp-pap.name}
       servers:
       - message-router
       topicCommInfrastructure: dmaap
-    - topic: POLICY-NOTIFICATION
+    - topic: ${pap.topic.notification.name}
       servers:
       - message-router
       topicCommInfrastructure: dmaap
index 4086b6a..2a4cdc4 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
  * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -36,7 +36,6 @@ import java.util.function.Consumer;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.mockito.ArgumentCaptor;
-import org.mockito.invocation.InvocationOnMock;
 import org.mockito.stubbing.Answer;
 import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure;
 import org.onap.policy.common.endpoints.listeners.RequestIdDispatcher;
@@ -77,6 +76,7 @@ public class CommonRequestBase {
     protected static final PdpState MY_STATE = PdpState.SAFE;
     protected static final PdpState DIFF_STATE = PdpState.TERMINATED;
     protected static final int RETRIES = 1;
+    protected static final String PDP_PAP_TOPIC = "POLICY-PDP-PAP";
 
     protected Publisher<PdpMessage> publisher;
     protected PolicyNotifier notifier;
@@ -112,12 +112,9 @@ public class CommonRequestBase {
         listener = mock(RequestListener.class);
         PdpParameters pdpParams = mock(PdpParameters.class);
 
-        doAnswer(new Answer<Object>() {
-            @Override
-            public Object answer(InvocationOnMock invocation) throws Throwable {
-                queue.add(invocation.getArgument(0, QueueToken.class));
-                return null;
-            }
+        doAnswer((Answer<Object>) invocation -> {
+            queue.add(invocation.getArgument(0, QueueToken.class));
+            return null;
         }).when(publisher).enqueue(any());
 
         when(timers.register(any(), any())).thenReturn(timer);
@@ -151,7 +148,7 @@ public class CommonRequestBase {
 
         verify(dispatcher).register(any(), processResp.capture());
 
-        processResp.getValue().onTopicEvent(CommInfrastructure.NOOP, PapConstants.TOPIC_POLICY_PDP_PAP, response);
+        processResp.getValue().onTopicEvent(CommInfrastructure.NOOP, PDP_PAP_TOPIC, response);
     }
 
     /**
index 51ced7b..c33790a 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -43,7 +44,6 @@ import org.onap.policy.common.utils.coder.CoderException;
 import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.models.pdp.concepts.PdpMessage;
 import org.onap.policy.models.pdp.concepts.PdpStateChange;
-import org.onap.policy.pap.main.PapConstants;
 import org.onap.policy.pap.main.PolicyPapException;
 import org.onap.policy.pap.main.parameters.CommonTestData;
 import org.onap.policy.pap.main.parameters.PapParameterGroup;
@@ -58,6 +58,8 @@ public class PublisherTest extends Threaded {
     private static final String JSON1;
     private static final String JSON2;
 
+    protected static final String PDP_PAP_TOPIC = "POLICY-PDP-PAP";
+
     static {
         try {
             Coder coder = new StandardCoder();
@@ -81,10 +83,9 @@ public class PublisherTest extends Threaded {
     /**
      * Configures the topic and attaches a listener.
      *
-     * @throws Exception if an error occurs
      */
     @BeforeClass
-    public static void setUpBeforeClass() throws Exception {
+    public static void setUpBeforeClass() {
         final PapParameterGroup parameterGroup = new CommonTestData().getPapParameterGroup(6969);
         TopicEndpointManager.getManager().shutdown();
 
@@ -93,7 +94,7 @@ public class PublisherTest extends Threaded {
     }
 
     @AfterClass
-    public static void tearDownAfterClass() throws Exception {
+    public static void tearDownAfterClass() {
         TopicEndpointManager.getManager().shutdown();
     }
 
@@ -106,10 +107,10 @@ public class PublisherTest extends Threaded {
     public void setUp() throws Exception {
         super.setUp();
 
-        pub = new Publisher<>(PapConstants.TOPIC_POLICY_PDP_PAP);
+        pub = new Publisher<>(PDP_PAP_TOPIC);
 
         listener = new MyListener();
-        TopicEndpointManager.getManager().getNoopTopicSink(PapConstants.TOPIC_POLICY_PDP_PAP).register(listener);
+        TopicEndpointManager.getManager().getNoopTopicSink(PDP_PAP_TOPIC).register(listener);
     }
 
     /**
@@ -119,7 +120,7 @@ public class PublisherTest extends Threaded {
      */
     @After
     public void tearDown() throws Exception {
-        TopicEndpointManager.getManager().getNoopTopicSink(PapConstants.TOPIC_POLICY_PDP_PAP).unregister(listener);
+        TopicEndpointManager.getManager().getNoopTopicSink(PDP_PAP_TOPIC).unregister(listener);
 
         super.tearDown();
     }
@@ -143,7 +144,7 @@ public class PublisherTest extends Threaded {
     }
 
     @Test
-    public void testPublisher_Ex() throws Exception {
+    public void testPublisher_Ex() {
         assertThatThrownBy(() -> new Publisher<>("unknwon-topic")).isInstanceOf(PolicyPapException.class);
     }
 
index 359f9cb..14fa42d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
  *  Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
  * ================================================================================
@@ -27,16 +27,19 @@ import static org.junit.Assert.assertEquals;
 import static org.mockito.Mockito.when;
 
 import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.SyncInvoker;
 import org.junit.Test;
 import org.onap.policy.common.endpoints.report.HealthCheckReport;
 import org.onap.policy.models.base.PfModelRuntimeException;
 import org.springframework.boot.test.mock.mockito.MockBean;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
- * Class to perform unit test of {@link PapRestServer}.
+ * Class to perform unit test of {@link HealthCheckRestControllerV1}.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
+@ActiveProfiles("test")
 public class TestHealthCheckRestControllerV1 extends CommonPapRestServer {
 
     private static final String HEALTHCHECK_ENDPOINT = "healthcheck";
@@ -53,10 +56,10 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer {
     public void testHealthCheckSuccess() throws Exception {
         final Invocation.Builder invocationBuilder = sendRequest(HEALTHCHECK_ENDPOINT);
         final HealthCheckReport report = invocationBuilder.get(HealthCheckReport.class);
-        validateHealthCheckReport(NAME, SELF, true, 200, ALIVE, report);
+        validateHealthCheckReport(true, 200, ALIVE, report);
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(HEALTHCHECK_ENDPOINT, req -> req.get());
+        checkUnauthRequest(HEALTHCHECK_ENDPOINT, SyncInvoker::get);
     }
 
     @Test
@@ -68,7 +71,7 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer {
         var response = invocationBuilder.get();
         var report = response.readEntity(HealthCheckReport.class);
         assertThat(response.getStatus()).isEqualTo(503);
-        validateHealthCheckReport(NAME, SELF, false, 503, NOT_ALIVE, report);
+        validateHealthCheckReport(false, 503, NOT_ALIVE, report);
     }
 
     @Test
@@ -78,13 +81,13 @@ public class TestHealthCheckRestControllerV1 extends CommonPapRestServer {
         var response = invocationBuilder.get();
         var report = response.readEntity(HealthCheckReport.class);
         assertThat(response.getStatus()).isEqualTo(503);
-        validateHealthCheckReport(NAME, SELF, false, 503, NOT_ALIVE, report);
+        validateHealthCheckReport(false, 503, NOT_ALIVE, report);
     }
 
-    private void validateHealthCheckReport(final String name, final String url, final boolean healthy, final int code,
-            final String message, final HealthCheckReport report) {
-        assertEquals(name, report.getName());
-        assertEquals(url, report.getUrl());
+    private void validateHealthCheckReport(final boolean healthy, final int code,
+                                           final String message, final HealthCheckReport report) {
+        assertEquals(CommonPapRestServer.NAME, report.getName());
+        assertEquals(CommonPapRestServer.SELF, report.getUrl());
         assertEquals(healthy, report.isHealthy());
         assertEquals(code, report.getCode());
         assertEquals(message, report.getMessage());
index 2b08b2c..6649dc7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,10 +33,12 @@ import org.onap.policy.models.pap.concepts.PdpGroupUpdateResponse;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
 import org.onap.policy.models.pdp.concepts.PdpSubGroup;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
  */
+@ActiveProfiles("test")
 public class TestPdpGroupCreateOrUpdateControllerV1 extends CommonPapRestServer {
 
     private static final String CREATEORUPDATE_GROUPS_ENDPOINT = "pdps/groups/batch";
index 0f1ab1f..033461f 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -24,13 +24,16 @@ package org.onap.policy.pap.main.rest;
 import static org.junit.Assert.assertEquals;
 
 import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.SyncInvoker;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
 import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
  */
+@ActiveProfiles("test")
 public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
 
     private static final String GROUP_NOT_FOUND = "group not found";
@@ -61,7 +64,7 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
         assertEquals(GROUP_NOT_FOUND, resp.getErrorDetails());
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.delete());
+        checkUnauthRequest(uri, SyncInvoker::delete);
     }
 
     @Test
@@ -80,7 +83,7 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
         assertEquals("cannot find policy: my-name null", resp.getErrorDetails());
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.delete());
+        checkUnauthRequest(uri, SyncInvoker::delete);
     }
 
     @Test
@@ -99,6 +102,6 @@ public class TestPdpGroupDeleteControllerV1 extends CommonPapRestServer {
         assertEquals("cannot find policy: my-name 3", resp.getErrorDetails());
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.delete());
+        checkUnauthRequest(uri, SyncInvoker::delete);
     }
 }
index f2d3337..5d48ecc 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2021 Nordix Foundation.
+ *  Copyright (C) 2019-2022 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -25,6 +25,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import java.util.Arrays;
+import java.util.List;
 import javax.ws.rs.client.Entity;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.MediaType;
@@ -36,10 +37,12 @@ import org.onap.policy.models.pdp.concepts.DeploymentGroup;
 import org.onap.policy.models.pdp.concepts.DeploymentGroups;
 import org.onap.policy.models.pdp.concepts.DeploymentSubGroup;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
  */
+@ActiveProfiles("test")
 public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
 
     private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch";
@@ -95,10 +98,10 @@ public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
 
         DeploymentGroup group = new DeploymentGroup();
         group.setName("drools-group");
-        group.setDeploymentSubgroups(Arrays.asList(subgrp));
+        group.setDeploymentSubgroups(List.of(subgrp));
 
         DeploymentGroups groups = new DeploymentGroups();
-        groups.setGroups(Arrays.asList(group));
+        groups.setGroups(List.of(group));
 
         return Entity.entity(groups, MediaType.APPLICATION_JSON);
     }
index f61e859..f149d3e 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,15 +24,18 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.SyncInvoker;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
 import org.onap.policy.models.pdp.concepts.Pdps;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Class to perform unit test of {@link PdpGroupHealthCheckControllerV1}.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
+@ActiveProfiles("test")
 public class TestPdpGroupHealthCheckControllerV1 extends CommonPapRestServer {
 
     private static final String ENDPOINT = "pdps/healthcheck";
@@ -58,6 +61,6 @@ public class TestPdpGroupHealthCheckControllerV1 extends CommonPapRestServer {
         assertNotNull(resp);
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.get());
+        checkUnauthRequest(uri, SyncInvoker::get);
     }
 }
index e49ecbc..255718b 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -24,15 +24,18 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
 import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.SyncInvoker;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Class to perform unit test of {@link PdpGroupQueryControllerV1}.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
+@ActiveProfiles("test")
 public class TestPdpGroupQueryControllerV1 extends CommonPapRestServer {
 
     private static final String GROUP_ENDPOINT = "pdps";
@@ -43,7 +46,7 @@ public class TestPdpGroupQueryControllerV1 extends CommonPapRestServer {
     }
 
     @Test
-    public void testchangeGroupState() throws Exception {
+    public void testChangeGroupState() throws Exception {
         final String uri = GROUP_ENDPOINT;
 
         final Invocation.Builder invocationBuilder = sendRequest(uri);
@@ -58,6 +61,6 @@ public class TestPdpGroupQueryControllerV1 extends CommonPapRestServer {
         assertNotNull(resp);
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.get());
+        checkUnauthRequest(uri, SyncInvoker::get);
     }
 }
index 9e21d6e..4800911 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -28,12 +28,15 @@ import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
 import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Class to perform unit test of {@link PdpGroupStateChangeControllerV1}.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
+@ActiveProfiles("test")
 public class TestPdpGroupStateChangeControllerV1 extends CommonPapRestServer {
 
     private static final String GROUP_ENDPOINT = "pdps/groups";
@@ -44,7 +47,7 @@ public class TestPdpGroupStateChangeControllerV1 extends CommonPapRestServer {
     }
 
     @Test
-    public void testchangeGroupState() throws Exception {
+    public void testChangeGroupState() throws Exception {
         final String uri = GROUP_ENDPOINT + "/my-name?state=ACTIVE";
 
         final Invocation.Builder invocationBuilder = sendRequest(uri);
index 5683352..8658b7d 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  * Copyright (C) 2021 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -23,10 +24,13 @@ import static org.junit.Assert.assertEquals;
 import javax.ws.rs.client.Invocation;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
  */
+@ActiveProfiles("test")
 public class TestPolicyAuditControllerV1 extends CommonPapRestServer {
 
     private static final String POLICY_AUDIT_ENDPOINT = "policies/audit";
index e07d35c..9eec5e1 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2020, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2020-2021 AT&T Inc.
  *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
@@ -35,12 +35,14 @@ import org.junit.Test;
 import org.onap.policy.common.endpoints.parameters.RestClientParameters;
 import org.onap.policy.pap.main.parameters.PapParameterGroup;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Class to perform unit test of {@link PolicyComponentsHealthCheckControllerV1}.
  *
  * @author Yehui Wang (yehui.wang@est.tech)
  */
+@ActiveProfiles("test")
 public class TestPolicyComponentsHealthCheckControllerV1 extends CommonPapRestServer {
 
     private static final String ENDPOINT = "components/healthcheck";
index 04d4cf9..3db1ed8 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2020 Nordix Foundation.
+ *  Copyright (C) 2020, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2020-2021 AT&T Corp.
  *  Modifications Copyright (C) 2020-2022 Bell Canada. All rights reserved.
  * ================================================================================
@@ -30,7 +30,6 @@ import static org.mockito.Mockito.when;
 import java.io.File;
 import java.net.HttpURLConnection;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.List;
 import java.util.Map;
 import javax.ws.rs.core.Response;
@@ -150,6 +149,7 @@ public class TestPolicyComponentsHealthCheckProvider {
         ReflectionTestUtils.setField(provider, "papParameterGroup", papParameterGroup);
         provider.initializeClientHealthCheckExecutorService();
         ReflectionTestUtils.setField(provider, "clients", clients);
+        ReflectionTestUtils.setField(provider, "topicPolicyPdpPap", "POLICY-PDP-PAP");
     }
 
     /**
@@ -260,7 +260,7 @@ public class TestPolicyComponentsHealthCheckProvider {
 
     private DmaapGetTopicResponse createDmaapResponse() {
         DmaapGetTopicResponse response = new DmaapGetTopicResponse();
-        response.setTopics(Arrays.asList(PapConstants.TOPIC_POLICY_PDP_PAP));
+        response.setTopics(List.of("POLICY-PDP-PAP"));
         return response;
     }
 }
index fc86fef..907e6c5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019,2021 Nordix Foundation.
+ *  Copyright (C) 2019, 2021-2022 Nordix Foundation.
  *  Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
  *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
  * ================================================================================
@@ -26,12 +26,15 @@ import static org.assertj.core.api.Assertions.assertThat;
 import static org.junit.Assert.assertEquals;
 
 import javax.ws.rs.client.Invocation;
+import javax.ws.rs.client.SyncInvoker;
 import javax.ws.rs.core.Response;
 import org.junit.Test;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
  * Note: this tests failure cases; success cases are tested by tests in the "e2e" package.
  */
+@ActiveProfiles("test")
 public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
 
     private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
@@ -51,10 +54,8 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
 
     @Test
     public void testQueryAllDeployedPolicies() throws Exception {
-        String uri = POLICY_STATUS_ENDPOINT;
-
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.get());
+        checkUnauthRequest(POLICY_STATUS_ENDPOINT, SyncInvoker::get);
         checkRequest(POLICY_STATUS_ENDPOINT);
     }
 
@@ -73,10 +74,8 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
 
     @Test
     public void testGetStatusOfAllPolicies() throws Exception {
-        String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT;
-
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.get());
+        checkUnauthRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT, SyncInvoker::get);
     }
 
     @Test
@@ -102,7 +101,7 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
         assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.get());
+        checkUnauthRequest(uri, SyncInvoker::get);
     }
 
     private void checkInvalidRegexRequest(String uri) throws Exception {
@@ -113,7 +112,7 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
         assertThat(entity).contains("error parsing regexp");
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.get());
+        checkUnauthRequest(uri, SyncInvoker::get);
     }
 
     private void checkEmptyRegexRequest(String uri) throws Exception {
@@ -124,6 +123,6 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
         assertThat(entity).contains("empty string passed as a regex");
 
         // verify it fails when no authorization info is included
-        checkUnauthRequest(uri, req -> req.get());
+        checkUnauthRequest(uri, SyncInvoker::get);
     }
 }
index 70deedc..0ed36d5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019-2020 Nordix Foundation.
+ *  Copyright (C) 2019-2020, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2019 AT&T Intellectual Property.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,12 +27,15 @@ import javax.ws.rs.client.Invocation;
 import org.junit.Test;
 import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.pap.main.PapConstants;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.ActiveProfiles;
 
 /**
- * Class to perform unit test of {@link PapRestServer}.
+ * Class to perform unit test of {@link StatisticsRestControllerV1}.
  *
  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
  */
+@ActiveProfiles("test")
 public class TestStatisticsRestControllerV1 extends CommonPapRestServer {
 
     private static final String STATISTICS_ENDPOINT = "statistics";
index 575e33f..48bc1e0 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2019-2020 Nordix Foundation.
+ * Modifications Copyright (C) 2019-2020, 2022 Nordix Foundation.
  * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -30,6 +30,7 @@ import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import lombok.Getter;
 import org.junit.After;
 import org.onap.policy.common.parameters.ValidationResult;
 import org.onap.policy.common.utils.coder.Coder;
@@ -38,7 +39,6 @@ import org.onap.policy.common.utils.coder.StandardCoder;
 import org.onap.policy.common.utils.resources.PrometheusUtils;
 import org.onap.policy.common.utils.resources.ResourceUtils;
 import org.onap.policy.models.base.PfConceptKey;
-import org.onap.policy.models.base.PfModelException;
 import org.onap.policy.models.pdp.concepts.PdpGroup;
 import org.onap.policy.models.pdp.concepts.PdpGroups;
 import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
@@ -56,8 +56,10 @@ import org.onap.policy.pap.main.service.ToscaServiceTemplateService;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ActiveProfiles;
 import org.yaml.snakeyaml.Yaml;
 
+@ActiveProfiles("test-e2e")
 public abstract class End2EndBase extends CommonPapRestServer {
     private static final Logger logger = LoggerFactory.getLogger(End2EndBase.class);
 
@@ -87,6 +89,12 @@ public abstract class End2EndBase extends CommonPapRestServer {
     @Autowired
     public MeterRegistry meterRegistry;
 
+    @Getter
+    private final String topicPolicyPdpPap = "pdp-pap-topic";
+
+    @Getter
+    private final String topicPolicyNotification = "notification-topic";
+
     public String deploymentsCounterName = "pap_" + PrometheusUtils.POLICY_DEPLOYMENTS_METRIC;
     public String[] deploymentSuccessTag = {PrometheusUtils.OPERATION_METRIC_LABEL, PrometheusUtils.DEPLOY_OPERATION,
         PrometheusUtils.STATUS_METRIC_LABEL, State.SUCCESS.name()};
@@ -115,9 +123,8 @@ public abstract class End2EndBase extends CommonPapRestServer {
      * Adds Tosca Policy Types to the DB.
      *
      * @param yamlFile name of the YAML file specifying the data to be loaded
-     * @throws PfModelException if a DAO error occurs
      */
-    public void addToscaPolicyTypes(final String yamlFile) throws PfModelException {
+    public void addToscaPolicyTypes(final String yamlFile) {
         final ToscaServiceTemplate serviceTemplate = loadYamlFile(yamlFile, ToscaServiceTemplate.class);
         JpaToscaServiceTemplate jpaToscaServiceTemplate = mergeWithExistingTemplate(serviceTemplate);
         serviceTemplateRepository.save(jpaToscaServiceTemplate);
@@ -127,9 +134,8 @@ public abstract class End2EndBase extends CommonPapRestServer {
      * Adds Tosca Policies to the DB.
      *
      * @param yamlFile name of the YAML file specifying the data to be loaded
-     * @throws PfModelException if a DAO error occurs
      */
-    public void addToscaPolicies(final String yamlFile) throws PfModelException {
+    public void addToscaPolicies(final String yamlFile) {
         final ToscaServiceTemplate serviceTemplate = loadYamlFile(yamlFile, ToscaServiceTemplate.class);
         JpaToscaServiceTemplate jpaToscaServiceTemplate = mergeWithExistingTemplate(serviceTemplate);
         serviceTemplateRepository.save(jpaToscaServiceTemplate);
@@ -139,7 +145,7 @@ public abstract class End2EndBase extends CommonPapRestServer {
         JpaToscaServiceTemplate jpaToscaServiceTemplate = new JpaToscaServiceTemplate(serviceTemplate);
         Optional<JpaToscaServiceTemplate> dbServiceTemplateOpt = serviceTemplateRepository
             .findById(new PfConceptKey(JpaToscaServiceTemplate.DEFAULT_NAME, JpaToscaServiceTemplate.DEFAULT_VERSION));
-        if (!dbServiceTemplateOpt.isEmpty()) {
+        if (dbServiceTemplateOpt.isPresent()) {
             JpaToscaServiceTemplate dbServiceTemplate = dbServiceTemplateOpt.get();
             if (dbServiceTemplate.getPolicyTypes() != null) {
                 jpaToscaServiceTemplate.setPolicyTypes(dbServiceTemplate.getPolicyTypes());
@@ -159,9 +165,8 @@ public abstract class End2EndBase extends CommonPapRestServer {
      * Adds PDP groups to the DB.
      *
      * @param jsonFile name of the JSON file specifying the data to be loaded
-     * @throws PfModelException if a DAO error occurs
      */
-    public void addGroups(final String jsonFile) throws PfModelException {
+    public void addGroups(final String jsonFile) {
         final PdpGroups groups = loadJsonFile(jsonFile, PdpGroups.class);
 
         final ValidationResult result = groups.validatePapRest();
@@ -176,9 +181,8 @@ public abstract class End2EndBase extends CommonPapRestServer {
      * Fetch PDP groups from the DB.
      *
      * @param name name of the pdpGroup
-     * @throws PfModelException if a DAO error occurs
      */
-    public List<PdpGroup> fetchGroups(final String name) throws PfModelException {
+    public List<PdpGroup> fetchGroups(final String name) {
         return pdpGroupService.getPdpGroups(name);
     }
 
@@ -188,10 +192,9 @@ public abstract class End2EndBase extends CommonPapRestServer {
      * @param instanceId name of the pdpStatistics
      * @param groupName name of the pdpGroup
      * @param subGroupName name of the pdpSubGroup
-     * @throws PfModelException if a DAO error occurs
      */
     public Map<String, Map<String, List<PdpStatistics>>> fetchPdpStatistics(final String instanceId,
-        final String groupName, final String subGroupName) throws PfModelException {
+        final String groupName, final String subGroupName) {
         return pdpStatisticsService.fetchDatabaseStatistics(groupName, subGroupName, instanceId, 100, null, null);
     }
 
@@ -199,9 +202,8 @@ public abstract class End2EndBase extends CommonPapRestServer {
      * Adds PdpPolicyStatus records to the DB.
      *
      * @param jsonFile name of the JSON file specifying the data to be loaded
-     * @throws PfModelException if a DAO error occurs
      */
-    public void addPdpPolicyStatus(final String jsonFile) throws PfModelException {
+    public void addPdpPolicyStatus(final String jsonFile) {
         final PolicyStatusRecords data = loadJsonFile(jsonFile, PolicyStatusRecords.class);
         policyStatusService.cudPolicyStatus(data.records, null, null);
     }
index 38ffe8d..c910a7b 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -124,14 +125,15 @@ public class End2EndContext {
      */
     private TopicListener topicListener = (infra, topic, text) -> toPdps.add(text);
 
+    private String topicPolicyPdpPap = "pdp-pap-topic";
 
     /**
      * Constructs the object.
      */
     public End2EndContext() {
-        toPapTopic = TopicEndpointManager.getManager().getNoopTopicSource(PapConstants.TOPIC_POLICY_PDP_PAP);
+        toPapTopic = TopicEndpointManager.getManager().getNoopTopicSource(topicPolicyPdpPap);
 
-        TopicEndpointManager.getManager().getNoopTopicSink(PapConstants.TOPIC_POLICY_PDP_PAP).register(topicListener);
+        TopicEndpointManager.getManager().getNoopTopicSink(topicPolicyPdpPap).register(topicListener);
 
         dispatcher = new MessageTypeDispatcher("messageName");
         dispatcher.register(PdpMessageType.PDP_UPDATE.name(), new UpdateListener());
@@ -200,7 +202,7 @@ public class End2EndContext {
         toPap.clear();
         pdps.forEach(pdp -> toPap.add(DONE));
 
-        TopicEndpointManager.getManager().getNoopTopicSink(PapConstants.TOPIC_POLICY_PDP_PAP).unregister(topicListener);
+        TopicEndpointManager.getManager().getNoopTopicSink(topicPolicyPdpPap).unregister(topicListener);
     }
 
     /**
@@ -245,7 +247,7 @@ public class End2EndContext {
                     break;
                 }
 
-                dispatcher.onTopicEvent(CommInfrastructure.NOOP, PapConstants.TOPIC_POLICY_PDP_PAP, text);
+                dispatcher.onTopicEvent(CommInfrastructure.NOOP, topicPolicyPdpPap, text);
             }
         }
     }
@@ -256,15 +258,11 @@ public class End2EndContext {
      * {@link End2EndContext#DONE} message <i>for each PDP</i>.
      */
     private class ToPapThread extends Thread {
-        /**
-         * Number of DONE messages that have been received.
-         */
-        private long ndone;
 
         @Override
         public void run() {
             // pretend we received DONE from PDPs that are already finished
-            ndone = pdps.stream().filter(pdp -> pdp.finished).count();
+            long ndone = pdps.stream().filter(pdp -> pdp.finished).count();
 
             while (ndone < pdps.size()) {
                 String text;
@@ -364,9 +362,8 @@ public class End2EndContext {
          *
          * @param reply reply to be added to the list
          * @return this PDP
-         * @throws CoderException if the reply cannot be encoded
          */
-        public PseudoPdp addReply(PdpStatus reply) throws CoderException {
+        public PseudoPdp addReply(PdpStatus reply) {
             replies.add(reply);
             finished = false;
             return this;
index f429afb..296a660 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +22,7 @@
 package org.onap.policy.pap.main.rest.e2e;
 
 import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
 
 import java.net.HttpURLConnection;
 import javax.ws.rs.client.Invocation;
@@ -37,7 +39,7 @@ public class HealthCheckTest extends End2EndBase {
 
         assertEquals(NAME, report.getName());
         assertEquals(SELF, report.getUrl());
-        assertEquals(true, report.isHealthy());
+        assertTrue(report.isHealthy());
         assertEquals(HttpURLConnection.HTTP_OK, report.getCode());
         assertEquals(ALIVE, report.getMessage());
     }
index a838788..5e2ca38 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
  * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -44,7 +44,6 @@ import org.onap.policy.models.pap.concepts.PolicyNotification;
 import org.onap.policy.models.pap.concepts.PolicyStatus;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.pap.main.PapConstants;
 import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1;
 
 public class PdpGroupDeleteTest extends End2EndBase {
@@ -119,10 +118,8 @@ public class PdpGroupDeleteTest extends End2EndBase {
 
         // arrange to catch notifications
         LinkedBlockingQueue<String> notifications = new LinkedBlockingQueue<>();
-        NoopTopicSink notifier = NoopTopicFactories.getSinkFactory().get(PapConstants.TOPIC_POLICY_NOTIFICATION);
-        notifier.register((infra, topic, msg) -> {
-            notifications.add(msg);
-        });
+        NoopTopicSink notifier = NoopTopicFactories.getSinkFactory().get(getTopicPolicyNotification());
+        notifier.register((infra, topic, msg) -> notifications.add(msg));
 
         String uri = DELETE_POLICIES_ENDPOINT + "/onap.restart.tcaB";
 
index df749a8..f28ccd1 100644 (file)
@@ -3,7 +3,7 @@
  * ONAP PAP
  * ================================================================================
  * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
- * Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021-2022 Nordix Foundation.
  * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
@@ -28,7 +28,6 @@ import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
-import java.util.Arrays;
 import java.util.List;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.TimeUnit;
@@ -50,7 +49,6 @@ import org.onap.policy.models.pdp.concepts.DeploymentGroups;
 import org.onap.policy.models.pdp.concepts.PdpStatus;
 import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
-import org.onap.policy.pap.main.PapConstants;
 import org.onap.policy.pap.main.rest.PdpGroupDeployControllerV1;
 
 public class PdpGroupDeployTest extends End2EndBase {
@@ -83,7 +81,7 @@ public class PdpGroupDeployTest extends End2EndBase {
         status11.setPdpType(DEPLOY_SUBGROUP);
         status11.setPdpSubgroup(DEPLOY_SUBGROUP);
 
-        List<ToscaConceptIdentifier> idents = Arrays.asList(new ToscaConceptIdentifier("onap.restart.tca", "1.0.0"));
+        List<ToscaConceptIdentifier> idents = List.of(new ToscaConceptIdentifier("onap.restart.tca", "1.0.0"));
         status11.setPolicies(idents);
 
         PdpStatus status12 = new PdpStatus();
@@ -144,10 +142,10 @@ public class PdpGroupDeployTest extends End2EndBase {
         status11.setPdpType(DEPLOY_SUBGROUP);
         status11.setPdpSubgroup(DEPLOY_SUBGROUP);
 
-        final ToscaConceptIdentifier ident = new ToscaConceptIdentifier("onap.restart.tcaB", "1.0.0");
+        final ToscaConceptIdentifier identifier = new ToscaConceptIdentifier("onap.restart.tcaB", "1.0.0");
 
-        List<ToscaConceptIdentifier> idents = Arrays.asList(ident);
-        status11.setPolicies(idents);
+        List<ToscaConceptIdentifier> identifiers = List.of(identifier);
+        status11.setPolicies(identifiers);
 
         PdpStatus status12 = new PdpStatus();
         status12.setName("pdpBA_2");
@@ -155,7 +153,7 @@ public class PdpGroupDeployTest extends End2EndBase {
         status12.setPdpGroup("deployPolicies");
         status12.setPdpType(DEPLOY_SUBGROUP);
         status12.setPdpSubgroup(DEPLOY_SUBGROUP);
-        status12.setPolicies(idents);
+        status12.setPolicies(identifiers);
 
         context.addPdp("pdpBA_1", DEPLOY_SUBGROUP).addReply(status11);
         context.addPdp("pdpBA_2", DEPLOY_SUBGROUP).addReply(status12);
@@ -165,12 +163,10 @@ public class PdpGroupDeployTest extends End2EndBase {
 
         // arrange to catch notifications
         LinkedBlockingQueue<String> notifications = new LinkedBlockingQueue<>();
-        NoopTopicSink notifier = NoopTopicFactories.getSinkFactory().get(PapConstants.TOPIC_POLICY_NOTIFICATION);
-        notifier.register((infra, topic, msg) -> {
-            notifications.add(msg);
-        });
+        NoopTopicSink notifier = NoopTopicFactories.getSinkFactory().get(getTopicPolicyNotification());
+        notifier.register((infra, topic, msg) -> notifications.add(msg));
 
-        assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isEqualTo(0);
+        assertThat(meterRegistry.counter(deploymentsCounterName, deploymentSuccessTag).count()).isZero();
 
         Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
 
@@ -197,7 +193,7 @@ public class PdpGroupDeployTest extends End2EndBase {
         assertEquals(2, added.getSuccessCount());
         assertEquals(0, added.getFailureCount());
         assertEquals(0, added.getIncompleteCount());
-        assertEquals(ident, added.getPolicy());
+        assertEquals(identifier, added.getPolicy());
 
         // one of the PDPs should not have handled any requests
         assertEquals(1, context.getPdps().stream().filter(pdp -> pdp.getHandled().isEmpty()).count());
index 121318f..09c8a2a 100644 (file)
@@ -4,6 +4,7 @@
  * ================================================================================
  * Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
  * Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
+ * Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -50,13 +51,11 @@ public class PolicyStatusTest extends End2EndBase {
 
     @Test
     public void testQueryAllDeployedPolicies() throws Exception {
-        String uri = POLICY_STATUS_ENDPOINT;
-
-        Invocation.Builder invocationBuilder = sendRequest(uri);
+        Invocation.Builder invocationBuilder = sendRequest(POLICY_STATUS_ENDPOINT);
         Response rawresp = invocationBuilder.get();
         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
 
-        List<PolicyStatus> resp = rawresp.readEntity(new GenericType<List<PolicyStatus>>() {});
+        List<PolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
         assertEquals(1, resp.size());
         checkAssertions(resp.get(0));
     }
@@ -69,7 +68,7 @@ public class PolicyStatusTest extends End2EndBase {
         Response rawresp = invocationBuilder.get();
         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
 
-        List<PolicyStatus> resp = rawresp.readEntity(new GenericType<List<PolicyStatus>>() {});
+        List<PolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
         assertEquals(1, resp.size());
         checkAssertions(resp.get(0));
     }
@@ -88,13 +87,11 @@ public class PolicyStatusTest extends End2EndBase {
 
     @Test
     public void testGetStatusOfAllDeployedPolicies() throws Exception {
-        String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT;
-
-        Invocation.Builder invocationBuilder = sendRequest(uri);
+        Invocation.Builder invocationBuilder = sendRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT);
         Response rawresp = invocationBuilder.get();
         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
 
-        List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<List<PdpPolicyStatus>>() {});
+        List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
         assertEquals(1, resp.size());
         checkAssertionsForDeploymentStatus(resp.get(0));
     }
@@ -107,7 +104,7 @@ public class PolicyStatusTest extends End2EndBase {
         Response rawresp = invocationBuilder.get();
         assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
 
-        List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<List<PdpPolicyStatus>>() {});
+        List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<>() {});
         assertEquals(1, resp.size());
         checkAssertionsForDeploymentStatus(resp.get(0));
     }
index 549eb96..4edb05d 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -39,7 +40,9 @@ import org.onap.policy.models.pdp.enums.PdpState;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.pap.main.rest.CommonPapRestServer;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ActiveProfiles;
 
+@ActiveProfiles("test")
 public class PdpGroupServiceTest extends CommonPapRestServer {
 
     private static final String FIELD_IS_NULL = "%s is marked non-null but is null";
@@ -97,7 +100,7 @@ public class PdpGroupServiceTest extends CommonPapRestServer {
         assertThat(activePdpGroups.get(0).getPdpSubgroups()).hasSize(3);
 
         assertThat(pdpGroupService.getPdpGroups(CREATE_GROUPS, PdpState.PASSIVE)).hasSize(1);
-        assertThat(pdpGroupService.getPdpGroups("invalid-group", PdpState.PASSIVE)).hasSize(0);
+        assertThat(pdpGroupService.getPdpGroups("invalid-group", PdpState.PASSIVE)).isEmpty();
         assertThat(pdpGroupService.getPdpGroups(DEFAULT_GROUP, PdpState.ACTIVE)).hasSize(1);
 
         PdpGroupFilter filter = PdpGroupFilter.builder()
index 7bfc997..1d429ee 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -34,7 +35,9 @@ import org.onap.policy.models.pdp.concepts.PdpStatistics;
 import org.onap.policy.pap.main.repository.PdpStatisticsRepository;
 import org.onap.policy.pap.main.rest.CommonPapRestServer;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ActiveProfiles;
 
+@ActiveProfiles("test")
 public class PdpStatisticsServiceTest extends CommonPapRestServer {
 
     private static final String NAME3 = "name3";
@@ -67,10 +70,10 @@ public class PdpStatisticsServiceTest extends CommonPapRestServer {
     @Before
     public void setUp() throws Exception {
         super.setUp();
-        pdpStatistics1 = generatePdpStatistics(NAME1, TIMESTAMP1, GROUP, SUBGROUP);
-        pdpStatistics2 = generatePdpStatistics("name2", TIMESTAMP1, GROUP, SUBGROUP);
-        pdpStatistics3 = generatePdpStatistics(NAME1, TIMESTAMP2, GROUP, SUBGROUP);
-        pdpStatistics4 = generatePdpStatistics(NAME3, TIMESTAMP2, GROUP0, SUBGROUP);
+        pdpStatistics1 = generatePdpStatistics(NAME1, TIMESTAMP1, GROUP);
+        pdpStatistics2 = generatePdpStatistics("name2", TIMESTAMP1, GROUP);
+        pdpStatistics3 = generatePdpStatistics(NAME1, TIMESTAMP2, GROUP);
+        pdpStatistics4 = generatePdpStatistics(NAME3, TIMESTAMP2, GROUP0);
     }
 
     /**
@@ -93,98 +96,90 @@ public class PdpStatisticsServiceTest extends CommonPapRestServer {
     @Test
     public void testCreatePdpStatisticsFailure() {
 
-        assertThatThrownBy(() -> {
-            pdpStatisticsService.createPdpStatistics(null);
-        }).hasMessageMatching(LIST_IS_NULL);
+        assertThatThrownBy(() -> pdpStatisticsService.createPdpStatistics(null)).hasMessageMatching(LIST_IS_NULL);
 
         PdpStatistics pdpStatisticsErr = new PdpStatistics();
         pdpStatisticsErr.setPdpInstanceId("NULL");
         pdpStatisticsErr.setPdpGroupName(GROUP);
-        assertThatThrownBy(() -> {
-            pdpStatisticsService.createPdpStatistics(List.of(pdpStatisticsErr));
-        }).hasMessageContaining("item \"name\" value \"NULL\" INVALID, is null");
+        assertThatThrownBy(() -> pdpStatisticsService.createPdpStatistics(List.of(pdpStatisticsErr)))
+            .hasMessageContaining("item \"name\" value \"NULL\" INVALID, is null");
     }
 
     @Test
     public void testFetchDatabaseStatistics() {
-
         List<PdpStatistics> createList = List.of(pdpStatistics1, pdpStatistics3, pdpStatistics4, pdpStatistics2);
         pdpStatisticsService.createPdpStatistics(createList);
-        Map<String, Map<String, List<PdpStatistics>>> created =
-            pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, null, null);
-        assertThat(created).hasSize(2);
-        assertThat(created.get(GROUP0)).hasSize(1);
-        assertThat(created.get(GROUP0).get(SUBGROUP)).hasSize(1);
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).hasSize(3);
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, TIMESTAMP2, TIMESTAMP2);
-        assertThat(created).hasSize(2);
-        assertThat(created.get(GROUP0)).hasSize(1);
-        assertThat(created.get(GROUP0).get(SUBGROUP)).isEqualTo(List.of(pdpStatistics4));
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).isEqualTo(List.of(pdpStatistics3));
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, null, TIMESTAMP1);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).hasSize(2);
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, TIMESTAMP2, null);
-        assertThat(created).hasSize(2);
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(GROUP0, NUMBER_RECORDS, TIMESTAMP2, TIMESTAMP2);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP0)).hasSize(1);
-        assertThat(created.get(GROUP0).get(SUBGROUP)).isEqualTo(List.of(pdpStatistics4));
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(GROUP, NUMBER_RECORDS, null, TIMESTAMP1);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).hasSize(2);
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(GROUP, NUMBER_RECORDS, TIMESTAMP2, null);
-        assertThat(created).hasSize(1);
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NUMBER_RECORDS, TIMESTAMP1, TIMESTAMP2);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).hasSize(3);
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NUMBER_RECORDS, null, TIMESTAMP1);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).hasSize(2);
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NUMBER_RECORDS, TIMESTAMP2, null);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).isEqualTo(List.of(pdpStatistics3));
-
-        created = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NAME1, NUMBER_RECORDS, TIMESTAMP1,
+
+        Map<String, Map<String, List<PdpStatistics>>> statistics;
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, null, null);
+        assertGroupAndSubgroupSize(statistics, 2, GROUP0, 1);
+        assertGroupAndSubgroupSize(statistics, 2, GROUP, 3);
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, TIMESTAMP2, TIMESTAMP2);
+        assertGroupAndSubgroupSize(statistics, 2, GROUP0, 1);
+        assertThat(statistics.get(GROUP0)).containsEntry(SUBGROUP, List.of(pdpStatistics4));
+        assertGroupAndSubgroupSize(statistics, 2, GROUP, 1);
+        assertThat(statistics.get(GROUP)).containsEntry(SUBGROUP, List.of(pdpStatistics3));
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, null, TIMESTAMP1);
+        assertGroupAndSubgroupSize(statistics, 1, GROUP, 2);
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(NUMBER_RECORDS, TIMESTAMP2, null);
+        assertThat(statistics).hasSize(2);
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(GROUP0, NUMBER_RECORDS, TIMESTAMP2, TIMESTAMP2);
+        assertThat(statistics).hasSize(1);
+        assertThat(statistics.get(GROUP0)).hasSize(1);
+        assertThat(statistics.get(GROUP0)).containsEntry(SUBGROUP, List.of(pdpStatistics4));
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(GROUP, NUMBER_RECORDS, null, TIMESTAMP1);
+        assertGroupAndSubgroupSize(statistics, 1, GROUP, 2);
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(GROUP, NUMBER_RECORDS, TIMESTAMP2, null);
+        assertThat(statistics).hasSize(1);
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NUMBER_RECORDS, TIMESTAMP1,
+            TIMESTAMP2);
+        assertGroupAndSubgroupSize(statistics, 1, GROUP, 3);
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NUMBER_RECORDS, null, TIMESTAMP1);
+        assertGroupAndSubgroupSize(statistics, 1, GROUP, 2);
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NUMBER_RECORDS, TIMESTAMP2, null);
+        assertThat(statistics).hasSize(1);
+        assertThat(statistics.get(GROUP)).containsEntry(SUBGROUP, List.of(pdpStatistics3));
+
+        statistics = pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NAME1, NUMBER_RECORDS, TIMESTAMP1,
             TIMESTAMP2);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).hasSize(2);
+        assertGroupAndSubgroupSize(statistics, 1, GROUP, 2);
 
-        created =
+        statistics =
             pdpStatisticsService.fetchDatabaseStatistics(GROUP, SUBGROUP, NAME1, NUMBER_RECORDS, null, TIMESTAMP1);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP)).hasSize(1);
-        assertThat(created.get(GROUP).get(SUBGROUP)).hasSize(1);
+        assertGroupAndSubgroupSize(statistics, 1, GROUP, 1);
 
-        created =
+        statistics =
             pdpStatisticsService.fetchDatabaseStatistics(GROUP0, SUBGROUP, NAME3, NUMBER_RECORDS, TIMESTAMP2, null);
-        assertThat(created).hasSize(1);
-        assertThat(created.get(GROUP0).get(SUBGROUP)).isEqualTo(List.of(pdpStatistics4));
+        assertThat(statistics).hasSize(1);
+        assertThat(statistics.get(GROUP0)).containsEntry(SUBGROUP, List.of(pdpStatistics4));
+    }
+
+    /**
+     * Asserts if statistics list is the expected size and the subgroup list is also the expected size.
+     */
+    private void assertGroupAndSubgroupSize(Map<String, Map<String, List<PdpStatistics>>> statistics, int listSize,
+                                            String group, int subGroupSize) {
+        assertThat(statistics).hasSize(listSize);
+        assertThat(statistics.get(group)).hasSize(1);
+        assertThat(statistics.get(group).get(SUBGROUP)).hasSize(subGroupSize);
     }
 
-    private PdpStatistics generatePdpStatistics(String pdpInstanceId, Instant date, String group,
-        String subgroup) {
+    private PdpStatistics generatePdpStatistics(String pdpInstanceId, Instant date, String group) {
         PdpStatistics pdpStatistics11 = new PdpStatistics();
         pdpStatistics11.setPdpInstanceId(pdpInstanceId);
         pdpStatistics11.setTimeStamp(date);
         pdpStatistics11.setPdpGroupName(group);
-        pdpStatistics11.setPdpSubGroupName(subgroup);
+        pdpStatistics11.setPdpSubGroupName(PdpStatisticsServiceTest.SUBGROUP);
         pdpStatistics11.setPolicyDeployCount(2);
         pdpStatistics11.setPolicyDeployFailCount(1);
         pdpStatistics11.setPolicyDeploySuccessCount(1);
index 68044ad..8c351e2 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -36,7 +37,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.pap.main.repository.PolicyAuditRepository;
 import org.onap.policy.pap.main.rest.CommonPapRestServer;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ActiveProfiles;
 
+@ActiveProfiles("test")
 public class PolicyAuditServiceTest extends CommonPapRestServer {
 
     private static final String FIELD_IS_NULL = "%s is marked .*ull but is null";
@@ -74,14 +77,12 @@ public class PolicyAuditServiceTest extends CommonPapRestServer {
             PolicyAudit.builder().pdpType("pdpType").action(AuditAction.DEPLOYMENT).timestamp(Instant.now()).build());
 
         assertThrows(PfModelRuntimeException.class, () -> policyAuditService.createAuditRecords(audits));
-        assertThatThrownBy(() -> {
-            policyAuditService.createAuditRecords(audits);
-        }).isInstanceOf(PfModelRuntimeException.class)
+        assertThatThrownBy(() -> policyAuditService.createAuditRecords(audits))
+            .isInstanceOf(PfModelRuntimeException.class)
             .hasMessageContaining("\"createAuditRecords\" INVALID, item has status INVALID");
 
-        assertThatThrownBy(() -> {
-            policyAuditService.createAuditRecords(null);
-        }).hasMessageMatching(String.format(FIELD_IS_NULL, "audits"));
+        assertThatThrownBy(() -> policyAuditService.createAuditRecords(null))
+            .hasMessageMatching(String.format(FIELD_IS_NULL, "audits"));
     }
 
     @Test
@@ -109,9 +110,9 @@ public class PolicyAuditServiceTest extends CommonPapRestServer {
             NUMBER_RECORDS, null, null)).hasSize(2);
         assertThat(
             policyAuditService.getAuditRecords(GROUP_A, MY_POLICY.getName(), "9.9.9", NUMBER_RECORDS, null, null))
-                .hasSize(0);
+                .isEmpty();
         assertThat(policyAuditService.getAuditRecords(GROUP_B, MY_POLICY.getName(), MY_POLICY.getVersion(),
-            NUMBER_RECORDS, null, null)).hasSize(0);
+            NUMBER_RECORDS, null, null)).isEmpty();
         assertThat(policyAuditService.getAuditRecords(GROUP_B, MY_POLICY2.getName(), MY_POLICY2.getVersion(),
             NUMBER_RECORDS, null, null)).hasSize(2);
         assertThat(policyAuditService.getAuditRecords(MY_POLICY2.getName(), MY_POLICY2.getVersion(), NUMBER_RECORDS,
index 2a35403..aeb2fdb 100644 (file)
@@ -1,6 +1,7 @@
 /*-
  * ============LICENSE_START=======================================================
  *  Copyright (C) 2022 Bell Canada. All rights reserved.
+ *  Modifications Copyright (C) 2022 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -33,7 +34,9 @@ import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifier;
 import org.onap.policy.models.tosca.authorative.concepts.ToscaConceptIdentifierOptVersion;
 import org.onap.policy.pap.main.rest.CommonPapRestServer;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.test.context.ActiveProfiles;
 
+@ActiveProfiles("test")
 public class PolicyStatusServiceTest extends CommonPapRestServer {
 
     private static final String GROUP_A = "groupA";
index c11af69..6792138 100644 (file)
@@ -1,6 +1,6 @@
 /*-
  * ============LICENSE_START=======================================================
- *  Copyright (C) 2019 Nordix Foundation.
+ *  Copyright (C) 2019, 2022 Nordix Foundation.
  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
  *  Modifications Copyright (C) 2021-2022 Bell Canada. All rights reserved.
  * ================================================================================
@@ -34,14 +34,15 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.nio.charset.StandardCharsets;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
+import org.onap.policy.common.endpoints.event.comm.TopicEndpointManager;
 import org.onap.policy.common.endpoints.http.server.HttpServletServerFactoryInstance;
 import org.onap.policy.common.utils.network.NetworkUtil;
 import org.onap.policy.common.utils.services.Registry;
 import org.onap.policy.pap.main.PapConstants;
-import org.onap.policy.pap.main.PolicyPapException;
 import org.onap.policy.pap.main.comm.PdpHeartbeatListener;
 import org.onap.policy.pap.main.comm.PdpModifyRequestMap;
 import org.onap.policy.pap.main.notification.PolicyNotifier;
@@ -58,15 +59,13 @@ import org.onap.policy.pap.main.rest.PapStatisticsManager;
 public class TestPapActivator {
     private static final String CONFIG_FILE = "src/test/resources/parameters/TestConfigParams.json";
 
-    private static int port;
-
     private PapActivator activator;
 
     /**
      * Allocates a new DB name, server port, and creates a config file.
      */
     @BeforeClass
-    public static void setUpBeforeClass() throws Exception {
+    public static void setUpBeforeClass() {
         CommonTestData.newDb();
     }
 
@@ -78,9 +77,10 @@ public class TestPapActivator {
     @Before
     public void setUp() throws Exception {
         Registry.newRegistry();
+        TopicEndpointManager.getManager().shutdown();
         HttpServletServerFactoryInstance.getServerFactory().destroy();
 
-        port = NetworkUtil.allocPort();
+        int port = NetworkUtil.allocPort();
 
         String json = new CommonTestData().getPapParameterGroupAsString(port);
 
@@ -110,8 +110,13 @@ public class TestPapActivator {
         }
     }
 
+    @AfterClass
+    public static void afterClass() {
+        Registry.newRegistry();
+    }
+
     @Test
-    public void testPapActivator() throws PolicyPapException {
+    public void testPapActivator() {
         assertFalse(activator.isAlive());
         activator.start();
         assertTrue(activator.isAlive());
@@ -130,7 +135,7 @@ public class TestPapActivator {
     }
 
     @Test
-    public void testTerminate() throws Exception {
+    public void testTerminate() {
         activator.start();
         activator.stop();
         assertFalse(activator.isAlive());
diff --git a/main/src/test/resources/application-test-e2e.yaml b/main/src/test/resources/application-test-e2e.yaml
new file mode 100644 (file)
index 0000000..09a2ca6
--- /dev/null
@@ -0,0 +1,90 @@
+spring:
+  security:
+    user:
+      name: policyadmin
+      password: zb!XztG34
+  http:
+    converters:
+      preferred-json-mapper: gson
+  datasource:
+    url: jdbc:h2:mem:testdb
+    driverClassName: org.h2.Driver
+  jpa:
+    properties:
+      hibernate:
+        dialect: org.hibernate.dialect.H2Dialect
+    hibernate:
+      ddl-auto: create-drop
+      naming:
+        physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
+        implicit-strategy: org.onap.policy.common.spring.utils.CustomImplicitNamingStrategy
+
+server:
+  port: 6969
+
+pap:
+  name: "PapGroupE2E"
+  aaf: false
+  topic:
+    pdp-pap.name: pdp-pap-topic
+    notification.name: notification-topic
+    heartbeat.name: heartbeat-topic
+  pdpParameters:
+    updateParameters:
+      maxRetryCount: 1
+      maxWaitMs: 3000
+    stateChangeParameters:
+      maxRetryCount: 1
+      maxWaitMs: 3000
+    heartBeatMs: 6000
+    maxMessageAgeMs: 20000
+  savePdpStatisticsInDb: true
+  topicParameterGroup:
+    topicSources:
+    - topic: ${pap.topic.pdp-pap.name}
+      servers:
+        - message-router
+      topicCommInfrastructure: noop
+    - topic: ${pap.topic.heartbeat.name}
+      effectiveTopic: ${pap.topic.pdp-pap.name}
+      consumerGroup: policy-pap
+      servers:
+        - message-router
+      topicCommInfrastructure: noop
+    topicSinks:
+    - topic: ${pap.topic.pdp-pap.name}
+      servers:
+        - message-router
+      topicCommInfrastructure: noop
+    - topic: ${pap.topic.notification.name}
+      servers:
+        - message-router
+      topicCommInfrastructure: noop
+  healthCheckRestClientParameters:
+  - clientName: api
+    hostname: policy-api
+    port: 6969
+    userName: policyadmin
+    password: zb!XztG34
+    useHttps: true
+    basePath: policy/api/v1/healthcheck
+  - clientName: distribution
+    hostname: policy-distribution
+    port: 6969
+    userName: healthcheck
+    password: zb!XztG34
+    useHttps: true
+    basePath: healthcheck
+  - clientName: dmaap
+    hostname: message-router
+    port: 3905
+    useHttps: true
+    basePath: topics
+
+management:
+  endpoints:
+    web:
+      base-path: /
+      exposure:
+        include: health, metrics, prometheus
+      path-mapping.prometheus: metrics
@@ -14,7 +14,7 @@ spring:
       hibernate:
         dialect: org.hibernate.dialect.H2Dialect
     hibernate:
-      ddl-auto: update
+      ddl-auto: create-drop
       naming:
         physical-strategy: org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
         implicit-strategy: org.onap.policy.common.spring.utils.CustomImplicitNamingStrategy
@@ -25,6 +25,10 @@ server:
 pap:
   name: "PapGroup"
   aaf: false
+  topic:
+    pdp-pap.name: POLICY-PDP-PAP
+    notification.name: POLICY-NOTIFICATION
+    heartbeat.name: POLICY-HEARTBEAT
   pdpParameters:
     updateParameters:
       maxRetryCount: 1
@@ -37,22 +41,22 @@ pap:
   savePdpStatisticsInDb: true
   topicParameterGroup:
     topicSources:
-    - topic: POLICY-PDP-PAP
+    - topic: ${pap.topic.pdp-pap.name}
       servers:
       - message-router
       topicCommInfrastructure: noop
-    - topic: POLICY-HEARTBEAT
-      effectiveTopic: POLICY-PDP-PAP
+    - topic: ${pap.topic.heartbeat.name}
+      effectiveTopic: ${pap.topic.pdp-pap.name}
       consumerGroup: policy-pap
       servers:
       - message-router
       topicCommInfrastructure: noop
     topicSinks:
-    - topic: POLICY-PDP-PAP
+    - topic: ${pap.topic.pdp-pap.name}
       servers:
       - message-router
       topicCommInfrastructure: noop
-    - topic: POLICY-NOTIFICATION
+    - topic: ${pap.topic.notification.name}
       servers:
       - message-router
       topicCommInfrastructure: noop
index b2e100a..e7f3377 100644 (file)
@@ -1,5 +1,5 @@
 {
-    "name": "PapGroup",
+    "name": "PapGroupE2E",
     "restServerParameters": {
         "host": "0.0.0.0",
         "port": ${port},
     },
     "topicParameterGroup": {
         "topicSources" : [{
-            "topic" : "POLICY-PDP-PAP",
+            "topic" : "pdp-pap-topic",
             "servers" : [ "message-router" ],
             "topicCommInfrastructure" : "noop"
         },
         {
-            "topic" : "POLICY-HEARTBEAT",
+            "topic" : "heartbeat-topic",
             "effectiveTopic": "POLICY-PDP-PAP",
             "consumerGroup": "policy-pap",
             "servers" : [ "message-router" ],
             "topicCommInfrastructure" : "noop"
         }],
         "topicSinks" : [{
-            "topic" : "POLICY-PDP-PAP",
+            "topic" : "pdp-pap-topic",
             "servers" : [ "message-router" ],
             "topicCommInfrastructure" : "noop"
         },{
-            "topic" : "POLICY-NOTIFICATION",
+            "topic" : "notification-topic",
             "servers" : [ "message-router" ],
             "topicCommInfrastructure" : "noop"
         }]