1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
package org.openecomp.sdc.translator.services.heattotosca.mapping;
import org.openecomp.sdc.heat.datatypes.model.HeatOrchestrationTemplate;
import org.openecomp.sdc.tosca.datatypes.model.NodeTemplate;
import org.openecomp.sdc.tosca.services.ToscaConstants;
import org.openecomp.sdc.tosca.services.ToscaFileOutputService;
import org.openecomp.sdc.tosca.services.impl.ToscaFileOutputServiceCsarImpl;
import org.openecomp.sdc.translator.services.heattotosca.TranslationContext;
import org.openecomp.core.utilities.file.FileUtils;
import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
import java.util.List;
public class TranslatorHeatToToscaFunctionConverterTest {
@Test
public void testGetFileWithExtensionFunction() {
String functionName = "get_file";
Object function = "scripFileName.sh";
String heatFileName = "heatFileName";
HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
NodeTemplate nodeTemplate = new NodeTemplate();
TranslationContext context = new TranslationContext();
testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
nodeTemplate, context);
}
@Test
public void testGetFileWithoutExtensionFunction() {
String functionName = "get_file";
Object function = "scripFileName";
String heatFileName = "heatFileName";
HeatOrchestrationTemplate heatOrchestrationTemplate = new HeatOrchestrationTemplate();
NodeTemplate nodeTemplate = new NodeTemplate();
TranslationContext context = new TranslationContext();
//# route_targets: { "Fn::Split" : [ ",", Ref: route_targets ] }
testGetToscaFunctionForGetFile(functionName, function, heatFileName, heatOrchestrationTemplate,
nodeTemplate, context);
}
private void testGetToscaFunctionForGetFile(String functionName, Object function,
String heatFileName,
HeatOrchestrationTemplate heatOrchestrationTemplate,
NodeTemplate nodeTemplate,
TranslationContext context) {
Object result = TranslatorHeatToToscaFunctionConverter
.getToscaFunction(functionName, function, heatFileName, heatOrchestrationTemplate,
nodeTemplate, context);
Assert.assertNotNull(((HashMap) result).get("get_artifact"));
List artifactParameters = (List) ((HashMap) result).get("get_artifact");
Assert.assertNotNull(artifactParameters);
Assert.assertEquals(artifactParameters.size(), 2);
Assert.assertEquals(artifactParameters.get(0), ToscaConstants.MODELABLE_ENTITY_NAME_SELF);
Assert.assertEquals(artifactParameters.get(1), ((String) function).split("\\.")[0]);
Assert.assertNotNull(nodeTemplate.getArtifacts());
Assert.assertNotNull(
nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function)));
ToscaFileOutputService toscaFileOutputService = new ToscaFileOutputServiceCsarImpl();
Assert.assertEquals(
nodeTemplate.getArtifacts().get(FileUtils.getFileWithoutExtention((String) function))
.getFile(), "../" + toscaFileOutputService.getArtifactsFolderName() + "/" + function);
}
}
|