Test coverage for ParseAdminArtifact 09/78209/2
authorJoss Armstrong <joss.armstrong@ericsson.com>
Mon, 11 Feb 2019 12:59:49 +0000 (12:59 +0000)
committerTakamune Cho <takamune.cho@att.com>
Mon, 11 Feb 2019 14:21:10 +0000 (14:21 +0000)
Increased coverage from 65% to 85%

Issue-ID: APPC-1409
Change-Id: If39c07b3edbcaad6d618e54b27483323848410fe
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java
appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifactTest.java [new file with mode: 0644]

index e68a6f4..5118970 100644 (file)
@@ -3,6 +3,8 @@
  * ONAP : APPC
  * ================================================================================
  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,7 +27,6 @@ import java.io.IOException;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.function.Consumer;
 
 import org.apache.commons.lang.StringUtils;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
@@ -47,22 +48,22 @@ public class ParseAdminArtifcat implements SvcLogicJavaPlugin {
     private static String fqdn = null;
     private SvcLogicResource serviceLogic;
 
+    public ParseAdminArtifcat() {
+        serviceLogic = new SqlResource();
+    }
+
     public static ParseAdminArtifcat initialise() {
         parseArtifact = new ParseAdminArtifcat();
         return parseArtifact;
     }
 
-    public ParseAdminArtifcat() {
-        serviceLogic = new SqlResource();
-    }
-
     protected ParseAdminArtifcat(SqlResource svcLogic) {
         serviceLogic = svcLogic;
     }
 
     protected static Map<String, String> parseAdminArtifact(ArtifactMapper js) {
         List<FqdnList> fqdnList = js.getFqdnList();
-        Map<String, String> mp = new HashMap<String, String>();
+        Map<String, String> mp = new HashMap<>();
         for (FqdnList listFqdn : fqdnList) {
 
             for (CloudOwnerList clList : listFqdn.getCloudOwnerList()) {
@@ -143,10 +144,10 @@ public class ParseAdminArtifcat implements SvcLogicJavaPlugin {
         QueryStatus status = null;
         String fn = "ParseAdminArtifcat:getAdminArtifact";
         String jsonContent = null;
-        String artifcatName = "ansible_admin_FQDN_Artifact_0.0.1V.json";
+        String artifactName = "ansible_admin_FQDN_Artifact_0.0.1V.json";
         try {
             String query = "SELECT ARTIFACT_CONTENT as adminjson" + " FROM ASDC_ARTIFACTS " + "WHERE ARTIFACT_NAME = '"
-                    + artifcatName + "' " + "ORDER BY INTERNAL_VERSION DESC LIMIT 1 ";
+                    + artifactName + "' " + "ORDER BY INTERNAL_VERSION DESC LIMIT 1 ";
             log.info("Getting artifact details :" + query);
             status = serviceLogic.query("SQL", false, null, query, null, null, ctx);
             jsonContent = ctx.getAttribute("adminjson");
diff --git a/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifactTest.java b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifactTest.java
new file mode 100644 (file)
index 0000000..8f5a69f
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * Copyright (C) 2019 Ericsson
+ * ================================================================================
+ * 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.encryptiontool.fqdn;
+
+import static org.hamcrest.CoreMatchers.isA;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.ccsdk.sli.adaptors.resource.sql.SqlResource;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import org.powermock.reflect.Whitebox;
+
+public class ParseAdminArtifactTest {
+
+    @Rule
+    public ExpectedException expectedEx = ExpectedException.none();
+
+    @Test
+    public void test() throws SvcLogicException {
+        ParseAdminArtifcat artifact = ParseAdminArtifcat.initialise();
+        SqlResource sqlResource = Mockito.mock(SqlResource.class);
+        Mockito.when(sqlResource.query(Mockito.anyString(), Mockito.anyBoolean(), Mockito.anyString(), Mockito.anyString(),
+                Mockito.anyString(), Mockito.anyString(), Mockito.any(SvcLogicContext.class))).thenReturn(QueryStatus.FAILURE);
+        Whitebox.setInternalState(artifact, "serviceLogic", sqlResource);
+        SvcLogicContext ctx = new SvcLogicContext();
+        expectedEx.expect(RuntimeException.class);
+        expectedEx.expectCause(isA(SvcLogicException.class));
+        artifact.getAdminArtifact(ctx);
+    }
+
+}