update sdc to version 1.3.2
[sdc.git] / openecomp-be / backend / openecomp-sdc-vendor-software-product-manager / src / test / java / org / openecomp / sdc / vendorsoftwareproduct / services / schemagenerator / SchemaGeneratorTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.vendorsoftwareproduct.services.schemagenerator;
22
23 public class SchemaGeneratorTest {
24   /*
25
26   private static int getMinOfVmMax(JSONObject schemaJson) {
27     return schemaJson.getJSONObject("properties").getJSONObject("compute")
28         .getJSONObject("properties").getJSONObject("numOfVMs").getJSONObject("properties")
29         .getJSONObject("maximum").getInt("minimum");
30   }
31
32   private static JSONObject validateSchema(String schema) {
33     System.out.println(schema);
34     Assert.assertNotNull(schema);
35     Assert.assertTrue(JsonUtil.isValidJson(schema));
36     JSONObject schemaJson = new JSONObject(schema);
37     Assert.assertFalse(SchemaLoader.load(schemaJson) instanceof EmptySchema);
38     return schemaJson;
39   }
40
41   // TODO: 3/15/2017 fix and enable   //@Test
42   public void testGenerateVspQuestionnaire() {
43     String schema = SchemaGenerator
44         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.vsp, null);
45     validateSchema(schema);
46   }
47
48   @Test
49   public void testGenerateNetworkCompositionUpload() {
50     Network network = new Network();
51     network.setName("upload network1 name");
52     network.setDhcp(true);
53
54     NetworkCompositionSchemaInput input = new NetworkCompositionSchemaInput();
55     input.setManual(false);
56     input.setNetwork(network);
57
58     String schema = SchemaGenerator
59         .generate(SchemaTemplateContext.composition, CompositionEntityType.network, input);
60     validateSchema(schema);
61   }
62
63   @Test
64   public void testGenerateNetworkCompositionManual() {
65     NetworkCompositionSchemaInput input = new NetworkCompositionSchemaInput();
66     input.setManual(true);
67
68     String schema = SchemaGenerator
69         .generate(SchemaTemplateContext.composition, CompositionEntityType.network, input);
70
71     validateSchema(schema);
72   }
73
74   @Test
75   public void testGenerateComponentQuestionnaireWithoutInput() {
76     String schema = SchemaGenerator
77         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, null);
78     validateSchema(schema);
79   }
80
81   @Test
82   public void testGenerateComponentQuestionnaireWithMissingInput() {
83     ComponentQuestionnaireSchemaInput
84         input = new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
85         JsonUtil.json2Object("{\n" +
86             "  \"compute\": {\n" +
87             "    \"numOfVMs\": {\n" +
88             "      \"blabla\": 70\n" + // no minimum
89             "    }\n" +
90             "  }\n" +
91             "}", Map.class));
92     String schema = SchemaGenerator
93         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
94     JSONObject schemaJson = validateSchema(schema);
95     //Assert.assertEquals(getMinOfVmMax(schemaJson), 0);
96   }
97
98   @Test
99   public void testGenerateComponentQuestionnaireWithInvalidTypeInput() {
100     ComponentQuestionnaireSchemaInput input =
101         new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
102             JsonUtil.json2Object("{\n" +
103                 "  \"compute\": {\n" +
104                 "    \"numOfVMs\": {\n" +
105                 "      \"minimum\": \"some string instead of integer\"\n" +
106                 // invalid minimum - string
107                 "    }\n" +
108                 "  }\n" +
109                 "}", Map.class));
110     String schema = SchemaGenerator
111         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
112     JSONObject schemaJson = validateSchema(schema);
113     Assert.assertEquals(getMinOfVmMax(schemaJson), 0);
114   }
115
116   @Test
117   public void testGenerateComponentQuestionnaireWithInvalidRangeInput() {
118     ComponentQuestionnaireSchemaInput input =
119         new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
120             JsonUtil.json2Object("{\n" +
121                 "  \"compute\": {\n" +
122                 "    \"numOfVMs\": {\n" +
123                 "      \"minimum\": 150\n" + // invalid minimum - integer out of range (0-100)
124                 "    }\n" +
125                 "  }\n" +
126                 "}", Map.class));
127     String schema = SchemaGenerator
128         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
129     JSONObject schemaJson = validateSchema(schema);
130     Assert.assertEquals(getMinOfVmMax(schemaJson), 0);
131   }
132
133   @Test
134   public void testGenerateComponentQuestionnaireWithValidInput() {
135     ComponentQuestionnaireSchemaInput input =
136         new ComponentQuestionnaireSchemaInput(Arrays.asList("nic1", "nic2"),
137             JsonUtil.json2Object("{\n" +
138                 "  \"compute\": {\n" +
139                 "    \"numOfVMs\": {\n" +
140                 "      \"minimum\": 30\n" + // valid minimum - integer at the correct range (0-100)
141                 "    }\n" +
142                 "  }\n" +
143                 "}", Map.class));
144     String schema = SchemaGenerator
145         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.component, input);
146     JSONObject schemaJson = validateSchema(schema);
147     Assert.assertEquals(getMinOfVmMax(schemaJson), 30);
148   }
149
150   @Test
151   public void testGenerateNicQuestionnaire() {
152     String schema = SchemaGenerator
153         .generate(SchemaTemplateContext.questionnaire, CompositionEntityType.nic, null);
154     validateSchema(schema);
155   }
156
157   @Test
158   public void testGenerateComponentCompositionUpload() {
159     ComponentData component = new ComponentData();
160     component.setName("upload comp1 name");
161     component.setDescription("upload comp1 desc");
162
163     ComponentCompositionSchemaInput input = new ComponentCompositionSchemaInput();
164     input.setManual(false);
165     input.setComponent(component);
166
167     String schema = SchemaGenerator
168         .generate(SchemaTemplateContext.composition, CompositionEntityType.component, input);
169     validateSchema(schema);
170   }
171
172   @Test
173   public void testGenerateComponentCompositionManual() {
174     ComponentCompositionSchemaInput input = new ComponentCompositionSchemaInput();
175     input.setManual(true);
176
177     String schema = SchemaGenerator
178         .generate(SchemaTemplateContext.composition, CompositionEntityType.component, input);
179     validateSchema(schema);
180   }
181
182   @Test
183   public void testGenerateNicCompositionUpload() {
184     Nic nic = new Nic();
185     nic.setName("upload nic1 name");
186     nic.setDescription("upload nic1 desc");
187     nic.setNetworkId("upload nic1 networkId");
188     //nic.setNetworkName("upload nic1 networkName");
189     nic.setNetworkType(NetworkType.External);
190
191     NicCompositionSchemaInput input = new NicCompositionSchemaInput();
192     input.setManual(false);
193     input.setNic(nic);
194
195     String schema = SchemaGenerator
196         .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
197     validateSchema(schema);
198   }
199
200
201 //    @Test
202 //    public void testGenerateNicCompositionManualWithoutNetworkId() {
203 //        Nic nic = new Nic();
204 //        nic.setName("upload nic1 name");
205 //        nic.setDescription("upload nic1 desc");
206 //        //nic.setNetworkName("upload nic1 networkName");
207 //        nic.setNetworkType(NetworkType.External);
208 //
209 //        NicCompositionSchemaInput input = new NicCompositionSchemaInput();
210 //        input.setManual(true);
211 //        input.setNic(nic);
212 //
213 //        String schema = SchemaGenerator.generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
214 //        validateSchema(schema);
215 //    }
216
217   @Test
218   public void testGenerateNicCompositionUploadWithoutNetworkId() {
219     Nic nic = new Nic();
220     nic.setName("upload nic1 name");
221     nic.setDescription("upload nic1 desc");
222     //nic.setNetworkName("upload nic1 networkName");
223     nic.setNetworkType(NetworkType.External);
224
225     NicCompositionSchemaInput input = new NicCompositionSchemaInput();
226     input.setManual(false);
227     input.setNic(nic);
228
229     String schema = SchemaGenerator
230         .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
231     validateSchema(schema);
232   }
233
234   @Test
235   public void testGenerateNicCompositionManual() {Nic nic = new Nic();
236     nic.setName("upload nic1 name");
237     nic.setDescription("upload nic1 desc");
238     nic.setNetworkType(NetworkType.Internal);
239     NicCompositionSchemaInput input = new NicCompositionSchemaInput();
240
241     input.setManual(true);
242     input.setNetworkIds(
243         Arrays.asList("manual networkId1", "manual networkId2", "manual networkId3"));
244     input.setNic(nic);
245     String schema = SchemaGenerator
246         .generate(SchemaTemplateContext.composition, CompositionEntityType.nic, input);
247     validateSchema(schema);
248   }
249   */
250 }