summaryrefslogtreecommitdiffstats
path: root/main/src/test
diff options
context:
space:
mode:
authora.sreekumar <ajith.sreekumar@bell.ca>2021-02-15 13:05:44 +0000
committera.sreekumar <ajith.sreekumar@bell.ca>2021-02-17 11:23:10 +0000
commitf7674432acc22a4c80967bd27d0c576cef6daa98 (patch)
treec5daf2112d4950ac632e08dbc0908be389844f3d /main/src/test
parentbcbdb26288e9bd6b1bd0cf8fb2d463d9f49f6333 (diff)
Updating PAP deployment API to reflect actual status
Change-Id: I5281937fe5a742916c0c86983f71e280bbe126b2 Issue-ID: POLICY-2526 Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main/src/test')
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java26
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java149
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeleteTest.java20
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PdpGroupDeployTest.java15
-rw-r--r--main/src/test/java/org/onap/policy/pap/main/rest/e2e/PolicyStatusTest.java91
5 files changed, 230 insertions, 71 deletions
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java
index 985ff904..1d0c7aa7 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusControllerV1.java
@@ -2,6 +2,7 @@
* ============LICENSE_START=======================================================
* Copyright (C) 2019 Nordix Foundation.
* Modifications Copyright (C) 2019-2020 AT&T Intellectual Property.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,13 +34,18 @@ import org.junit.Test;
public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
+ private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status";
@Test
public void testSwagger() throws Exception {
super.testSwagger(POLICY_STATUS_ENDPOINT);
-
super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}");
super.testSwagger(POLICY_STATUS_ENDPOINT + "/{name}/{version}");
+
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT);
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}");
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}");
+ super.testSwagger(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/{pdpGroupName}/{policyName}/{policyVersion}");
}
@Test
@@ -52,20 +58,26 @@ public class TestPolicyStatusControllerV1 extends CommonPapRestServer {
@Test
public void testQueryDeployedPolicies() throws Exception {
- String uri = POLICY_STATUS_ENDPOINT + "/my-name";
+ checkRequest(POLICY_STATUS_ENDPOINT + "/my-name");
+ checkRequest(POLICY_STATUS_ENDPOINT + "/my-name/1.2.3");
+ }
- Invocation.Builder invocationBuilder = sendRequest(uri);
- Response rawresp = invocationBuilder.get();
- assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
+ @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());
}
@Test
- public void testQueryDeployedPolicy() throws Exception {
- String uri = POLICY_STATUS_ENDPOINT + "/my-name/1.2.3";
+ public void testGetStatusOfPolicies() throws Exception {
+ checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name");
+ checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name");
+ checkRequest(POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/my-group-name/my-name/1.2.3");
+ }
+ private void checkRequest(String uri) throws Exception {
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.get();
assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
diff --git a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java
index 44c8d828..81ed6805 100644
--- a/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java
+++ b/main/src/test/java/org/onap/policy/pap/main/rest/TestPolicyStatusProvider.java
@@ -3,6 +3,7 @@
* ONAP
* ================================================================================
* Copyright (C) 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +22,8 @@
package org.onap.policy.pap.main.rest;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.when;
import java.util.ArrayList;
@@ -77,27 +80,12 @@ public class TestPolicyStatusProvider extends ProviderSuper {
@Test
public void testGetStatus_testAccumulate() throws PfModelException {
- PdpPolicyStatusBuilder builder = PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE)
- .policyType(POLICY_TYPE).state(State.WAITING);
-
- PdpPolicyStatus notDeployed = builder.deploy(false).policy(POLICY_B).pdpId(PDP_A).build();
-
- // remaining policies are deployed
- builder.deploy(true);
-
- // @formatter:off
- when(dao.getAllPolicyStatus()).thenReturn(List.of(
- builder.policy(POLICY_A).pdpId(PDP_A).build(),
- builder.policy(POLICY_A).pdpId(PDP_B).build(),
- notDeployed,
- builder.policy(POLICY_C).pdpId(PDP_A).build()
- ));
- // @formatter:on
+ buildPolicyStatusToReturn1();
List<PolicyStatus> result = new ArrayList<>(prov.getStatus());
Collections.sort(result, (rec1, rec2) -> rec1.getPolicy().compareTo(rec2.getPolicy()));
- assertThat(result).hasSize(2);
+ assertThat(result).hasSize(3);
Iterator<PolicyStatus> iter = result.iterator();
@@ -109,6 +97,13 @@ public class TestPolicyStatusProvider extends ProviderSuper {
assertThat(status.getSuccessCount()).isZero();
status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_B);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getIncompleteCount()).isZero();
+ assertThat(status.getFailureCount()).isZero();
+ assertThat(status.getSuccessCount()).isEqualTo(1);
+
+ status = iter.next();
assertThat(status.getPolicy()).isEqualTo(POLICY_C);
assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
assertThat(status.getIncompleteCount()).isEqualTo(1);
@@ -119,8 +114,113 @@ public class TestPolicyStatusProvider extends ProviderSuper {
@Test
public void testGetStatusToscaConceptIdentifierOptVersion() throws PfModelException {
+ ToscaConceptIdentifierOptVersion optIdent = buildPolicyStatusToReturn2();
+
+ List<PolicyStatus> result = new ArrayList<>(prov.getStatus(optIdent));
+ assertThat(result).hasSize(1);
+
+ Iterator<PolicyStatus> iter = result.iterator();
+
+ PolicyStatus status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getIncompleteCount()).isEqualTo(2);
+ assertThat(status.getFailureCount()).isZero();
+ assertThat(status.getSuccessCount()).isZero();
+ }
+
+ @Test
+ public void testGetPolicyStatus() throws PfModelException {
+
+ buildPolicyStatusToReturn1();
+
+ List<PdpPolicyStatus> result = new ArrayList<>(prov.getPolicyStatus());
+ Collections.sort(result, (rec1, rec2) -> rec1.getPolicy().compareTo(rec2.getPolicy()));
+
+ assertThat(result).hasSize(5);
+ Iterator<PdpPolicyStatus> iter = result.iterator();
+
+ PdpPolicyStatus status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getPdpId()).isEqualTo(PDP_A);
+ assertThat(status.getPdpType()).isEqualTo(MY_PDP_TYPE);
+ assertThat(status.getPdpGroup()).isEqualTo(MY_GROUP);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPdpId()).isEqualTo(PDP_B);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_B);
+ assertThat(status.getPdpId()).isEqualTo(PDP_A);
+ assertFalse(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_B);
+ assertThat(status.getPdpId()).isEqualTo(PDP_B);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.SUCCESS);
+ }
+
+ @Test
+ public void testGetPolicyStatusByGroupAndPolicyIdVersion() throws PfModelException {
+
+ ToscaConceptIdentifierOptVersion optIdent = buildPolicyStatusToReturn2();
+
+ List<PdpPolicyStatus> result = new ArrayList<>(prov.getPolicyStatus(MY_GROUP, optIdent));
+ assertThat(result).hasSize(3);
+
+ Iterator<PdpPolicyStatus> iter = result.iterator();
+
+ PdpPolicyStatus status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getPdpId()).isEqualTo(PDP_A);
+ assertThat(status.getPdpType()).isEqualTo(MY_PDP_TYPE);
+ assertThat(status.getPdpGroup()).isEqualTo(MY_GROUP);
+ assertTrue(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.WAITING);
+
+ status = iter.next();
+ assertThat(status.getPolicy()).isEqualTo(POLICY_A);
+ assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
+ assertThat(status.getPdpId()).isEqualTo(PDP_B);
+ assertThat(status.getPdpType()).isEqualTo(MY_PDP_TYPE);
+ assertThat(status.getPdpGroup()).isEqualTo(MY_GROUP);
+ assertFalse(status.isDeploy());
+ assertThat(status.getState()).isEqualTo(State.FAILURE);
+ }
+
+ private void buildPolicyStatusToReturn1() throws PfModelException {
+
PdpPolicyStatusBuilder builder = PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE)
- .policy(POLICY_A).policyType(POLICY_TYPE);
+ .policyType(POLICY_TYPE).state(State.WAITING);
+
+ PdpPolicyStatus notDeployed = builder.deploy(false).policy(POLICY_B).pdpId(PDP_A).build();
+
+ // remaining policies are deployed
+ builder.deploy(true);
+
+ // @formatter:off
+ when(dao.getAllPolicyStatus()).thenReturn(List.of(
+ builder.policy(POLICY_A).pdpId(PDP_A).build(),
+ builder.policy(POLICY_A).pdpId(PDP_B).build(),
+ notDeployed,
+ builder.policy(POLICY_C).pdpId(PDP_A).build(),
+ builder.policy(POLICY_B).pdpId(PDP_B).state(State.SUCCESS).build()
+ ));
+ // @formatter:on
+ }
+
+ private ToscaConceptIdentifierOptVersion buildPolicyStatusToReturn2() throws PfModelException {
+ PdpPolicyStatusBuilder builder =
+ PdpPolicyStatus.builder().pdpGroup(MY_GROUP).pdpType(MY_PDP_TYPE).policy(POLICY_A).policyType(POLICY_TYPE);
PdpPolicyStatus notDeployed = builder.deploy(false).pdpId(PDP_B).state(State.FAILURE).build();
@@ -136,17 +236,6 @@ public class TestPolicyStatusProvider extends ProviderSuper {
builder.policy(POLICY_A).pdpId(PDP_C).build()
));
// @formatter:on
-
- List<PolicyStatus> result = new ArrayList<>(prov.getStatus(optIdent));
- assertThat(result).hasSize(1);
-
- Iterator<PolicyStatus> iter = result.iterator();
-
- PolicyStatus status = iter.next();
- assertThat(status.getPolicy()).isEqualTo(POLICY_A);
- assertThat(status.getPolicyType()).isEqualTo(POLICY_TYPE);
- assertThat(status.getIncompleteCount()).isEqualTo(2);
- assertThat(status.getFailureCount()).isZero();
- assertThat(status.getSuccessCount()).isZero();
+ return optIdent;
}
}
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 55cf2f4c..9b80bb7e 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
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -38,11 +39,13 @@ import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicFactories;
import org.onap.policy.common.endpoints.event.comm.bus.NoopTopicSink;
import org.onap.policy.common.utils.coder.StandardCoder;
import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
+import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
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 {
private static final String DELETE_GROUP_ENDPOINT = "pdps/groups";
@@ -136,8 +139,10 @@ public class PdpGroupDeleteTest extends End2EndBase {
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
- PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
assertNull(resp.getErrorDetails());
context.await();
@@ -157,7 +162,7 @@ public class PdpGroupDeleteTest extends End2EndBase {
assertEquals(new ToscaConceptIdentifier("onap.restart.tcaB", "1.0.0"), deleted.getPolicy());
rawresp = invocationBuilder.delete();
- resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
assertEquals("policy does not appear in any PDP group: onap.restart.tcaB null", resp.getErrorDetails());
}
@@ -188,14 +193,15 @@ public class PdpGroupDeleteTest extends End2EndBase {
Invocation.Builder invocationBuilder = sendRequest(uri);
Response rawresp = invocationBuilder.delete();
- PdpGroupDeleteResponse resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
-
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
context.await();
rawresp = invocationBuilder.delete();
- resp = rawresp.readEntity(PdpGroupDeleteResponse.class);
+ resp = rawresp.readEntity(PdpGroupDeployResponse.class);
assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
assertEquals("policy does not appear in any PDP group: onap.restart.tcaC 1.0.0", resp.getErrorDetails());
}
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 3c5bed87..08974ed8 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
@@ -4,6 +4,7 @@
* ================================================================================
* Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
* Modifications Copyright (C) 2021 Nordix Foundation.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -50,6 +51,7 @@ 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 {
private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch";
@@ -115,7 +117,7 @@ public class PdpGroupDeployTest extends End2EndBase {
Entity<DeploymentGroups> entity = Entity.entity(groups, MediaType.APPLICATION_JSON);
Response rawresp = invocationBuilder.post(entity);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
context.await();
@@ -126,7 +128,9 @@ public class PdpGroupDeployTest extends End2EndBase {
// repeat - should be OK
rawresp = invocationBuilder.post(entity);
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
assertNull(resp.getErrorDetails());
// repeat with unknown group - should fail
@@ -181,8 +185,9 @@ public class PdpGroupDeployTest extends End2EndBase {
Entity<PdpDeployPolicies> entity = Entity.entity(policies, MediaType.APPLICATION_JSON);
Response rawresp = invocationBuilder.post(entity);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- System.out.println(resp.getErrorDetails());
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
+ assertEquals(PdpGroupDeployControllerV1.DEPLOYMENT_RESPONSE_MSG, resp.getMessage());
+ assertEquals(PdpGroupDeployControllerV1.POLICY_STATUS_URI, resp.getUri());
assertNull(resp.getErrorDetails());
context.await();
@@ -207,7 +212,7 @@ public class PdpGroupDeployTest extends End2EndBase {
// repeat - should be OK
rawresp = invocationBuilder.post(entity);
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+ assertEquals(Response.Status.ACCEPTED.getStatusCode(), rawresp.getStatus());
assertNull(resp.getErrorDetails());
}
}
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 19a5f990..b44d4af7 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
@@ -3,6 +3,7 @@
* ONAP PAP
* ================================================================================
* Copyright (C) 2019, 2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -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.util.List;
import javax.ws.rs.client.Invocation;
@@ -29,9 +31,15 @@ import javax.ws.rs.core.Response;
import org.junit.BeforeClass;
import org.junit.Test;
import org.onap.policy.models.pap.concepts.PolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus;
+import org.onap.policy.models.pdp.concepts.PdpPolicyStatus.State;
public class PolicyStatusTest extends End2EndBase {
+ private static final String POLICY_NAME = "onap.restart.tca";
+ private static final String POLICY_TYPE_NAME = "onap.policies.monitoring.cdap.tca.hi.lo.app";
+ private static final String VERSION = "1.0.0";
private static final String POLICY_STATUS_ENDPOINT = "policies/deployed";
+ private static final String POLICY_DEPLOYMENT_STATUS_ENDPOINT = "policies/status";
/**
* Starts Main and adds policies to the DB.
@@ -54,15 +62,7 @@ public class PolicyStatusTest extends End2EndBase {
List<PolicyStatus> resp = rawresp.readEntity(new GenericType<List<PolicyStatus>>() {});
assertEquals(1, resp.size());
-
- PolicyStatus status = resp.get(0);
- assertEquals("onap.restart.tca", status.getPolicyId());
- assertEquals("1.0.0", status.getPolicyVersion());
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", status.getPolicyTypeId());
- assertEquals("1.0.0", status.getPolicyTypeVersion());
- assertEquals(0, status.getFailureCount());
- assertEquals(1, status.getIncompleteCount());
- assertEquals(0, status.getSuccessCount());
+ checkAssertions(resp.get(0));
}
@Test
@@ -75,15 +75,7 @@ public class PolicyStatusTest extends End2EndBase {
List<PolicyStatus> resp = rawresp.readEntity(new GenericType<List<PolicyStatus>>() {});
assertEquals(1, resp.size());
-
- PolicyStatus status = resp.get(0);
- assertEquals("onap.restart.tca", status.getPolicyId());
- assertEquals("1.0.0", status.getPolicyVersion());
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", status.getPolicyTypeId());
- assertEquals("1.0.0", status.getPolicyTypeVersion());
- assertEquals(0, status.getFailureCount());
- assertEquals(1, status.getIncompleteCount());
- assertEquals(0, status.getSuccessCount());
+ checkAssertions(resp.get(0));
}
@Test
@@ -95,12 +87,67 @@ public class PolicyStatusTest extends End2EndBase {
assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
PolicyStatus status = rawresp.readEntity(PolicyStatus.class);
- assertEquals("onap.restart.tca", status.getPolicyId());
- assertEquals("1.0.0", status.getPolicyVersion());
- assertEquals("onap.policies.monitoring.cdap.tca.hi.lo.app", status.getPolicyTypeId());
- assertEquals("1.0.0", status.getPolicyTypeVersion());
+ checkAssertions(status);
+ }
+
+ @Test
+ public void testGetStatusOfAllDeployedPolicies() throws Exception {
+ String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT;
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.get();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+
+ List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<List<PdpPolicyStatus>>() {});
+ assertEquals(1, resp.size());
+ checkAssertionsForDeploymentStatus(resp.get(0));
+ }
+
+ @Test
+ public void testGetStatusOfDeployedPolicies() throws Exception {
+ String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.get();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+
+ List<PdpPolicyStatus> resp = rawresp.readEntity(new GenericType<List<PdpPolicyStatus>>() {});
+ assertEquals(1, resp.size());
+ checkAssertionsForDeploymentStatus(resp.get(0));
+ }
+
+ @Test
+ public void testGetStatusOfDeployedPolicy() throws Exception {
+ String uri = POLICY_DEPLOYMENT_STATUS_ENDPOINT + "/policyStatus/onap.restart.tca/1.0.0";
+
+ Invocation.Builder invocationBuilder = sendRequest(uri);
+ Response rawresp = invocationBuilder.get();
+ assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
+
+ PdpPolicyStatus status = rawresp.readEntity(PdpPolicyStatus.class);
+ checkAssertionsForDeploymentStatus(status);
+ }
+
+
+ private void checkAssertions(PolicyStatus status) {
+ assertEquals(POLICY_NAME, status.getPolicyId());
+ assertEquals(VERSION, status.getPolicyVersion());
+ assertEquals(POLICY_TYPE_NAME, status.getPolicyTypeId());
+ assertEquals(VERSION, status.getPolicyTypeVersion());
assertEquals(0, status.getFailureCount());
assertEquals(1, status.getIncompleteCount());
assertEquals(0, status.getSuccessCount());
}
+
+ private void checkAssertionsForDeploymentStatus(PdpPolicyStatus status) {
+ assertEquals(POLICY_NAME, status.getPolicy().getName());
+ assertEquals(VERSION, status.getPolicy().getVersion());
+ assertEquals(POLICY_TYPE_NAME, status.getPolicyType().getName());
+ assertEquals(VERSION, status.getPolicyType().getVersion());
+ assertEquals("policyStatus", status.getPdpGroup());
+ assertEquals("pdpB_1", status.getPdpId());
+ assertEquals("pdpTypeB", status.getPdpType());
+ assertEquals(State.WAITING, status.getState());
+ assertTrue(status.isDeploy());
+ }
}