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.features.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.features.model.ConfigModelConstant;
\r
28 import org.onap.ccsdk.features.model.ValidTypes;
\r
29 import org.onap.ccsdk.features.model.data.ResourceAssignment;
\r
30 import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils;
\r
31 import org.onap.ccsdk.features.model.utils.TransformationUtils;
\r
33 import com.att.eelf.configuration.EELFLogger;
\r
34 import com.att.eelf.configuration.EELFManager;
\r
35 import com.fasterxml.jackson.databind.JsonNode;
\r
37 public class ResourceAssignmentGenerationTest {
\r
39 private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentGenerationTest.class);
\r
42 public void testResourceDataSetting() {
\r
44 logger.info(" **************** testResourceDataSetting *****************");
\r
45 String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
\r
46 .getResourceAsStream("assignments/alltype-empty-value-mapping.json"), Charset.defaultCharset());
\r
48 List<ResourceAssignment> assignments =
\r
49 TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
\r
50 if (assignments != null) {
\r
51 Map<String, Object> componentContext = new HashMap<>();
\r
52 componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "sample-recipe");
\r
53 for (ResourceAssignment resourceAssignment : assignments) {
\r
54 if (resourceAssignment != null && resourceAssignment.getProperty() != null) {
\r
55 String type = resourceAssignment.getProperty().getType();
\r
56 Object value = null;
\r
57 if (ValidTypes.DATA_TYPE_STRING.equals(type)) {
\r
58 value = new String("abcdef");
\r
59 } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) {
\r
60 value = new Integer(1234);
\r
61 } else if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) {
\r
62 value = new Boolean(true);
\r
63 } else if (ValidTypes.DATA_TYPE_LIST.equals(type)) {
\r
64 String entityType = resourceAssignment.getProperty().getEntrySchema().getType();
\r
65 if (ValidTypes.DATA_TYPE_STRING.equals(entityType)) {
\r
66 value = "[\"abcd-array\"]";
\r
68 String content = "[{\"name\" : \"abcd-array-complex\"}]";
\r
69 JsonNode node = TransformationUtils.getJsonNodeForString(content);
\r
73 String content = "{\"name\" : \"abcd-complex\"}";
\r
74 JsonNode node = TransformationUtils.getJsonNodeForString(content);
\r
77 ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);
\r
80 String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
\r
81 logger.trace("Generated Data " + generatedData);
\r
83 Assert.assertNotNull("Failed to generate resource data", generatedData);
\r
85 } catch (Exception e) {
\r
86 e.printStackTrace();
\r
91 public void testGenerateResourceData() {
\r
93 logger.info(" **************** testGenerateResourceData *****************");
\r
94 String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
\r
95 .getResourceAsStream("assignments/alltype-mapping.json"), Charset.defaultCharset());
\r
97 List<ResourceAssignment> assignments =
\r
98 TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
\r
99 if (assignments != null) {
\r
101 String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
\r
102 logger.trace("Generated Data " + generatedData);
\r
104 Assert.assertNotNull("Failed to generate resource data", generatedData);
\r
106 } catch (Exception e) {
\r
107 e.printStackTrace();
\r