2 * Copyright © 2017-2018 AT&T Intellectual Property.
\r
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
\r
5 * in compliance with the License. You may obtain a copy of the License at
\r
7 * http://www.apache.org/licenses/LICENSE-2.0
\r
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
\r
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
\r
11 * or implied. See the License for the specific language governing permissions and limitations under
\r
15 package org.onap.ccsdk.config.assignment.service;
\r
17 import java.nio.charset.Charset;
\r
18 import java.util.HashMap;
\r
19 import java.util.List;
\r
20 import java.util.Map;
\r
21 import org.apache.commons.io.IOUtils;
\r
22 import org.junit.Assert;
\r
23 import org.junit.Test;
\r
24 import org.onap.ccsdk.config.model.ConfigModelConstant;
\r
25 import org.onap.ccsdk.config.model.ValidTypes;
\r
26 import org.onap.ccsdk.config.model.data.ResourceAssignment;
\r
27 import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;
\r
28 import org.onap.ccsdk.config.model.utils.TransformationUtils;
\r
29 import com.att.eelf.configuration.EELFLogger;
\r
30 import com.att.eelf.configuration.EELFManager;
\r
31 import com.fasterxml.jackson.databind.JsonNode;
\r
33 public class ResourceAssignmentGenerationTest {
\r
35 private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentGenerationTest.class);
\r
38 public void testResourceDataSetting() {
\r
40 logger.info(" **************** testResourceDataSetting *****************");
\r
41 String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
\r
42 .getResourceAsStream("assignments/alltype-empty-value-mapping.json"), Charset.defaultCharset());
\r
44 List<ResourceAssignment> assignments =
\r
45 TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
\r
46 if (assignments != null) {
\r
47 Map<String, Object> componentContext = new HashMap<>();
\r
48 componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "sample-recipe");
\r
49 for (ResourceAssignment resourceAssignment : assignments) {
\r
50 if (resourceAssignment != null && resourceAssignment.getProperty() != null) {
\r
51 String type = resourceAssignment.getProperty().getType();
\r
52 Object value = null;
\r
53 if (ValidTypes.DATA_TYPE_STRING.equals(type)) {
\r
54 value = new String("abcdef");
\r
55 } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) {
\r
56 value = new Integer(1234);
\r
57 } else if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) {
\r
58 value = new Boolean(true);
\r
59 } else if (ValidTypes.DATA_TYPE_LIST.equals(type)) {
\r
60 String entityType = resourceAssignment.getProperty().getEntrySchema().getType();
\r
61 if (ValidTypes.DATA_TYPE_STRING.equals(entityType)) {
\r
62 value = "[\"abcd-array\"]";
\r
64 String content = "[{\"name\" : \"abcd-array-complex\"}]";
\r
65 JsonNode node = TransformationUtils.getJsonNodeForString(content);
\r
69 String content = "{\"name\" : \"abcd-complex\"}";
\r
70 JsonNode node = TransformationUtils.getJsonNodeForString(content);
\r
73 ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);
\r
76 String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
\r
77 logger.trace("Generated Data " + generatedData);
\r
79 Assert.assertNotNull("Failed to generate resource data", generatedData);
\r
81 } catch (Exception e) {
\r
82 e.printStackTrace();
\r
87 public void testGenerateResourceData() {
\r
89 logger.info(" **************** testGenerateResourceData *****************");
\r
90 String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
\r
91 .getResourceAsStream("assignments/alltype-mapping.json"), Charset.defaultCharset());
\r
93 List<ResourceAssignment> assignments =
\r
94 TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
\r
95 if (assignments != null) {
\r
97 String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
\r
98 logger.trace("Generated Data " + generatedData);
\r
100 Assert.assertNotNull("Failed to generate resource data", generatedData);
\r
102 } catch (Exception e) {
\r
103 e.printStackTrace();
\r