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.csar.AsdPackageHelper;
25 import org.openecomp.sdc.tosca.csar.ManifestUtils;
26 import org.openecomp.sdc.tosca.services.ToscaConstants;
27 import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
28 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
29 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
30 import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
32 import java.util.HashMap;
33 import java.util.List;
35 import static org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation.FunctionTranslator.getFunctionTranslateTo;
37 public class FunctionTranslationGetFileImplTest {
39 public void testGetFileWithExtensionFunction() {
40 String functionName = "get_file";
41 Object function = "scripFileName.sh";
42 String heatFileName = "heatFileName";
43 HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
44 NodeTemplate nodeTemplate = new NodeTemplate();
45 TranslationContext context = new TranslationContext();
47 testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
48 nodeTemplate, context);
52 public void testGetFileWithoutExtensionFunction() {
53 String functionName = "get_file";
54 Object function = "scripFileName";
55 String heatFileName = "heatFileName";
56 HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
57 NodeTemplate nodeTemplate = new NodeTemplate();
58 TranslationContext context = new TranslationContext();
60 //# route_targets: { "Fn::Split" : [ ",", Ref: route_targets ] }
61 testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
62 nodeTemplate, context);
65 private void testGetToscaFunctionForGetFile(String functionName, Object function,
67 HeatOrchestrationTemplate heatOrchestrationTemplate,
68 NodeTemplate nodeTemplate,
69 TranslationContext context) {
70 Assert.assertTrue(FunctionTranslationFactory.getInstance(functionName).isPresent());
71 if(FunctionTranslationFactory.getInstance(functionName).isPresent()) {
72 FunctionTranslator functionTranslator = new FunctionTranslator(getFunctionTranslateTo(null, null, heatFileName,
73 heatOrchestrationTemplate, context), null, function, nodeTemplate);
74 Object result = FunctionTranslationFactory.getInstance(functionName).get()
75 .translateFunction(functionTranslator);
76 Assert.assertNotNull(((HashMap) result).get("get_artifact"));
77 List artifactParameters = (List) ((HashMap) result).get("get_artifact");
78 Assert.assertNotNull(artifactParameters);
79 Assert.assertEquals(2, artifactParameters.size());
80 Assert.assertEquals(ToscaConstants.MODELABLE_ENTITY_NAME_SELF, artifactParameters.get(0));
81 Assert.assertEquals(((String) function).split("\\.")[0], artifactParameters.get(1));
83 Assert.assertNotNull(nodeTemplate.getArtifacts());
85 nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function)));
86 ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl(new AsdPackageHelper(new ManifestUtils()));
88 nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function))
89 .getFile(), "../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);