-/*-
+/*
* ============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");
package org.onap.policy.pap.main.rest;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
+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;
import javax.ws.rs.core.Response;
-
import org.junit.Test;
import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
-import org.onap.policy.models.pdp.concepts.PdpGroup;
-import org.onap.policy.models.pdp.concepts.PdpSubGroup;
-import org.onap.policy.models.pdp.concepts.ToscaPolicyIdentifierOptVersion;
-
+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", "default" })
public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
- private static final String DEPLOY_GROUP_ENDPOINT = "pdps";
+ private static final String DEPLOY_GROUP_ENDPOINT = "pdps/deployments/batch";
private static final String DEPLOY_POLICIES_ENDPOINT = "pdps/policies";
@Test
}
@Test
- public void testDeployGroup() throws Exception {
- final Entity<PdpGroup> entgrp = makePdpGroupEntity();
+ public void testUpdateGroupPolicies() throws Exception {
+ Entity<DeploymentGroups> entgrp = makeDeploymentGroupsEntity();
- final Invocation.Builder invocationBuilder = sendRequest(DEPLOY_GROUP_ENDPOINT);
+ Invocation.Builder invocationBuilder = sendRequest(DEPLOY_GROUP_ENDPOINT);
Response rawresp = invocationBuilder.post(entgrp);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
+ assertNotNull(resp.getErrorDetails());
rawresp = invocationBuilder.post(entgrp);
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), rawresp.getStatus());
+ assertNotNull(resp.getErrorDetails());
// verify it fails when no authorization info is included
checkUnauthRequest(DEPLOY_GROUP_ENDPOINT, req -> req.post(entgrp));
@Test
public void testDeployPolicies() throws Exception {
- final Entity<PdpDeployPolicies> entgrp = makePdpPoliciesEntity();
+ Entity<PdpDeployPolicies> entgrp = makePdpPoliciesEntity();
- final Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
+ Invocation.Builder invocationBuilder = sendRequest(DEPLOY_POLICIES_ENDPOINT);
Response rawresp = invocationBuilder.post(entgrp);
PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
+ assertNotNull(resp.getErrorDetails());
rawresp = invocationBuilder.post(entgrp);
resp = rawresp.readEntity(PdpGroupDeployResponse.class);
- assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
- assertNull(resp.getErrorDetails());
+ assertEquals(Response.Status.NOT_FOUND.getStatusCode(), rawresp.getStatus());
+ assertNotNull(resp.getErrorDetails());
// verify it fails when no authorization info is included
checkUnauthRequest(DEPLOY_POLICIES_ENDPOINT, req -> req.post(entgrp));
}
- private Entity<PdpGroup> makePdpGroupEntity() {
- final PdpSubGroup subgrp = new PdpSubGroup();
+ private Entity<DeploymentGroups> makeDeploymentGroupsEntity() {
+ DeploymentSubGroup subgrp = new DeploymentSubGroup();
subgrp.setPdpType("drools");
- final PdpGroup group = new PdpGroup();
+ DeploymentGroup group = new DeploymentGroup();
group.setName("drools-group");
- group.setDescription("my description");
- group.setVersion("my-version");
- group.setPdpSubgroups(Arrays.asList(subgrp));
+ group.setDeploymentSubgroups(List.of(subgrp));
+
+ DeploymentGroups groups = new DeploymentGroups();
+ groups.setGroups(List.of(group));
- return Entity.entity(group, MediaType.APPLICATION_JSON);
+ return Entity.entity(groups, MediaType.APPLICATION_JSON);
}
private Entity<PdpDeployPolicies> makePdpPoliciesEntity() {
- final ToscaPolicyIdentifierOptVersion pol1 = new ToscaPolicyIdentifierOptVersion();
- pol1.setName("policy-a");
- pol1.setVersion("1");
-
- final ToscaPolicyIdentifierOptVersion pol2 = new ToscaPolicyIdentifierOptVersion();
- pol2.setName("policy-b");
+ ToscaConceptIdentifierOptVersion pol1 = new ToscaConceptIdentifierOptVersion("policy-a", "1");
+ ToscaConceptIdentifierOptVersion pol2 = new ToscaConceptIdentifierOptVersion("policy-b", null);
- final PdpDeployPolicies policies = new PdpDeployPolicies();
+ PdpDeployPolicies policies = new PdpDeployPolicies();
policies.setPolicies(Arrays.asList(pol1, pol2));
return Entity.entity(policies, MediaType.APPLICATION_JSON);