aboutsummaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-artifact-handler
diff options
context:
space:
mode:
authorDilip kumar Pampana <dilip.kumar.pampana@ibm.com>2018-08-13 15:48:47 -0400
committerTakamune Cho <tc012c@att.com>2018-08-31 00:15:14 +0000
commit9197e727349f035c9f782f5e841c4b3e2f2ff1f5 (patch)
tree399a0b4e2b6b8577bd792d5050c2c59a1986a39d /appc-inbound/appc-artifact-handler
parent9cf887eb3204cfa86eb37914e4aea9d61a1648a1 (diff)
Junit for code coverage in artifact-handler
Junit Test cases for checking Exceptions part and also for isUpdate in DBService.java file Issue-ID: APPC-1140 Change-Id: Ibbfe9daf5465f4efcc8d42e8ed508d0b5e5129bb Signed-off-by: Dilip kumar Pampana <dilip.kumar.pampana@ibm.com>
Diffstat (limited to 'appc-inbound/appc-artifact-handler')
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java31
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java8
-rw-r--r--appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/TestDBServiceExceptions.java153
3 files changed, 186 insertions, 6 deletions
diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java
index ede019e7f..aac7cbe00 100644
--- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java
+++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/DBServiceTest.java
@@ -6,6 +6,8 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
+ * Modifications Copyright (C) 2018 IBM
+ * ================================================================================
* 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
@@ -23,13 +25,10 @@
package org.onap.appc.artifact.handler.dbservices;
-import java.nio.charset.Charset;
-import org.json.JSONObject;
import org.junit.Ignore;
import org.junit.Test;
import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
-import org.powermock.reflect.Whitebox;
import static org.junit.Assert.assertEquals;
public class DBServiceTest {
@@ -194,13 +193,27 @@ public class DBServiceTest {
dbService.processVnfcReference(ctx, isUpdate);
}
- //@Test
+ @Test
public void testProcessDeviceAuthentication() throws Exception {
MockDBService dbService = MockDBService.initialise();
SvcLogicContext ctx = new SvcLogicContext();
ctx.setAttribute("test", "test");
+ ctx.setAttribute("url", "");
+ String expectedKey ="update DEVICE_AUTHENTICATION set USER_NAME = '' , PORT_NUMBER = 0, URL = '' where VNF_TYPE = $vnf-type AND PROTOCOL = $device-protocol AND ACTION = $action";
boolean isUpdate = true;
dbService.processDeviceAuthentication(ctx, isUpdate);
+ assertEquals(expectedKey,ctx.getAttribute("keys"));
+ }
+
+ @Test
+ public void testProcessDeviceAuthenticationforFalse() throws Exception {
+ MockDBService dbService = MockDBService.initialise();
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("test", "test");
+ ctx.setAttribute("url", "");
+ boolean isUpdate = false;
+ dbService.processDeviceAuthentication(ctx, isUpdate);
+ assertEquals(true,ctx.getAttribute("keys").contains("DEVICE_AUTHENTICATION"));
}
//@Test
@@ -222,6 +235,16 @@ public class DBServiceTest {
}
@Test
+ public void testProcessDeviceInterfaceProtocolForFalse() throws Exception {
+ MockDBService dbService = MockDBService.initialise();
+ SvcLogicContext ctx = new SvcLogicContext();
+ ctx.setAttribute("test", "test");
+ boolean isUpdate = false;
+ dbService.processDeviceInterfaceProtocol(ctx, isUpdate);
+ assertEquals(true,ctx.getAttribute("keys").contains("DEVICE_INTERFACE_PROTOCOL"));
+ }
+
+ @Test
public void testProcessDeviceInterfaceProtocolException() throws Exception {
MockDBService dbService = MockDBService.initialise();
SvcLogicContext ctx = new SvcLogicContext();
diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java
index df5b329d1..6513e6ab1 100644
--- a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java
+++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/MockSvcLogicResource.java
@@ -6,6 +6,8 @@
* ================================================================================
* Copyright (C) 2017 Amdocs
* =============================================================================
+ * Modifications Copyright (C) 2018 IBM
+ * ================================================================================
* 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
@@ -25,6 +27,8 @@ package org.onap.appc.artifact.handler.dbservices;
import java.util.Map;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
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;
@@ -35,6 +39,7 @@ public class MockSvcLogicResource extends SqlResource {
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("keys",key);
ctx.setAttribute("id", "testId");
ctx.setAttribute("VNF_TYPE", "testvnf");
ctx.setAttribute("maximum", "1");
@@ -47,8 +52,7 @@ public class MockSvcLogicResource extends SqlResource {
@Override
public QueryStatus save(String resource, boolean force, boolean localOnly, String key, Map<String, String> parms,
String prefix, SvcLogicContext ctx) throws SvcLogicException {
+ ctx.setAttribute("keys", key);
return QueryStatus.SUCCESS;
}
-
-
}
diff --git a/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/TestDBServiceExceptions.java b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/TestDBServiceExceptions.java
new file mode 100644
index 000000000..3c4298559
--- /dev/null
+++ b/appc-inbound/appc-artifact-handler/provider/src/test/java/org/onap/appc/artifact/handler/dbservices/TestDBServiceExceptions.java
@@ -0,0 +1,153 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2018 IBM
+ * =============================================================================
+ * 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.onap.appc.artifact.handler.dbservices;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.onap.appc.artifact.handler.utils.SdcArtifactHandlerConstants;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.powermock.reflect.Whitebox;
+
+@RunWith(MockitoJUnitRunner.class)
+public class TestDBServiceExceptions {
+
+ private MockDBService dbService;
+
+ private MockSvcLogicResource mockSVCLogicResource;
+
+ private SvcLogicContext ctx ;
+
+ @Before
+ public void setup(){
+ dbService = MockDBService.initialise();
+ mockSVCLogicResource = Mockito.spy(MockSvcLogicResource.class);
+ ctx = new SvcLogicContext();
+ }
+
+ @Test
+ public void testSaveArtifacts() throws Exception {
+ String artifactName = "TestArtifact";
+ String prefix ="";
+ ctx.setAttribute("test", "test");
+ String result= dbService.getInternalVersionNumber(ctx, artifactName, prefix);
+ assertEquals("1",result);
+
+ }
+
+ @Test
+ public void testProcessSdcReferencesForCapability() throws Exception {
+ ctx.setAttribute("test", "test");
+ ctx.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, "capability");
+ boolean isUpdate = false;
+ String expectedKey = "insert into ASDC_REFERENCE set VNFC_TYPE = null , FILE_CATEGORY = $file-category , " +
+ "VNF_TYPE = $vnf-type , ACTION = null , ARTIFACT_TYPE = null , ARTIFACT_NAME = $artifact-name";
+ dbService.processSdcReferences(ctx, isUpdate);
+ assertEquals(expectedKey,ctx.getAttribute("keys"));
+ }
+
+ @Test
+ public void testProcessSdcReferences() throws Exception {
+ ctx.setAttribute("test", "test");
+ ctx.setAttribute(SdcArtifactHandlerConstants.FILE_CATEGORY, "Test");
+ String expectedKey = "insert into ASDC_REFERENCE set VNFC_TYPE = $vnfc-type , FILE_CATEGORY = $file-category , VNF_TYPE = $vnf-type , ACTION = $action , ARTIFACT_TYPE = $artifact-type , ARTIFACT_NAME = $artifact-name";
+ boolean isUpdate = false;
+ dbService.processSdcReferences(ctx, isUpdate);
+ assertEquals(expectedKey,ctx.getAttribute("keys"));
+ }
+
+ @Test(expected = Exception.class)
+ public void testGetDownLoadDGReference() throws Exception {
+ ctx.setAttribute("test", "test");
+ ctx.setAttribute(SdcArtifactHandlerConstants.DEVICE_PROTOCOL, "");
+ dbService.getDownLoadDGReference(ctx);
+ }
+
+ @Test
+ public void testProcessConfigActionDg() throws Exception {
+ ctx.setAttribute("test", "test");
+ boolean isUpdate = false;
+ ctx.setAttribute(SdcArtifactHandlerConstants.DOWNLOAD_DG_REFERENCE, "Reference");
+ String expectedKey = "insert into CONFIGURE_ACTION_DG set DOWNLOAD_CONFIG_DG = $download-dg-reference , ACTION = $action , VNF_TYPE = $vnf-type";
+ dbService.processConfigActionDg(ctx, isUpdate);
+ assertEquals(expectedKey,ctx.getAttribute("keys"));
+ }
+
+ @Test
+ public void testProcessConfigActionDgForElse() throws Exception {
+ ctx.setAttribute("test", "test");
+ boolean isUpdate = false;
+ String expectedKey = null;
+ dbService.processConfigActionDg(ctx, isUpdate);
+ assertEquals(expectedKey,ctx.getAttribute("keys"));
+ }
+
+ @Test
+ public void testprocessDpwnloadDGReference() throws Exception {
+ ctx.setAttribute("test", "test");
+ boolean isUpdate = false;
+ String expectedKey = "insert into DOWNLOAD_DG_REFERENCE set DOWNLOAD_CONFIG_DG = $download-dg-reference , PROTOCOL = $device-protocol";
+ dbService.processDownloadDgReference(ctx, isUpdate);
+ assertEquals(expectedKey,ctx.getAttribute("keys"));
+ }
+
+ @Test
+ public void testResolveWhereClause() throws Exception {
+ ctx.setAttribute("test", "test");
+ String db="DOWNLOAD_DG_REFERENCE";
+ String whereClause="";
+ String result = Whitebox.invokeMethod(dbService, "resolveWhereClause", ctx, db, whereClause);
+ assertEquals(true, result.contains("PROTOCOL"));
+ }
+
+ @Test
+ public void testResolveWhereClauseForDevice_Authentication() throws Exception {
+ ctx.setAttribute("test", "test");
+ String db="DEVICE_AUTHENTICATION";
+ String whereClause="Test";
+ String result = Whitebox.invokeMethod(dbService, "resolveWhereClause", ctx, db, whereClause);
+ assertEquals(true, result.contains("Test"));
+ }
+
+ @Test
+ public void testResolveWhereClauseCONFIGURE_ACTION_DG() throws Exception {
+ ctx.setAttribute("test", "test");
+ String db="CONFIGURE_ACTION_DG";
+ String whereClause="Test";
+ String result = Whitebox.invokeMethod(dbService, "resolveWhereClause", ctx, db, whereClause);
+ assertEquals(true, result.contains("Test"));
+ }
+
+ @Test
+ public void testResolveWhereClauseVNFC_REFERENCE() throws Exception {
+ ctx.setAttribute("test", "test");
+ String db="VNFC_REFERENCE";
+ String whereClause="TestVNFC_REFERENCE";
+ String result = Whitebox.invokeMethod(dbService, "resolveWhereClause", ctx, db, whereClause);
+ assertEquals(true, result.contains("TestVNFC_REFERENCE"));
+ }
+
+}