22aeff2fc4ceb842b4a89133becaeb9e9fd30df6
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2021 Bell Canada.
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.distribution.forwarding.testclasses;
23
24 import io.swagger.annotations.ApiParam;
25 import javax.ws.rs.Consumes;
26 import javax.ws.rs.POST;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.PathParam;
29 import javax.ws.rs.Produces;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32 import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
33 import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
34 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
35
36 /**
37  * Class to provide rest end points for LifecycycleApiSimulator.
38  *
39  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
40  */
41 @Path("/policy")
42 @Produces(MediaType.APPLICATION_JSON)
43 public class LifecycycleApiSimulatorEndpoint {
44
45     /**
46      * Create policy type endpoint.
47      *
48      * @param body the post body
49      * @return the response object
50      */
51     @POST
52     @Path("/api/v1/policytypes")
53     @Consumes(MediaType.APPLICATION_JSON)
54     @Produces(MediaType.APPLICATION_JSON)
55     public Response createPolicyTypes(final ToscaServiceTemplate body) {
56         return Response.status(Response.Status.OK).entity(body).build();
57     }
58
59     /**
60      * Create policy endpoint.
61      *
62      * @param policyTypeId the policy type id
63      * @param policyTypeVersion the policy type version
64      * @param body the post body
65      * @return the response object
66      */
67     @POST
68     @Path("/api/v1/policies")
69     @Consumes(MediaType.APPLICATION_JSON)
70     @Produces(MediaType.APPLICATION_JSON)
71     public Response createPolicies(@PathParam("policyTypeId") final String policyTypeId,
72             @PathParam("policyTypeVersion") final String policyTypeVersion,
73             @ApiParam(value = "Entity body of policy", required = true) final ToscaServiceTemplate body) {
74         if ("onap.policies.acm.operational.ApexFailure".equals(policyTypeId)) {
75             return Response.status(Response.Status.NOT_FOUND).build();
76         } else {
77             return Response.status(Response.Status.OK).entity(body).build();
78         }
79     }
80
81     /**
82      * Deploy policy endpoint.
83      *
84      * @param policies the post body
85      * @return the response object
86      */
87     @POST
88     @Path("/pap/v1/pdps/policies")
89     @Consumes(MediaType.APPLICATION_JSON)
90     @Produces(MediaType.APPLICATION_JSON)
91     public Response deployPolicies(final PdpDeployPolicies policies) {
92         return Response.status(Response.Status.OK).entity(new PdpGroupDeployResponse()).build();
93     }
94 }