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;
 
  24 import java.util.HashMap;
 
  27 import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
 
  28 import org.glassfish.jersey.media.sse.SseFeature;
 
  29 import org.glassfish.jersey.server.ResourceConfig;
 
  30 import org.junit.Test;
 
  31 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 
  32 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 
  33 import static org.hamcrest.MatcherAssert.assertThat;
 
  34 import static org.hamcrest.core.Is.is;
 
  36 public class TestRestconfDiscoveryNode {
 
  38     private static final URI CONTEXT = URI.create("http://localhost:8080/");
 
  41     public void testEstablishPersistentConnection() throws SvcLogicException,
 
  42             InterruptedException {
 
  43         final ResourceConfig resourceConfig = new ResourceConfig(
 
  44                 SseServerMock.class, SseFeature.class);
 
  45         GrizzlyHttpServerFactory.createHttpServer(CONTEXT, resourceConfig);
 
  46         SvcLogicContext ctx = new SvcLogicContext();
 
  47         ctx.setAttribute("prop.encoding-json", "encoding-json");
 
  48         ctx.setAttribute("restapi-result.response-code", "200");
 
  49         ctx.setAttribute("restapi-result.ietf-subscribed-notifications" +
 
  50                                  ":output.identifier", "100");
 
  52         Map<String, String> p = new HashMap<>();
 
  53         p.put("sseConnectURL", "http://localhost:8080/events");
 
  54         p.put("subscriberId", "networkId");
 
  55         p.put("responsePrefix", "restapi-result");
 
  56         RestconfDiscoveryNode rdn = new RestconfDiscoveryNode();
 
  57         rdn.establishPersistentConnection(p, ctx, "networkId");
 
  59         rdn.deleteSubscription(p, ctx);
 
  62     @Test(expected = SvcLogicException.class)
 
  63     public void testSubGraphExecution() throws SvcLogicException{
 
  64         SvcLogicGraphInfo subDg = new SvcLogicGraphInfo();
 
  66         subDg.module("l3VpnService");
 
  67         subDg.rpc("createVpn");
 
  69         SvcLogicContext ctx = new SvcLogicContext();
 
  70         subDg.executeGraph(ctx);
 
  73     @Test(expected = SvcLogicException.class)
 
  74     public void testEstablishSubscriptionWithoutSubscriberId()
 
  75             throws SvcLogicException{
 
  76         SvcLogicContext ctx = new SvcLogicContext();
 
  77         Map<String, String> p = new HashMap<>();
 
  78         RestconfDiscoveryNode rdn = new RestconfDiscoveryNode();
 
  79         rdn.establishSubscription(p, ctx);
 
  83     public void testResponseCode() {
 
  84         SvcLogicContext ctx = new SvcLogicContext();
 
  85         ctx.setAttribute("restapi-result.response-code", "200");
 
  86         ctx.setAttribute("response-code", "404");
 
  87         RestconfDiscoveryNode rdn = new RestconfDiscoveryNode();
 
  88         assertThat(rdn.getResponseCode("restapi-result", ctx),
 
  90         assertThat(rdn.getResponseCode(null, ctx),
 
  95     public void testOutputIdentifier() {
 
  96         SvcLogicContext ctx = new SvcLogicContext();
 
  97         ctx.setAttribute("restapi-result.ietf-subscribed-notifications:" +
 
  98                                  "output.identifier", "89");
 
  99         ctx.setAttribute("ietf-subscribed-notifications:output.identifier",
 
 101         RestconfDiscoveryNode rdn = new RestconfDiscoveryNode();
 
 102         assertThat(rdn.getOutputIdentifier("restapi-result", ctx),