2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * Modifications Copyright (C) 2019 AT&T Intellectual Property.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.pap.main.rest;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNull;
27 import java.util.Arrays;
28 import javax.ws.rs.client.Entity;
29 import javax.ws.rs.client.Invocation;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32 import org.junit.Test;
33 import org.onap.policy.models.pap.concepts.PdpGroup;
34 import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
35 import org.onap.policy.models.pap.concepts.PdpSubGroup;
37 public class TestPdpGroupDeployControllerV1 extends CommonPapRestServer {
39 private static final String DEPLOY_ENDPOINT = "pdps";
42 public void testSwagger() throws Exception {
43 super.testSwagger(DEPLOY_ENDPOINT);
47 public void testDeploy() throws Exception {
48 Entity<PdpGroup> entgrp = makePdpGroupEntity();
50 Invocation.Builder invocationBuilder = sendRequest(DEPLOY_ENDPOINT);
51 Response rawresp = invocationBuilder.post(entgrp);
52 PdpGroupDeployResponse resp = rawresp.readEntity(PdpGroupDeployResponse.class);
53 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
54 assertNull(resp.getErrorDetails());
56 rawresp = invocationBuilder.post(entgrp);
57 resp = rawresp.readEntity(PdpGroupDeployResponse.class);
58 assertEquals(Response.Status.OK.getStatusCode(), rawresp.getStatus());
59 assertNull(resp.getErrorDetails());
61 // verify it fails when no authorization info is included
62 checkUnauthRequest(DEPLOY_ENDPOINT, req -> req.post(entgrp));
65 private Entity<PdpGroup> makePdpGroupEntity() {
66 PdpSubGroup subgrp = new PdpSubGroup();
67 subgrp.setPdpType("drools");
69 PdpGroup group = new PdpGroup();
70 group.setName("drools-group");
71 group.setDescription("my description");
72 group.setVersion("my-version");
73 group.setPdpSubgroups(Arrays.asList(subgrp));
75 Entity<PdpGroup> entgrp = Entity.entity(group, MediaType.APPLICATION_JSON);