From 2643d2300a1096da8da1aea7933f73a0f6417c51 Mon Sep 17 00:00:00 2001 From: "k.kedron" Date: Thu, 30 May 2019 13:05:18 +0200 Subject: [PATCH] Add new unit test for CsarInfo. Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron Change-Id: Icda5004063b9a5e52b9308a164bf1e1477361c92 --- .../sdc/be/components/csar/CsarInfoTest.java | 126 +++++++++++++++++++++ catalog-be/src/test/resources/mock_service.csar | Bin 0 -> 1602 bytes 2 files changed, 126 insertions(+) create mode 100644 catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java create mode 100644 catalog-be/src/test/resources/mock_service.csar diff --git a/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java new file mode 100644 index 0000000000..d39c097de5 --- /dev/null +++ b/catalog-be/src/test/java/org/openecomp/sdc/be/components/csar/CsarInfoTest.java @@ -0,0 +1,126 @@ +/*- + * ============LICENSE_START=============================================== + * ONAP SDC + * ======================================================================== + * Copyright (C) 2019 Samsung. 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 org.openecomp.sdc.be.components.csar; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.net.URISyntaxException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; + +import org.openecomp.sdc.be.components.impl.exceptions.ComponentException; +import org.openecomp.sdc.be.dao.api.ActionStatus; +import org.openecomp.sdc.be.model.NodeTypeInfo; +import org.openecomp.sdc.be.model.User; +import org.openecomp.sdc.common.util.ZipUtil; + +@RunWith(MockitoJUnitRunner.class) +public class CsarInfoTest { + + private CsarInfo csarInfo; + + @Mock + private User user; + + private static final String CSAR_UUID = "csarUUID"; + private static final String PAYLOAD_NAME = "mock_service.csar"; + private static final String RESOURCE_NAME = "resourceName"; + private static final String MAIN_TEMPLATE_NAME = "Definitions/tosca_mock_vf.yaml"; + + private static final String NEW_NODE_NAME = "new_db"; + private static final String NODE_TYPE = "tosca.nodes.Compute"; + private static final String DELIVER_FOR = "tosca.nodes.Root"; + + @Before + public void setup() throws IOException, URISyntaxException { + + // given + Map payload = loadPayload(PAYLOAD_NAME); + String main_template_content = new String(payload.get(MAIN_TEMPLATE_NAME)); + + csarInfo = new CsarInfo(user, CSAR_UUID, payload, RESOURCE_NAME, + MAIN_TEMPLATE_NAME, main_template_content, true); + } + + @Test + public void add2TimesTheSameNodeTest() { + + try { + // when + csarInfo.addNodeToQueue(NEW_NODE_NAME); + csarInfo.addNodeToQueue(NEW_NODE_NAME); + fail("AddNodeToQueue not throw the exception!"); + } catch (ComponentException e) { + List expectParam = Arrays.asList(NEW_NODE_NAME, RESOURCE_NAME); + + // then + assertEquals(ActionStatus.CFVC_LOOP_DETECTED, e.getActionStatus()); + assertTrue(Arrays.stream(e.getParams()).allMatch(expectParam::contains)); + } + } + + @Test + public void addMultipleTimesNodeTest() { + + // when + csarInfo.addNodeToQueue(NEW_NODE_NAME); + csarInfo.removeNodeFromQueue(); + csarInfo.addNodeToQueue(NEW_NODE_NAME); + } + + @Test + public void csarCheckNodeTypesInfoTest() { + + // when + Map nodeTypeInfoMap = csarInfo.extractNodeTypesInfo(); + NodeTypeInfo nodeTypeInfo = nodeTypeInfoMap.get(NODE_TYPE); + + // then + assertNotNull(nodeTypeInfo); + assertTrue(nodeTypeInfo.getDerivedFrom().contains(DELIVER_FOR)); + assertEquals(NODE_TYPE, nodeTypeInfo.getType()); + + assertEquals(MAIN_TEMPLATE_NAME, csarInfo.getMainTemplateName()); + assertEquals(csarInfo.getMainTemplateName(), nodeTypeInfo.getTemplateFileName()); + } + + private Map loadPayload(String payloadName) throws IOException, URISyntaxException { + + Path path = Paths.get(getClass().getResource("/" + payloadName).toURI()); + byte[] data = Files.readAllBytes(path); + + return ZipUtil.readZip(data); + } +} diff --git a/catalog-be/src/test/resources/mock_service.csar b/catalog-be/src/test/resources/mock_service.csar new file mode 100644 index 0000000000000000000000000000000000000000..536080508c6efb6598761cdad43038de4557368e GIT binary patch literal 1602 zcmWIWW@Zs#0D);q`~1KRD8a*^z~GXamYJ7Xl9``ZtREV}%fMcv1VByVV3-Ir>DBisF|9z8HUhC6nn@-3#mR~Bx%tW2@nvaxm5I4IV6%&WW_JTI zh(3pZ_=P`7DAv)`e*L$ghbsu|zjvp;X-cHU9VH*1#g z4_$7v3zKBUOr}Lvd@X!tJbw;%Q{lxV_h*kfeob%s^?UK|OZq;V?212sG>35TYL|XE zt?N6}C!x1^1+&lEch)ksnzQC*Y~Q)}%r>!~_8Dc2zSEOes=ebzcu+5OpWlB6pYmxy z&z%Eea|RidpmNX2PfE-QE=?*f$t)=a1z$*IL27YuYEfBca%xCwZb43BNh;LmoD9qn zo8QNPFq*GJdpGhOGT?FfUemgNLDN=dp;t#*Sne*~Qg|>($bDn<#r^8M!na@EyF7Q( znR8V!8WV-oH%g1GT*#j5q4BJttlaR%W?RX}fzO;GXBQhXJf6*R?04~wL;h{y4^Fa9 zC>2tT6=nVKSSpG&@m8WhcwT1W3Lk3&wT>_@;YI6-Uk~mwB6Hd zP5!^!cE;5jMp!T~F!0(~xC4C;2mHWz4)G6mcGUGvElEsCEJ=hUnpa)SVNq+}$3y}# znipY)aWMR8nc>kpt879#(70+Kmc%p+Y_?u5&}?ve*>g)Kya2ng+#mVN%C3C%)%Cnm zdisp#RbFpht#fD2Zw@lJV*H?puZ+h@%^?ui z(gax#pvyghm<#CoAXi5hUst`7iW0DMCoX#*gUh)^r6nIrw?2Brb@GHx7zfDlAsQN| z{DDpnW#CfLdh$#?U7KaO*wj?DB@EPXs7GE%FLgNE03yH#Q@#I z$RxsyJ39j%1_pl}K@@438)h>0>