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.io.File;
\r
21 import java.nio.charset.Charset;
\r
22 import java.util.HashMap;
\r
23 import java.util.Map;
\r
24 import org.apache.commons.io.FileUtils;
\r
25 import org.apache.commons.lang3.StringUtils;
\r
26 import org.apache.sling.testing.mock.osgi.MockOsgi;
\r
27 import org.junit.Assert;
\r
28 import org.junit.Before;
\r
29 import org.junit.Rule;
\r
30 import org.junit.Test;
\r
31 import org.junit.rules.ExpectedException;
\r
32 import org.junit.runner.RunWith;
\r
33 import org.mockito.Mock;
\r
34 import org.mockito.MockitoAnnotations;
\r
35 import org.mockito.runners.MockitoJUnitRunner;
\r
36 import org.onap.ccsdk.features.assignment.ConfigAssignmentConstants;
\r
37 import org.onap.ccsdk.features.assignment.service.ConfigAssignmentNode;
\r
38 import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService;
\r
39 import org.onap.ccsdk.features.generator.service.ConfigGeneratorService;
\r
40 import org.onap.ccsdk.features.generator.service.ConfigGeneratorServiceImpl;
\r
41 import org.onap.ccsdk.features.model.ConfigModelConstant;
\r
42 import org.onap.ccsdk.features.model.service.ComponentNodeDelegate;
\r
43 import org.onap.ccsdk.features.model.service.ComponentNodeService;
\r
44 import org.onap.ccsdk.features.model.service.ComponentNodeServiceImpl;
\r
45 import org.onap.ccsdk.features.model.service.ConfigModelService;
\r
46 import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl;
\r
47 import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService;
\r
48 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
\r
49 import org.osgi.framework.BundleContext;
\r
50 import com.att.eelf.configuration.EELFLogger;
\r
51 import com.att.eelf.configuration.EELFManager;
\r
53 @RunWith(MockitoJUnitRunner.class)
\r
54 public class ConfigAssignmentNodeTest {
\r
56 private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentNodeTest.class);
\r
59 public ExpectedException thrown = ExpectedException.none();
\r
62 private ConfigResourceService configResourceService;
\r
65 private ConfigRestAdaptorService configRestAdaptorService;
\r
67 private ConfigModelService configModelService;
\r
69 private ComponentNodeService componentNodeService;
\r
71 private ConfigGeneratorService configGeneratorService;
\r
73 BundleContext bundleContext = MockOsgi.newBundleContext();
\r
75 @SuppressWarnings("unchecked")
\r
77 public void before() throws Exception {
\r
78 MockitoAnnotations.initMocks(this);
\r
80 * ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(componentNodeService,
\r
81 * configResourceService, configModelService, configRestAdaptorService, configGeneratorService);
\r
82 * bundleContext.registerService(ConfigAssignmentNode.class, configAssignmentNode, null);
\r
87 public void testResourceAssignment() throws Exception {
\r
88 ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService);
\r
90 ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment");
\r
92 ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService,
\r
93 "assignments/empty-dictionary.json");
\r
95 ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService);
\r
97 componentNodeService =
\r
98 new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService);
\r
99 configModelService = new ConfigModelServiceImpl(configRestAdaptorService);
\r
100 configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService);
\r
102 ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService,
\r
103 configRestAdaptorService, configModelService, componentNodeService, configGeneratorService);
\r
105 String inputContent = FileUtils.readFileToString(
\r
106 new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset());
\r
108 Map<String, String> inParams = new HashMap<>();
\r
109 inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test");
\r
110 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234");
\r
111 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234");
\r
112 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type");
\r
113 inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig");
\r
114 inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0");
\r
115 inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action");
\r
116 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent);
\r
117 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]");
\r
119 // Populate the SvcContext ( Simulation)
\r
120 SvcLogicContext svcLogicContext = new SvcLogicContext();
\r
121 Map<String, String> context = new HashMap<>();
\r
122 context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action");
\r
123 context = configModelService.prepareContext(context, inputContent, "vpe-201802-baseconfig", "1.0.0");
\r
124 context.forEach((key, value) -> svcLogicContext.setAttribute(key, value));
\r
126 Map<String, Object> componentContext = new HashMap<>();
\r
127 configAssignmentNode.process(inParams, svcLogicContext, componentContext);
\r
128 Assert.assertNotNull("Failed to get response status", svcLogicContext.getAttribute("test.status"));
\r
133 public void testSimplePreview() throws Exception {
\r
134 ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService);
\r
136 ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment");
\r
138 ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService,
\r
139 "assignments/empty-dictionary.json");
\r
141 ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService);
\r
143 componentNodeService =
\r
144 new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService);
\r
145 configModelService = new ConfigModelServiceImpl(configRestAdaptorService);
\r
146 configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService);
\r
148 ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService,
\r
149 configRestAdaptorService, configModelService, componentNodeService, configGeneratorService);
\r
151 String inputContent = FileUtils.readFileToString(
\r
152 new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset());
\r
154 Map<String, String> inParams = new HashMap<>();
\r
155 inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test");
\r
156 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234");
\r
157 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234");
\r
158 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type");
\r
159 inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig");
\r
160 inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0");
\r
161 inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action");
\r
162 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent);
\r
163 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]");
\r
164 SvcLogicContext ctx = new SvcLogicContext();
\r
165 configAssignmentNode.process(inParams, ctx);
\r
166 Assert.assertNotNull("Failed to get response mashed Content",
\r
167 ctx.getAttribute("test.mashed-data.base-config-template"));
\r
171 public void testComplexPreview() throws Exception {
\r
172 ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService);
\r
174 ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "vpe-201802-baseconfig");
\r
176 ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService,
\r
177 "service_templates/vpe-201802-baseconfig/dict.json");
\r
179 ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService);
\r
181 componentNodeService =
\r
182 new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService);
\r
183 configModelService = new ConfigModelServiceImpl(configRestAdaptorService);
\r
184 configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService);
\r
186 ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService,
\r
187 configRestAdaptorService, configModelService, componentNodeService, configGeneratorService);
\r
189 String inputContent = FileUtils.readFileToString(
\r
190 new File("src/test/resources/service_templates/vpe-201802-baseconfig/input-complex.json"),
\r
191 Charset.defaultCharset());
\r
193 Map<String, String> inParams = new HashMap<>();
\r
194 inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "complex-test");
\r
195 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "request-1234");
\r
196 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234");
\r
197 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type");
\r
198 inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig");
\r
199 inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0");
\r
200 inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action");
\r
201 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent);
\r
202 inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]");
\r
203 SvcLogicContext ctx = new SvcLogicContext();
\r
204 configAssignmentNode.process(inParams, ctx);
\r
205 Assert.assertNotNull("Failed to get response mashed Content",
\r
206 ctx.getAttribute("complex-test.mashed-data.base-config-template"));
\r
211 public void inputValidator() {
\r
212 SvcLogicContext ctx = new SvcLogicContext();
\r
215 logger.info(" ******************************* inputValidator ***************************");
\r
216 String serviceTemplateContent = FileUtils.readFileToString(
\r
217 new File("src/test/resources/service_templates/resource_assignment.json"),
\r
218 Charset.defaultCharset());
\r
220 String inputcontent = FileUtils.readFileToString(
\r
221 new File("src/test/resources/service_templates/input/inputValidateTest.json"),
\r
222 Charset.defaultCharset());
\r
224 Map<String, String> context = new HashMap<>();
\r
225 configModelService.prepareContext(context, inputcontent, serviceTemplateContent);
\r
227 // TransformationUtils.printMap(context);
\r
229 context.forEach((name, value) -> {
\r
230 if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) {
\r
231 ctx.setAttribute(name, value);
\r
235 ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService);
\r
236 Map<String, String> inParams = new HashMap<>();
\r
237 inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment");
\r
238 componentNodeDelegate.process(inParams, ctx);
\r
240 } catch (Exception e) {
\r
241 logger.error("Failed in inputValidator" + e.getMessage());
\r
242 logger.info("** ctx.getAttribute Check for **" + ctx.getAttribute("resource-assignment.error-message"));
\r