diff options
Diffstat (limited to 'main/src/test/java/org/onap/policy/pap/main/rest/e2e')
6 files changed, 48 insertions, 57 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java index 575e33ff..48bc1e05 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndBase.java @@ -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); } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java index 38ffe8db..c910a7b4 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/End2EndContext.java @@ -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; diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java index f429afbd..296a6609 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/HealthCheckTest.java @@ -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()); } diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java index a8387881..5e2ca38f 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java @@ -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"; diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java index df749a88..f28ccd14 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java @@ -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()); diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java index 121318f5..09c8a2ac 100644 --- a/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java +++ b/main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java @@ -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)); } |