2 * ============LICENSE_START=======================================================
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
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.model.operations.impl.util;
23 import com.google.gson.Gson;
24 import com.google.gson.JsonElement;
25 import com.google.gson.reflect.TypeToken;
26 import fj.data.Either;
27 import org.apache.commons.lang3.tuple.ImmutablePair;
28 import org.junit.Test;
29 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
30 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
31 import org.openecomp.sdc.be.model.DataTypeDefinition;
32 import org.openecomp.sdc.be.model.PropertyDefinition;
33 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
34 import org.openecomp.sdc.be.model.tosca.converters.ListConverter;
35 import org.openecomp.sdc.be.model.tosca.converters.MapConverter;
36 import org.openecomp.sdc.be.model.tosca.validators.DataTypeValidatorConverter;
37 import org.openecomp.sdc.be.model.tosca.validators.ListValidator;
38 import org.openecomp.sdc.be.model.tosca.validators.MapValidator;
39 import org.slf4j.Logger;
40 import org.slf4j.LoggerFactory;
42 import java.lang.reflect.Type;
45 import static org.junit.Assert.*;
47 public class DataTypeValidatorTest {
48 private static final Logger log = LoggerFactory.getLogger(DataTypeValidatorTest.class);
49 private static Gson gson = new Gson();
51 DataTypeValidatorConverter dataTypeValidator = DataTypeValidatorConverter.getInstance();
54 public void testDerivedFromPrimitiveEmptyValue() {
56 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
57 allDataTypes.put("integer", getPrimitiveDataType("integer"));
59 DataTypeDefinition fromIntegerType = buildDerivedFromIntegerType();
60 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate("", fromIntegerType,
63 assertTrue("check result is valid", validate.right.booleanValue());
64 assertNull("check value is the same as sent", validate.left);
66 validate = dataTypeValidator.validateAndUpdate(null, fromIntegerType, allDataTypes);
68 assertTrue("check result is valid", validate.right.booleanValue());
69 assertNull("check value is the same as sent", validate.left);
71 validate = dataTypeValidator.validateAndUpdate("88", fromIntegerType, allDataTypes);
73 assertTrue("check result is valid", validate.right.booleanValue());
74 assertEquals("check value is the same as sent", "88", validate.left.toString());
79 public void testCompositeWithParameterDerivedFromPrimitiveEmptyValue() {
81 DataTypeDefinition derivedFromIntegerType = buildDerivedFromIntegerType();
82 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
83 allDataTypes.put("myinteger", derivedFromIntegerType);
85 DataTypeDefinition personDataType = buildPersonDataType();
87 Person person = new Person("my address", 32);
88 String json = gson.toJson(person);
91 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, personDataType,
93 assertTrue("check valid value", validate.right.booleanValue());
95 person = new Person("my address", 32);
96 json = gson.toJson(person);
97 json = json.replace("32", "32a");
100 validate = dataTypeValidator.validateAndUpdate(json, personDataType, allDataTypes);
101 assertFalse("check valid value", validate.right.booleanValue());
106 public void testCompositeWithEmptyListValue() {
108 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
110 String[] strArr = {};
111 List<String> strList = Arrays.asList(strArr);
114 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, strList);
115 City mycity = new City("myadd<br><<br>", 55);
116 credential.setMycity(mycity);
118 String json = gson.toJson(credential);
121 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
122 DataTypeDefinition cityDataType = buildCityDataType();
123 allDataTypes.put("city", cityDataType);
125 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
127 assertTrue("check valid value", validate.right.booleanValue());
129 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
130 assertEquals("check empty list", 0, credentialRes.getMylist().size());
132 log.debug("Result is = {}", validate.left.toString());
137 public void testCompositeWithListNullValue() {
138 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
140 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
141 DataTypeDefinition cityDataType = buildCityDataType();
142 allDataTypes.put("city", cityDataType);
144 // Check list is NULL
145 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, null);
146 City mycity = new City("myadd<br><<br>", 55);
147 credential.setMycity(mycity);
149 String json = gson.toJson(credential);
151 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
153 assertTrue("check valid value", validate.right.booleanValue());
155 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
156 assertNull("check list is null", credentialRes.getMylist());
157 log.debug("Result is = {}", validate.left.toString());
162 public void testCompositeWithUserNullValue() {
163 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
165 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
166 DataTypeDefinition cityDataType = buildCityDataType();
167 allDataTypes.put("city", cityDataType);
169 // Check user is null
170 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, null, true, null);
171 City mycity = new City("myadd<br><<br>", 55);
172 credential.setMycity(mycity);
174 String json = gson.toJson(credential);
176 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
178 assertTrue("check valid value", validate.right.booleanValue());
180 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
181 assertNull("check list is null", credentialRes.getUser());
182 log.debug("Result is = {}", validate.left.toString());
186 public void testCompositeWithEmptyUserValue() {
188 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
190 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
191 DataTypeDefinition cityDataType = buildCityDataType();
192 allDataTypes.put("city", cityDataType);
193 // Check user is empty
194 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "", true, null);
195 City mycity = new City("myadd<br><<br>", 55);
196 credential.setMycity(mycity);
198 String json = gson.toJson(credential);
201 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
203 assertTrue("check valid value", validate.right.booleanValue());
205 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
206 assertNotNull("check list is not null", credentialRes.getUser());
207 assertEquals("check user is empty", "", credentialRes.getUser());
208 log.debug("Result is = {}", validate.left.toString());
213 public void testCompositeWithSumNullValue() {
214 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
216 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
217 DataTypeDefinition cityDataType = buildCityDataType();
218 allDataTypes.put("city", cityDataType);
220 // Check user is null
221 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
222 City mycity = new City("myadd<br><<br>", 55);
223 credential.setMycity(mycity);
225 String json = gson.toJson(credential);
227 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
229 assertTrue("check valid value", validate.right.booleanValue());
231 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
232 assertNull("check list is null", credentialRes.getSum());
233 log.debug("Result is = {}", validate.left.toString());
237 public void testInvalidJson() {
238 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
240 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
241 DataTypeDefinition cityDataType = buildCityDataType();
242 allDataTypes.put("city", cityDataType);
244 // Check user is null
245 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
246 City mycity = new City("myadd<br><<br>", 55);
247 credential.setMycity(mycity);
249 String json = gson.toJson(credential);
253 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
255 assertFalse("check valid value", validate.right.booleanValue());
260 public void testInvalidInnerValue() {
262 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
264 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
265 DataTypeDefinition cityDataType = buildCityDataType();
266 allDataTypes.put("city", cityDataType);
268 // Check user is null
269 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
270 City mycity = new City("myadd<br><<br>", 55);
271 credential.setMycity(mycity);
273 String json = gson.toJson(credential);
275 json = json.replace("55", "a55b");
277 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
279 assertFalse("check valid value", validate.right.booleanValue());
284 public void testInvalidInnerJson() {
286 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
288 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
289 DataTypeDefinition cityDataType = buildCityDataType();
290 allDataTypes.put("city", cityDataType);
292 // Check user is null
293 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
294 City mycity = new City("", null);
296 credential.setMycity(mycity);
298 String json = gson.toJson(credential);
300 json = json.replace("{\"address\":\"\"}", "scalar");
302 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
304 assertFalse("check valid value", validate.right.booleanValue());
309 public void testInvalidPropertyJson() {
311 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
313 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
314 DataTypeDefinition cityDataType = buildCityDataType();
315 allDataTypes.put("city", cityDataType);
317 // Check user is null
318 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
319 City mycity = new City("myadd<br><<br>", 55);
320 credential.setMycity(mycity);
322 String json = gson.toJson(credential);
324 json = json.replace("55", "a55b");
326 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
328 assertFalse("check valid value", validate.right.booleanValue());
333 public void testCompositeDataTypeWithInternalComposite() {
335 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
337 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
338 List<String> strList = Arrays.asList(strArr);
340 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, strList);
341 City mycity = new City("myadd<br><<br>", 55);
342 credential.setMycity(mycity);
344 String json = gson.toJson(credential);
346 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
347 DataTypeDefinition cityDataType = buildCityDataType();
348 allDataTypes.put("city", cityDataType);
350 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
352 assertTrue("check valid value", validate.right.booleanValue());
354 log.debug("Result is = {}", validate.left.toString());
359 public void testMapValidator() {
361 MapValidator validator = new MapValidator();
362 Gson gson = new Gson();
364 // 1 - Map<String,Integer> check OK
365 Map<String, Integer> map_1 = new HashMap<>();
366 map_1.put("key1", 2);
367 map_1.put("key2", 3);
368 String value = gson.toJson(map_1);
369 String innerType = "integer";
370 assertTrue("Test Map validation with inner integer type", validator.isValid(value, innerType, null));
372 // 2 - Map<String,Boolean> check OK
373 Map<String, Boolean> map_2 = new HashMap<>();
374 map_2.put("key1", true);
375 map_2.put("key2", false);
376 value = gson.toJson(map_2);
377 innerType = "boolean";
378 assertTrue("Test Map validation with inner boolean type", validator.isValid(value, innerType, null));
380 // 3 - give integer with quotes
381 innerType = "integer";
382 value = "{\"key1\":\"5\",\"key2\":\"7\"}";
383 assertTrue("Test Map validation with inner integer type, but qouted values",
384 validator.isValid(value, innerType, null));
386 // 4 - empty default value
389 assertTrue("Test Map validation with inner float type", validator.isValid(value, innerType, null));
392 // 5 - mismatch in data type
393 value = gson.toJson(map_1);
394 innerType = "boolean";
395 assertFalse("Test Map faulty validation with inner boolean type", validator.isValid(value, innerType, null));
396 // 6 - mismatch in data type
397 value = gson.toJson(map_2);
398 innerType = "integer";
399 assertFalse("Test Map faulty validation with inner integer type", validator.isValid(value, innerType, null));
404 public void testMapConverter() {
406 MapConverter converter = new MapConverter();
407 Gson gson = new Gson();
409 Map<String, String> map_1 = new HashMap<>();
410 Map<String, String> resMap_1 = new HashMap<>();
412 // 1 - check Spaces eliminated + html square brackets eliminated
413 map_1.put("key1", "<b>test</b>");
414 map_1.put("key2", " test");
415 resMap_1.put("key1", "test");
416 resMap_1.put("key2", " test");
417 String value = gson.toJson(map_1);
418 String expectedVal = gson.toJson(resMap_1);
419 String innerType = "string";
420 assertEquals("Test Map validation with inner string type", expectedVal,
421 converter.convert(value, innerType, null));
423 // 2 - float converter
425 value = "{\"key1\":0.4545,\"key2\":0.2f}";
426 expectedVal = "{\"key1\":0.4545,\"key2\":0.2}";
427 assertEquals("Test Map validation with inner float type", expectedVal,
428 converter.convert(value, innerType, null));
430 // 3 - check default empty value converter
434 assertEquals("Test Map validation with inner float type", expectedVal,
435 converter.convert(value, innerType, null));
438 // 3 - check default empty value converter
440 value = "{1345234556@#(";
442 assertEquals("Test Map validation with inner float type", expectedVal,
443 converter.convert(value, innerType, null));
448 public void testCompositeDataTypeWithMapComposite() {
450 DataTypeDefinition fileDataTypeDefinition = buildFileDataType();
451 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
452 DataTypeDefinition cityDataType = buildCityDataType();
453 allDataTypes.put("city", cityDataType);
455 MyFile myFile = new MyFile();
457 Map<String, City> attributes = new HashMap<>();
458 attributes.put("key1", new City("address1<br>", 11));
459 attributes.put("key2", new City("address2<br>", 22));
460 myFile.setAttributes(attributes);
462 String str = gson.toJson(myFile);
465 ImmutablePair<JsonElement, Boolean> convert = dataTypeValidator.validateAndUpdate(str, fileDataTypeDefinition,
468 assertTrue("check map converter succeed", convert.right);
470 JsonElement convertedValue = convert.left;
472 log.debug("{}", convertedValue);
473 MyFile fromJson = gson.fromJson(convertedValue, MyFile.class);
475 assertEquals("check age", 88, fromJson.getAge().intValue());
476 assertEquals("check address 1", "address1", fromJson.getAttributes().get("key1").getAddress());
477 assertEquals("check address 2", "address2", fromJson.getAttributes().get("key2").getAddress());
482 public void testMapConverterWithComplexInnerType() {
484 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
485 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
486 DataTypeDefinition cityDataType = buildCityDataType();
487 allDataTypes.put("city", cityDataType);
488 allDataTypes.put("credential", credentialDataTypeDefinition);
490 Gson gson = new Gson();
492 Map<String, Object> map_1 = new HashMap<>();
494 // 1 - check Spaces eliminated + html square brackets eliminated
496 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
497 List<String> strList = Arrays.asList(strArr);
498 Credential credential1 = new Credential("protocol;:,.\"<br>>", 5, "token_type", "token", null, "user", true,
500 City mycity1 = new City("myadd<br><<br>", 55);
501 credential1.setMycity(mycity1);
503 Credential credential2 = new Credential("protocol;:,.\"<br>>", 5, "token_type", "token", null, "user", true,
505 City mycity2 = new City("myadd<br><<br>", 66);
506 credential2.setMycity(mycity2);
508 map_1.put("key1", credential1);
509 map_1.put("key2", credential2);
511 String str = gson.toJson(map_1);
514 MapConverter mapConverter = new MapConverter();
515 Either<String, Boolean> convert = mapConverter.convertWithErrorResult(str, "credential", allDataTypes);
517 assertTrue("check map converter succeed", convert.isLeft());
519 String convertedValue = convert.left().value();
521 Type type = new TypeToken<Map<String, Credential>>() {
524 Map<String, Credential> fromJson = gson.fromJson(convertedValue, type);
526 Credential actualCredential1 = fromJson.get("key1");
527 assertEquals("check sum", 5, actualCredential1.getSum().intValue());
528 assertEquals("check protocol", "protocol;:,.\">", actualCredential1.getProtocol());
529 String[] convertedStrArr = { "aaa", "bbb", "cdcc" };
530 List<String> convertedStrList = Arrays.asList(convertedStrArr);
531 assertEquals("check list", convertedStrList, actualCredential1.getMylist());
533 assertEquals("check city address", "myadd<", actualCredential1.getMycity().getAddress());
534 assertEquals("check city address", 55, actualCredential1.getMycity().getAge().intValue());
536 Credential actualCredential2 = fromJson.get("key2");
537 assertEquals("check city address", 66, actualCredential2.getMycity().getAge().intValue());
542 public void testListConverterWithComplexInnerType() {
544 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
545 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
546 DataTypeDefinition cityDataType = buildCityDataType();
547 allDataTypes.put("city", cityDataType);
548 allDataTypes.put("credential", credentialDataTypeDefinition);
550 Gson gson = new Gson();
552 List<Object> list = buildListOf2CredentialObjects();
554 String str = gson.toJson(list);
557 ListConverter listConverter = new ListConverter();
559 Either<String, Boolean> convert = listConverter.convertWithErrorResult(str, "credential", allDataTypes);
561 assertTrue("check map converter succeed", convert.isLeft());
563 String convertedValue = convert.left().value();
565 validateListOfCredential(gson, convertedValue);
569 str = gson.toJson(list);
572 convert = listConverter.convertWithErrorResult(str, "credential", allDataTypes);
574 assertTrue("check map converter succeed", convert.isLeft());
576 validateListOfCredential(gson, convertedValue);
580 public void testListValidatorWithComplexInnerType() {
582 Map<String, DataTypeDefinition> allDataTypes = new HashMap<>();
583 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
584 DataTypeDefinition cityDataType = buildCityDataType();
585 allDataTypes.put("city", cityDataType);
586 allDataTypes.put("credential", credentialDataTypeDefinition);
588 Gson gson = new Gson();
590 List<Object> list = buildListOf2CredentialObjects();
592 String str = gson.toJson(list);
595 ListValidator listValidator = new ListValidator();
597 boolean isValid = listValidator.isValid(str, "credential", allDataTypes);
599 assertTrue("check valid value", isValid);
601 String badStr = str.replace("protocol", "protocol1");
603 isValid = listValidator.isValid(badStr, "credential", allDataTypes);
605 assertFalse("check valid value", isValid);
607 badStr = str.replace("55", "\"aa\"");
609 isValid = listValidator.isValid(badStr, "credential", allDataTypes);
611 assertFalse("check valid value", isValid);
615 private List<Object> buildListOf2CredentialObjects() {
616 List<Object> list = new ArrayList<>();
618 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
619 List<String> strList = Arrays.asList(strArr);
620 Credential credential1 = new Credential("protocol.,\":;<br>>", 5, "token_type", "token", null, "user", true,
622 City mycity1 = new City("myadd<br><<br>", 55);
623 credential1.setMycity(mycity1);
625 Credential credential2 = new Credential("protocol.,\":;<br>>", 5, "token_type", "token", null, "user", true,
627 City mycity2 = new City("myadd<br><<br>", 66);
628 credential2.setMycity(mycity2);
630 list.add(credential1);
631 list.add(credential2);
635 private void validateListOfCredential(Gson gson, String convertedValue) {
637 log.debug(convertedValue);
638 Type type = new TypeToken<List<Credential>>() {
641 List<Credential> fromJson = gson.fromJson(convertedValue, type);
643 assertEquals("check list size", 2, fromJson.size());
645 // Credential actualCredential1 = gson.fromJson(list.get(0).toString(),
646 // Credential.class);
647 Credential actualCredential1 = fromJson.get(0);
648 assertEquals("check sum", 5, actualCredential1.getSum().intValue());
649 assertEquals("check protocol", "protocol.,\":;>", actualCredential1.getProtocol());
650 String[] convertedStrArr = { "aaa", "bbb", "cdcc" };
651 List<String> convertedStrList = Arrays.asList(convertedStrArr);
652 assertEquals("check list", convertedStrList, actualCredential1.getMylist());
654 assertEquals("check city address", "myadd<", actualCredential1.getMycity().getAddress());
655 assertEquals("check city address", 55, actualCredential1.getMycity().getAge().intValue());
657 // Credential actualCredential2 = gson.fromJson(list.get(1).toString(),
658 // Credential.class);
659 Credential actualCredential2 = fromJson.get(1);
660 assertEquals("check city address", 66, actualCredential2.getMycity().getAge().intValue());
663 private DataTypeDefinition buildCredentialDataType() {
664 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
665 dataTypeDefinition.setName("datatype.1");
666 List<PropertyDefinition> properties = new ArrayList<>();
667 PropertyDefinition propertyDefinition1 = new PropertyDefinition();
668 propertyDefinition1.setName("sum");
669 propertyDefinition1.setType(ToscaPropertyType.INTEGER.getType());
670 PropertyDefinition propertyDefinition2 = new PropertyDefinition();
671 propertyDefinition2.setName("protocol");
672 propertyDefinition2.setType(ToscaPropertyType.STRING.getType());
673 PropertyDefinition propertyDefinition3 = new PropertyDefinition();
674 propertyDefinition3.setName("token_type");
675 propertyDefinition3.setType(ToscaPropertyType.STRING.getType());
676 PropertyDefinition propertyDefinition4 = new PropertyDefinition();
677 propertyDefinition4.setName("token");
678 propertyDefinition4.setType(ToscaPropertyType.STRING.getType());
679 PropertyDefinition propertyDefinition5 = new PropertyDefinition();
680 propertyDefinition5.setName("keys");
681 propertyDefinition5.setType(ToscaPropertyType.MAP.getType());
682 PropertyDefinition propertyDefinition6 = new PropertyDefinition();
683 propertyDefinition6.setName("mylist");
684 propertyDefinition6.setType(ToscaPropertyType.LIST.getType());
685 SchemaDefinition entrySchema = new SchemaDefinition();
686 PropertyDataDefinition property = new PropertyDataDefinition();
687 property.setType("string");
688 entrySchema.setProperty(property);
689 propertyDefinition6.setSchema(entrySchema);
690 PropertyDefinition propertyDefinition7 = new PropertyDefinition();
691 propertyDefinition7.setName("user");
692 propertyDefinition7.setType(ToscaPropertyType.STRING.getType());
693 PropertyDefinition propertyDefinition8 = new PropertyDefinition();
694 propertyDefinition8.setName("isMandatory");
695 propertyDefinition8.setType(ToscaPropertyType.BOOLEAN.getType());
697 PropertyDefinition propertyDefinition9 = new PropertyDefinition();
698 propertyDefinition9.setName("mycity");
699 propertyDefinition9.setType("city");
701 properties.add(propertyDefinition1);
702 properties.add(propertyDefinition2);
703 properties.add(propertyDefinition3);
704 properties.add(propertyDefinition4);
705 properties.add(propertyDefinition5);
706 properties.add(propertyDefinition6);
707 properties.add(propertyDefinition7);
708 properties.add(propertyDefinition8);
709 properties.add(propertyDefinition9);
711 dataTypeDefinition.setProperties(properties);
712 return dataTypeDefinition;
715 private static DataTypeDefinition buildCityDataType() {
716 DataTypeDefinition cityDataType = new DataTypeDefinition();
717 cityDataType.setName("city");
718 List<PropertyDefinition> cityProperties = new ArrayList<>();
719 PropertyDefinition cityPropertyDefinition1 = new PropertyDefinition();
720 cityPropertyDefinition1.setName("age");
721 cityPropertyDefinition1.setType(ToscaPropertyType.INTEGER.getType());
722 PropertyDefinition cityPropertyDefinition2 = new PropertyDefinition();
723 cityPropertyDefinition2.setName("address");
724 cityPropertyDefinition2.setType(ToscaPropertyType.STRING.getType());
726 cityProperties.add(cityPropertyDefinition1);
727 cityProperties.add(cityPropertyDefinition2);
729 cityDataType.setProperties(cityProperties);
733 private static DataTypeDefinition buildPersonDataType() {
734 DataTypeDefinition personDataType = new DataTypeDefinition();
735 personDataType.setName("person");
736 List<PropertyDefinition> personProperties = new ArrayList<>();
737 PropertyDefinition personPropertyDefinition1 = new PropertyDefinition();
738 personPropertyDefinition1.setName("age");
739 personPropertyDefinition1.setType("myinteger");
740 PropertyDefinition personPropertyDefinition2 = new PropertyDefinition();
741 personPropertyDefinition2.setName("address");
742 personPropertyDefinition2.setType(ToscaPropertyType.STRING.getType());
744 personProperties.add(personPropertyDefinition1);
745 personProperties.add(personPropertyDefinition2);
747 personDataType.setProperties(personProperties);
748 return personDataType;
751 private static DataTypeDefinition buildFileDataType() {
752 DataTypeDefinition fileDataType = new DataTypeDefinition();
753 fileDataType.setName("file");
754 List<PropertyDefinition> fileProperties = new ArrayList<>();
755 PropertyDefinition filePropertyDefinition1 = new PropertyDefinition();
756 filePropertyDefinition1.setName("age");
757 filePropertyDefinition1.setType("integer");
759 PropertyDefinition filePropertyDefinition2 = new PropertyDefinition();
760 filePropertyDefinition2.setName("attributes");
761 filePropertyDefinition2.setType(ToscaPropertyType.MAP.getType());
763 fileProperties.add(filePropertyDefinition1);
764 fileProperties.add(filePropertyDefinition2);
766 SchemaDefinition entrySchema = new SchemaDefinition();
767 PropertyDataDefinition property = new PropertyDataDefinition();
768 property.setType("city");
769 entrySchema.setProperty(property);
770 filePropertyDefinition2.setSchema(entrySchema);
772 fileDataType.setProperties(fileProperties);
776 private static DataTypeDefinition getPrimitiveDataType(String type) {
778 DataTypeDefinition derivedFrom = new DataTypeDefinition();
779 derivedFrom.setName(type);
785 private static DataTypeDefinition buildDerivedFromIntegerType() {
787 DataTypeDefinition derivedFrom = getPrimitiveDataType("integer");
789 DataTypeDefinition myIntegerDataType = new DataTypeDefinition();
790 myIntegerDataType.setDerivedFrom(derivedFrom);
792 myIntegerDataType.setName("myinteger");
794 return myIntegerDataType;
797 public static class MyFile {
801 Map<String, City> attributes;
803 public Integer getAge() {
807 public void setAge(Integer age) {
811 public Map<String, City> getAttributes() {
815 public void setAttributes(Map<String, City> attributes) {
816 this.attributes = attributes;
821 public static class City {
826 public City(String address, Integer age) {
828 this.address = address;
832 public String getAddress() {
836 public void setAddress(String address) {
837 this.address = address;
840 public Integer getAge() {
844 public void setAge(Integer age) {
850 public static class Person {
855 public Person(String address, Integer age) {
857 this.address = address;
861 public String getAddress() {
865 public void setAddress(String address) {
866 this.address = address;
869 public Integer getAge() {
873 public void setAge(Integer age) {
878 public String toString() {
879 return "Person [address=" + address + ", age=" + age + "]";
884 public static class Credential {
890 Map<String, String> keys;
896 public Credential(String protocol, Integer sum, String token_type, String token, Map<String, String> keys,
897 String user, Boolean isMandatory, List<String> mylist) {
899 this.protocol = protocol;
901 this.token_type = token_type;
905 this.isMandatory = isMandatory;
906 this.mylist = mylist;
909 public String getProtocol() {
913 public void setProtocol(String protocol) {
914 this.protocol = protocol;
917 public String getToken_type() {
921 public void setToken_type(String token_type) {
922 this.token_type = token_type;
925 public String getToken() {
929 public void setToken(String token) {
933 public Map<String, String> getKeys() {
937 public void setKeys(Map<String, String> keys) {
941 public String getUser() {
945 public void setUser(String user) {
949 public Boolean getIsMandatory() {
953 public void setIsMandatory(Boolean isMandatory) {
954 this.isMandatory = isMandatory;
957 public Integer getSum() {
961 public void setSum(Integer sum) {
965 public List<String> getMylist() {
969 public void setMylist(List<String> mylist) {
970 this.mylist = mylist;
973 public City getMycity() {
977 public void setMycity(City mycity) {
978 this.mycity = mycity;
982 public String toString() {
983 return "Credential [protocol=" + protocol + ", token_type=" + token_type + ", token=" + token + ", keys="
984 + keys + ", user=" + user + ", isMandatory=" + isMandatory + "]";