Fix VFC map or list property update
[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.operations.impl.PropertyOperation;
57 import org.openecomp.sdc.exception.ResponseFormat;
58
59 class PropertyValueConstraintValidationUtilTest {
60
61         @Mock
62         ApplicationDataTypeCache applicationDataTypeCache;
63
64         @Spy
65         @InjectMocks
66         PropertyValueConstraintValidationUtil propertyValueConstraintValidationUtil;
67
68         private Map<String, DataTypeDefinition> dataTypeDefinitionMap;
69
70         @BeforeEach
71         void init() throws IOException {
72                 MockitoAnnotations.openMocks(this);
73                 ResponseFormatManager responseFormatManagerMock = mock(ResponseFormatManager.class);
74                 when(responseFormatManagerMock.getResponseFormat(any())).thenReturn(new ResponseFormat());
75                 when(responseFormatManagerMock.getResponseFormat(any(), any())).thenReturn(new ResponseFormat());
76                 when(responseFormatManagerMock.getResponseFormat(any(), any(), any())).thenReturn(new ResponseFormat());
77                 when(propertyValueConstraintValidationUtil.getResponseFormatManager()).thenReturn(responseFormatManagerMock);
78
79                 createDataTypeMap();
80         }
81
82         @Test
83         void primitiveValueSuccessTest() {
84                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
85                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
86
87                 PropertyDefinition propertyDefinition = new PropertyDefinition();
88                 propertyDefinition.setType("integer");
89                 propertyDefinition.setValue("10");
90
91                 Either<Boolean, ResponseFormat> responseEither =
92                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
93                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
94
95                 assertTrue(responseEither.isLeft());
96         }
97
98         @Test
99         void primitiveValueFailTest() {
100                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
101                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
102
103                 PropertyDefinition propertyDefinition = new PropertyDefinition();
104                 propertyDefinition.setType("integer");
105                 propertyDefinition.setValue("abcd");
106
107                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
108                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
109
110                 assertTrue(responseEither.isRight());
111         }
112
113         @Test
114         void complexWithValidValueSuccessTest() {
115                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
116                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
117
118                 PropertyDefinition propertyDefinition = new PropertyDefinition();
119                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
120                 propertyDefinition.setValue("{\"prefixlen\":\"4\"}");
121
122                 Either<Boolean, ResponseFormat> responseEither =
123                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
124                                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
125
126                 assertTrue(responseEither.isLeft());
127         }
128
129         @Test
130         void complexWithValidValueFailTest() {
131                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
132                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
133
134                 PropertyDefinition propertyDefinition = new PropertyDefinition();
135                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
136                 propertyDefinition.setValue("{\"prefixlen\":\"5\"}");
137
138                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil
139                         .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
140
141                 assertTrue(responseEither.isRight());
142         }
143
144         @Test
145         void complexWithListWithPrimitiveValueSuccessTest() {
146                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
147                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
148
149                 PropertyDefinition propertyDefinition = new PropertyDefinition();
150                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
151                 propertyDefinition.setValue("{\"allocation_pools\":[\"slaac\"]}");
152
153                 Either<Boolean, ResponseFormat> responseEither =
154                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
155                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
156
157                 assertTrue(responseEither.isLeft());
158         }
159
160         @Test
161         void complexWithListWithPrimitiveValueFailTest() {
162                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
163                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
164
165                 PropertyDefinition propertyDefinition = new PropertyDefinition();
166                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
167                 propertyDefinition.setValue("{\"allocation_pools\":[\"value\"]}");
168
169                 Either<Boolean, ResponseFormat> responseEither =
170                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
171                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
172
173                 assertTrue(responseEither.isRight());
174         }
175
176         @Test
177         void complexWithMapWithPrimitiveValueSuccessTest() {
178                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
179                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
180
181                 PropertyDefinition propertyDefinition = new PropertyDefinition();
182                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
183                 propertyDefinition.setValue("{\"value_specs\":{\"key\":\"slaac\"}}");
184
185                 Either<Boolean, ResponseFormat> responseEither =
186                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
187                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
188
189                 assertTrue(responseEither.isLeft());
190         }
191
192         @Test
193         void complexWithMapWithPrimitiveValueFailTest() {
194                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
195                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
196
197                 PropertyDefinition propertyDefinition = new PropertyDefinition();
198                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
199                 propertyDefinition.setValue("{\"value_specs\":{\"key\":\"value\"}}");
200
201                 Either<Boolean, ResponseFormat> responseEither =
202                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
203                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
204
205                 assertTrue(responseEither.isRight());
206         }
207
208         @Test
209         void inputValidValueSuccessTest() {
210                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
211                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
212
213                 InputDefinition inputDefinition = new InputDefinition();
214                 inputDefinition.setInputPath("propetyName#ipv6_ra_mode");
215                 inputDefinition.setDefaultValue("slaac");
216                 inputDefinition.setType("string");
217                 ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
218                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
219                 inputDefinition.setProperties(Collections.singletonList(propertyDefinition));
220
221                 Either<Boolean, ResponseFormat> responseEither =
222                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
223                                                 Collections.singletonList(inputDefinition), applicationDataTypeCache, null);
224
225                 assertTrue(responseEither.isLeft());
226         }
227
228         @Test
229         void inputValidValueFailTest() {
230                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
231                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
232
233                 InputDefinition inputDefinition = new InputDefinition();
234                 inputDefinition.setInputPath("propetyName#ipv6_ra_mode");
235                 inputDefinition.setDefaultValue("incorrectValue");
236                 ComponentInstanceProperty propertyDefinition = new ComponentInstanceProperty();
237                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
238                 inputDefinition.setProperties(Collections.singletonList(propertyDefinition));
239
240                 Either<Boolean, ResponseFormat> responseEither =
241                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
242                                                 Collections.singletonList(inputDefinition), applicationDataTypeCache, null);
243
244                 assertTrue(responseEither.isRight());
245         }
246
247         @Test
248         void serviceConsumptionValidValueSuccessTest() {
249                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
250                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
251
252                 PropertyDefinition propertyDefinition = new PropertyDefinition();
253                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
254                 propertyDefinition.setValue("{\"ipv6_ra_mode\":\"slaac\"}");
255                 propertyDefinition.setName("ipv6_ra_mode");
256
257                 Either<Boolean, ResponseFormat> responseEither =
258                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
259                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
260
261                 assertTrue(responseEither.isLeft());
262         }
263
264         @Test
265         void listOfComplexSuccessTest() {
266                 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
267
268                 final var propertyDefinition = new PropertyDefinition();
269                 final String type = "list";
270                 propertyDefinition.setType(type);
271                 final SchemaDefinition schemaDefinition = new SchemaDefinition();
272                 final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
273                 final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
274                 schemaProperty.setType(schemaType);
275                 schemaDefinition.setProperty(schemaProperty);
276                 propertyDefinition.setSchema(schemaDefinition);
277                 final String value = "[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}]";
278                 propertyDefinition.setValue(value);
279                 final String name = "listOfComplex";
280                 propertyDefinition.setName(name);
281
282                 Either<Boolean, ResponseFormat> responseEither =
283                         propertyValueConstraintValidationUtil
284                                 .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
285
286                 assertTrue(responseEither.isLeft());
287                 //original object values should not be changed
288                 assertEquals(name, propertyDefinition.getName());
289                 assertEquals(type, propertyDefinition.getType());
290                 assertEquals(value, propertyDefinition.getValue());
291                 assertEquals(schemaType, propertyDefinition.getSchemaType());
292         }
293
294         @Test
295         void listOfComplexSuccessTest1() {
296                 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
297
298                 final var propertyDefinition = new PropertyDefinition();
299                 final String type = "list";
300                 propertyDefinition.setType(type);
301                 final String listSchemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
302                 final PropertyDataDefinition listSchemaProperty = new PropertyDataDefinition();
303                 listSchemaProperty.setType(listSchemaType);
304                 final SchemaDefinition listSchemaDefinition = new SchemaDefinition();
305                 listSchemaDefinition.setProperty(listSchemaProperty);
306                 final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
307                 schemaProperty.setSchema(listSchemaDefinition);
308                 final String schemaType = "list";
309                 schemaProperty.setType(schemaType);
310                 final SchemaDefinition schemaDefinition = new SchemaDefinition();
311                 schemaDefinition.setProperty(schemaProperty);
312                 propertyDefinition.setSchema(schemaDefinition);
313                 final String value = "[[{\"ipv6_address_mode\": \"dhcpv6-stateful\"}, {\"ipv6_address_mode\": \"dhcpv6-stateless\"}], [{\"ipv6_address_mode\": \"dhcpv6-stateful\"}]]";
314                 propertyDefinition.setValue(value);
315                 final String name = "listOfComplex";
316                 propertyDefinition.setName(name);
317
318                 Either<Boolean, ResponseFormat> responseEither =
319                         propertyValueConstraintValidationUtil
320                                 .validatePropertyConstraints(Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
321
322                 assertTrue(responseEither.isLeft());
323                 //original object values should not be changed
324                 assertEquals(name, propertyDefinition.getName());
325                 assertEquals(type, propertyDefinition.getType());
326                 assertEquals(value, propertyDefinition.getValue());
327                 assertEquals(schemaType, propertyDefinition.getSchemaType());
328         }
329
330         @Test
331         void mapOfComplexSuccessTest() {
332                 when(applicationDataTypeCache.getAll(null)).thenReturn(Either.left(dataTypeDefinitionMap));
333
334                 final var propertyDefinition = new PropertyDefinition();
335                 final String type = "map";
336                 propertyDefinition.setType(type);
337                 final SchemaDefinition schemaDefinition = new SchemaDefinition();
338                 final PropertyDataDefinition schemaProperty = new PropertyDataDefinition();
339                 final String schemaType = "org.openecomp.datatypes.heat.network.neutron.Subnet";
340                 schemaProperty.setType(schemaType);
341                 schemaDefinition.setProperty(schemaProperty);
342                 propertyDefinition.setSchema(schemaDefinition);
343                 final String value = "{\"key1\": {\"ipv6_address_mode\": \"dhcpv6-stateful\"}, \"key2\": {\"ipv6_address_mode\": \"dhcpv6-stateless\"}}";
344                 propertyDefinition.setValue(value);
345                 final String name = "mapOfComplex";
346                 propertyDefinition.setName(name);
347
348                 Either<Boolean, ResponseFormat> responseEither =
349                         propertyValueConstraintValidationUtil.validatePropertyConstraints(
350                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
351
352                 assertTrue(responseEither.isLeft());
353                 //original object values should not be changed
354                 assertEquals(name, propertyDefinition.getName());
355                 assertEquals(type, propertyDefinition.getType());
356                 assertEquals(value, propertyDefinition.getValue());
357                 assertEquals(schemaType, propertyDefinition.getSchemaType());
358         }
359
360         @Test
361         void serviceConsumptionValidValueFailTest() {
362                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
363                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
364
365                 PropertyDefinition propertyDefinition = new PropertyDefinition();
366                 propertyDefinition.setType("org.openecomp.datatypes.heat.network.neutron.Subnet");
367                 propertyDefinition.setValue("{\"ipv6_ra_mode\":\"incorrectValue\"}");
368                 propertyDefinition.setName("ipv6_ra_mode");
369
370                 Either<Boolean, ResponseFormat> responseEither =
371                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
372                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
373
374                 assertTrue(responseEither.isRight());
375         }
376
377         @Test
378         void bandwidthTypeValueSuccessTest(){
379                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
380                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
381
382                 PropertyDefinition propertyDefinition = new PropertyDefinition();
383                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
384                 propertyDefinition.setValue("{\"bandwidth_type\":\"guaranteed\"}");
385                 propertyDefinition.setName("bandwidth_type");
386
387                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
388                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
389                 assertTrue(responseEither.isLeft());
390         }
391
392         @Test
393         void bandwidthTypeValueFailTest(){
394                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
395                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
396
397                 PropertyDefinition propertyDefinition = new PropertyDefinition();
398                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
399                 propertyDefinition.setValue("{\"bandwidth_type\":\"incorrectValue\"}");
400                 propertyDefinition.setName("bandwidth_type");
401
402                 Either<Boolean, ResponseFormat> responseEither = propertyValueConstraintValidationUtil.validatePropertyConstraints(
403                         Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
404
405                 assertTrue(responseEither.isRight());
406         }
407
408         @Test
409         void bandwidthDownstreamValueSuccessTest(){
410                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
411                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
412
413                 PropertyDefinition propertyDefinition = new PropertyDefinition();
414                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
415                 propertyDefinition.setValue("{\"downstream\":\"128\"}");
416                 propertyDefinition.setName("downstream");
417
418                 Either<Boolean, ResponseFormat> responseEither =
419                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
420                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
421
422                 assertTrue(responseEither.isLeft());
423         }
424
425         @Test
426         void bandwidthDownstreamValueFailTest(){
427                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
428                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
429
430                 PropertyDefinition propertyDefinition = new PropertyDefinition();
431                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
432                 propertyDefinition.setValue("{\"downstream\":\"incorrectValue\"}");
433                 propertyDefinition.setName("downstream");
434
435                 Either<Boolean, ResponseFormat> responseEither =
436                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
437                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
438
439                 assertTrue(responseEither.isRight());
440         }
441
442         @Test
443         void bandwidthUpstreamValueSuccessTest(){
444                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
445                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
446
447                 PropertyDefinition propertyDefinition = new PropertyDefinition();
448                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
449                 propertyDefinition.setValue("{\"upstream\":\"128\"}");
450                 propertyDefinition.setName("upstream");
451
452                 Either<Boolean, ResponseFormat> responseEither =
453                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
454                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
455
456                 assertTrue(responseEither.isLeft());
457         }
458
459         @Test
460         void bandwidthUpstreamValueFailTest(){
461                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
462                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
463
464                 PropertyDefinition propertyDefinition = new PropertyDefinition();
465                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
466                 propertyDefinition.setValue("{\"upstream\":\"incorrectValue\"}");
467                 propertyDefinition.setName("upstream");
468
469                 Either<Boolean, ResponseFormat> responseEither =
470                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
471                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
472
473                 assertTrue(responseEither.isRight());
474         }
475
476         @Test
477         void bandwidthUnitsValueSuccessTest(){
478                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
479                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
480
481                 PropertyDefinition propertyDefinition = new PropertyDefinition();
482                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
483                 propertyDefinition.setValue("{\"units\":\"M\"}");
484                 propertyDefinition.setName("units");
485
486                 Either<Boolean, ResponseFormat> responseEither =
487                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
488                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
489
490                 assertTrue(responseEither.isLeft());
491         }
492
493         @Test
494         void bandwidthUnitsValueFailTest(){
495                 Either<Map<String, DataTypeDefinition>, JanusGraphOperationStatus> either = Either.left(dataTypeDefinitionMap);
496                 when(applicationDataTypeCache.getAll(null)).thenReturn(either);
497
498                 PropertyDefinition propertyDefinition = new PropertyDefinition();
499                 propertyDefinition.setType("onap.datatypes.partner.bandwidth");
500                 propertyDefinition.setValue("{\"units\":\"incorrectValue\"}");
501                 propertyDefinition.setName("units");
502
503                 Either<Boolean, ResponseFormat> responseEither =
504                                 propertyValueConstraintValidationUtil.validatePropertyConstraints(
505                                                 Collections.singletonList(propertyDefinition), applicationDataTypeCache, null);
506
507                 assertTrue(responseEither.isRight());
508         }
509
510         private void createDataTypeMap() throws IOException {
511                 Type constraintType = new TypeToken<PropertyConstraint>() {}.getType();
512                 Type typeOfHashMap = new TypeToken<Map<String, DataTypeDefinition>>() { }.getType();
513                 Gson gson = new GsonBuilder().registerTypeAdapter(constraintType,
514                                 new PropertyOperation.PropertyConstraintDeserialiser()).create();
515
516                 dataTypeDefinitionMap = gson.fromJson(readDataTypeDefinitionFile(), typeOfHashMap);
517
518                 DataTypeDefinition dataTypeDefinition = dataTypeDefinitionMap.get("org.openecomp.datatypes.heat.network"
519                                 + ".neutron.Subnet");
520
521                 PropertyDefinition mapProperty = null;
522                 PropertyDefinition listProperty = null;
523                 List<PropertyConstraint> constraints = null;
524                 for (PropertyDefinition propertyDefinition : dataTypeDefinition.getProperties()) {
525                         if ("value_specs".equals(propertyDefinition.getName())) {
526                                 mapProperty = propertyDefinition;
527                         } else if ("allocation_pools".equals(propertyDefinition.getName())) {
528                                 listProperty = propertyDefinition;
529                         } else if ("ipv6_ra_mode".equals(propertyDefinition.getName())) {
530                                 constraints = propertyDefinition.getConstraints();
531                         }
532                 }
533
534                 PropertyDefinition definition = new PropertyDefinition(mapProperty.getSchema().getProperty());
535                 definition.setConstraints(constraints);
536                 mapProperty.getSchema().setProperty(definition);
537
538                 definition = new PropertyDefinition(listProperty.getSchema().getProperty());
539                 definition.setConstraints(constraints);
540                 listProperty.getSchema().setProperty(definition);
541         }
542
543         private static String readDataTypeDefinitionFile() throws IOException {
544                 return Files.readString(Paths.get("src/test/resources/types/datatypes/constraintTest.json"));
545         }
546
547 }
548