aboutsummaryrefslogtreecommitdiffstats
path: root/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/tests/YamlTest.java
blob: 812b4459e5c208eeaa8c4a7a0ff57b38ecb762ad (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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*-
 * ============LICENSE_START=======================================================
 * ONAP - SO
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.mso.asdc.client.tests;


import static org.junit.Assert.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.io.IOUtils;
import org.junit.Test;

import org.openecomp.mso.asdc.installer.heat.VfResourceInstaller;
import org.openecomp.mso.asdc.util.YamlEditor;
import org.openecomp.mso.db.catalog.beans.HeatTemplateParam;


public class YamlTest {
    @Test
    public void getYamlResourceTypeTestList() throws Exception {

        InputStream input = new FileInputStream(new File("src/test/resources/resource-examples/simpleTest.yaml"));
        YamlEditor decoder = new YamlEditor(IOUtils.toByteArray(input));
        List<String> typeList = decoder.getYamlNestedFileResourceTypeList();

        assertTrue(typeList.size() == 1 && typeList.get(0).equals("file:///my_test.yaml"));
    }

    @Test
    public void getParameterListTest() throws Exception {

        InputStream input = new FileInputStream(new File("src/test/resources/resource-examples/simpleTest.yaml"));
        YamlEditor decoder = new YamlEditor(IOUtils.toByteArray(input));
        Set<HeatTemplateParam> paramSet = decoder.getParameterList("123456");

        assertTrue(paramSet.size() == 5);

        for (HeatTemplateParam param : paramSet) {
            if ("ip_port_snmp_manager".equals(param.getParamName()) || "cor_direct_net_name".equals(param.getParamName()) || "cor_direct_net_RT".equals(param.getParamName())) {

                assertTrue(param.isRequired() == false);
            } else {

                assertTrue(param.isRequired() == true);
            }

            assertTrue("string".equals(param.getParamType()));
        }
    }

    @Test
    public void addParameterListWhenEmptyTest() throws Exception {

        InputStream input = new FileInputStream(new File("src/test/resources/resource-examples/simpleTestWithoutParam.yaml"));
        YamlEditor decoder = new YamlEditor(IOUtils.toByteArray(input));

        Set<HeatTemplateParam> newParamSet = new HashSet<>();

        HeatTemplateParam heatParam1 = new HeatTemplateParam();
        heatParam1.setHeatTemplateArtifactUuid("1");
        heatParam1.setParamName("testos1");
        heatParam1.setParamType("string");

        HeatTemplateParam heatParam2 = new HeatTemplateParam();
        heatParam2.setHeatTemplateArtifactUuid("2");
        heatParam2.setParamName("testos2");
        heatParam2.setParamType("number");

        newParamSet.add(heatParam1);
        newParamSet.add(heatParam2);

        decoder.addParameterList(newParamSet);

        Set<HeatTemplateParam> paramSet = decoder.getParameterList("123456");
        assertTrue(paramSet.size() == 2);

        assertTrue(decoder.encode().contains("testos1"));
        assertTrue(decoder.encode().contains("string"));
        assertTrue(decoder.encode().contains("testos2"));
        assertTrue(decoder.encode().contains("number"));
    }

    @Test
    public void addParameterListTest() throws Exception {

        InputStream input = new FileInputStream(new File("src/test/resources/resource-examples/simpleTest.yaml"));
        YamlEditor decoder = new YamlEditor(IOUtils.toByteArray(input));

        Set<HeatTemplateParam> newParamSet = new HashSet<>();

        HeatTemplateParam heatParam1 = new HeatTemplateParam();
        heatParam1.setHeatTemplateArtifactUuid("1");
        heatParam1.setParamName("testos1");
        heatParam1.setParamType("string");

        HeatTemplateParam heatParam2 = new HeatTemplateParam();
        heatParam2.setHeatTemplateArtifactUuid("2");
        heatParam2.setParamName("testos2");
        heatParam2.setParamType("number");

        newParamSet.add(heatParam1);
        newParamSet.add(heatParam2);

        decoder.addParameterList(newParamSet);

        Set<HeatTemplateParam> paramSet = decoder.getParameterList("123456");

        assertTrue(paramSet.size() == 7);

        Boolean check1 = Boolean.FALSE;
        Boolean check2 = Boolean.FALSE;

        for (HeatTemplateParam param : paramSet) {
            if ("ip_port_snmp_manager".equals(param.getParamName()) || "cor_direct_net_name".equals(param.getParamName()) || "cor_direct_net_RT".equals(param.getParamName())) {
                assertFalse(param.isRequired());
            } else {
                assertTrue(param.isRequired());
            }

            if ("testos1".equals(param.getParamName()) && "string".equals(param.getParamType())) {
                check1 = Boolean.TRUE;
            }

            if ("testos2".equals(param.getParamName()) && "number".equals(param.getParamType())) {
                check2 = Boolean.TRUE;
            }

        }

        assertTrue(check1);
        assertTrue(check2);
    }

    @Test
    public void VfResourceInstallerTest() throws Exception {

        assertTrue("mon ami toto, est dans le bois: toto ici".equals(VfResourceInstaller.verifyTheFilePrefixInString("mon ami toto, est dans le bois: toto ici", "toto")));
        assertTrue("mon ami toto, est dans le bois: toto ici".equals(VfResourceInstaller.verifyTheFilePrefixInString("mon ami file:///toto, est dans le bois: file:///toto ici", "toto")));
        assertTrue("mon ami toto, est dans le bois: toto ici".equals(VfResourceInstaller.verifyTheFilePrefixInString("mon ami file:///toto, est dans le bois: toto ici", "toto")));
        assertTrue("mon ami toto, est dans le bois: toto ici".equals(VfResourceInstaller.verifyTheFilePrefixInString("mon ami toto, est dans le bois: file:///toto ici", "toto")));

    }
}