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 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
61 new RestconfApiCallNode(new RestapiCallNode()));
62 rdn.establishPersistentConnection(p, ctx, "networkId");
64 rdn.deleteSubscription(p, ctx);
67 @Test(expected = SvcLogicException.class)
68 public void testSubGraphExecution() throws SvcLogicException{
69 SvcLogicGraphInfo subDg = new SvcLogicGraphInfo();
71 subDg.module("l3VpnService");
72 subDg.rpc("createVpn");
74 SvcLogicContext ctx = new SvcLogicContext();
75 subDg.executeGraph(ctx);
78 @Test(expected = SvcLogicException.class)
79 public void testEstablishSubscriptionWithoutSubscriberId()
80 throws SvcLogicException{
81 SvcLogicContext ctx = new SvcLogicContext();
82 Map<String, String> p = new HashMap<>();
83 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
84 new RestconfApiCallNode(new RestapiCallNode()));
85 rdn.establishSubscription(p, ctx);
89 public void testResponseCode() {
90 SvcLogicContext ctx = new SvcLogicContext();
91 ctx.setAttribute("restapi-result.response-code", "200");
92 ctx.setAttribute("response-code", "404");
93 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
94 new RestconfApiCallNode(new RestapiCallNode()));
95 assertThat(rdn.getResponseCode("restapi-result", ctx),
97 assertThat(rdn.getResponseCode(null, ctx),
102 public void testOutputIdentifier() {
103 SvcLogicContext ctx = new SvcLogicContext();
104 ctx.setAttribute("restapi-result.ietf-subscribed-notifications:" +
105 "establish-subscription.output.identifier",
107 ctx.setAttribute("ietf-subscribed-notifications:establish-subscripti" +
108 "on.output.identifier", "89");
109 RestconfDiscoveryNode rdn = new RestconfDiscoveryNode(
110 new RestconfApiCallNode(new RestapiCallNode()));
111 assertThat(rdn.getOutputIdentifier("restapi-result", ctx),