2dc37f17e43f4378630ef41f2494055cf8380ed0
[sdc.git] /
1 package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;
2
3 import org.junit.After;
4 import org.junit.Before;
5 import org.junit.Test;
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;
9
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;
15 import java.util.Map;
16
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;
21
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             "Entry-Manifest: MainServiceTemplate.mf\n" +
29             "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";
34
35     private String finalNonManoLocation = "Deployment/VES_EVENTS/test.xml";
36     private String finalOtherNonManoLocation = "Informational/OTHER/test.xml";
37
38     @Before
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);
44     }
45
46     @After
47     public void tearDown() {
48         etsiService = null;
49     }
50
51     @Test
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));
56     }
57
58     @Test
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));
63     }
64
65     @Test
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));
70     }
71
72     @Test
73     public void testIsSol004FalseWithNull() throws IOException  {
74         FileContentHandler fileContentHandler = new FileContentHandler();
75         assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
76     }
77
78     @Test
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));
90     }
91
92     @Test
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));
104     }
105
106     @Test
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));
118     }
119
120     @Test
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));
132     }
133 }