diff options
author | Ramya Balaji <rb111y@att.com> | 2017-09-11 15:50:25 -0400 |
---|---|---|
committer | Skip Wonnell <skip@att.com> | 2017-09-12 12:50:28 +0000 |
commit | c0eaebba5cd79c295b3e112e2f3632bc5559b237 (patch) | |
tree | fb434fad80b01504bff28d000fb00f1c72858ef6 /appc-inbound/appc-artifact-handler/provider/src/test | |
parent | 66384fab722a35403c8510f25b30f9b9c9ad9a0b (diff) |
Junit Cases for Artifact Handler.
Issue-ID : APPC-168
Change-Id: Id2b211d5656ffa8d5f326c30d745bc497e76f4d0
Signed-off-by: Ramya Balaji <rb111y@att.com>
Diffstat (limited to 'appc-inbound/appc-artifact-handler/provider/src/test')
8 files changed, 879 insertions, 8 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/DBServiceTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/DBServiceTest.java new file mode 100644 index 000000000..043283fb1 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/DBServiceTest.java @@ -0,0 +1,287 @@ +/*- + * ============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.artifact.handler.dbservices; + +import java.nio.charset.Charset; +import org.json.JSONObject; +import org.junit.Test; +import org.openecomp.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.powermock.reflect.Whitebox; + +public class DBServiceTest { + + @Test + public void testSaveArtifacts() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + int internalVersion = 1; + dbService.saveArtifacts(ctx, internalVersion); + } + + @Test(expected = Exception.class) + public void testSaveArtifactsException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + int internalVersion = 1; + dbService.saveArtifacts(ctx, internalVersion); + } + + @Test + public void testLogData() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String prefix = "test"; + dbService.logData(ctx, prefix); + } + + + @Test(expected = Exception.class) + public void testLogDataException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String prefix = "test"; + dbService.logData(ctx, prefix); + } + + @Test + public void testProcessConfigActionDg() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference"); + dbService.processConfigActionDg(ctx, isUpdate); + } + + @Test(expected = Exception.class) + public void testProcessConfigActionDgException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference"); + dbService.processConfigActionDg(ctx, isUpdate); + } + + @Test + public void testGetModelDataInformationbyArtifactName() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + dbService.getModelDataInformationbyArtifactName(artifactName); + } + + @Test(expected = Exception.class) + public void testGetModelDataInformationbyArtifactNameException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + dbService.getModelDataInformationbyArtifactName(artifactName); + } + + @Test + public void testUpdateYangContents() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + String artifactId = "TestArtifact"; + String yangContents = "TestYangContents"; + dbService.updateYangContents(ctx, artifactId, yangContents); + } + + @Test(expected = Exception.class) + public void testUpdateYangContentsException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String artifactName = "test"; + String artifactId = "TestArtifact"; + String yangContents = "TestYangContents"; + dbService.updateYangContents(ctx, artifactId, yangContents); + } + + @Test + public void testInsertProtocolReference() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String vnfType = "testVnf"; + String protocol = "testProtocol"; + String action = "testAction"; + String actionLevel = "testActionLevel"; + String template = "testTemplateData"; + dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template); + } + + + @Test(expected = Exception.class) + public void testInsertProtocolReferenceException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String vnfType = "testVnf"; + String protocol = "testProtocol"; + String action = "testAction"; + String actionLevel = "testActionLevel"; + String template = "testTemplateData"; + dbService.insertProtocolReference(ctx, vnfType, protocol, action, actionLevel, template); + } + + @Test + public void testprocessDpwnloadDGReference() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDownloadDgReference(ctx, isUpdate); + } + + @Test(expected = Exception.class) + public void testprocessDpwnloadDGReferenceException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDownloadDgReference(ctx, isUpdate); + } + + @Test + public void testProcessVnfcReference() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processVnfcReference(ctx, isUpdate); + } + + @Test(expected = Exception.class) + public void testProcessVnfcReferenceException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processVnfcReference(ctx, isUpdate); + } + + @Test + public void testProcessDeviceAuthentication() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceAuthentication(ctx, isUpdate); + } + + @Test(expected = Exception.class) + public void testProcessDeviceAuthenticationException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceAuthentication(ctx, isUpdate); + } + + @Test + public void testProcessDeviceInterfaceProtocol() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceInterfaceProtocol(ctx, isUpdate); + } + + @Test(expected = Exception.class) + public void testProcessDeviceInterfaceProtocolException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processDeviceInterfaceProtocol(ctx, isUpdate); + } + + @Test + public void testProcessSdcReferences() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processSdcReferences(ctx, isUpdate); + } + + @Test(expected = Exception.class) + public void testProcessSdcReferencesException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + boolean isUpdate = true; + dbService.processSdcReferences(ctx, isUpdate); + } + + @Test + public void testIsArtifactUpdateRequired() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.isArtifactUpdateRequired(ctx, db); + } + + @Test(expected = Exception.class) + public void testIsArtifactUpdateRequiredExcetion() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.isArtifactUpdateRequired(ctx, db); + } + + + @Test + public void testgetArtifactID() throws Exception { + MockDBService dbService = MockDBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.getArtifactID(ctx, db); + } + + @Test(expected = Exception.class) + public void testgetArtifactIDException() throws Exception { + DBService dbService = DBService.initialise(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + String db = "db"; + dbService.getArtifactID(ctx, db); + } +} + diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/TestArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockDBService.java index 96a44764b..ef1aae9e7 100644 --- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/TestArtifactHandlerNode.java +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockDBService.java @@ -22,15 +22,30 @@ * ============LICENSE_END========================================================= */ -package org.openecomp.appc.artifact.handler.node; +package org.openecomp.appc.artifact.handler.dbservices; -import java.io.InputStream; -import java.nio.charset.Charset; -import java.util.Enumeration; -import java.util.Properties; +public class MockDBService extends DBService { + private static MockDBService mockDgGeneralDBService = null; + private static MockSvcLogicResource serviceLogic = new MockSvcLogicResource();; -import org.apache.commons.io.IOUtils; -import org.json.JSONObject; + public MockDBService() { + super(serviceLogic); + if (mockDgGeneralDBService != null) { + mockDgGeneralDBService = new MockDBService(serviceLogic); + } + + } + + public MockDBService(MockSvcLogicResource serviceLogic2) { + super(serviceLogic); + } + + public static MockDBService initialise() { + if (mockDgGeneralDBService == null) { + mockDgGeneralDBService = new MockDBService(serviceLogic); + } + return mockDgGeneralDBService; + } -public class TestArtifactHandlerNode { } + diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockSvcLogicResource.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockSvcLogicResource.java new file mode 100644 index 000000000..ae09e459c --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/dbservices/MockSvcLogicResource.java @@ -0,0 +1,54 @@ +/*- + * ============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.artifact.handler.dbservices; + +import java.util.Map; + +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource; + +public class MockSvcLogicResource extends SqlResource { + + @Override + public QueryStatus query(String resource, boolean localOnly, String select, String key, String prefix, + String orderBy, SvcLogicContext ctx) throws SvcLogicException { + QueryStatus status = QueryStatus.SUCCESS; + ctx.setAttribute("id", "testId"); + ctx.setAttribute("VNF_TYPE", "testvnf"); + ctx.setAttribute("maximum", "1"); + ctx.setAttribute("COUNT(*)", "1"); + return status; + } + + + @Override + public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms, + String prefix, SvcLogicContext ctx) throws SvcLogicException { + return QueryStatus.SUCCESS; + } + + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNodeTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNodeTest.java new file mode 100644 index 000000000..895aabe24 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/ArtifactHandlerNodeTest.java @@ -0,0 +1,168 @@ +/*- + * ============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.artifact.handler.node; + +import java.io.InputStream; +import java.nio.charset.Charset; +import java.util.Enumeration; +import java.util.Properties; + +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.Test; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.powermock.reflect.Whitebox; +import static org.junit.Assert.assertTrue; +import org.openecomp.appc.artifact.handler.dbservices.DBService; +import org.openecomp.appc.artifact.handler.dbservices.MockDBService; +import org.openecomp.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.openecomp.appc.artifact.handler.utils.ArtifactHandlerProviderUtilTest; + +import java.util.Map; +import java.util.HashMap; + +public class ArtifactHandlerNodeTest { + + @Test + public void testProcessArtifact() throws Exception { + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("test", "test"); + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + Map<String, String> inParams = new HashMap<String, String>(); + JSONObject postData = new JSONObject(); + JSONObject input = new JSONObject(); + inParams.put("response_prefix", "prefix"); + JSONObject requestInfo = new JSONObject(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); + requestInfo.put("RequestInfo", "testValue"); + input.put(SdcArtifactHandlerConstants.DOCUMENT_PARAMETERS, documentInfo); + input.put(SdcArtifactHandlerConstants.REQUEST_INFORMATION, requestInfo); + postData.put("input", input); + inParams.put("postData", postData.toString()); + ah.processArtifact(inParams, ctx); + } + + @Test(expected = Exception.class) + public void testStoreReferenceData() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); + JSONObject requestInfo = new JSONObject(); + requestInfo.put("RequestInfo", "testStoreReferenceData"); + ah.storeReferenceData(requestInfo, documentInfo); + } + + @Test + public void testPopulateProtocolReference() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + String contentStr = + "{\"action\": \"TestAction\",\"action-level\": \"vnf\",\"scope\": {\"vnf-type\": \"vDBE-I\",\"vnfc-type\": null},\"template\": \"N\",\"device-protocol\": \"REST\"}"; + JSONObject content = new JSONObject(contentStr); + MockDBService dbService = MockDBService.initialise(); + Whitebox.invokeMethod(ah, "populateProtocolReference", dbService, content); + } + + @Test + public void testProcessAndStoreCapablitiesArtifact() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + JSONObject capabilities = new JSONObject(); + JSONObject documentInfo = new JSONObject(); + MockDBService dbService = MockDBService.initialise(); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_UUID, "testuid"); + documentInfo.put(SdcArtifactHandlerConstants.DISTRIBUTION_ID, "testDist"); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_NAME, "testName"); + documentInfo.put(SdcArtifactHandlerConstants.SERVICE_DESCRIPTION, "testDesc"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_UUID, "testRes"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_INSTANCE_NAME, "testResIns"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_VERSOIN, "testVers"); + documentInfo.put(SdcArtifactHandlerConstants.RESOURCE_TYPE, "testResType"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_UUID, "testArtifactUuid"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_VERSOIN, "testArtifactVers"); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_DESRIPTION, "testArtifactDesc"); + Whitebox.invokeMethod(ah, "processAndStoreCapablitiesArtifact", dbService, documentInfo, capabilities, + "artifactName", "someVnf"); + } + + @Test + public void testCleanVnfcInstance() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + SvcLogicContext ctx = new SvcLogicContext(); + Whitebox.invokeMethod(ah, "cleanVnfcInstance", ctx); + assertTrue(true); + } + + @Test(expected = Exception.class) + public void testGetArtifactIDException() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + String yFileName = "yFileName"; + Whitebox.invokeMethod(ah, "getArtifactID", yFileName); + } + + @Test(expected = Exception.class) + public void testStoreUpdateSdcArtifacts() throws Exception { + ArtifactHandlerNode ah = new ArtifactHandlerNode(); + String postDataStr = + "{\"request-information\":{},\"document-parameters\":{\"artifact-name\":\"testArtifact\",\"artifact-contents\":{\"content\":\"TestContent\"}}}"; + JSONObject postData = new JSONObject(postDataStr); + Whitebox.invokeMethod(ah, "storeUpdateSdcArtifacts", postData); + } + + @Test(expected = Exception.class) + public void testUpdateStoreArtifacts() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + JSONObject documentInfo = new JSONObject(); + String artifactContent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template"), Charset.defaultCharset()); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_CONTENTS, artifactContent); + documentInfo.put(SdcArtifactHandlerConstants.ARTIFACT_NAME, "reference_Junit.json"); + JSONObject requestInfo = new JSONObject(); + requestInfo.put("RequestInfo", "testupdateStoreArtifacts"); + ah.updateStoreArtifacts(requestInfo, documentInfo); + } + + @Test + public void testCleanArtifactInstanceData() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + SvcLogicContext ctx = new SvcLogicContext(); + Whitebox.invokeMethod(ah, "cleanArtifactInstanceData", ctx); + } + + @Test(expected = Exception.class) + public void testUpdateYangContents() throws Exception { + MockArtifactHandlerNode ah = new MockArtifactHandlerNode(); + String artifactId = "1"; + String yangContents = "SomeContent"; + Whitebox.invokeMethod(ah, "updateYangContents", artifactId, yangContents); + } + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/MockArtifactHandlerNode.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/MockArtifactHandlerNode.java new file mode 100644 index 000000000..437fa2678 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/node/MockArtifactHandlerNode.java @@ -0,0 +1,65 @@ +/*- + * ============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.artifact.handler.node; + +import org.json.JSONObject; +import org.openecomp.appc.artifact.handler.dbservices.MockDBService; +import org.openecomp.appc.artifact.handler.utils.SdcArtifactHandlerConstants; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; + +public class MockArtifactHandlerNode extends ArtifactHandlerNode { + + @Override + public boolean updateStoreArtifacts(JSONObject request_information, JSONObject document_information) + throws Exception { + if (request_information != null && request_information.get("RequestInfo").equals("testupdateStoreArtifacts")) { + super.updateStoreArtifacts(request_information, document_information); + } + SvcLogicContext context = new SvcLogicContext(); + MockDBService dbservice = MockDBService.initialise(); + int intversion = 0; + context.setAttribute("artifact_name", + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME)); + String internal_version = dbservice.getInternalVersionNumber(context, + document_information.getString(SdcArtifactHandlerConstants.ARTIFACT_NAME), null); + if (internal_version != null) { + intversion = Integer.parseInt(internal_version); + intversion++; + } + + return true; + + } + + @Override + public boolean storeReferenceData(JSONObject request_information, JSONObject document_information) + throws Exception { + if (request_information != null && request_information.get("RequestInfo").equals("testStoreReferenceData")) { + super.storeReferenceData(request_information, document_information); + } + return true; + } + +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java new file mode 100644 index 000000000..be7e3cfd2 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/openecomp/appc/artifact/handler/utils/ArtifactHandlerProviderUtilTest.java @@ -0,0 +1,82 @@ +/*- + * ============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.artifact.handler.utils; + +import static org.junit.Assert.assertTrue; +import java.nio.charset.Charset; +import org.apache.commons.io.IOUtils; +import org.json.JSONObject; +import org.junit.Test; +import org.powermock.reflect.Whitebox; + +public class ArtifactHandlerProviderUtilTest { + + @Test(expected = Exception.class) + public void testProcessTemplate() throws Exception { + String artifact_conetent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template.json"), Charset.defaultCharset()); + JSONObject obj = new JSONObject(); + obj.put("artifact-name", "reference_JunitTestArtifact"); + obj.put("artifact-version", "0.01"); + obj.put("artifact-contents", artifact_conetent); + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + ahprovider.processTemplate(obj.toString()); + } + + @Test(expected = Exception.class) + public void testcreateDummyRequestData() throws Exception { + String artifact_conetent = IOUtils.toString(ArtifactHandlerProviderUtilTest.class.getClassLoader() + .getResourceAsStream("templates/reference_template.json"), Charset.defaultCharset()); + JSONObject obj = new JSONObject(); + obj.put("artifact-name", "reference_JunitTestArtifact"); + obj.put("artifact-version", "0.01"); + obj.put("artifact-contents", artifact_conetent); + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + String requestInfo = ahprovider.createDummyRequestData(); + } + + @Test + public void testEscapeSql() throws Exception { + String testStr = "Test String is 'test'"; + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + ahprovider.escapeSql(testStr); + assertTrue(true); + } + + @Test + public void testGetRandom() throws Exception { + ArtifactHandlerProviderUtil ahprovider = new ArtifactHandlerProviderUtil(); + Whitebox.invokeMethod(ahprovider, "getRandom"); + assertTrue(true); + } + + @Test + public void testEscapeUtils() throws Exception { + String str = "The Test string is 'test'"; + EscapeUtils.escapeSql(str); + assertTrue(true); + } +} + diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/resources/templates/reference_template b/appc-inbound/appc-artifact-handler/provider/src/test/resources/templates/reference_template index e69de29bb..ef4772df8 100755 --- a/appc-inbound/appc-artifact-handler/provider/src/test/resources/templates/reference_template +++ b/appc-inbound/appc-artifact-handler/provider/src/test/resources/templates/reference_template @@ -0,0 +1,100 @@ +{ +"reference_data" : [ +{ +"action": "ConfigureTest", +"action-level":"VNF", +"scope": { +"vnf-type": "TestvUSP - vDBE-IPX HUB", +"vnfc-type": "TestDBE-VM #1" +}, +"template": "Y", +"vm": [ +{ +"vm-instance": 1, +"vnfc": [ +{ +"vnfc-instance": 1, +"vnfc-type": "TestDBE-VM #1", +"vnfc-function-code": "Testdbg", +"group-notation-type": "GNType", +"ipaddress-v4-oam-vip": "N", +"group-notation-value": "GNValue" +}, +{ +"vnfc-instance": 2, +"vnfc-type": "TestDBE-VM #1", +"vnfc-function-code": "Testdbg", +"group-notation-type": "GNType", +"ipaddress-v4-oam-vip": "Y", +"group-notation-value": "GNValue" +} +] +}, +{ +"vm-instance": 2, +"vnfc": [{ +"vnfc-instance": 1, +"vnfc-type": "TestDBE-VM #1", +"vnfc-function-code": "Testdbg", +"group-notation-type": "GNType", +"ipaddress-v4-oam-vip": "Y", +"group-notation-value": "GNValue" +} +] +} +], +"device-protocol": "TestNETCONF-XML", +"user-name": "Testnetconf", +"port-number": "22", +"download-dg-reference" : "TestDownloadDGReference", +"artifact-list": [ +{ +"artifact-name": "TestvDBE-I_template.json", +"artifact-type": "Testconfig_template" +}, +{ +"artifact-name": "TESTvDBE-I_parameter_definitions.json", +"artifact-type": "Testparameter_definitions" +}, +{ +"artifact-name": "PD_JunitTESTvDBE-I_parameter_yang.json", +"artifact-type": "PD_definations" +} +] +}, +{ + "action": "ConfigModify", + "action-level": "VNF", + "scope": { + "vnf-type": "vDBE-I", + "vnfc-type": null + }, + "template": "Y", + "device-protocol": "NETCONF-XML", + "user-name": "Testnetconf", + "port-number": "22", + "artifact-list": [ + { + "artifact-name": "template_ConfigModify_vDBE-I_0.0.1V.xml", + "artifact-type": "config_template" + }, + { + "artifact-name": "pd_ConfigModify_vDBE-I_0.0.1V.yaml", + "artifact-type": "parameter_definitions" + } + ] +}, + +{ + "action": "HealthCheck", + "action-level": "VM", + "scope": { + "vnf-type": "vDBE-I", + "vnfc-type": null + }, + "template": "N", + "device-protocol": "REST", + "vnfc-function-code": ["SSC","MMSC"] +} +] +} diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/resources/templates/reference_template.json b/appc-inbound/appc-artifact-handler/provider/src/test/resources/templates/reference_template.json new file mode 100755 index 000000000..ef4772df8 --- /dev/null +++ b/appc-inbound/appc-artifact-handler/provider/src/test/resources/templates/reference_template.json @@ -0,0 +1,100 @@ +{ +"reference_data" : [ +{ +"action": "ConfigureTest", +"action-level":"VNF", +"scope": { +"vnf-type": "TestvUSP - vDBE-IPX HUB", +"vnfc-type": "TestDBE-VM #1" +}, +"template": "Y", +"vm": [ +{ +"vm-instance": 1, +"vnfc": [ +{ +"vnfc-instance": 1, +"vnfc-type": "TestDBE-VM #1", +"vnfc-function-code": "Testdbg", +"group-notation-type": "GNType", +"ipaddress-v4-oam-vip": "N", +"group-notation-value": "GNValue" +}, +{ +"vnfc-instance": 2, +"vnfc-type": "TestDBE-VM #1", +"vnfc-function-code": "Testdbg", +"group-notation-type": "GNType", +"ipaddress-v4-oam-vip": "Y", +"group-notation-value": "GNValue" +} +] +}, +{ +"vm-instance": 2, +"vnfc": [{ +"vnfc-instance": 1, +"vnfc-type": "TestDBE-VM #1", +"vnfc-function-code": "Testdbg", +"group-notation-type": "GNType", +"ipaddress-v4-oam-vip": "Y", +"group-notation-value": "GNValue" +} +] +} +], +"device-protocol": "TestNETCONF-XML", +"user-name": "Testnetconf", +"port-number": "22", +"download-dg-reference" : "TestDownloadDGReference", +"artifact-list": [ +{ +"artifact-name": "TestvDBE-I_template.json", +"artifact-type": "Testconfig_template" +}, +{ +"artifact-name": "TESTvDBE-I_parameter_definitions.json", +"artifact-type": "Testparameter_definitions" +}, +{ +"artifact-name": "PD_JunitTESTvDBE-I_parameter_yang.json", +"artifact-type": "PD_definations" +} +] +}, +{ + "action": "ConfigModify", + "action-level": "VNF", + "scope": { + "vnf-type": "vDBE-I", + "vnfc-type": null + }, + "template": "Y", + "device-protocol": "NETCONF-XML", + "user-name": "Testnetconf", + "port-number": "22", + "artifact-list": [ + { + "artifact-name": "template_ConfigModify_vDBE-I_0.0.1V.xml", + "artifact-type": "config_template" + }, + { + "artifact-name": "pd_ConfigModify_vDBE-I_0.0.1V.yaml", + "artifact-type": "parameter_definitions" + } + ] +}, + +{ + "action": "HealthCheck", + "action-level": "VM", + "scope": { + "vnf-type": "vDBE-I", + "vnfc-type": null + }, + "template": "N", + "device-protocol": "REST", + "vnfc-function-code": ["SSC","MMSC"] +} +] +} |