2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.translator.services.heattotosca.impl.functiontranslation;
23 import org.junit.Assert;
24 import org.junit.Test;
25 import org.openecomp.core.utilities.file.FileUtils;
26 import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
27 import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
28 import org.openecomp.sdc.tosca.services.ToscaConstants;
29 import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
30 import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
31 import org.openecomp.sdc.translator.datatypes.heattotosca.TranslationContext;
32 import org.openecomp.sdc.translator.services.heattotosca.FunctionTranslationFactory;
34 import java.util.HashMap;
35 import java.util.List;
39 * @since December 18, 2016.
41 public class FunctionTranslationGetFileImplTest {
43 public void testGetFileWithExtensionFunction() {
44 String functionName = "get_file";
45 Object function = "scripFileName.sh";
46 String heatFileName = "heatFileName";
47 HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
48 NodeTemplate nodeTemplate = new NodeTemplate();
49 TranslationContext context = new TranslationContext();
51 testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
52 nodeTemplate, context);
56 public void testGetFileWithoutExtensionFunction() {
57 String functionName = "get_file";
58 Object function = "scripFileName";
59 String heatFileName = "heatFileName";
60 HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
61 NodeTemplate nodeTemplate = new NodeTemplate();
62 TranslationContext context = new TranslationContext();
64 //# route_targets: { "Fn::Split" : [ ",", Ref: route_targets ] }
65 testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
66 nodeTemplate, context);
69 private void testGetToscaFunctionForGetFile(String functionName, Object function,
71 HeatOrchestrationTemplate heatOrchestrationTemplate,
72 NodeTemplate nodeTemplate,
73 TranslationContext context) {
74 Assert.assertEquals(true, FunctionTranslationFactory.getInstance(functionName).isPresent());
75 if(FunctionTranslationFactory.getInstance(functionName).isPresent()) {
76 Object result = FunctionTranslationFactory.getInstance(functionName).get()
77 .translateFunction(null, null, null, functionName, function, heatFileName,
78 heatOrchestrationTemplate,
79 nodeTemplate, context);
80 Assert.assertNotNull(((HashMap) result).get("get_artifact"));
81 List artifactParameters = (List) ((HashMap) result).get("get_artifact");
82 Assert.assertNotNull(artifactParameters);
83 Assert.assertEquals(artifactParameters.size(), 2);
84 Assert.assertEquals(artifactParameters.get(0), ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
85 Assert.assertEquals(artifactParameters.get(1), ((String) function).split("\\.")[0]);
87 Assert.assertNotNull(nodeTemplate.getArtifacts());
89 nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function)));
90 ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
92 nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function))
93 .getFile(), "../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);