summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java6
-rw-r--r--appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java23
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java456
-rw-r--r--appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java93
4 files changed, 508 insertions, 70 deletions
diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java
index a17c257c3..ff2d8cdd0 100644
--- a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java
+++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/AppcDataServiceConstant.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * 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.
@@ -36,13 +38,13 @@ public class AppcDataServiceConstant {
public static final String INPUT_PARAM_SDC_ARTIFACT_IND = "asdcArtifactInd";
public static final String INPUT_PARAM_VNF_ID = "vnfId";
public static final String INPUT_PARAM_VM_NAME = "vmName";
-
public static final String INPUT_PARAM_FILE_ID = "fileId";
-
public static final String INPUT_PARAM_UPLOAD_CONFIG_ID= "uploadConfigId";
public static final String CAPABILITY_VM_LEVEL="vm";
public static final String KEY_VSERVER_ID = "vserver-id";
public static final String KEY_VNFC_FUNCTION_CODE = "vnfc-function-code";
+ public static final String TEMPLATE_NAME = "template-name";
+ public static final String TEMPLATE_MODEL_ID = "template-model-id";
public enum ACTIONS
{
diff --git a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
index 13d7d2874..219bb0a2e 100644
--- a/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
+++ b/appc-config/appc-data-services/provider/src/main/java/org/onap/appc/data/services/node/ConfigResourceNode.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * 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.
@@ -188,8 +190,8 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
String fileCategory = inParams.get(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY);
- String templateName = ctx.getAttribute("template-name");
- String templateModelId = ctx.getAttribute("template-model-id");
+ String templateName = ctx.getAttribute(AppcDataServiceConstant.TEMPLATE_NAME);
+ String templateModelId = ctx.getAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID);
QueryStatus status;
String responsePrefix1 = "";
@@ -201,7 +203,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
if (StringUtils.isBlank(templateName)) {
if (StringUtils.isNotBlank(templateModelId)) {
- status = db.getTemplateWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId);
+ status = db.getTemplateWithTemplateModelId(ctx, responsePrefix, fileCategory, templateModelId);
if (status == QueryStatus.FAILURE) {
throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
}
@@ -219,7 +221,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
if (status == QueryStatus.NOT_FOUND) {
if (StringUtils.isNotBlank(templateModelId)) {
- status = db.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, fileCategory,templateModelId);
+ status = db.getTemplateByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, fileCategory, templateModelId);
if (status == QueryStatus.FAILURE) {
throw new QueryException(UNABLE_TO_READ_STR + fileCategory);
}
@@ -553,7 +555,7 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
saveConfigFiles(inParams, ctx);
}
- private void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ protected void saveConfigurationData(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
ctx.setAttribute(DATA_SOURCE, ctx.getAttribute("originator-id"));
ctx.setAttribute(FILE_CONTENT, ctx.getAttribute(CONFIG_PARAMS));
ctx.setAttribute(FILE_CATEGORY_PARAM, "config_data");
@@ -571,7 +573,6 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
String vmName = inParams.get(AppcDataServiceConstant.INPUT_PARAM_VM_NAME);
try {
QueryStatus status = db.getConfigFilesByVnfVmNCategory(ctx, responsePrefix, fileCategory, vnfId, vmName);
-
if (status == QueryStatus.NOT_FOUND || status == QueryStatus.FAILURE) {
throw new QueryException("Unable to get " + ctx.getAttribute("fileCategory") + " from configfiles");
}
@@ -658,25 +659,23 @@ public class ConfigResourceNode implements SvcLogicJavaPlugin {
log.info("Received getVnfcReference call with params : " + inParams);
String responsePrefix = inParams.get(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX);
- String templateModelId = ctx.getAttribute("template-model-id");
- log.info("getVnfcReference():::"+templateModelId);
+ String templateModelId = ctx.getAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID);
+ log.info("getVnfcReference():::" + templateModelId);
QueryStatus status = null;
try {
if (!StringUtils.isBlank(ctx.getAttribute("vnfc-type"))) {
-
status = db.getVnfcReferenceByVnfcTypeNAction(ctx, responsePrefix);
-
if (status == QueryStatus.FAILURE) {
throw new QueryException("Unable to Read vnfc-reference");
}
}
if (StringUtils.isNotBlank(templateModelId)) {
- status = db.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix,templateModelId);
+ status = db.getVnfcReferenceByVnfTypeNActionWithTemplateModelId(ctx, responsePrefix, templateModelId);
if (status == QueryStatus.FAILURE) {
- throw new QueryException("Unable to Read vnfc-reference with template-model-id");
+ throw new QueryException("Unable to Read vnfc-reference with " + AppcDataServiceConstant.TEMPLATE_MODEL_ID);
}
}
if (StringUtils.isBlank(templateModelId) || (StringUtils.isNotBlank(templateModelId) && (status == QueryStatus.NOT_FOUND))) {
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java
index 5ecdbc49c..056adb726 100644
--- a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java
+++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/ConfigResourceNodeTest.java
@@ -5,6 +5,8 @@
* Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
* ================================================================================
* Modifications Copyright (C) 2018-2019 IBM.
+ * ================================================================================
+ * 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 @@ package org.onap.appc.data.services.node;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
import static org.mockito.Matchers.anyString;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
@@ -57,23 +58,29 @@ import static org.onap.appc.data.services.node.ConfigResourceNode.UNABLE_TO_SAVE
import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_ID_PARAM;
import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_INFO_PREFIX;
import static org.onap.appc.data.services.node.ConfigResourceNode.UPLOAD_CONFIG_PREFIX;
-import com.fasterxml.jackson.databind.JsonNode;
-import com.fasterxml.jackson.databind.ObjectMapper;
-import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import java.util.HashMap;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
import org.onap.appc.data.services.AppcDataServiceConstant;
import org.onap.appc.data.services.db.DGGeneralDBService;
import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
import org.onap.ccsdk.sli.core.sli.SvcLogicException;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource;
import org.onap.ccsdk.sli.core.sli.SvcLogicResource.QueryStatus;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
public class ConfigResourceNodeTest {
+ private static final String TEST_MESSAGE = "TEST_MESSAGE";
+ private static final String SOME_FILE_CATEGORY = "some file category";
+ private static final String SOME_FILE_ID = "some file id";
+ private static final String SOME_PREFIX = "some prefix";
+ private static final String TEST = "test";
private HashMap<String, String> inParams;
private SvcLogicContext contextMock;
@@ -110,6 +117,40 @@ public class ConfigResourceNodeTest {
}
@Test
+ public void shouldProcessCapabilitiesForVMLevelNoSubCapabilities() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
+ String findCapability = "Restart";
+ JsonNodeFactory.instance.objectNode();
+ String subCaps = "{}";
+ ObjectMapper m = new ObjectMapper();
+ JsonNode subCapabilities = m.readTree(subCaps);
+ String vServerId = "testServer";
+ ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "MMC");
+ ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
+ node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
+ assertEquals("None", ctx.getAttribute(ConfigResourceNode.CAPABILITIES));
+ }
+
+ @Test
+ public void shouldProcessCapabilitiesForVMLevelBlankVnfcFunctionCode() throws Exception {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
+ String findCapability = "Restart";
+ JsonNodeFactory.instance.objectNode();
+ String subCaps =
+ "[{\"Restart\":[\"SSC\",\"MMC\"]},{\"Rebuild\":[\"SSC\"]},{\"Migrate\":[\"SSC\"]},"
+ + "{\"Snapshot\":[\"SSC\"]},{\"Start\":[\"SSC\"]},{\"Stop\":[\"SSC\"]}]";
+ ObjectMapper m = new ObjectMapper();
+ JsonNode subCapabilities = m.readTree(subCaps);
+ String vServerId = "testServer";
+ ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-function-code", "");
+ ctx.setAttribute("tmp.vnfInfo.vm.vnfc.vnfc-name", "testVnfc");
+ node.processCapabilitiesForVMLevel(vServerId, ctx, findCapability, subCapabilities);
+ assertEquals(ConfigResourceNode.NOT_SUPPORTED, ctx.getAttribute(ConfigResourceNode.CAPABILITIES));
+ }
+
+ @Test
public void shouldCheckIfCapabilityCheckNeeded() {
ConfigResourceNode node = new ConfigResourceNode(DGGeneralDBService.initialise());
String findCapability = "Start";
@@ -146,7 +187,7 @@ public class ConfigResourceNodeTest {
configResourceNode.getTemplate(inParams, contextMock);
verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
-
+
@Test
public void testGetVnfcReference() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
@@ -156,7 +197,54 @@ public class ConfigResourceNodeTest {
configResourceNode.getVnfcReference(inParams, contextMock);
verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
-
+
+ @Test
+ public void testGetVnfcReferenceWithVnfcType() throws Exception {
+ SvcLogicContext context = new SvcLogicContext();
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getVnfcReferenceByVnfcTypeNAction(TEST, SvcLogicResource.QueryStatus.FAILURE).build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ context.setAttribute("vnfc-type", "testVnfcType");
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read vnfc-reference");
+ configResourceNode.getVnfcReference(inParams, context);
+ }
+
+ @Test
+ public void testGetVnfcReferenceWithVnfcTypeAndTemplateModelId() throws Exception {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID, TEST);
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getVnfcReferenceByVnfcTypeNAction(TEST, SvcLogicResource.QueryStatus.SUCCESS)
+ .getVnfcReferenceByVnfTypeNActionWithTemplateModelId(TEST, TEST,
+ SvcLogicResource.QueryStatus.FAILURE).build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ context.setAttribute("vnfc-type", "testVnfcType");
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read vnfc-reference with "
+ + AppcDataServiceConstant.TEMPLATE_MODEL_ID);
+ configResourceNode.getVnfcReference(inParams, context);
+ }
+
+ @Test
+ public void testGetVnfcReferenceWithVnfcTypeAndTemplateModelIdNotFound() throws Exception {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID, TEST);
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
+ .getVnfcReferenceByVnfcTypeNAction(TEST, SvcLogicResource.QueryStatus.SUCCESS)
+ .getVnfcReferenceByVnfTypeNActionWithTemplateModelId(TEST, TEST,
+ SvcLogicResource.QueryStatus.NOT_FOUND).getVnfcReferenceByVnfTypeNAction(TEST,
+ SvcLogicResource.QueryStatus.FAILURE).build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ context.setAttribute("vnfc-type", "testVnfcType");
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to Read vnfc reference");
+ configResourceNode.getVnfcReference(inParams, context);
+ }
+
@Test
public void testGetCapability() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
@@ -169,7 +257,82 @@ public class ConfigResourceNodeTest {
configResourceNode.getCapability(inParams, contextMock);
verify(contextMock).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
-
+
+ @Test
+ public void testGetCapabilityNoCheckRequired() throws Exception {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put("caplevel", "start");
+ inParams.put("checkCapability", "start");
+ configResourceNode.getCapability(inParams, context);
+ assertEquals(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS,
+ context.getAttribute(AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
+ }
+
+ @Test
+ public void testGetCapabilityWithVnfType() throws Exception {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getCapability(TEST,
+ "{\"capabilities\": {\"vm\":\"test\"}}").build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put("vnf-type", TEST);
+ inParams.put("caplevel", "vm");
+ configResourceNode.getCapability(inParams, context);
+ assertEquals(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS,
+ context.getAttribute(AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
+ }
+
+ @Test
+ public void testGetCapabilityWithVnfTypeAndSubCapabilities() throws Exception {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getCapability(TEST,
+ "{\"capabilities\": {\"vm\": {\"start\":\"test\"}}}").build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put("vnf-type", TEST);
+ inParams.put("caplevel", "vm");
+ inParams.put("checkCapability", "start");
+ configResourceNode.getCapability(inParams, context);
+ assertEquals(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS,
+ context.getAttribute(AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
+ }
+
+ @Test
+ public void testGetCapabilityNotSupported() throws Exception {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getCapability(TEST,
+ "{\"capabilities\": {\"vm\": {\"stop\":\"test\"}}}").build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put("vnf-type", TEST);
+ inParams.put("caplevel", "vm");
+ inParams.put("checkCapability", "start");
+ configResourceNode.getCapability(inParams, context);
+ assertEquals(ConfigResourceNode.NOT_SUPPORTED, context.getAttribute(ConfigResourceNode.CAPABILITIES));
+ }
+
+ @Test
+ public void testGetCapabilityNoFindCapability() throws Exception {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getCapability(TEST,
+ "{\"capabilities\": {\"vm\": {\"stop\":\"test\"}}}").build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put("vnf-type", TEST);
+ inParams.put("caplevel", "vm");
+ configResourceNode.getCapability(inParams, context);
+ assertEquals("{\"stop\":\"test\"}", context.getAttribute("capabilities.vm"));
+ }
+
+ @Test
+ public void testGetCapabilityException() throws Exception {
+ DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().getCapability(TEST, "\\\\").build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put("vnf-type", TEST);
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unexpected character");
+ configResourceNode.getCapability(inParams, context);
+ }
+
@Test
public void testGetConfigFilesByVnfVmNCategory() throws Exception {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
@@ -183,6 +346,23 @@ public class ConfigResourceNodeTest {
}
@Test
+ public void testGetConfigFilesByVnfVmNCategoryException() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_ID);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_VNF_ID, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_VM_NAME, TEST);
+ context.setAttribute("fileCategory", TEST);
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().getConfigFilesByVnfVmNCategory(TEST, SOME_FILE_ID, TEST,
+ TEST, SvcLogicResource.QueryStatus.NOT_FOUND).build();
+ ConfigResourceNode configResourceNode = Mockito.spy(new ConfigResourceNode(dbServiceMock));
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to get test from configfiles");
+ configResourceNode.getConfigFilesByVnfVmNCategory(inParams, context);
+ }
+
+ @Test
public void should_add_attribute_with_success_if_save_config_files_succeed() throws SvcLogicException {
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder().build();
@@ -406,11 +586,11 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_db_template_failure() throws SvcLogicException {
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, SOME_PREFIX);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_CATEGORY);
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE).build();
+ .getTemplate(SOME_PREFIX, SOME_FILE_CATEGORY, SvcLogicResource.QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -421,12 +601,12 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_db_template_by_action_failure() throws SvcLogicException {
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, SOME_PREFIX);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_CATEGORY);
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
- .getTemplateByVnfTypeNAction("some prefix", "some file category", SvcLogicResource.QueryStatus.FAILURE)
+ .getTemplate(SOME_PREFIX, SOME_FILE_CATEGORY, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getTemplateByVnfTypeNAction(SOME_PREFIX, SOME_FILE_CATEGORY, SvcLogicResource.QueryStatus.FAILURE)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -438,12 +618,12 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_db_template_by_action_missing() throws SvcLogicException {
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, SOME_PREFIX);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_CATEGORY);
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .getTemplate("some prefix", "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
- .getTemplateByVnfTypeNAction("some prefix", "some file category",
+ .getTemplate(SOME_PREFIX, SOME_FILE_CATEGORY, SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getTemplateByVnfTypeNAction(SOME_PREFIX, SOME_FILE_CATEGORY,
SvcLogicResource.QueryStatus.NOT_FOUND)
.build();
@@ -456,14 +636,14 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_db_template_by_name_missing() throws SvcLogicException {
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, SOME_PREFIX);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_CATEGORY);
SvcLogicContext context = new SvcLogicContext();
- context.setAttribute("template-name", "test template");
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_NAME, "test template");
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getTemplateByTemplateName(SOME_PREFIX, "test template", SvcLogicResource.QueryStatus.NOT_FOUND)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -475,14 +655,14 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_db_template_by_name_failure() throws SvcLogicException {
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, "some file category");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, SOME_PREFIX);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_CATEGORY);
SvcLogicContext context = new SvcLogicContext();
- context.setAttribute("template-name", "test template");
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_NAME, "test template");
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .getTemplateByTemplateName("some prefix", "test template", SvcLogicResource.QueryStatus.FAILURE)
+ .getTemplateByTemplateName(SOME_PREFIX, "test template", SvcLogicResource.QueryStatus.FAILURE)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -495,7 +675,7 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_save_config_failure() throws SvcLogicException {
SvcLogicContext context = new SvcLogicContext();
- context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
+ context.setAttribute(FILE_CATEGORY_PARAM, SOME_FILE_CATEGORY);
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
.saveConfigFiles(CONFIG_FILES_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
@@ -510,10 +690,10 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_get_max_config_id_missing() throws SvcLogicException {
SvcLogicContext context = new SvcLogicContext();
- context.setAttribute(FILE_CATEGORY_PARAM, "some file category");
+ context.setAttribute(FILE_CATEGORY_PARAM, SOME_FILE_CATEGORY);
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, "some file category", SvcLogicResource.QueryStatus.NOT_FOUND)
+ .getMaxConfigFileId(MAX_CONF_FILE_PREFIX, SOME_FILE_CATEGORY, SvcLogicResource.QueryStatus.NOT_FOUND)
.build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -527,10 +707,10 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_save_config_files_failure() throws SvcLogicException {
SvcLogicContext context = new SvcLogicContext();
- context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
+ context.setAttribute(CONFIG_FILE_ID_PARAM, SOME_FILE_ID);
DGGeneralDBService dbServiceMock =
- new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID, SDC_IND,
SvcLogicResource.QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -592,10 +772,10 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_get_download_config_failure() throws SvcLogicException {
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "some prefix");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, SOME_PREFIX);
DGGeneralDBService dbServiceMock = new MockDbServiceBuilder()
- .getDownloadConfigTemplateByVnf("some prefix", SvcLogicResource.QueryStatus.FAILURE).build();
+ .getDownloadConfigTemplateByVnf(SOME_PREFIX, SvcLogicResource.QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -650,10 +830,10 @@ public class ConfigResourceNodeTest {
@Test
public void should_throw_exception_on_save_prepare_relationship_failure() throws SvcLogicException {
inParams.put(AppcDataServiceConstant.INPUT_PARAM_SDC_ARTIFACT_IND, "some sdnc index");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_ID, "some file id");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_ID, SOME_FILE_ID);
DGGeneralDBService dbServiceMock =
- new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID,
"some sdnc index", QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -671,7 +851,7 @@ public class ConfigResourceNodeTest {
when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("");
DGGeneralDBService dbServiceMock =
- new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID,
"some sdnc index", QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
@@ -690,7 +870,7 @@ public class ConfigResourceNodeTest {
when(contextMock.getAttribute(CONFIG_PARAMS)).thenReturn("non empty");
DGGeneralDBService dbServiceMock =
- new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id",
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID,
"some sdnc index", QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = spy(new ConfigResourceNode(dbServiceMock));
@@ -701,15 +881,15 @@ public class ConfigResourceNodeTest {
verify(configResourceNode).saveConfigBlock(inParams, contextMock);
verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
-
+
@Test
public void testSaveTemplateConfig() throws SvcLogicException
{
SvcLogicContext context = new SvcLogicContext();
- context.setAttribute(CONFIG_FILE_ID_PARAM, "some file id");
+ context.setAttribute(CONFIG_FILE_ID_PARAM, SOME_FILE_ID);
DGGeneralDBService dbServiceMock =
- new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID, SDC_IND,
SvcLogicResource.QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -717,17 +897,51 @@ public class ConfigResourceNodeTest {
verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
-
+
+ @Test
+ public void testSaveTemplateConfigWithConfigParams() throws SvcLogicException
+ {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(CONFIG_FILE_ID_PARAM, SOME_FILE_ID);
+ context.setAttribute(CONFIG_PARAMS, TEST);
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID, SDC_IND,
+ SvcLogicResource.QueryStatus.FAILURE).build();
+ ConfigResourceNode configResourceNode = Mockito.spy(new ConfigResourceNode(dbServiceMock));
+ Mockito.doNothing().when(configResourceNode).saveConfigurationData(Mockito.anyMap(), Mockito.any(SvcLogicContext.class));
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage(ConfigResourceNode.UNABLE_TO_SAVE_RELATIONSHIP_STR);
+ configResourceNode.saveTemplateConfig(inParams, context);
+ }
+
+ @Test
+ public void testSaveTemplateConfigWithConfigParamsAndQueryStatusFailure() throws SvcLogicException
+ {
+ SvcLogicContext context = new SvcLogicContext();
+ context.setAttribute(CONFIG_FILE_ID_PARAM, SOME_FILE_ID);
+ context.setAttribute(CONFIG_PARAMS, TEST);
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, null, "Y",
+ SvcLogicResource.QueryStatus.FAILURE).build();
+ ConfigResourceNode configResourceNode = Mockito.spy(new ConfigResourceNode(dbServiceMock));
+ Mockito.doNothing().when(configResourceNode).saveConfigurationData(Mockito.anyMap(), Mockito.any(SvcLogicContext.class));
+ Mockito.doNothing().when(configResourceNode).saveDeviceConfiguration(Mockito.anyMap(), Mockito.any(SvcLogicContext.class),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage(ConfigResourceNode.UNABLE_TO_SAVE_RELATIONSHIP_STR);
+ configResourceNode.saveTemplateConfig(inParams, context);
+ }
+
@Test
public void testSaveStyleSheetConfig() throws SvcLogicException
{
SvcLogicContext context = new SvcLogicContext();
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
- context.setAttribute("tmp.merge.mergedData", "test");
- context.setAttribute("tmp.convertconfig.escapeData", "test");
- context.setAttribute("tmp.merge.mergedData", "test");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ context.setAttribute("tmp.merge.mergedData", TEST);
+ context.setAttribute("tmp.convertconfig.escapeData", TEST);
+ context.setAttribute("tmp.merge.mergedData", TEST);
DGGeneralDBService dbServiceMock =
- new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID, SDC_IND,
SvcLogicResource.QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
@@ -735,24 +949,154 @@ public class ConfigResourceNodeTest {
verify(contextMock, atLeastOnce()).setAttribute(anyString(), eq(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS));
}
-
+
+ @Test
+ public void testSaveStyleSheetConfigException() throws SvcLogicException
+ {
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ context.setAttribute("tmp.merge.mergedData", TEST);
+ context.setAttribute("tmp.convertconfig.escapeData", TEST);
+ context.setAttribute("tmp.merge.mergedData", TEST);
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID, SDC_IND,
+ SvcLogicResource.QueryStatus.FAILURE).build();
+
+ ConfigResourceNode configResourceNode = Mockito.spy(new ConfigResourceNode(dbServiceMock));
+ Mockito.doThrow(new SvcLogicException(TEST_MESSAGE)).when(configResourceNode).saveDeviceConfiguration(Mockito.anyMap(), Mockito.any(SvcLogicContext.class),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage(TEST_MESSAGE);
+ configResourceNode.saveStyleSheetConfig(inParams, contextMock);
+ }
+
@Test
public void testSaveConfigTransactionLog() throws SvcLogicException
{
SvcLogicContext context = new SvcLogicContext();
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, "test");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, "test");
- inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, "test");
-
- context.setAttribute("request-id", "test");
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, TEST);
+
+ context.setAttribute("request-id", TEST);
DGGeneralDBService dbServiceMock =
- new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, "some file id", SDC_IND,
+ new MockDbServiceBuilder().savePrepareRelationship(PREPARE_RELATIONSHIP_PARAM, SOME_FILE_ID, SDC_IND,
SvcLogicResource.QueryStatus.FAILURE).build();
ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
configResourceNode.saveConfigTransactionLog(inParams, contextMock);
- assertEquals(null,contextMock.getAttribute("log-message"));
+ assertEquals(null, contextMock.getAttribute("log-message"));
+ }
+
+ @Test
+ public void testSaveConfigTransactionLogException() throws SvcLogicException
+ {
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, TEST);
+
+ context.setAttribute("request-id", TEST);
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().saveConfigTransactionLog("test.", SvcLogicResource.QueryStatus.FAILURE)
+ .build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage("Unable to insert into config_transaction_log");
+ configResourceNode.saveConfigTransactionLog(inParams, contextMock);
+ }
+
+ @Test
+ public void testGetTemplateByTemplateModelIdFailedQuery() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_ID);
+
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_NAME, "");
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID, TEST);
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().getTemplateByTemplateModelId(TEST, SOME_FILE_ID, TEST,
+ SvcLogicResource.QueryStatus.FAILURE).build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage(ConfigResourceNode.UNABLE_TO_READ_STR);
+ configResourceNode.getTemplate(inParams, context);
+ }
+
+ @Test
+ public void testGetTemplateByTemplateModelIdSuccessQuery() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_ID);
+
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_NAME, "");
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID, TEST);
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().getTemplateByTemplateModelId(TEST, SOME_FILE_ID, TEST,
+ SvcLogicResource.QueryStatus.SUCCESS).build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.getTemplate(inParams, context);
+ assertEquals(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS, context.getAttribute("test."
+ + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
+ }
+
+ @Test
+ public void testGetTemplateByTemplateModelIdNotFoundQuery() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_ID);
+
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_NAME, "");
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID, TEST);
+
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().getTemplateByTemplateModelId(TEST, SOME_FILE_ID, TEST,
+ SvcLogicResource.QueryStatus.NOT_FOUND).getTemplate(TEST, SOME_FILE_ID,
+ SvcLogicResource.QueryStatus.NOT_FOUND).build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ configResourceNode.getTemplate(inParams, context);
+ assertEquals(AppcDataServiceConstant.OUTPUT_STATUS_SUCCESS, context.getAttribute("test."
+ + AppcDataServiceConstant.OUTPUT_PARAM_STATUS));
+ }
+
+ @Test
+ public void testGetTemplateByTemplateModelIdNotFoundByVnfTypeNAction() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_RESPONSE_PREFIX, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE_TYPE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_MESSAGE, TEST);
+ inParams.put(AppcDataServiceConstant.INPUT_PARAM_FILE_CATEGORY, SOME_FILE_ID);
+
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_NAME, "");
+ context.setAttribute(AppcDataServiceConstant.TEMPLATE_MODEL_ID, TEST);
+
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().getTemplateByTemplateModelId(TEST, SOME_FILE_ID, TEST,
+ SvcLogicResource.QueryStatus.NOT_FOUND).getTemplate(TEST, SOME_FILE_ID,
+ SvcLogicResource.QueryStatus.NOT_FOUND).getTemplateByVnfTypeNActionWithTemplateModelId
+ (TEST, SOME_FILE_ID, TEST, SvcLogicResource.QueryStatus.FAILURE).build();
+ ConfigResourceNode configResourceNode = new ConfigResourceNode(dbServiceMock);
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage(ConfigResourceNode.UNABLE_TO_READ_STR);
+ configResourceNode.getTemplate(inParams, context);
+ }
+
+ @Test
+ public void testSaveConfigBlock() throws SvcLogicException {
+ SvcLogicContext context = new SvcLogicContext();
+ DGGeneralDBService dbServiceMock =
+ new MockDbServiceBuilder().build();
+ ConfigResourceNode configResourceNode = Mockito.spy(new ConfigResourceNode(dbServiceMock));
+ Mockito.doThrow(new SvcLogicException(TEST_MESSAGE)).when(configResourceNode).saveDeviceConfiguration(Mockito.anyMap(), Mockito.any(SvcLogicContext.class),
+ Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+ expectedException.expect(SvcLogicException.class);
+ expectedException.expectMessage(TEST_MESSAGE);
+ configResourceNode.saveConfigBlock(inParams, context);
}
-
-
}
diff --git a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java
index 2da8d5316..f37d5bdda 100644
--- a/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java
+++ b/appc-config/appc-data-services/provider/src/test/java/org/onap/appc/data/services/node/MockDbServiceBuilder.java
@@ -1,3 +1,24 @@
+/*
+ * ============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.data.services.node;
import static org.mockito.Matchers.any;
@@ -65,6 +86,15 @@ class MockDbServiceBuilder {
return this;
}
+ public MockDbServiceBuilder getTemplateByVnfTypeNActionWithTemplateModelId(String prefix, String fileCategory, String templateModelId,
+ SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getTemplateByVnfTypeNActionWithTemplateModelId(any(SvcLogicContext.class), eq(prefix), eq(fileCategory), eq(templateModelId));
+
+ return this;
+ }
+
public MockDbServiceBuilder getTemplateByTemplateName(String prefix, String fileCategory, SvcLogicResource.QueryStatus status) throws SvcLogicException {
doReturn(status)
.when(dbServiceMock)
@@ -73,6 +103,15 @@ class MockDbServiceBuilder {
return this;
}
+ public MockDbServiceBuilder getTemplateByTemplateModelId(String prefix, String fileCategory, String templateModelId,
+ SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getTemplateWithTemplateModelId(any(SvcLogicContext.class), eq(prefix), eq(fileCategory), eq(templateModelId));
+
+ return this;
+ }
+
public MockDbServiceBuilder saveConfigFiles(String prefix, SvcLogicResource.QueryStatus status) throws SvcLogicException {
doReturn(status)
.when(dbServiceMock)
@@ -137,7 +176,61 @@ class MockDbServiceBuilder {
return this;
}
+ public MockDbServiceBuilder getConfigFilesByVnfVmNCategory(String prefix, String fileCategory, String vnfId,
+ String vmName, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getConfigFilesByVnfVmNCategory(any(SvcLogicContext.class), eq(prefix), eq(fileCategory), eq(vnfId), eq(vmName));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder saveConfigTransactionLog(String prefix, SvcLogicResource.QueryStatus status)
+ throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .saveConfigTransactionLog(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getVnfcReferenceByVnfcTypeNAction(String prefix, SvcLogicResource.QueryStatus status)
+ throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getVnfcReferenceByVnfcTypeNAction(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
DGGeneralDBService build() {
return dbServiceMock;
}
+
+ public MockDbServiceBuilder getVnfcReferenceByVnfTypeNActionWithTemplateModelId(String prefix,
+ String templateModelId, SvcLogicResource.QueryStatus status) throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getVnfcReferenceByVnfTypeNActionWithTemplateModelId(any(SvcLogicContext.class), eq(prefix),
+ eq(templateModelId));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getVnfcReferenceByVnfTypeNAction(String prefix, SvcLogicResource.QueryStatus status)
+ throws SvcLogicException {
+ doReturn(status)
+ .when(dbServiceMock)
+ .getVnfcReferenceByVnfTypeNAction(any(SvcLogicContext.class), eq(prefix));
+
+ return this;
+ }
+
+ public MockDbServiceBuilder getCapability(String type, String returnString) throws SvcLogicException {
+ doReturn(returnString)
+ .when(dbServiceMock)
+ .getCapability(any(SvcLogicContext.class), eq(type));
+
+ return this;
+ }
}