From 96119e62a35496ecb0093c0f55300dffb95c8d33 Mon Sep 17 00:00:00 2001 From: Anand Chaturvedi Date: Thu, 24 Aug 2017 00:10:17 -0400 Subject: Added New Junit Cases for APPC Design Services Issue-ID: APPC-168 Change-Id: Ib321bb77af3cb47abfce80d96f50a6b75b34b34e Signed-off-by: Anand Chaturvedi --- .../design/validator/TestArifactHandlerClient.java | 59 +++++++++ .../appc/design/validator/TestDBService.java | 48 -------- .../appc/design/validator/TestDesigndata.java | 116 ++++++++++++++++++ .../appc/design/validator/TestEscapeUtils.java | 19 +++ .../design/validator/TestValidatorService.java | 136 +++++++++++++++++++++ 5 files changed, 330 insertions(+), 48 deletions(-) create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java delete mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java create mode 100644 appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java (limited to 'appc-inbound/appc-design-services/provider/src/test/java/org') diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java new file mode 100644 index 000000000..bc0720eff --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestArifactHandlerClient.java @@ -0,0 +1,59 @@ +package org.openecomp.appc.design.validator; + +import org.junit.Before; +import org.junit.Test; +import org.openecomp.appc.design.services.util.ArtifactHandlerClient; + +import junit.framework.Assert; + +import static org.mockito.Mockito.*; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Properties; + +import org.apache.commons.io.FileUtils; + +public class TestArifactHandlerClient { + + @Test + public void testCreateArtifactData(){ + try{ + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": " + + content + + " } "; + String requestID ="0000"; + ArtifactHandlerClient ahi = new ArtifactHandlerClient(); + String value = ahi.createArtifactData(payload, requestID); + System.out.println(value); + Assert.assertTrue(!value.isEmpty());; + + + }catch(Exception e) + { + e.printStackTrace(); + } + + } + + + @Test + public void testExecute() throws Exception{ + try{ + String content = FileUtils.readFileToString(new File("src/test/resources/uploadArtifact")); + String payload = " { \"userID\": \"00000\", \"vnf-type\" : \"DesigTest-VNF\", \"action\" : \"Configure\", \"artifact-name\":\"DesignRestArtifact_reference\",\"artifact-version\" :\"0.01\",\"artifact-type\" :\"DESIGNTOOL-TEST\",\"artifact-contents\": " + + content + + " } "; + String rpc = "Test_Configure"; + + ArtifactHandlerClient ahi = new ArtifactHandlerClient(); + ahi.execute(payload, rpc); + }catch(Exception e) + { + e.printStackTrace(); + } + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java deleted file mode 100644 index 81a620afa..000000000 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDBService.java +++ /dev/null @@ -1,48 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP : APPC - * ================================================================================ - * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * Copyright (C) 2017 Amdocs - * ============================================================================= - * 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. - * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. - * ============LICENSE_END========================================================= - */ - -package org.openecomp.appc.design.validator; - -import java.io.File; -import java.io.InputStream; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.Properties; - -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Test; -import org.openecomp.appc.design.dbervices.DesignDBService; -import org.openecomp.appc.design.services.util.DesignServiceConstants; -import org.openecomp.appc.design.services.util.EscapeUtils; -import org.openecomp.sdnc.sli.SvcLogicContext; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import junit.framework.Assert; - -public class TestDBService { - -//Onap Migration -} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java new file mode 100644 index 000000000..4d46a0e45 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestDesigndata.java @@ -0,0 +1,116 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Copyright (C) 2017 Amdocs + * ============================================================================= + * 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. + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ============LICENSE_END========================================================= + */ + +package org.openecomp.appc.design.validator; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Rule; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.opendaylight.yang.gen.v1.org.openecomp.appc.rev170627.DbserviceInput; +import org.openecomp.appc.design.data.ArtifactInfo; +import org.openecomp.appc.design.data.DesignInfo; +import org.openecomp.appc.design.data.DesignRequest; +import org.openecomp.appc.design.data.DesignResponse; +import org.openecomp.appc.design.data.StatusInfo; +import org.openecomp.appc.design.dbervices.DbResponseProcessor; +import org.openecomp.appc.design.dbervices.DbService; +import org.openecomp.appc.design.services.impl.DesignServicesImpl; +import org.openecomp.sdnc.sli.resource.dblib.DbLibService; + +public class TestDesigndata { + + + + DesignResponse dr = new DesignResponse(); + + + + @Test + public void testSetUserID(){ + + dr.setUserId("00000"); + + String str = dr.getUserId(); + System.out.println(str); + } + + @Test + public void testSetDesignInfoList(){ + DesignInfo di = new DesignInfo(); + List li = new ArrayList(); + di.setAction("TestAction"); + di.setArtifact_name("TestName"); + di.setArtifact_type("TestType"); + di.setInCart("TestCart"); + di.setProtocol("TestProtocol"); + di.setVnf_type("TestVNF"); + di.setVnfc_type("TestVNFC"); + li.add(di); + dr.setDesignInfoList(li); + System.out.println(dr.getDesignInfoList()); + } + + @Test + public void testSetArtifactInfo(){ + ArtifactInfo ai = new ArtifactInfo(); + List li = new ArrayList(); + ai.setArtifact_content("TestContent"); + li.add(ai); + dr.setArtifactInfo(li); + System.out.println(dr.getArtifactInfo()); + + } + @Test + public void testStatusInfo(){ + StatusInfo si = new StatusInfo(); + List li = new ArrayList(); + si.setAction("TestAction"); + si.setAction_status("TestActionStatus"); + si.setArtifact_status("TestArtifactStatus"); + si.setVnf_type("TestVNF"); + si.setVnfc_type("TestVNFC"); + li.add(si); + dr.setStatusInfoList(li); + System.out.println(dr.getStatusInfoList()); + } + @Test + public void testDesignRequest(){ + DesignRequest dreq = new DesignRequest(); + dreq.setAction("TestAction"); + dreq.setArtifact_contents("TestContent"); + dreq.setArtifact_name("TestName"); + dreq.setProtocol("TestProtocol"); + dreq.setUserId("0000"); + dreq.setVnf_type("testvnf"); + dreq.setVnfc_type("testvnfc"); + System.out.println(dreq.getAction() + dreq.getArtifact_contents() + dreq.getArtifact_name() + dreq.getProtocol() + dreq.getUserId() + dreq.getVnf_type()+ dreq.getVnfc_type()); + System.out.println(dreq.toString()); + } + + +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java new file mode 100644 index 000000000..e3c5c17f4 --- /dev/null +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestEscapeUtils.java @@ -0,0 +1,19 @@ +package org.openecomp.appc.design.validator; + +import org.junit.Test; +import org.openecomp.appc.design.services.util.EscapeUtils; + +public class TestEscapeUtils { + + @Test + public void EscapeUtils(){ + + EscapeUtils escapeUtils = new EscapeUtils(); + + String str = escapeUtils.escapeSql("\\'Test Data\\'"); + + System.out.println(str); + + + } +} diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java index 1757c3c94..05aeb3008 100644 --- a/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java +++ b/appc-inbound/appc-design-services/provider/src/test/java/org/openecomp/appc/design/validator/TestValidatorService.java @@ -42,4 +42,140 @@ public class TestValidatorService { //Onap Migration + private final Logger logger = LoggerFactory.getLogger(TestValidatorService.class); +@Test + public void testvalidXMLValidation() throws Exception { + String response = null; + String xmlString = "" + + "create" + + "" + + "" + + "SDN-GP" + + "" + + "" + + "" + + ""; + + ValidatorService vs = new ValidatorService(); + try{ + response = vs.execute("", xmlString, "XML"); + } + catch(Exception e){ + System.out.println(e.getMessage()); + } + + Assert.assertEquals("success", response); + + } + @Test + public void testInvalidXMLValidation() throws Exception { + String response = null; + String xmlString = "" + + "create" + + "" + + "" + + "SDN-GP" + + "" + + "" + + ""; + + ValidatorService vs = new ValidatorService(); + try{ + response = vs.execute("", xmlString, "XML"); + } + catch(Exception e){ + System.out.println(e.getMessage()); + } + + Assert.assertEquals(null, response); + + } + @Test + public void testYAMLValidation() throws Exception { + String response = null; + String YAMLString = "en:"; + + + ValidatorService vs = new ValidatorService(); + try{ + response = vs.execute("", YAMLString, "YAML"); + } + catch(Exception e){ + System.out.println(e.getMessage()); + e.printStackTrace(); + } + + Assert.assertEquals("success", response); + + } + @Test + public void testInvalidYAMLValidation() throws Exception { + String response = null; + String YAMLString = "Test \n A:"; + + + ValidatorService vs = new ValidatorService(); + try{ + response = vs.execute("", YAMLString,"YAML"); + } + catch(Exception e){ + System.out.println(e.getMessage()); + } + + Assert.assertEquals(null, response); + + } + +@Test + public void testJSONValidation() throws Exception { + String response = null; + String YAMLString = "{\"Test\": \"Test1\" }"; + + + ValidatorService vs = new ValidatorService(); + try{ + response = vs.execute("", YAMLString, "JSON"); + } + catch(Exception e){ + System.out.println(e.getMessage()); + + } + Assert.assertEquals("success", response); + + } + @Test + public void testInvalidJSONValidation() throws Exception { + String response = null; + String YAMLString = "{\"Test\" \"Test1\" }"; + + + ValidatorService vs = new ValidatorService(); + try{ + response = vs.execute("", YAMLString, "JSON"); + } + catch(Exception e){ + System.out.println(e.getMessage()); + + } + Assert.assertEquals(null, response); + + } + + @Test + public void testainvalidvalidateVelocity() throws Exception { + String response = null; + String validateVelocity = "{\"Test\" \"Test1\" }"; + + + ValidatorService vs = new ValidatorService(); + try{ + response = vs.execute("", validateVelocity, "Velocity"); + } + catch(Exception e){ + System.out.println(e.getMessage()); + + } + Assert.assertEquals(null, response); + + } } -- cgit 1.2.3-korg