2b38434c94e0fb602f10e9844a2e18a86b60f9bc
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.distribution.forwarding.testclasses;
22
23 import io.swagger.annotations.ApiParam;
24 import javax.ws.rs.Consumes;
25 import javax.ws.rs.POST;
26 import javax.ws.rs.Path;
27 import javax.ws.rs.PathParam;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31 import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
32 import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
33 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
34
35 /**
36  * Class to provide rest end points for LifecycycleApiSimulator.
37  *
38  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
39  */
40 @Path("/policy")
41 @Produces(MediaType.APPLICATION_JSON)
42 public class LifecycycleApiSimulatorEndpoint {
43
44     /**
45      * Create policy type endpoint.
46      *
47      * @param body the post body
48      * @return the response object
49      */
50     @POST
51     @Path("/api/v1/policytypes")
52     @Consumes(MediaType.APPLICATION_JSON)
53     @Produces(MediaType.APPLICATION_JSON)
54     public Response createPolicyTypes(final ToscaServiceTemplate body) {
55         return Response.status(Response.Status.OK).entity(body).build();
56     }
57
58     /**
59      * Create policy endpoint.
60      *
61      * @param policyTypeId the policy type id
62      * @param policyTypeVersion the policy type version
63      * @param body the post body
64      * @return the response object
65      */
66     @POST
67     @Path("/api/v1/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
68     @Consumes(MediaType.APPLICATION_JSON)
69     @Produces(MediaType.APPLICATION_JSON)
70     public Response createPolicies(@PathParam("policyTypeId") final String policyTypeId,
71             @PathParam("policyTypeVersion") final String policyTypeVersion,
72             @ApiParam(value = "Entity body of policy", required = true) final ToscaServiceTemplate body) {
73         if ("onap.policies.controlloop.operational.ApexFailure".equals(policyTypeId)) {
74             return Response.status(Response.Status.NOT_FOUND).build();
75         } else {
76             return Response.status(Response.Status.OK).entity(body).build();
77         }
78     }
79
80     /**
81      * Deploy policy endpoint.
82      *
83      * @param policies the post body
84      * @return the response object
85      */
86     @POST
87     @Path("/pap/v1/pdps/policies")
88     @Consumes(MediaType.APPLICATION_JSON)
89     @Produces(MediaType.APPLICATION_JSON)
90     public Response deployPolicies(final PdpDeployPolicies policies) {
91         return Response.status(Response.Status.OK).entity(new PdpGroupDeployResponse()).build();
92     }
93 }