From: Dan Timoney Date: Fri, 19 Apr 2019 00:28:37 +0000 (+0000) Subject: Merge "[CCSDK-1241] Increase GRToolkit Unit Test Coverage" X-Git-Tag: 0.4.2~2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=31785e54cb0bdee86b57e0cdde4480dfac61aa85;hp=3a50557405e66759277ab71d85963d0943cd08d2;p=ccsdk%2Fsli%2Fplugins.git Merge "[CCSDK-1241] Increase GRToolkit Unit Test Coverage" --- diff --git a/restapi-call-node/provider/pom.xml b/restapi-call-node/provider/pom.xml index 1f698ead..32089455 100755 --- a/restapi-call-node/provider/pom.xml +++ b/restapi-call-node/provider/pom.xml @@ -93,4 +93,5 @@ test + diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java new file mode 100644 index 00000000..b4a30d3a --- /dev/null +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/MockCookieAuthServer.java @@ -0,0 +1,40 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2019 Huawei Technologies Co., Ltd. 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. + * ============LICENSE_END========================================================= + */ +package jtest.org.onap.ccsdk.sli.plugins.restapicall; + +import javax.ws.rs.Consumes; +import javax.ws.rs.Produces; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.NewCookie; +import javax.ws.rs.core.Response; + +@Path("get-cookie") +public class MockCookieAuthServer { + @GET + @Path("cookie") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + public Response getCookie() { + return Response.status(200).entity("success").cookie(new NewCookie("cookieResponse", "cookieValueInReturn")).build(); + } +} diff --git a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java index 7a24ca1a..52da4615 100644 --- a/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java +++ b/restapi-call-node/provider/src/test/java/jtest/org/onap/ccsdk/sli/plugins/restapicall/TestRestapiCallNode.java @@ -25,6 +25,7 @@ import java.net.URI; import java.util.HashMap; import java.util.Map; +import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory; import org.glassfish.jersey.media.multipart.MultiPartFeature; import org.junit.Test; @@ -666,7 +667,7 @@ public class TestRestapiCallNode { public void testMultipartFormData() throws SvcLogicException { final ResourceConfig resourceConfig = new ResourceConfig( MultipartServerMock.class, MultiPartFeature.class); - GrizzlyHttpServerFactory.createHttpServer( + HttpServer server = GrizzlyHttpServerFactory.createHttpServer( URI.create("http://localhost:8080/"),resourceConfig); Map p = new HashMap<>(); @@ -680,5 +681,27 @@ public class TestRestapiCallNode { rcn.sendRequest(p, ctx); assertThat(ctx.getAttribute("response-code"), is("200")); assertThat(ctx.getAttribute("httpResponse"), is( "test-template.json")); + server.shutdownNow(); + } + + @Test + public void testCookieResponse() throws SvcLogicException { + final ResourceConfig resourceConfig = new ResourceConfig( + MockCookieAuthServer.class); + HttpServer server = GrizzlyHttpServerFactory.createHttpServer( + URI.create("http://localhost:8080/"),resourceConfig); + + Map p = new HashMap<>(); + p.put("format", "none"); + p.put("httpMethod", "get"); + p.put("restapiUrl", "http://localhost:8080/get-cookie/cookie"); + p.put("dumpHeaders", "true"); + + SvcLogicContext ctx = new SvcLogicContext(); + RestapiCallNode rcn = new RestapiCallNode(); + rcn.sendRequest(p, ctx); + assertThat(ctx.getAttribute("response-code"), is("200")); + assertThat(ctx.getAttribute("header.Set-Cookie"), is("cookieResponse=cookieValueInReturn;Version=1")); + server.shutdownNow(); } } diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java index 759fe802..0eca40d0 100644 --- a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/pnserializer/MdsalPropertiesNodeSerializer.java @@ -29,6 +29,8 @@ import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.DOT_REGEX; import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.MdsalPropertiesNodeUtils.SLASH; @@ -52,6 +54,8 @@ import static org.onap.ccsdk.sli.plugins.yangserializers.pnserializer.NodeType.S */ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer { + private static final Logger log = LoggerFactory.getLogger( + MdsalPropertiesNodeSerializer.class); private SchemaNode curSchema; private PropertiesNode node; @@ -111,6 +115,8 @@ public class MdsalPropertiesNodeSerializer extends PropertiesNodeSerializer childsFromAugmentation = parent - .augmentations().get(augSchema); - if (!childsFromAugmentation.isEmpty()) { - for (PropertiesNode pNode : childsFromAugmentation) { - if (pNode.name().equals(name)) { - return pNode; - } + if (augSchema == null) { + return null; + } + + Collection childsFromAugmentation = parent + .augmentations().get(augSchema); + if (!childsFromAugmentation.isEmpty()) { + for (PropertiesNode pNode : childsFromAugmentation) { + if (pNode.name().equals(name)) { + return pNode; } } } + return null; } @@ -218,10 +221,12 @@ public final class MdsalPropertiesNodeUtils { * @param appInfo application info * @param type node type * @return new properties node + * @throws SvcLogicException exception while creating properties node */ public static PropertiesNode createNode(String name, Namespace namespace, String uri, PropertiesNode parent, - Object appInfo, NodeType type) { + Object appInfo, NodeType type) + throws SvcLogicException { switch (type) { case SINGLE_INSTANCE_NODE: return new SingleInstanceNode(name, namespace, uri, parent, appInfo, type); @@ -230,7 +235,7 @@ public final class MdsalPropertiesNodeUtils { case MULTI_INSTANCE_LEAF_HOLDER_NODE: return new LeafListHolderNode(name, namespace, uri, parent, appInfo, type); default: - throw new RuntimeException("Invalid node type"); + throw new SvcLogicException("Invalid node type " + type); } } @@ -265,6 +270,9 @@ public final class MdsalPropertiesNodeUtils { return new SchemaPathHolder(id, uri1); } catch (IllegalArgumentException | RestconfDocumentedException | NullPointerException e) { + log.info("Exception while converting uri to instance identifier" + + " context. Process each node in uri to get instance identifier" + + " context " + e); return processNodesAndAppendPath(uri, context); } } @@ -294,6 +302,7 @@ public final class MdsalPropertiesNodeUtils { try { id = processIdentifier(uriParts[i], context, actPath); } catch (IllegalArgumentException e) { + log.info(format(EXC_MSG, e)); id.setUri(actPath+ uriParts[i] + sec); return id; } @@ -340,7 +349,7 @@ public final class MdsalPropertiesNodeUtils { return new SchemaPathHolder(id, val); } catch (IllegalArgumentException | RestconfDocumentedException | NullPointerException e) { - log.info(format(INFO_MSG, val)); + log.info(format(INFO_MSG, val, e)); } firstHalf.append(values[i]).append(UNDERSCORE); secondHalf = secondHalf.replaceFirst(