1791033e66ddee4caf3213ca5f339ae5717dd382
[policy/apex-pdp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
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.adapt.restserver;
22
23 import static org.junit.Assert.assertEquals;
24
25 import java.io.IOException;
26
27 import javax.ws.rs.client.Client;
28 import javax.ws.rs.client.ClientBuilder;
29 import javax.ws.rs.client.Entity;
30 import javax.ws.rs.core.Response;
31
32 import org.junit.Ignore;
33 import org.junit.Test;
34 import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
35 import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
36 import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
37 import org.onap.policy.apex.service.engine.main.ApexMain;
38
39
40 public class TestRestServerVpnContext {
41     private static int eventsSent = 0;
42
43     @Ignore
44     @Test
45     public void testRestServerPut() throws MessagingException, ApexException, IOException {
46         final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventContextJava.json"};
47         final ApexMain apexMain = new ApexMain(args);
48
49         final Client client = ClientBuilder.newClient();
50
51         Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
52                 .request("application/json").put(Entity.json(setupLinkContext("L09", true)));
53         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
54
55         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
56                 .put(Entity.json(setupLinkContext("L10", true)));
57         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
58
59         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
60                 .put(Entity.json(setupCustomerContext("A", "L09 L10", 300, 50)));
61         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
62
63         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
64                 .put(Entity.json(setupCustomerContext("B", "L09 L10", 300, 299)));
65         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
66
67         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
68                 .put(Entity.json(setupCustomerContext("C", "L09 L10", 300, 300)));
69         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
70
71         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
72                 .put(Entity.json(setupCustomerContext("D", "L09 L10", 300, 400)));
73         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
74
75         ThreadUtilities.sleep(100000);
76
77         apexMain.shutdown();
78     }
79
80     @Ignore
81     @Test
82     public void testRestServerPutAvro() throws MessagingException, ApexException, IOException {
83         final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventContextAvro.json"};
84         final ApexMain apexMain = new ApexMain(args);
85
86         final Client client = ClientBuilder.newClient();
87
88         Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
89                 .request("application/json").put(Entity.json(setupLinkContext("L09", true)));
90         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
91
92         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
93                 .put(Entity.json(setupLinkContext("L10", true)));
94         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
95
96         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
97                 .put(Entity.json(setupCustomerContext("A", "L09 L10", 300, 50)));
98         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
99
100         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
101                 .put(Entity.json(setupCustomerContext("B", "L09 L10", 300, 299)));
102         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
103
104         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
105                 .put(Entity.json(setupCustomerContext("C", "L09 L10", 300, 300)));
106         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
107
108         response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
109                 .put(Entity.json(setupCustomerContext("D", "L09 L10", 300, 400)));
110         assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
111
112         ThreadUtilities.sleep(100000);
113
114         apexMain.shutdown();
115     }
116
117     private String setupLinkContext(final String link, final Boolean isUp) {
118         final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.domains.vpn.events\",\n"
119                 + "\"name\": \"VPNLinkCtxtTriggerEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
120                 + eventsSent++ + "\",\n" + "\"target\": \"apex\",\n" + "\"Link\": \"" + link + "\",\n" + "\"LinkUp\": "
121                 + isUp + "\n" + "}";
122
123         return eventString;
124     }
125
126     private String setupCustomerContext(final String customerName, final String linkList, final int slaDt,
127             final int ytdDt) {
128         final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.domains.vpn.events\",\n"
129                 + "\"name\": \"VPNCustomerCtxtTriggerEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
130                 + eventsSent++ + "\",\n" + "\"target\": \"apex\",\n" + "\"CustomerName\": \"" + customerName + "\",\n"
131                 + "\"LinkList\": \"" + linkList + "\",\n" + "\"SlaDT\": \"" + slaDt + "\",\n" + "\"YtdDT\": " + ytdDt
132                 + "\n" + "}";
133
134         return eventString;
135     }
136 }