f0b670008b3c62579ab06c748f4917b027f5d3ba
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2020 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.apex.testsuites.integration.uservice.taskparameters;
22
23 import javax.ws.rs.GET;
24 import javax.ws.rs.POST;
25 import javax.ws.rs.Path;
26 import javax.ws.rs.PathParam;
27 import javax.ws.rs.core.Response;
28
29 /**
30  * The Class RestClientEndpointForTaskParameters.
31  */
32 @Path("/apex")
33 public class RestClientEndpointForTaskParameters {
34
35     private static String closedLoopId;
36     private static String serviceId;
37
38     /**
39      * Get event that triggers policy for testing TaskParameters.
40      *
41      * @return the response
42      */
43     @Path("/event/GetEvent")
44     @GET
45     public Response getEvent() {
46         return Response.status(200).entity("{\"event\": \"CLTriggerEvent\"}").build();
47     }
48
49     /**
50      * Fetch information of service using serviceId.
51      *
52      * @param servicId the service id
53      *
54      * @return the response
55      */
56     @Path("/service/getInfoForServiceId/{servicId}")
57     @POST
58     public Response getInfoForServiceId(@PathParam("servicId") String servicId) {
59         serviceId = servicId;
60         return Response.status(200)
61             .entity("{\"name\": \"ServiceInfoEvent\", \"serviceDetails\": \"serviceDetailsFullBody\"}").build();
62     }
63
64     /**
65      * Closed loop action using closedLoopId.
66      *
67      * @param closedLpId the closedLoopId
68      *
69      * @return the response
70      */
71     @Path("/action/doActionForCL/{closedLpId}")
72     @POST
73     public Response doActionForCL(@PathParam("closedLpId") String closedLpId) {
74         closedLoopId = closedLpId;
75         return Response.status(200).entity("{\"name\": \"CLOutputEvent\", \"status\": \"ClosedLoop Success\"}").build();
76     }
77
78     /**
79      * Get details that are set as part of the policy execution.
80      *
81      * @return the response
82      */
83     @Path("/event/getDetails")
84     @GET
85     public Response getDetails() {
86         if (null == serviceId || null == closedLoopId) {
87             return Response.status(500).entity("Error: Flow incomplete").build();
88         }
89         return Response.status(200).entity("{\"closedLoopId\": " + closedLoopId + ",\"serviceId\": " + serviceId + "}")
90             .build();
91     }
92
93     /**
94      * Clear details that are set as part of the policy execution.
95      *
96      * @return the response
97      */
98     @Path("/event/clearDetails")
99     @GET
100     public Response clearDetails() {
101         closedLoopId = null;
102         serviceId = null;
103         return Response.status(200).entity("Details cleared.").build();
104     }
105 }