c1e33a8474b8f7fe517f82f137232a47c6197963
[sdc.git] / catalog-be / src / test / java / org / openecomp / sdc / be / datamodel / utils / PropertyValueConstraintValidationUtilTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
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.be.datamodel.utils;
22
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;
28
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;
39 import java.util.Map;
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;
59
60 class PropertyValueConstraintValidationUtilTest {
61
62         @Mock
63         ApplicationDataTypeCache applicationDataTypeCache;
64
65         @Mock
66         ToscaOperationFacade toscaOperationFacade;
67
68         @Spy
69         @InjectMocks
70         PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil;
71
72         private Map<String, DataTypeDefinition> dataTypeDefinitionMap;
73
74         @BeforeEach
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);
82
83                 createDataTypeMap();
84         }
85
86         @Test
87         void primitiveValueSuccessTest() {
88                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
89                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
90
91                 PropertyDefinition propertyDefinition = new PropertyDefinition();
92                 propertyDefinition.setType("integer");
93                 propertyDefinition.setValue("10");
94
95                 Either<Boolean, ResponseFormat> responseEither =
96                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
97                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
98
99                 assertTrue(responseEither.isLeft());
100         }
101
102         @Test
103         void primitiveValueFailTest() {
104                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
105                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
106
107                 PropertyDefinition propertyDefinition = new PropertyDefinition();
108                 propertyDefinition.setType("integer");
109                 propertyDefinition.setValue("abcd");
110
111                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
112                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
113
114                 assertTrue(responseEither.isRight());
115         }
116
117         @Test
118         void complexWithValidValueSuccessTest() {
119                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
120                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
121
122                 PropertyDefinition propertyDefinition = new PropertyDefinition();
123                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
124                 propertyDefinition.setValue("{\"prefixlen\":\"4\"}");
125
126                 Either<Boolean, ResponseFormat> responseEither =
127                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
128                                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
129
130                 assertTrue(responseEither.isLeft());
131         }
132
133         @Test
134         void complexWithValidValueFailTest() {
135                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
136                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
137
138                 PropertyDefinition propertyDefinition = new PropertyDefinition();
139                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
140                 propertyDefinition.setValue("{\"prefixlen\":\"5\"}");
141
142                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil
143                         .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
144
145                 assertTrue(responseEither.isRight());
146         }
147
148         @Test
149         void complexWithListWithPrimitiveValueSuccessTest() {
150                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
151                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
152
153                 PropertyDefinition propertyDefinition = new PropertyDefinition();
154                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
155                 propertyDefinition.setValue("{\"allocation_pools\":[\"slaac\"]}");
156
157                 Either<Boolean, ResponseFormat> responseEither =
158                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
159                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
160
161                 assertTrue(responseEither.isLeft());
162         }
163
164         @Test
165         void complexWithListWithPrimitiveValueFailTest() {
166                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
167                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
168
169                 PropertyDefinition propertyDefinition = new PropertyDefinition();
170                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
171                 propertyDefinition.setValue("{\"allocation_pools\":[\"value\"]}");
172
173                 Either<Boolean, ResponseFormat> responseEither =
174                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
175                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
176
177                 assertTrue(responseEither.isRight());
178         }
179
180         @Test
181         void complexWithMapWithPrimitiveValueSuccessTest() {
182                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
183                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
184
185                 PropertyDefinition propertyDefinition = new PropertyDefinition();
186                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
187                 propertyDefinition.setValue("{\"value_specs\":{\"key\":\"slaac\"}}");
188
189                 Either<Boolean, ResponseFormat> responseEither =
190                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
191                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
192
193                 assertTrue(responseEither.isLeft());
194         }
195
196         @Test
197         void complexWithMapWithPrimitiveValueFailTest() {
198                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
199                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
200
201                 PropertyDefinition propertyDefinition = new PropertyDefinition();
202                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
203                 propertyDefinition.setValue("{\"value_specs\":{\"key\":\"value\"}}");
204
205                 Either<Boolean, ResponseFormat> responseEither =
206                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
207                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
208
209                 assertTrue(responseEither.isRight());
210         }
211
212         @Test
213         void inputValidValueSuccessTest() {
214                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
215                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
216
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));
224
225                 Either<Boolean, ResponseFormat> responseEither =
226                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
227                                                 Collections.singletonList(inputDefinition), applicationDataTypeCache, null);
228
229                 assertTrue(responseEither.isLeft());
230         }
231
232         @Test
233         void inputValidValueFailTest() {
234                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
235                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
236
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));
243
244                 Either<Boolean, ResponseFormat> responseEither =
245                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
246                                                 Collections.singletonList(inputDefinition), applicationDataTypeCache, null);
247
248                 assertTrue(responseEither.isRight());
249         }
250
251         @Test
252         void serviceConsumptionValidValueSuccessTest() {
253                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
254                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
255
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");
260
261                 Either<Boolean, ResponseFormat> responseEither =
262                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
263                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
264
265                 assertTrue(responseEither.isLeft());
266         }
267
268         @Test
269         void listOfComplexSuccessTest() {
270                 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
271
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);
285
286                 Either<Boolean, ResponseFormat> responseEither =
287                         propertyValueConstraintValidationUtil
288                                 .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
289
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());
296         }
297
298         @Test
299         void listOfComplexSuccessTest1() {
300                 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
301
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);
321
322                 Either<Boolean, ResponseFormat> responseEither =
323                         propertyValueConstraintValidationUtil
324                                 .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
325
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());
332         }
333
334         @Test
335         void mapOfComplexSuccessTest() {
336                 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
337
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);
351
352                 Either<Boolean, ResponseFormat> responseEither =
353                         propertyValueConstraintValidationUtil.validatePropertyConstraints(
354                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
355
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());
362         }
363
364         @Test
365         void serviceConsumptionValidValueFailTest() {
366                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
367                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
368
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");
373
374                 Either<Boolean, ResponseFormat> responseEither =
375                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
376                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
377
378                 assertTrue(responseEither.isRight());
379         }
380
381         @Test
382         void bandwidthTypeValueSuccessTest(){
383                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
384                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
385
386                 PropertyDefinition propertyDefinition = new PropertyDefinition();
387                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
388                 propertyDefinition.setValue("{\"bandwidth_type\":\"guaranteed\"}");
389                 propertyDefinition.setName("bandwidth_type");
390
391                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
392                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
393                 assertTrue(responseEither.isLeft());
394         }
395
396         @Test
397         void bandwidthTypeValueFailTest(){
398                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
399                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
400
401                 PropertyDefinition propertyDefinition = new PropertyDefinition();
402                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
403                 propertyDefinition.setValue("{\"bandwidth_type\":\"incorrectValue\"}");
404                 propertyDefinition.setName("bandwidth_type");
405
406                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
407                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
408
409                 assertTrue(responseEither.isRight());
410         }
411
412         @Test
413         void bandwidthDownstreamValueSuccessTest(){
414                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
415                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
416
417                 PropertyDefinition propertyDefinition = new PropertyDefinition();
418                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
419                 propertyDefinition.setValue("{\"downstream\":\"128\"}");
420                 propertyDefinition.setName("downstream");
421
422                 Either<Boolean, ResponseFormat> responseEither =
423                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
424                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
425
426                 assertTrue(responseEither.isLeft());
427         }
428
429         @Test
430         void bandwidthDownstreamValueFailTest(){
431                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
432                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
433
434                 PropertyDefinition propertyDefinition = new PropertyDefinition();
435                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
436                 propertyDefinition.setValue("{\"downstream\":\"incorrectValue\"}");
437                 propertyDefinition.setName("downstream");
438
439                 Either<Boolean, ResponseFormat> responseEither =
440                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
441                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
442
443                 assertTrue(responseEither.isRight());
444         }
445
446         @Test
447         void bandwidthUpstreamValueSuccessTest(){
448                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
449                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
450
451                 PropertyDefinition propertyDefinition = new PropertyDefinition();
452                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
453                 propertyDefinition.setValue("{\"upstream\":\"128\"}");
454                 propertyDefinition.setName("upstream");
455
456                 Either<Boolean, ResponseFormat> responseEither =
457                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
458                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
459
460                 assertTrue(responseEither.isLeft());
461         }
462
463         @Test
464         void bandwidthUpstreamValueFailTest(){
465                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
466                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
467
468                 PropertyDefinition propertyDefinition = new PropertyDefinition();
469                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
470                 propertyDefinition.setValue("{\"upstream\":\"incorrectValue\"}");
471                 propertyDefinition.setName("upstream");
472
473                 Either<Boolean, ResponseFormat> responseEither =
474                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
475                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
476
477                 assertTrue(responseEither.isRight());
478         }
479
480         @Test
481         void bandwidthUnitsValueSuccessTest(){
482                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
483                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
484
485                 PropertyDefinition propertyDefinition = new PropertyDefinition();
486                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
487                 propertyDefinition.setValue("{\"units\":\"M\"}");
488                 propertyDefinition.setName("units");
489
490                 Either<Boolean, ResponseFormat> responseEither =
491                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
492                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
493
494                 assertTrue(responseEither.isLeft());
495         }
496
497         @Test
498         void bandwidthUnitsValueFailTest(){
499                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
500                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
501
502                 PropertyDefinition propertyDefinition = new PropertyDefinition();
503                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
504                 propertyDefinition.setValue("{\"units\":\"incorrectValue\"}");
505                 propertyDefinition.setName("units");
506
507                 Either<Boolean, ResponseFormat> responseEither =
508                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
509                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
510
511                 assertTrue(responseEither.isRight());
512         }
513
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();
519
520                 dataTypeDefinitionMap = gson.fromJson(readDataTypeDefinitionFile(), typeOfHashMap);
521
522                 DataTypeDefinition dataTypeDefinition = dataTypeDefinitionMap.get("org.openecomp.datatypes.heat.network"
523                                 + ".neutron.Subnet");
524
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();
535                         }
536                 }
537
538                 PropertyDefinition definition = new PropertyDefinition(mapProperty.getSchema().getProperty());
539                 definition.setConstraints(constraints);
540                 mapProperty.getSchema().setProperty(definition);
541
542                 definition = new PropertyDefinition(listProperty.getSchema().getProperty());
543                 definition.setConstraints(constraints);
544                 listProperty.getSchema().setProperty(definition);
545         }
546
547         private static String readDataTypeDefinitionFile() throws IOException {
548                 return Files.readString(Paths.get("src/test/resources/types/datatypes/constraintTest.json"));
549         }
550
551 }
552