aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-vendor-software-product-lib/openecomp-sdc-vendor-software-product-core/src/test/java/org/openecomp/sdc/vendorsoftwareproduct/services/impl/etsi/ETSIServiceImplTest.java
blob: ae69415f1d9e929b23c1b2c69ed9299dec4f7613 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package org.openecomp.sdc.vendorsoftwareproduct.services.impl.etsi;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.onap.sdc.tosca.parser.utils.YamlToObjectConverter;
import org.openecomp.core.utilities.file.FileContentHandler;
import org.openecomp.sdc.tosca.csar.Manifest;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

public class ETSIServiceImplTest {
    private ETSIService etsiService;
    private String sol004MetaFile = "TOSCA-Meta-Version: 1.0\n" +
            "CSAR-Version: 1.0\n" +
            "Created-By: Kuku\n" +
            "Entry-Definitions: MainServiceTemplate.yaml\n" +
            "Entry-Manifest: MainServiceTemplate.mf\n" +
            "Entry-Change-Log: MainServiceTemplate.log";
    private String metaFile = "TOSCA-Meta-Version: 1.0\n" +
            "CSAR-Version: 1.0\n" +
            "Created-By: Kuku\n" +
            "Entry-Definitions: MainServiceTemplate.yaml";

    private String finalNonManoLocation = "Deployment/VES_EVENTS/test.xml";
    private String finalOtherNonManoLocation = "Informational/OTHER/test.xml";

    @Before
    public void setUp() throws IOException {
        YamlToObjectConverter yamlToObjectConverter = new YamlToObjectConverter();
        Configuration configuration = yamlToObjectConverter.convert("src/test/resources",
                Configuration.class, "nonManoConfig.yaml");
        etsiService = new ETSIServiceImpl(configuration);
    }

    @After
    public void tearDown() {
        etsiService = null;
    }

    @Test
    public void testIsSol004TrueOrigin() {
        FileContentHandler fileContentHandler = new FileContentHandler();
        fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", sol004MetaFile.getBytes(StandardCharsets.UTF_8));
        assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
    }

    @Test
    public void testIsSol004True() {
        FileContentHandler fileContentHandler = new FileContentHandler();
        fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta", sol004MetaFile.getBytes(StandardCharsets.UTF_8));
        assertTrue(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
    }

    @Test
    public void testIsSol004False() {
        FileContentHandler fileContentHandler = new FileContentHandler();
        fileContentHandler.addFile("TOSCA-Metadata/TOSCA.meta.original", metaFile.getBytes(StandardCharsets.UTF_8));
        assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
    }

    @Test
    public void testIsSol004FalseWithNull() {
        FileContentHandler fileContentHandler = new FileContentHandler();
        assertFalse(etsiService.isSol004WithToscaMetaDirectory(fileContentHandler));
    }

    @Test
    public void testMoveNonManoFileToArtifactFolder() throws IOException {
        Map<String, List<String>> nonManoSources = new HashMap<>();
        List<String> sources = new ArrayList<>();
        sources.add("Some/test.xml");
        nonManoSources.put("Some", sources);
        FileContentHandler fileContentHandler = new FileContentHandler();
        fileContentHandler.addFile("Some/test.xml", new byte[1]);
        Manifest manifest = mock(Manifest.class);
        when(manifest.getNonManoSources()).thenReturn(nonManoSources);
        etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
        assertTrue(fileContentHandler.containsFile(finalNonManoLocation));
    }

    @Test
    public void testMoveNonManoFileToArtifactFolderFileNotInFolder() throws IOException {
        Map<String, List<String>> nonManoSources = new HashMap<>();
        List<String> sources = new ArrayList<>();
        sources.add("test.xml");
        nonManoSources.put("foo", sources);
        FileContentHandler fileContentHandler = new FileContentHandler();
        fileContentHandler.addFile("test.xml", new byte[1]);
        Manifest manifest = mock(Manifest.class);
        when(manifest.getNonManoSources()).thenReturn(nonManoSources);
        etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
        assertFalse(fileContentHandler.containsFile(finalOtherNonManoLocation));
    }

    @Test
    public void testMoveNonManoFileToArtifactFolderNoMove() throws IOException {
        Map<String, List<String>> nonManoSources = new HashMap<>();
        List<String> sources = new ArrayList<>();
        sources.add(finalNonManoLocation);
        nonManoSources.put("Some", sources);
        FileContentHandler fileContentHandler = new FileContentHandler();
        fileContentHandler.addFile(finalNonManoLocation, new byte[1]);
        Manifest manifest = mock(Manifest.class);
        when(manifest.getNonManoSources()).thenReturn(nonManoSources);
        etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
        assertTrue(fileContentHandler.containsFile(finalNonManoLocation));
    }

    @Test
    public void testMoveNonManoFileToArtifactFolderMoveToKeyFolder() throws IOException {
        Map<String, List<String>> nonManoSources = new HashMap<>();
        List<String> sources = new ArrayList<>();
        sources.add("Artifacts/Deployment/test.xml");
        nonManoSources.put("Some", sources);
        FileContentHandler fileContentHandler = new FileContentHandler();
        fileContentHandler.addFile("Artifacts/Deployment/test.xml", new byte[1]);
        Manifest manifest = mock(Manifest.class);
        when(manifest.getNonManoSources()).thenReturn(nonManoSources);
        etsiService.moveNonManoFileToArtifactFolder(fileContentHandler, manifest);
        assertTrue(fileContentHandler.containsFile(finalNonManoLocation));
    }
}