1 package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
3 import org.junit.After;
4 import org.junit.Before;
6 import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter;
7 import org.openecomp.core.utilities.file.FileContentHandler;
8 import org.openecomp.sdc.tosca.csar.Manifest;
10 import java.io.IOException;
11 import java.nio.charset.StandardCharsets;
12 import java.util.ArrayList;
13 import java.util.HashMap;
14 import java.util.List;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertTrue;
19 import static org.mockito.Mockito.mock;
20 import static org.mockito.Mockito.when;
22 public class ETSIServiceImplTest {
23 private ETSIService etsiService;
24 private String sol004MetaFile = "TOSCA-Meta-Version: 1.0\n" +
25 "CSAR-Version: 1.0\n" +
26 "Created-By: Kuku\n" +
27 "Entry-Definitions: MainServiceTemplate.yaml\n" +
28 "ETSI-Entry-Manifest: MainServiceTemplate.mf\n" +
29 "ETSI-Entry-Change-Log: MainServiceTemplate.log";
30 private String metaFile = "TOSCA-Meta-Version: 1.0\n" +
31 "CSAR-Version: 1.0\n" +
32 "Created-By: Kuku\n" +
33 "Entry-Definitions: MainServiceTemplate.yaml";
35 private String finalNonManoLocation = "Deployment/VES_EVENTS/test.xml";
36 private String finalOtherNonManoLocation = "Informational/OTHER/test.xml";
39 public void setUp() throws IOException {
40 YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
41 Configuration configuration = yamlToObjectConverter.convert("src/test/resources",
42 Configuration.class, "nonManoConfig.yaml");
43 etsiService = new ETSIServiceImpl(configuration);
47 public void tearDown() {
52 public void testIsSol004TrueOrigin() throws IOException {
53 FileContentHandler fileContentHandler = new FileContentHandler();
54 fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", sol004MetaFile.getBytes(StandardCharsets.UTF_8));
55 assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
59 public void testIsSol004True() throws IOException {
60 FileContentHandler fileContentHandler = new FileContentHandler();
61 fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", sol004MetaFile.getBytes(StandardCharsets.UTF_8));
62 assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
66 public void testIsSol004False() throws IOException {
67 FileContentHandler fileContentHandler = new FileContentHandler();
68 fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", metaFile.getBytes(StandardCharsets.UTF_8));
69 assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
73 public void testIsSol004FalseWithNull() throws IOException {
74 FileContentHandler fileContentHandler = new FileContentHandler();
75 assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
79 public void testMoveNonManoFileToArtifactFolder() throws IOException {
80 Map<String, List<String>> nonManoSources = new HashMap<>();
81 List<String> sources = new ArrayList<>();
82 sources.add("Some/test.xml");
83 nonManoSources.put("Some", sources);
84 FileContentHandler fileContentHandler = new FileContentHandler();
85 fileContentHandler.addFile("Some/test.xml", new byte[1]);
86 Manifest manifest = mock(Manifest.class);
87 when(manifest.getNonManoSources()).thenReturn(nonManoSources);
88 etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
89 assertTrue(fileContentHandler.containsFile(finalNonManoLocation));
93 public void testMoveNonManoFileToArtifactFolderFileNotInFolder() throws IOException {
94 Map<String, List<String>> nonManoSources = new HashMap<>();
95 List<String> sources = new ArrayList<>();
96 sources.add("test.xml");
97 nonManoSources.put("foo", sources);
98 FileContentHandler fileContentHandler = new FileContentHandler();
99 fileContentHandler.addFile("test.xml", new byte[1]);
100 Manifest manifest = mock(Manifest.class);
101 when(manifest.getNonManoSources()).thenReturn(nonManoSources);
102 etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
103 assertFalse(fileContentHandler.containsFile(finalOtherNonManoLocation));
107 public void testMoveNonManoFileToArtifactFolderNoMove() throws IOException {
108 Map<String, List<String>> nonManoSources = new HashMap<>();
109 List<String> sources = new ArrayList<>();
110 sources.add(finalNonManoLocation);
111 nonManoSources.put("Some", sources);
112 FileContentHandler fileContentHandler = new FileContentHandler();
113 fileContentHandler.addFile(finalNonManoLocation, new byte[1]);
114 Manifest manifest = mock(Manifest.class);
115 when(manifest.getNonManoSources()).thenReturn(nonManoSources);
116 etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
117 assertTrue(fileContentHandler.containsFile(finalNonManoLocation));
121 public void testMoveNonManoFileToArtifactFolderMoveToKeyFolder() throws IOException {
122 Map<String, List<String>> nonManoSources = new HashMap<>();
123 List<String> sources = new ArrayList<>();
124 sources.add("Artifacts/Deployment/test.xml");
125 nonManoSources.put("Some", sources);
126 FileContentHandler fileContentHandler = new FileContentHandler();
127 fileContentHandler.addFile("Artifacts/Deployment/test.xml", new byte[1]);
128 Manifest manifest = mock(Manifest.class);
129 when(manifest.getNonManoSources()).thenReturn(nonManoSources);
130 etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
131 assertTrue(fileContentHandler.containsFile(finalNonManoLocation));