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