aboutsummaryrefslogtreecommitdiffstats
path: root/testsuites/integration/integration-uservice-test/src/test/java/org/onap/policy/apex/testsuites/integration/uservice/adapt/restserver/TestRestServerVpnContext.java
blob: 1791033e66ddee4caf3213ca5f339ae5717dd382 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
/*-
 * ============LICENSE_START=======================================================
 *  Copyright (C) 2016-2018 Ericsson. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * SPDX-License-Identifier: Apache-2.0
 * ============LICENSE_END=========================================================
 */

package org.onap.policy.apex.testsuites.integration.uservice.adapt.restserver;

import static org.junit.Assert.assertEquals;

import java.io.IOException;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.core.Response;

import org.junit.Ignore;
import org.junit.Test;
import org.onap.policy.apex.core.infrastructure.messaging.MessagingException;
import org.onap.policy.apex.core.infrastructure.threading.ThreadUtilities;
import org.onap.policy.apex.model.basicmodel.concepts.ApexException;
import org.onap.policy.apex.service.engine.main.ApexMain;


public class TestRestServerVpnContext {
    private static int eventsSent = 0;

    @Ignore
    @Test
    public void testRestServerPut() throws MessagingException, ApexException, IOException {
        final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventContextJava.json"};
        final ApexMain apexMain = new ApexMain(args);

        final Client client = ClientBuilder.newClient();

        Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
                .request("application/json").put(Entity.json(setupLinkContext("L09", true)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupLinkContext("L10", true)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("A", "L09 L10", 300, 50)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("B", "L09 L10", 300, 299)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("C", "L09 L10", 300, 300)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("D", "L09 L10", 300, 400)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        ThreadUtilities.sleep(100000);

        apexMain.shutdown();
    }

    @Ignore
    @Test
    public void testRestServerPutAvro() throws MessagingException, ApexException, IOException {
        final String[] args = {"src/test/resources/prodcons/RESTServerJsonEventContextAvro.json"};
        final ApexMain apexMain = new ApexMain(args);

        final Client client = ClientBuilder.newClient();

        Response response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn")
                .request("application/json").put(Entity.json(setupLinkContext("L09", true)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupLinkContext("L10", true)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("A", "L09 L10", 300, 50)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("B", "L09 L10", 300, 299)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("C", "L09 L10", 300, 300)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        response = client.target("http://localhost:23324/apex/FirstConsumer/EventIn").request("application/json")
                .put(Entity.json(setupCustomerContext("D", "L09 L10", 300, 400)));
        assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

        ThreadUtilities.sleep(100000);

        apexMain.shutdown();
    }

    private String setupLinkContext(final String link, final Boolean isUp) {
        final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.domains.vpn.events\",\n"
                + "\"name\": \"VPNLinkCtxtTriggerEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
                + eventsSent++ + "\",\n" + "\"target\": \"apex\",\n" + "\"Link\": \"" + link + "\",\n" + "\"LinkUp\": "
                + isUp + "\n" + "}";

        return eventString;
    }

    private String setupCustomerContext(final String customerName, final String linkList, final int slaDt,
            final int ytdDt) {
        final String eventString = "{\n" + "\"nameSpace\": \"org.onap.policy.apex.domains.vpn.events\",\n"
                + "\"name\": \"VPNCustomerCtxtTriggerEvent\",\n" + "\"version\": \"0.0.1\",\n" + "\"source\": \"REST_"
                + eventsSent++ + "\",\n" + "\"target\": \"apex\",\n" + "\"CustomerName\": \"" + customerName + "\",\n"
                + "\"LinkList\": \"" + linkList + "\",\n" + "\"SlaDT\": \"" + slaDt + "\",\n" + "\"YtdDT\": " + ytdDt
                + "\n" + "}";

        return eventString;
    }
}