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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.apex.testsuites.integration.uservice.adapt.restserver;
23 import static org.junit.Assert.assertEquals;
25 import java.io.IOException;
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;
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;
40 public class TestRestServerVpnContext {
41 private static int eventsSent = 0;
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);
49 final Client client = ClientBuilder.newClient();
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());
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());
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());
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());
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());
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());
75 ThreadUtilities.sleep(100000);
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);
86 final Client client = ClientBuilder.newClient();
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());
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());
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());
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());
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());
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());
112 ThreadUtilities.sleep(100000);
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\": "
126 private String setupCustomerContext(final String customerName, final String linkList, final int slaDt,
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