2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.ccsdk.sli.plugins.restconfdiscovery;
23 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
24 import org.glassfish.jersey.media.sse.SseFeature;
25 import org.glassfish.jersey.server.ResourceConfig;
26 import org.junit.Test;
27 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
28 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
29 import org.onap.ccsdk.sli.plugins.restapicall.RestapiCallNode;
30 import org.onap.ccsdk.sli.plugins.restconfapicall.RestconfApiCallNode;
33 import java.util.HashMap;
36 import static org.hamcrest.MatcherAssert.assertThat;
37 import static org.hamcrest.core.Is.is;
39 public class TestRestconfDiscoveryNode {
41 private static final URI CONTEXT = URI.create("http://localhost:8080/");
44 public void testEstablishPersistentConnection() throws SvcLogicException,
45 InterruptedException {
46 final ResourceConfig resourceConfig = new ResourceConfig(
47 SseServerMock.class, SseFeature.class);
48 GrizzlyHttpServerFactory.createHttpServer(CONTEXT, resourceConfig);
49 SvcLogicContext ctx = new SvcLogicContext();
50 ctx.setAttribute("prop.encoding-json", "encoding-json");
51 ctx.setAttribute("restapi-result.response-code", "200");
52 ctx.setAttribute("restapi-result.ietf-subscribed-notifications" +
53 ":establish-subscription.output.identifier",
56 Map<String, String> p = new HashMap<>();
57 p.put("sseConnectURL", "http://localhost:8080/events");
58 p.put("subscriberId", "networkId");
59 p.put("responsePrefix", "restapi-result");
60 p.put("restapiUser", "access");
61 p.put("restapiPassword", "abc@123");
62 p.put("customHttpHeaders", "X-ACCESS-TOKEN=x-ik2ps4ikvzupbx0486ft" +
63 "1ebzs7rt85futh9ho6eofy3wjsap7wqktemlqm4bbsmnar3vrtbyrzuk" +
64 "bv5itd6m1cftldpjarnyle3sdcqq9hftc4lebz464b5ffxmlbvg9");
65 p.put("restapiUrl", "https://localhost:8080/restconf/operations/" +
66 "ietf-subscribed-notifications:establish-subscription");
67 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
68 new RestconfApiCallNode(new RestapiCallNode()));
69 rdn.establishPersistentConnection(p, ctx, "networkId");
71 rdn.deleteSubscription(p, ctx);
74 @Test(expected = SvcLogicException.class)
75 public void testSubGraphExecution() throws SvcLogicException{
76 SvcLogicGraphInfo subDg = new SvcLogicGraphInfo();
78 subDg.module("l3VpnService");
79 subDg.rpc("createVpn");
81 SvcLogicContext ctx = new SvcLogicContext();
82 subDg.executeGraph(ctx);
85 @Test(expected = SvcLogicException.class)
86 public void testEstablishSubscriptionWithoutSubscriberId()
87 throws SvcLogicException{
88 SvcLogicContext ctx = new SvcLogicContext();
89 Map<String, String> p = new HashMap<>();
90 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
91 new RestconfApiCallNode(new RestapiCallNode()));
92 rdn.establishSubscription(p, ctx);
96 public void testResponseCode() {
97 SvcLogicContext ctx = new SvcLogicContext();
98 ctx.setAttribute("restapi-result.response-code", "200");
99 ctx.setAttribute("response-code", "404");
100 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
101 new RestconfApiCallNode(new RestapiCallNode()));
102 assertThat(rdn.getResponseCode("restapi-result", ctx),
104 assertThat(rdn.getResponseCode(null, ctx),
109 public void testOutputIdentifier() {
110 SvcLogicContext ctx = new SvcLogicContext();
111 ctx.setAttribute("restapi-result.ietf-subscribed-notifications:" +
112 "establish-subscription.output.identifier",
114 ctx.setAttribute("ietf-subscribed-notifications:establish-subscripti" +
115 "on.output.identifier", "89");
116 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
117 new RestconfApiCallNode(new RestapiCallNode()));
118 assertThat(rdn.getOutputIdentifier("restapi-result", ctx),
123 public void testGetTokenId() {
124 String customHttpHeaders = "X-ACCESS-TOKEN=x-ik2ps4ikvzupbx0486ft1ebzs7rt85" +
125 "futh9ho6eofy3wjsap7wqktemlqm4bbsmnar3vrtbyrzukbv5itd6m1cftldpjarny" +
126 "le3sdcqq9hftc4lebz464b5ffxmlbvg9";
127 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
128 new RestconfApiCallNode(new RestapiCallNode()));
130 assertThat(rdn.getTokenId(customHttpHeaders),
131 is("x-ik2ps4ikvzupbx0486ft1ebzs7rt85futh9ho6eofy3wjsap7wqkt" +
132 "emlqm4bbsmnar3vrtbyrzukbv5itd6m1cftldpjarnyle3sdcqq9h" +
133 "ftc4lebz464b5ffxmlbvg9"));