diff options
Diffstat (limited to 'appc-config')
2 files changed, 62 insertions, 8 deletions
diff --git a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java index e68a6f444..5118970eb 100644 --- a/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java +++ b/appc-config/appc-encryption-tool/provider/src/main/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifcat.java @@ -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 index 000000000..8f5a69fac --- /dev/null +++ b/appc-config/appc-encryption-tool/provider/src/test/java/org/onap/appc/encryptiontool/fqdn/ParseAdminArtifactTest.java @@ -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); + } + +} |