diff options
Diffstat (limited to 'blueprints-processor/plugin')
9 files changed, 665 insertions, 0 deletions
diff --git a/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessor.java b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessor.java new file mode 100644 index 000000000..5f3e6094c --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/main/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessor.java @@ -0,0 +1,267 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 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.
+ */
+
+package org.onap.ccsdk.config.assignment.processor;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.collections.CollectionUtils;
+import org.apache.commons.collections.MapUtils;
+import org.apache.commons.lang3.StringUtils;
+import org.onap.ccsdk.config.assignment.service.ConfigAssignmentUtils;
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;
+import org.onap.ccsdk.config.model.ConfigModelConstant;
+import org.onap.ccsdk.config.model.ConfigModelException;
+import org.onap.ccsdk.config.model.ValidTypes;
+import org.onap.ccsdk.config.model.data.ResourceAssignment;
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;
+import org.onap.ccsdk.config.model.data.dict.SourcesDefinition;
+import org.onap.ccsdk.config.model.service.ComponentNode;
+import org.onap.ccsdk.config.model.utils.JsonUtils;
+import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.node.ArrayNode;
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+
+public class DBResourceProcessor implements ComponentNode {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessor.class);
+ private ConfigResourceService configResourceService;
+ private Map<String, ResourceDefinition> dictionaries;
+
+ public DBResourceProcessor(ConfigResourceService configResourceService) {
+ this.configResourceService = configResourceService;
+ }
+
+ @Override
+ public Boolean preCondition(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ return Boolean.TRUE;
+ }
+
+ @Override
+ public void preProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ // Auto-generated method stub
+ }
+
+ @Override
+ public void process(Map<String, String> inParams, SvcLogicContext ctx) throws SvcLogicException {
+ // Auto-generated method stub
+ }
+
+ @SuppressWarnings("unchecked")
+ @Override
+ public void process(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ try {
+ List<ResourceAssignment> batchResourceAssignment =
+ (List<ResourceAssignment>) componentContext.get(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS);
+ dictionaries =
+ (Map<String, ResourceDefinition>) componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARIES);
+
+ if (CollectionUtils.isNotEmpty(batchResourceAssignment)) {
+ for (ResourceAssignment resourceAssignment : batchResourceAssignment) {
+ processResourceAssignment(ctx, componentContext, resourceAssignment);
+ }
+ }
+ } catch (Exception e) {
+ throw new SvcLogicException(String.format("DBResourceProcessor Exception : (%s)", e), e);
+ }
+ }
+
+ private void processResourceAssignment(SvcLogicContext ctx, Map<String, Object> componentContext,
+ ResourceAssignment resourceAssignment) throws SvcLogicException, ConfigModelException {
+ if (resourceAssignment != null) {
+ try {
+ validate(resourceAssignment);
+
+ // Check if It has Input
+ Object value = ConfigAssignmentUtils.getContextKeyValue(ctx, resourceAssignment.getName());
+ if (value != null) {
+ logger.info("db source template key ({}) found from input and value is ({})",
+ resourceAssignment.getName(), value);
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);
+ return;
+ }
+
+ ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName());
+ SourcesDefinition sourceDb = resourceDefinition.getSources().get("db");
+ if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) {
+ throw new SvcLogicException("db query property is missing");
+ }
+
+ String sql = sourceDb.getProperties().getQuery();
+ Map<String, String> inputKeyMapping = sourceDb.getProperties().getInputKeyMapping();
+
+ logger.info("Db dictionary information : ({}), ({}), ({})", sql, inputKeyMapping,
+ sourceDb.getProperties().getOutputKeyMapping());
+
+ Map<String, Object> namedParameters = populateNamedParameter(componentContext, inputKeyMapping);
+
+ logger.info("Parameter information : ({})", namedParameters);
+ List<Map<String, Object>> rows = configResourceService.query(sql, namedParameters);
+ if (rows != null && !rows.isEmpty()) {
+ processDBResults(ctx, componentContext, resourceAssignment, sourceDb, rows);
+ } else {
+ logger.warn("Failed to get db result for dictionary name ({}) the query ({})",
+ resourceAssignment.getDictionaryName(), sql);
+ }
+
+ // Check the value has populated for mandatory case
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(componentContext, resourceAssignment);
+ } catch (Exception e) {
+ ResourceAssignmentUtils.setFailedResourceDataValue(componentContext, resourceAssignment,
+ e.getMessage());
+ throw new SvcLogicException(
+ String.format("Failed in template key (%s) assignments : (%s)", resourceAssignment, e), e);
+ }
+ } else {
+ // Do Nothing
+ }
+ }
+
+ private void validate(ResourceAssignment resourceAssignment) throws SvcLogicException {
+ if (resourceAssignment == null) {
+ throw new SvcLogicException("resource assignment is not defined");
+ }
+
+ if (StringUtils.isBlank(resourceAssignment.getName())) {
+ throw new SvcLogicException("resource assignment template key is not defined");
+ }
+
+ if (StringUtils.isBlank(resourceAssignment.getDictionaryName())) {
+ throw new SvcLogicException(
+ String.format("resource assignment dictionary name is not defined for template key (%s)",
+ resourceAssignment.getName()));
+ }
+
+ if (!ConfigModelConstant.SOURCE_DB.equalsIgnoreCase(resourceAssignment.getDictionarySource())) {
+ throw new SvcLogicException(String.format("resource assignment source is not db, it is (%s)",
+ resourceAssignment.getDictionarySource()));
+ }
+
+ ResourceDefinition resourceDefinition = dictionaries.get(resourceAssignment.getDictionaryName());
+ if (resourceDefinition == null) {
+ throw new SvcLogicException(String.format("missing resource dictionary definition for name (%s) ",
+ resourceAssignment.getDictionaryName()));
+ }
+
+ if (resourceDefinition.getSources() == null || resourceDefinition.getSources().get("db") == null) {
+ throw new SvcLogicException(String.format("missing resource dictionary db source definition for name (%s) ",
+ resourceAssignment.getDictionaryName()));
+ }
+
+ SourcesDefinition sourceDb = resourceDefinition.getSources().get("db");
+ if (StringUtils.isBlank(sourceDb.getProperties().getQuery())) {
+ throw new SvcLogicException(String.format("Failed to get request Query for dictionary (%s)",
+ resourceAssignment.getDictionaryName()));
+ }
+
+ }
+
+ private Map<String, Object> populateNamedParameter(Map<String, Object> componentContext,
+ Map<String, String> inputKeyMapping) {
+ Map<String, Object> namedParameters = new HashMap<>();
+ if (MapUtils.isNotEmpty(inputKeyMapping)) {
+
+ for (Map.Entry<String, String> mapping : inputKeyMapping.entrySet()) {
+ ResourceDefinition referenceDictionaryDefinition = dictionaries.get(mapping.getValue());
+ Object expressionValue =
+ ResourceAssignmentUtils.getDictionaryKeyValue(componentContext, referenceDictionaryDefinition);
+ logger.trace("Reference dictionary key ({}), value ({})", mapping.getKey(), expressionValue);
+ namedParameters.put(mapping.getKey(), expressionValue);
+ }
+ }
+ return namedParameters;
+ }
+
+ @SuppressWarnings("squid:S3776")
+ private void processDBResults(SvcLogicContext ctx, Map<String, Object> componentContext,
+ ResourceAssignment resourceAssignment, SourcesDefinition sourceDb, List<Map<String, Object>> rows)
+ throws SvcLogicException, ConfigModelException {
+
+ Map<String, String> outputKeyMapping = sourceDb.getProperties().getOutputKeyMapping();
+ String type = resourceAssignment.getProperty().getType();
+ String entrySchema = null;
+ logger.info("Response processing type({})", type);
+ // Primitive Types
+ if (ValidTypes.getPrimitivePropertType().contains(type)) {
+
+ Map<String, Object> row = rows.get(0);
+ String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName());
+ Object dbColumnValue = row.get(dbColumnName);
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, dbColumnValue);
+
+ } else if (ValidTypes.getListPropertType().contains(type)) {
+ // Array Types
+ if (resourceAssignment.getProperty().getEntrySchema() != null) {
+ entrySchema = resourceAssignment.getProperty().getEntrySchema().getType();
+ }
+
+ if (StringUtils.isNotBlank(entrySchema)) {
+ ArrayNode arrayNode = JsonNodeFactory.instance.arrayNode();
+
+ for (Map<String, Object> row : rows) {
+ if (ValidTypes.getPrimitivePropertType().contains(entrySchema)) {
+ String dbColumnName = outputKeyMapping.get(resourceAssignment.getDictionaryName());
+ Object dbColumnValue = row.get(dbColumnName);
+ // Add Array JSON
+ JsonUtils.populatePrimitiveValues(dbColumnValue, entrySchema, arrayNode);
+ } else {
+ ObjectNode arrayChildNode = JsonNodeFactory.instance.objectNode();
+ for (Map.Entry<String, String> mapping : outputKeyMapping.entrySet()) {
+ Object dbColumnValue = row.get(mapping.getKey());
+ String propertyTypeForDataType =
+ ConfigAssignmentUtils.getPropertyType(ctx, entrySchema, mapping.getKey());
+ JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType,
+ arrayChildNode);
+ }
+ arrayNode.add(arrayChildNode);
+ }
+ }
+ // Set the List of Complex Values
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, arrayNode);
+ } else {
+ throw new SvcLogicException(String.format("Entry schema is not defined for dictionary (%s) info",
+ resourceAssignment.getDictionaryName()));
+ }
+ } else {
+ // Complex Types
+ Map<String, Object> row = rows.get(0);
+ ObjectNode objectNode = JsonNodeFactory.instance.objectNode();
+ for (Map.Entry<String, String> mapping : outputKeyMapping.entrySet()) {
+ Object dbColumnValue = row.get(mapping.getKey());
+ String propertyTypeForDataType = ConfigAssignmentUtils.getPropertyType(ctx, type, mapping.getKey());
+ JsonUtils.populatePrimitiveValues(mapping.getKey(), dbColumnValue, propertyTypeForDataType, objectNode);
+ }
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, objectNode);
+ }
+ }
+
+ @Override
+ public void postProcess(Map<String, String> inParams, SvcLogicContext ctx, Map<String, Object> componentContext)
+ throws SvcLogicException {
+ // Auto-generated method stub
+ }
+
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java new file mode 100644 index 000000000..5a704e995 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java @@ -0,0 +1,231 @@ +/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ * Modifications Copyright © 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.
+ */
+
+package org.onap.ccsdk.config.assignment.processor;
+
+import static org.mockito.Matchers.any;
+import java.io.File;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Matchers;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.mockito.stubbing.Answer;
+import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils;
+import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;
+import org.onap.ccsdk.config.model.ConfigModelConstant;
+import org.onap.ccsdk.config.model.data.ResourceAssignment;
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;
+import org.onap.ccsdk.config.model.utils.TransformationUtils;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import org.onap.ccsdk.sli.core.sli.SvcLogicException;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@RunWith(MockitoJUnitRunner.class)
+public class DBResourceProcessorTest {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessorTest.class);
+
+ @Mock
+ private ConfigResourceService configResourceService;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void before() {
+ MockitoAnnotations.initMocks(this);
+
+ try {
+ Mockito.doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ if (args != null) {
+ logger.trace("Transaction info " + Arrays.asList(args));
+ }
+ return null;
+ }
+ }).when(configResourceService).save(any(TransactionLog.class));
+
+ } catch (SvcLogicException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testDbSimpleProcess() throws Exception {
+ logger.info(" ******************************* testDbSimpleProcess ***************************");
+
+ Mockito.doAnswer(new Answer<List<Map<String, Object>>>() {
+ @Override
+ public List<Map<String, Object>> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ List<Map<String, Object>> results = new ArrayList<>();
+ if (args != null) {
+ logger.info("Query " + Arrays.asList(args));
+ Map<String, Object> record = new HashMap<>();
+ record.put("country", "US");
+ results.add(record);
+ }
+ return results;
+ }
+ }).when(configResourceService).query(Matchers.anyString(), Matchers.<Map<String, Object>>any());
+
+ String recipeName = "sample-recipe";
+
+ String resourceassignmentContent = FileUtils.readFileToString(
+ new File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset());
+ List<ResourceAssignment> batchResourceAssignment =
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);
+
+ String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-simple.json"),
+ Charset.defaultCharset());
+ Map<String, ResourceDefinition> dictionaries =
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);
+ DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService);
+ Map<String, Object> componentContext = new HashMap<>();
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);
+
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");
+
+ Map<String, String> inParams = new HashMap<>();
+ SvcLogicContext ctx = new SvcLogicContext();
+ dbResourceProcessor.process(inParams, ctx, componentContext);
+
+ logger.info(" Context " + componentContext);
+
+ }
+
+ @Test
+ public void testDbComplexProcess() throws Exception {
+ logger.info(" ******************************* testDbComplexProcess ***************************");
+
+ Mockito.doAnswer(new Answer<List<Map<String, Object>>>() {
+ @Override
+ public List<Map<String, Object>> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ List<Map<String, Object>> results = new ArrayList<>();
+ if (args != null) {
+ logger.info("Query " + Arrays.asList(args));
+ Map<String, Object> record = new HashMap<>();
+ record.put("db-country", "US");
+ record.put("db-state", "NJ");
+ results.add(record);
+ }
+ return results;
+ }
+ }).when(configResourceService).query(Matchers.anyString(), Matchers.<Map<String, Object>>any());
+
+ String recipeName = "sample-recipe";
+
+ String resourceassignmentContent = FileUtils.readFileToString(
+ new File("src/test/resources/mapping/db/resource-assignments-complex.json"), Charset.defaultCharset());
+ List<ResourceAssignment> batchResourceAssignment =
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);
+
+ String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-complex.json"),
+ Charset.defaultCharset());
+ Map<String, ResourceDefinition> dictionaries =
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);
+ DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService);
+ Map<String, Object> componentContext = new HashMap<>();
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");
+
+ Map<String, String> inParams = new HashMap<>();
+ SvcLogicContext ctx = new SvcLogicContext();
+ String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"),
+ Charset.defaultCharset());
+ ctx.setAttribute("data_types.dt-location", datatypeContent);
+ dbResourceProcessor.process(inParams, ctx, componentContext);
+
+ }
+
+ @Test
+ public void testDbArrayComplexProcess() throws Exception {
+ logger.info(" ******************************* testDbArrayComplexProcess ***************************");
+ Mockito.doAnswer(new Answer<List<Map<String, Object>>>() {
+ @Override
+ public List<Map<String, Object>> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ List<Map<String, Object>> results = new ArrayList<>();
+ if (args != null) {
+ logger.info("Query " + Arrays.asList(args));
+ Map<String, Object> record = new HashMap<>();
+ record.put("db-country", "US");
+ record.put("db-state", "NJ");
+ results.add(record);
+
+ Map<String, Object> record2 = new HashMap<>();
+ record2.put("db-country", "INDIA");
+ record2.put("db-state", "TN");
+ results.add(record2);
+ }
+ return results;
+ }
+ }).when(configResourceService).query(Matchers.anyString(), Matchers.<Map<String, Object>>any());
+
+ String recipeName = "sample-recipe";
+
+ String resourceassignmentContent = FileUtils.readFileToString(
+ new File("src/test/resources/mapping/db/resource-assignments-array.json"), Charset.defaultCharset());
+ List<ResourceAssignment> batchResourceAssignment =
+ TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class);
+
+ String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-array.json"),
+ Charset.defaultCharset());
+ Map<String, ResourceDefinition> dictionaries =
+ ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent);
+ DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService);
+ Map<String, Object> componentContext = new HashMap<>();
+ componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment);
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName);
+ componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template");
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries);
+ componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample");
+
+ Map<String, String> inParams = new HashMap<>();
+ SvcLogicContext ctx = new SvcLogicContext();
+ String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"),
+ Charset.defaultCharset());
+ ctx.setAttribute("data_types.dt-location", datatypeContent);
+ dbResourceProcessor.process(inParams, ctx, componentContext);
+ logger.info("Component Context = ({})", componentContext);
+ Assert.assertNotNull("faile dto populate Array Complex response ", componentContext);
+
+ }
+
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-array.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-array.json new file mode 100644 index 000000000..bab783544 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-array.json @@ -0,0 +1,40 @@ +{
+ "locations": {
+ "name": "locations",
+ "property": {
+ "type": "list",
+ "entry_schema": {
+ "type": "dt-location"
+ }
+ },
+ "sources": {
+ "db": {
+ "type": "source-sdnctl-db",
+ "properties": {
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
+ "input-key-mapping": {
+ "profile_name": "profile_name"
+ },
+ "output-key-mapping": {
+ "db-country": "country",
+ "db-state": "state"
+ },
+ "key-dependencies": [
+ "profile_name"
+ ]
+ }
+ }
+ }
+ },
+ "profile_name": {
+ "name": "profile_name",
+ "property": {
+ "type": "string"
+ },
+ "sources": {
+ "input": {
+ "type": "source-input"
+ }
+ }
+ }
+}
\ No newline at end of file diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-complex.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-complex.json new file mode 100644 index 000000000..7310500e3 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-complex.json @@ -0,0 +1,37 @@ +{
+ "location": {
+ "name": "location",
+ "property": {
+ "type": "dt-location"
+ },
+ "sources": {
+ "db": {
+ "type": "source-sdnctl-db",
+ "properties": {
+ "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
+ "input-key-mapping": {
+ "profile_name": "profile_name"
+ },
+ "output-key-mapping": {
+ "db-country": "country",
+ "db-state": "state"
+ },
+ "key-dependencies": [
+ "profile_name"
+ ]
+ }
+ }
+ }
+ },
+ "profile_name": {
+ "name": "profile_name",
+ "property": {
+ "type": "string"
+ },
+ "sources": {
+ "input": {
+ "type": "source-input"
+ }
+ }
+ }
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-simple.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-simple.json new file mode 100644 index 000000000..86d29c751 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/db-simple.json @@ -0,0 +1,36 @@ +{
+ "country": {
+ "name": "country",
+ "property": {
+ "type": "string"
+ },
+ "sources": {
+ "db": {
+ "type": "source-sdnctl-db",
+ "properties": {
+ "query": "SELECT country FROM DEVICE_PROFILE WHERE profile_name = :profile_name",
+ "input-key-mapping": {
+ "profile_name": "profile_name"
+ },
+ "output-key-mapping": {
+ "country": "country"
+ },
+ "key-dependencies": [
+ "profile_name"
+ ]
+ }
+ }
+ }
+ },
+ "profile_name": {
+ "name": "profile_name",
+ "property": {
+ "type": "string"
+ },
+ "sources": {
+ "input": {
+ "type": "source-input"
+ }
+ }
+ }
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/dt-location.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/dt-location.json new file mode 100644 index 000000000..52e0a7967 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/dt-location.json @@ -0,0 +1,15 @@ +{
+ "version": "1.0.0",
+ "description": "test Data Type",
+ "properties": {
+ "country": {
+ "required": true,
+ "type": "string"
+ },
+ "state": {
+ "required": false,
+ "type": "string"
+ }
+ },
+ "derived_from": "tosca.datatypes.Root"
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-array.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-array.json new file mode 100644 index 000000000..c82f9addc --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-array.json @@ -0,0 +1,15 @@ +[
+ {
+ "name": "locations",
+ "input-param": true,
+ "property": {
+ "type": "list",
+ "entry_schema": {
+ "type": "dt-location"
+ }
+ },
+ "dictionary-name": "locations",
+ "dictionary-source": "db",
+ "dependencies": []
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-complex.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-complex.json new file mode 100644 index 000000000..4cca99bde --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-complex.json @@ -0,0 +1,12 @@ +[
+ {
+ "name": "location",
+ "input-param": true,
+ "property": {
+ "type": "dt-location"
+ },
+ "dictionary-name": "location",
+ "dictionary-source": "db",
+ "dependencies": []
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-simple.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-simple.json new file mode 100644 index 000000000..02ce68be4 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/mapping/db/resource-assignments-simple.json @@ -0,0 +1,12 @@ +[
+ {
+ "name": "country",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "country",
+ "dictionary-source": "db",
+ "dependencies": []
+ }
+]
|