2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.datamodel.utils;
23 import static org.junit.jupiter.api.Assertions.assertEquals;
24 import static org.junit.jupiter.api.Assertions.assertTrue;
25 import static org.mockito.ArgumentMatchers.any;
26 import static org.mockito.Mockito.mock;
27 import static org.mockito.Mockito.when;
29 import com.google.gson.Gson;
30 import com.google.gson.GsonBuilder;
31 import com.google.gson.reflect.TypeToken;
32 import fj.data.Either;
33 import java.io.IOException;
34 import java.lang.reflect.Type;
35 import java.nio.file.Files;
36 import java.nio.file.Paths;
37 import java.util.Collections;
38 import java.util.List;
40 import org.junit.jupiter.api.BeforeEach;
41 import org.junit.jupiter.api.Test;
42 import org.mockito.InjectMocks;
43 import org.mockito.Mock;
44 import org.mockito.MockitoAnnotations;
45 import org.mockito.Spy;
46 import org.openecomp.sdc.be.components.impl.ResponseFormatManager;
47 import org.openecomp.sdc.be.dao.janusgraph.JanusGraphOperationStatus;
48 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
49 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
50 import org.openecomp.sdc.be.model.ComponentInstanceProperty;
51 import org.openecomp.sdc.be.model.DataTypeDefinition;
52 import org.openecomp.sdc.be.model.InputDefinition;
53 import org.openecomp.sdc.be.model.PropertyConstraint;
54 import org.openecomp.sdc.be.model.PropertyDefinition;
55 import org.openecomp.sdc.be.model.cache.ApplicationDataTypeCache;
56 import org.openecomp.sdc.be.model.jsonjanusgraph.operations.ToscaOperationFacade;
57 import org.openecomp.sdc.be.model.operations.impl.PropertyOperation;
58 import org.openecomp.sdc.exception.ResponseFormat;
60 class PropertyValueConstraintValidationUtilTest {
63 ApplicationDataTypeCache applicationDataTypeCache;
66 ToscaOperationFacade toscaOperationFacade;
70 PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil;
72 private Map<String, DataTypeDefinition> dataTypeDefinitionMap;
75 void init() throws IOException {
76 MockitoAnnotations.openMocks(this);
77 ResponseFormatManager responseFormatManagerMock = mock(ResponseFormatManager.class);
78 when(responseFormatManagerMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
79 when(responseFormatManagerMock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
80 when(responseFormatManagerMock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
81 when(propertyValueConstraintValidationUtil.getResponseFormatManager()).thenReturn(responseFormatManagerMock);
87 void primitiveValueSuccessTest() {
88 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
89 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
91 PropertyDefinition propertyDefinition = new PropertyDefinition();
92 propertyDefinition.setType("integer");
93 propertyDefinition.setValue("10");
95 Either<Boolean, ResponseFormat> responseEither =
96 propertyValueConstraintValidationUtil.validatePropertyConstraints(
97 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
99 assertTrue(responseEither.isLeft());
103 void primitiveValueFailTest() {
104 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
105 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
107 PropertyDefinition propertyDefinition = new PropertyDefinition();
108 propertyDefinition.setType("integer");
109 propertyDefinition.setValue("abcd");
111 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
112 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
114 assertTrue(responseEither.isRight());
118 void complexWithValidValueSuccessTest() {
119 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
120 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
122 PropertyDefinition propertyDefinition = new PropertyDefinition();
123 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
124 propertyDefinition.setValue("{\"prefixlen\":\"4\"}");
126 Either<Boolean, ResponseFormat> responseEither =
127 propertyValueConstraintValidationUtil.validatePropertyConstraints(
128 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
130 assertTrue(responseEither.isLeft());
134 void complexWithValidValueFailTest() {
135 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
136 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
138 PropertyDefinition propertyDefinition = new PropertyDefinition();
139 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
140 propertyDefinition.setValue("{\"prefixlen\":\"5\"}");
142 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil
143 .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
145 assertTrue(responseEither.isRight());
149 void complexWithListWithPrimitiveValueSuccessTest() {
150 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
151 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
153 PropertyDefinition propertyDefinition = new PropertyDefinition();
154 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
155 propertyDefinition.setValue("{\"allocation_pools\":[\"slaac\"]}");
157 Either<Boolean, ResponseFormat> responseEither =
158 propertyValueConstraintValidationUtil.validatePropertyConstraints(
159 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
161 assertTrue(responseEither.isLeft());
165 void complexWithListWithPrimitiveValueFailTest() {
166 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
167 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
169 PropertyDefinition propertyDefinition = new PropertyDefinition();
170 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
171 propertyDefinition.setValue("{\"allocation_pools\":[\"value\"]}");
173 Either<Boolean, ResponseFormat> responseEither =
174 propertyValueConstraintValidationUtil.validatePropertyConstraints(
175 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
177 assertTrue(responseEither.isRight());
181 void complexWithMapWithPrimitiveValueSuccessTest() {
182 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
183 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
185 PropertyDefinition propertyDefinition = new PropertyDefinition();
186 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
187 propertyDefinition.setValue("{\"value_specs\":{\"key\":\"slaac\"}}");
189 Either<Boolean, ResponseFormat> responseEither =
190 propertyValueConstraintValidationUtil.validatePropertyConstraints(
191 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
193 assertTrue(responseEither.isLeft());
197 void complexWithMapWithPrimitiveValueFailTest() {
198 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
199 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
201 PropertyDefinition propertyDefinition = new PropertyDefinition();
202 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
203 propertyDefinition.setValue("{\"value_specs\":{\"key\":\"value\"}}");
205 Either<Boolean, ResponseFormat> responseEither =
206 propertyValueConstraintValidationUtil.validatePropertyConstraints(
207 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
209 assertTrue(responseEither.isRight());
213 void inputValidValueSuccessTest() {
214 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
215 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
217 InputDefinition inputDefinition = new InputDefinition();
218 inputDefinition.setInputPath("propetyName#ipv6_ra_mode");
219 inputDefinition.setDefaultValue("slaac");
220 inputDefinition.setType("string");
221 ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
222 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
223 inputDefinition.setProperties(Collections.singletonList(propertyDefinition));
225 Either<Boolean, ResponseFormat> responseEither =
226 propertyValueConstraintValidationUtil.validatePropertyConstraints(
227 Collections.singletonList(inputDefinition), applicationDataTypeCache, null);
229 assertTrue(responseEither.isLeft());
233 void inputValidValueFailTest() {
234 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
235 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
237 InputDefinition inputDefinition = new InputDefinition();
238 inputDefinition.setInputPath("propetyName#ipv6_ra_mode");
239 inputDefinition.setDefaultValue("incorrectValue");
240 ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
241 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
242 inputDefinition.setProperties(Collections.singletonList(propertyDefinition));
244 Either<Boolean, ResponseFormat> responseEither =
245 propertyValueConstraintValidationUtil.validatePropertyConstraints(
246 Collections.singletonList(inputDefinition), applicationDataTypeCache, null);
248 assertTrue(responseEither.isRight());
252 void serviceConsumptionValidValueSuccessTest() {
253 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
254 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
256 PropertyDefinition propertyDefinition = new PropertyDefinition();
257 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
258 propertyDefinition.setValue("{\"ipv6_ra_mode\":\"slaac\"}");
259 propertyDefinition.setName("ipv6_ra_mode");
261 Either<Boolean, ResponseFormat> responseEither =
262 propertyValueConstraintValidationUtil.validatePropertyConstraints(
263 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
265 assertTrue(responseEither.isLeft());
269 void listOfComplexSuccessTest() {
270 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
272 final var propertyDefinition = new PropertyDefinition();
273 final String type = "list";
274 propertyDefinition.setType(type);
275 final SchemaDefinition schemaDefinition = new SchemaDefinition();
276 final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
277 final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
278 schemaProperty.setType(schemaType);
279 schemaDefinition.setProperty(schemaProperty);
280 propertyDefinition.setSchema(schemaDefinition);
281 final String value = "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}]";
282 propertyDefinition.setValue(value);
283 final String name = "listOfComplex";
284 propertyDefinition.setName(name);
286 Either<Boolean, ResponseFormat> responseEither =
287 propertyValueConstraintValidationUtil
288 .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
290 assertTrue(responseEither.isLeft());
291 //original object values should not be changed
292 assertEquals(name, propertyDefinition.getName());
293 assertEquals(type, propertyDefinition.getType());
294 assertEquals(value, propertyDefinition.getValue());
295 assertEquals(schemaType, propertyDefinition.getSchemaType());
299 void listOfComplexSuccessTest1() {
300 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
302 final var propertyDefinition = new PropertyDefinition();
303 final String type = "list";
304 propertyDefinition.setType(type);
305 final String listSchemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
306 final PropertyDataDefinition listSchemaProperty = new PropertyDataDefinition();
307 listSchemaProperty.setType(listSchemaType);
308 final SchemaDefinition listSchemaDefinition = new SchemaDefinition();
309 listSchemaDefinition.setProperty(listSchemaProperty);
310 final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
311 schemaProperty.setSchema(listSchemaDefinition);
312 final String schemaType = "list";
313 schemaProperty.setType(schemaType);
314 final SchemaDefinition schemaDefinition = new SchemaDefinition();
315 schemaDefinition.setProperty(schemaProperty);
316 propertyDefinition.setSchema(schemaDefinition);
317 final String value = "[[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}], [{\"ipv6_address_mode\": \"dhcpv6-stateful\"}]]";
318 propertyDefinition.setValue(value);
319 final String name = "listOfComplex";
320 propertyDefinition.setName(name);
322 Either<Boolean, ResponseFormat> responseEither =
323 propertyValueConstraintValidationUtil
324 .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
326 assertTrue(responseEither.isLeft());
327 //original object values should not be changed
328 assertEquals(name, propertyDefinition.getName());
329 assertEquals(type, propertyDefinition.getType());
330 assertEquals(value, propertyDefinition.getValue());
331 assertEquals(schemaType, propertyDefinition.getSchemaType());
335 void mapOfComplexSuccessTest() {
336 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
338 final var propertyDefinition = new PropertyDefinition();
339 final String type = "map";
340 propertyDefinition.setType(type);
341 final SchemaDefinition schemaDefinition = new SchemaDefinition();
342 final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
343 final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
344 schemaProperty.setType(schemaType);
345 schemaDefinition.setProperty(schemaProperty);
346 propertyDefinition.setSchema(schemaDefinition);
347 final String value = "{\"key1\": {\"ipv6_address_mode\": \"dhcpv6-stateful\"}, \"key2\": {\"ipv6_address_mode\": \"dhcpv6-stateless\"}}";
348 propertyDefinition.setValue(value);
349 final String name = "mapOfComplex";
350 propertyDefinition.setName(name);
352 Either<Boolean, ResponseFormat> responseEither =
353 propertyValueConstraintValidationUtil.validatePropertyConstraints(
354 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
356 assertTrue(responseEither.isLeft());
357 //original object values should not be changed
358 assertEquals(name, propertyDefinition.getName());
359 assertEquals(type, propertyDefinition.getType());
360 assertEquals(value, propertyDefinition.getValue());
361 assertEquals(schemaType, propertyDefinition.getSchemaType());
365 void serviceConsumptionValidValueFailTest() {
366 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
367 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
369 PropertyDefinition propertyDefinition = new PropertyDefinition();
370 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
371 propertyDefinition.setValue("{\"ipv6_ra_mode\":\"incorrectValue\"}");
372 propertyDefinition.setName("ipv6_ra_mode");
374 Either<Boolean, ResponseFormat> responseEither =
375 propertyValueConstraintValidationUtil.validatePropertyConstraints(
376 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
378 assertTrue(responseEither.isRight());
382 void bandwidthTypeValueSuccessTest(){
383 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
384 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
386 PropertyDefinition propertyDefinition = new PropertyDefinition();
387 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
388 propertyDefinition.setValue("{\"bandwidth_type\":\"guaranteed\"}");
389 propertyDefinition.setName("bandwidth_type");
391 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
392 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
393 assertTrue(responseEither.isLeft());
397 void bandwidthTypeValueFailTest(){
398 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
399 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
401 PropertyDefinition propertyDefinition = new PropertyDefinition();
402 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
403 propertyDefinition.setValue("{\"bandwidth_type\":\"incorrectValue\"}");
404 propertyDefinition.setName("bandwidth_type");
406 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
407 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
409 assertTrue(responseEither.isRight());
413 void bandwidthDownstreamValueSuccessTest(){
414 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
415 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
417 PropertyDefinition propertyDefinition = new PropertyDefinition();
418 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
419 propertyDefinition.setValue("{\"downstream\":\"128\"}");
420 propertyDefinition.setName("downstream");
422 Either<Boolean, ResponseFormat> responseEither =
423 propertyValueConstraintValidationUtil.validatePropertyConstraints(
424 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
426 assertTrue(responseEither.isLeft());
430 void bandwidthDownstreamValueFailTest(){
431 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
432 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
434 PropertyDefinition propertyDefinition = new PropertyDefinition();
435 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
436 propertyDefinition.setValue("{\"downstream\":\"incorrectValue\"}");
437 propertyDefinition.setName("downstream");
439 Either<Boolean, ResponseFormat> responseEither =
440 propertyValueConstraintValidationUtil.validatePropertyConstraints(
441 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
443 assertTrue(responseEither.isRight());
447 void bandwidthUpstreamValueSuccessTest(){
448 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
449 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
451 PropertyDefinition propertyDefinition = new PropertyDefinition();
452 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
453 propertyDefinition.setValue("{\"upstream\":\"128\"}");
454 propertyDefinition.setName("upstream");
456 Either<Boolean, ResponseFormat> responseEither =
457 propertyValueConstraintValidationUtil.validatePropertyConstraints(
458 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
460 assertTrue(responseEither.isLeft());
464 void bandwidthUpstreamValueFailTest(){
465 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
466 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
468 PropertyDefinition propertyDefinition = new PropertyDefinition();
469 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
470 propertyDefinition.setValue("{\"upstream\":\"incorrectValue\"}");
471 propertyDefinition.setName("upstream");
473 Either<Boolean, ResponseFormat> responseEither =
474 propertyValueConstraintValidationUtil.validatePropertyConstraints(
475 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
477 assertTrue(responseEither.isRight());
481 void bandwidthUnitsValueSuccessTest(){
482 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
483 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
485 PropertyDefinition propertyDefinition = new PropertyDefinition();
486 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
487 propertyDefinition.setValue("{\"units\":\"M\"}");
488 propertyDefinition.setName("units");
490 Either<Boolean, ResponseFormat> responseEither =
491 propertyValueConstraintValidationUtil.validatePropertyConstraints(
492 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
494 assertTrue(responseEither.isLeft());
498 void bandwidthUnitsValueFailTest(){
499 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
500 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
502 PropertyDefinition propertyDefinition = new PropertyDefinition();
503 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
504 propertyDefinition.setValue("{\"units\":\"incorrectValue\"}");
505 propertyDefinition.setName("units");
507 Either<Boolean, ResponseFormat> responseEither =
508 propertyValueConstraintValidationUtil.validatePropertyConstraints(
509 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
511 assertTrue(responseEither.isRight());
514 private void createDataTypeMap() throws IOException {
515 Type constraintType = new TypeToken<PropertyConstraint>() {}.getType();
516 Type typeOfHashMap = new TypeToken<Map<String, DataTypeDefinition>>() { }.getType();
517 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType,
518 new PropertyOperation.PropertyConstraintDeserialiser()).create();
520 dataTypeDefinitionMap = gson.fromJson(readDataTypeDefinitionFile(), typeOfHashMap);
522 DataTypeDefinition dataTypeDefinition = dataTypeDefinitionMap.get("org.openecomp.datatypes.heat.network"
523 + ".neutron.Subnet");
525 PropertyDefinition mapProperty = null;
526 PropertyDefinition listProperty = null;
527 List<PropertyConstraint> constraints = null;
528 for (PropertyDefinition propertyDefinition : dataTypeDefinition.getProperties()) {
529 if ("value_specs".equals(propertyDefinition.getName())) {
530 mapProperty = propertyDefinition;
531 } else if ("allocation_pools".equals(propertyDefinition.getName())) {
532 listProperty = propertyDefinition;
533 } else if ("ipv6_ra_mode".equals(propertyDefinition.getName())) {
534 constraints = propertyDefinition.getConstraints();
538 PropertyDefinition definition = new PropertyDefinition(mapProperty.getSchema().getProperty());
539 definition.setConstraints(constraints);
540 mapProperty.getSchema().setProperty(definition);
542 definition = new PropertyDefinition(listProperty.getSchema().getProperty());
543 definition.setConstraints(constraints);
544 listProperty.getSchema().setProperty(definition);
547 private static String readDataTypeDefinitionFile() throws IOException {
548 return Files.readString(Paths.get("src/test/resources/types/datatypes/constraintTest.json"));