2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
19 import org.junit.Assert;
20 import org.junit.Test;
21 import org.onap.sdc.tosca.datatypes.model.NodeTemplate;
22 import org.openecomp.core.utilities.file.FileUtils;
23 import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
24 import org.openecomp.sdc.tosca.services.ToscaConstants;
25 import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
26 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
27 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
28 import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
30 import java.util.HashMap;
31 import java.util.List;
33 import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
35 public class FunctionTranslationGetFileImplTest {
37 public void testGetFileWithExtensionFunction() {
38 String functionName = "get_file";
39 Object function = "scripFileName.sh";
40 String heatFileName = "heatFileName";
41 HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
42 NodeTemplate nodeTemplate = new NodeTemplate();
43 TranslationContext context = new TranslationContext();
45 testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
46 nodeTemplate, context);
50 public void testGetFileWithoutExtensionFunction() {
51 String functionName = "get_file";
52 Object function = "scripFileName";
53 String heatFileName = "heatFileName";
54 HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
55 NodeTemplate nodeTemplate = new NodeTemplate();
56 TranslationContext context = new TranslationContext();
58 //# route_targets: { "Fn::Split" : [ ",", Ref: route_targets ] }
59 testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
60 nodeTemplate, context);
63 private void testGetToscaFunctionForGetFile(String functionName, Object function,
65 HeatOrchestrationTemplate heatOrchestrationTemplate,
66 NodeTemplate nodeTemplate,
67 TranslationContext context) {
68 Assert.assertTrue(FunctionTranslationFactory.getInstance(functionName).isPresent());
69 if(FunctionTranslationFactory.getInstance(functionName).isPresent()) {
70 FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, heatFileName,
71 heatOrchestrationTemplate, context), null, function, nodeTemplate);
72 Object result = FunctionTranslationFactory.getInstance(functionName).get()
73 .translateFunction(functionTranslator);
74 Assert.assertNotNull(((HashMap) result).get("get_artifact"));
75 List artifactParameters = (List) ((HashMap) result).get("get_artifact");
76 Assert.assertNotNull(artifactParameters);
77 Assert.assertEquals(2, artifactParameters.size());
78 Assert.assertEquals(ToscaConstants.MODELABLE_ENTITY_NAME_SELF, artifactParameters.get(0));
79 Assert.assertEquals(((String) function).split("\\.")[0], artifactParameters.get(1));
81 Assert.assertNotNull(nodeTemplate.getArtifacts());
83 nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function)));
84 ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
86 nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function))
87 .getFile(), "../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);