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 static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertTrue;
29 import java.lang.reflect.Type;
30 import java.util.ArrayList;
31 import java.util.Arrays;
32 import java.util.HashMap;
33 import java.util.List;
36 import org.apache.commons.lang3.tuple.ImmutablePair;
37 import org.junit.Test;
38 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
39 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
40 import org.openecomp.sdc.be.model.DataTypeDefinition;
41 import org.openecomp.sdc.be.model.PropertyDefinition;
42 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
43 import org.openecomp.sdc.be.model.tosca.converters.ListConverter;
44 import org.openecomp.sdc.be.model.tosca.converters.MapConverter;
45 import org.openecomp.sdc.be.model.tosca.validators.DataTypeValidatorConverter;
46 import org.openecomp.sdc.be.model.tosca.validators.ListValidator;
47 import org.openecomp.sdc.be.model.tosca.validators.MapValidator;
48 import org.slf4j.Logger;
49 import org.slf4j.LoggerFactory;
51 import com.google.gson.Gson;
52 import com.google.gson.JsonElement;
53 import com.google.gson.reflect.TypeToken;
55 import fj.data.Either;
57 public class DataTypeValidatorTest {
58 private static Logger log = LoggerFactory.getLogger(DataTypeValidatorTest.class.getName());
59 private static Gson gson = new Gson();
61 DataTypeValidatorConverter dataTypeValidator = DataTypeValidatorConverter.getInstance();
64 public void testDerivedFromPrimitiveEmptyValue() {
66 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
67 allDataTypes.put("integer", getPrimitiveDataType("integer"));
69 DataTypeDefinition fromIntegerType = buildDerivedFromIntegerType();
70 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate("", fromIntegerType,
73 assertTrue("check result is valid", validate.right.booleanValue());
74 assertEquals("check value is the same as sent", null, validate.left);
76 validate = dataTypeValidator.validateAndUpdate(null, fromIntegerType, allDataTypes);
78 assertTrue("check result is valid", validate.right.booleanValue());
79 assertEquals("check value is the same as sent", null, validate.left);
81 validate = dataTypeValidator.validateAndUpdate("88", fromIntegerType, allDataTypes);
83 assertTrue("check result is valid", validate.right.booleanValue());
84 assertEquals("check value is the same as sent", "88", validate.left.toString());
89 public void testCompositeWithParameterDerivedFromPrimitiveEmptyValue() {
91 DataTypeDefinition derivedFromIntegerType = buildDerivedFromIntegerType();
92 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
93 allDataTypes.put("myinteger", derivedFromIntegerType);
95 DataTypeDefinition personDataType = buildPersonDataType();
97 Person person = new Person("my address", 32);
98 String json = gson.toJson(person);
101 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, personDataType,
103 assertTrue("check valid value", validate.right.booleanValue());
105 person = new Person("my address", 32);
106 json = gson.toJson(person);
107 json = json.replace("32", "32a");
110 validate = dataTypeValidator.validateAndUpdate(json, personDataType, allDataTypes);
111 assertFalse("check valid value", validate.right.booleanValue());
116 public void testCompositeWithEmptyListValue() {
118 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
120 String[] strArr = {};
121 List<String> strList = Arrays.asList(strArr);
124 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, strList);
125 City mycity = new City("myadd<br><<br>", 55);
126 credential.setMycity(mycity);
128 String json = gson.toJson(credential);
131 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
132 DataTypeDefinition cityDataType = buildCityDataType();
133 allDataTypes.put("city", cityDataType);
135 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
137 assertTrue("check valid value", validate.right.booleanValue());
139 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
140 assertEquals("check empty list", 0, credentialRes.getMylist().size());
142 log.debug("Result is = {}", validate.left.toString());
147 public void testCompositeWithListNullValue() {
148 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
150 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
151 DataTypeDefinition cityDataType = buildCityDataType();
152 allDataTypes.put("city", cityDataType);
154 // Check list is NULL
155 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, null);
156 City mycity = new City("myadd<br><<br>", 55);
157 credential.setMycity(mycity);
159 String json = gson.toJson(credential);
161 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
163 assertTrue("check valid value", validate.right.booleanValue());
165 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
166 assertNull("check list is null", credentialRes.getMylist());
167 log.debug("Result is = {}", validate.left.toString());
172 public void testCompositeWithUserNullValue() {
173 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
175 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
176 DataTypeDefinition cityDataType = buildCityDataType();
177 allDataTypes.put("city", cityDataType);
179 // Check user is null
180 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, null, true, null);
181 City mycity = new City("myadd<br><<br>", 55);
182 credential.setMycity(mycity);
184 String json = gson.toJson(credential);
186 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
188 assertTrue("check valid value", validate.right.booleanValue());
190 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
191 assertNull("check list is null", credentialRes.getUser());
192 log.debug("Result is = {}", validate.left.toString());
196 public void testCompositeWithEmptyUserValue() {
198 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
200 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
201 DataTypeDefinition cityDataType = buildCityDataType();
202 allDataTypes.put("city", cityDataType);
203 // Check user is empty
204 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "", true, null);
205 City mycity = new City("myadd<br><<br>", 55);
206 credential.setMycity(mycity);
208 String json = gson.toJson(credential);
211 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
213 assertTrue("check valid value", validate.right.booleanValue());
215 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
216 assertNotNull("check list is not null", credentialRes.getUser());
217 assertEquals("check user is empty", "", credentialRes.getUser());
218 log.debug("Result is = {}", validate.left.toString());
223 public void testCompositeWithSumNullValue() {
224 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
226 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
227 DataTypeDefinition cityDataType = buildCityDataType();
228 allDataTypes.put("city", cityDataType);
230 // Check user is null
231 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
232 City mycity = new City("myadd<br><<br>", 55);
233 credential.setMycity(mycity);
235 String json = gson.toJson(credential);
237 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
239 assertTrue("check valid value", validate.right.booleanValue());
241 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
242 assertNull("check list is null", credentialRes.getSum());
243 log.debug("Result is = {}", validate.left.toString());
247 public void testInvalidJson() {
248 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
250 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
251 DataTypeDefinition cityDataType = buildCityDataType();
252 allDataTypes.put("city", cityDataType);
254 // Check user is null
255 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
256 City mycity = new City("myadd<br><<br>", 55);
257 credential.setMycity(mycity);
259 String json = gson.toJson(credential);
263 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
265 assertFalse("check valid value", validate.right.booleanValue());
270 public void testInvalidInnerValue() {
272 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
274 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
275 DataTypeDefinition cityDataType = buildCityDataType();
276 allDataTypes.put("city", cityDataType);
278 // Check user is null
279 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
280 City mycity = new City("myadd<br><<br>", 55);
281 credential.setMycity(mycity);
283 String json = gson.toJson(credential);
285 json = json.replace("55", "a55b");
287 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
289 assertFalse("check valid value", validate.right.booleanValue());
294 public void testInvalidInnerJson() {
296 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
298 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
299 DataTypeDefinition cityDataType = buildCityDataType();
300 allDataTypes.put("city", cityDataType);
302 // Check user is null
303 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
304 City mycity = new City("", null);
306 credential.setMycity(mycity);
308 String json = gson.toJson(credential);
310 json = json.replace("{\"address\":\"\"}", "scalar");
312 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
314 assertFalse("check valid value", validate.right.booleanValue());
319 public void testInvalidPropertyJson() {
321 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
323 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
324 DataTypeDefinition cityDataType = buildCityDataType();
325 allDataTypes.put("city", cityDataType);
327 // Check user is null
328 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
329 City mycity = new City("myadd<br><<br>", 55);
330 credential.setMycity(mycity);
332 String json = gson.toJson(credential);
334 json = json.replace("55", "a55b");
336 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
338 assertFalse("check valid value", validate.right.booleanValue());
343 public void testCompositeDataTypeWithInternalComposite() {
345 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
347 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
348 List<String> strList = Arrays.asList(strArr);
350 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, strList);
351 City mycity = new City("myadd<br><<br>", 55);
352 credential.setMycity(mycity);
354 String json = gson.toJson(credential);
356 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
357 DataTypeDefinition cityDataType = buildCityDataType();
358 allDataTypes.put("city", cityDataType);
360 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
362 assertTrue("check valid value", validate.right.booleanValue());
364 log.debug("Result is = {}", validate.left.toString());
369 public void testMapValidator() {
371 MapValidator validator = new MapValidator();
372 Gson gson = new Gson();
374 // 1 - Map<String,Integer> check OK
375 Map<String, Integer> map_1 = new HashMap<>();
376 map_1.put("key1", 2);
377 map_1.put("key2", 3);
378 String value = gson.toJson(map_1);
379 String innerType = "integer";
380 assertTrue("Test Map validation with inner integer type", validator.isValid(value, innerType, null));
382 // 2 - Map<String,Boolean> check OK
383 Map<String, Boolean> map_2 = new HashMap<>();
384 map_2.put("key1", true);
385 map_2.put("key2", false);
386 value = gson.toJson(map_2);
387 innerType = "boolean";
388 assertTrue("Test Map validation with inner boolean type", validator.isValid(value, innerType, null));
390 // 3 - give integer with quotes
391 innerType = "integer";
392 value = "{\"key1\":\"5\",\"key2\":\"7\"}";
393 assertTrue("Test Map validation with inner integer type, but qouted values",
394 validator.isValid(value, innerType, null));
396 // 4 - empty default value
399 assertTrue("Test Map validation with inner float type", validator.isValid(value, innerType, null));
402 // 5 - mismatch in data type
403 value = gson.toJson(map_1);
404 innerType = "boolean";
405 assertFalse("Test Map faulty validation with inner boolean type", validator.isValid(value, innerType, null));
406 // 6 - mismatch in data type
407 value = gson.toJson(map_2);
408 innerType = "integer";
409 assertFalse("Test Map faulty validation with inner integer type", validator.isValid(value, innerType, null));
414 public void testMapConverter() {
416 MapConverter converter = new MapConverter();
417 Gson gson = new Gson();
419 Map<String, String> map_1 = new HashMap<>();
420 Map<String, String> resMap_1 = new HashMap<>();
422 // 1 - check Spaces eliminated + html square brackets eliminated
423 map_1.put("key1", "<b>test</b>");
424 map_1.put("key2", " test");
425 resMap_1.put("key1", "test");
426 resMap_1.put("key2", " test");
427 String value = gson.toJson(map_1);
428 String expectedVal = gson.toJson(resMap_1);
429 String innerType = "string";
430 assertEquals("Test Map validation with inner string type", expectedVal,
431 converter.convert(value, innerType, null));
433 // 2 - float converter
435 value = "{\"key1\":0.4545,\"key2\":0.2f}";
436 expectedVal = "{\"key1\":0.4545,\"key2\":0.2}";
437 assertEquals("Test Map validation with inner float type", expectedVal,
438 converter.convert(value, innerType, null));
440 // 3 - check default empty value converter
444 assertEquals("Test Map validation with inner float type", expectedVal,
445 converter.convert(value, innerType, null));
448 // 3 - check default empty value converter
450 value = "{1345234556@#(";
452 assertEquals("Test Map validation with inner float type", expectedVal,
453 converter.convert(value, innerType, null));
458 public void testCompositeDataTypeWithMapComposite() {
460 DataTypeDefinition fileDataTypeDefinition = buildFileDataType();
461 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
462 DataTypeDefinition cityDataType = buildCityDataType();
463 allDataTypes.put("city", cityDataType);
465 MyFile myFile = new MyFile();
467 Map<String, City> attributes = new HashMap<>();
468 attributes.put("key1", new City("address1<br>", 11));
469 attributes.put("key2", new City("address2<br>", 22));
470 myFile.setAttributes(attributes);
472 String str = gson.toJson(myFile);
475 ImmutablePair<JsonElement, Boolean> convert = dataTypeValidator.validateAndUpdate(str, fileDataTypeDefinition,
478 assertTrue("check map converter succeed", convert.right);
480 JsonElement convertedValue = convert.left;
482 log.debug("{}", convertedValue);
483 MyFile fromJson = gson.fromJson(convertedValue, MyFile.class);
485 assertEquals("check age", 88, fromJson.getAge().intValue());
486 assertEquals("check address 1", "address1", fromJson.getAttributes().get("key1").getAddress());
487 assertEquals("check address 2", "address2", fromJson.getAttributes().get("key2").getAddress());
492 public void testMapConverterWithComplexInnerType() {
494 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
495 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
496 DataTypeDefinition cityDataType = buildCityDataType();
497 allDataTypes.put("city", cityDataType);
498 allDataTypes.put("credential", credentialDataTypeDefinition);
500 Gson gson = new Gson();
502 Map<String, Object> map_1 = new HashMap<>();
504 // 1 - check Spaces eliminated + html square brackets eliminated
506 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
507 List<String> strList = Arrays.asList(strArr);
508 Credential credential1 = new Credential("protocol;:,.\"<br>>", 5, "token_type", "token", null, "user", true,
510 City mycity1 = new City("myadd<br><<br>", 55);
511 credential1.setMycity(mycity1);
513 Credential credential2 = new Credential("protocol;:,.\"<br>>", 5, "token_type", "token", null, "user", true,
515 City mycity2 = new City("myadd<br><<br>", 66);
516 credential2.setMycity(mycity2);
518 map_1.put("key1", credential1);
519 map_1.put("key2", credential2);
521 String str = gson.toJson(map_1);
524 MapConverter mapConverter = new MapConverter();
525 Either<String, Boolean> convert = mapConverter.convertWithErrorResult(str, "credential", allDataTypes);
527 assertTrue("check map converter succeed", convert.isLeft());
529 String convertedValue = convert.left().value();
531 Type type = new TypeToken<Map<String, Credential>>() {
534 Map<String, Credential> fromJson = gson.fromJson(convertedValue, type);
536 Credential actualCredential1 = fromJson.get("key1");
537 assertEquals("check sum", 5, actualCredential1.getSum().intValue());
538 assertEquals("check protocol", "protocol;:,.\">", actualCredential1.getProtocol());
539 String[] convertedStrArr = { "aaa", "bbb", "cdcc" };
540 List<String> convertedStrList = Arrays.asList(convertedStrArr);
541 assertEquals("check list", convertedStrList, actualCredential1.getMylist());
543 assertEquals("check city address", "myadd<", actualCredential1.getMycity().getAddress());
544 assertEquals("check city address", 55, actualCredential1.getMycity().getAge().intValue());
546 Credential actualCredential2 = fromJson.get("key2");
547 assertEquals("check city address", 66, actualCredential2.getMycity().getAge().intValue());
552 public void testListConverterWithComplexInnerType() {
554 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
555 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
556 DataTypeDefinition cityDataType = buildCityDataType();
557 allDataTypes.put("city", cityDataType);
558 allDataTypes.put("credential", credentialDataTypeDefinition);
560 Gson gson = new Gson();
562 List<Object> list = buildListOf2CredentialObjects();
564 String str = gson.toJson(list);
567 ListConverter listConverter = new ListConverter();
569 Either<String, Boolean> convert = listConverter.convertWithErrorResult(str, "credential", allDataTypes);
571 assertTrue("check map converter succeed", convert.isLeft());
573 String convertedValue = convert.left().value();
575 validateListOfCredential(gson, convertedValue);
579 str = gson.toJson(list);
582 convert = listConverter.convertWithErrorResult(str, "credential", allDataTypes);
584 assertTrue("check map converter succeed", convert.isLeft());
586 validateListOfCredential(gson, convertedValue);
590 public void testListValidatorWithComplexInnerType() {
592 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
593 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
594 DataTypeDefinition cityDataType = buildCityDataType();
595 allDataTypes.put("city", cityDataType);
596 allDataTypes.put("credential", credentialDataTypeDefinition);
598 Gson gson = new Gson();
600 List<Object> list = buildListOf2CredentialObjects();
602 String str = gson.toJson(list);
605 ListValidator listValidator = new ListValidator();
607 boolean isValid = listValidator.isValid(str, "credential", allDataTypes);
609 assertTrue("check valid value", isValid);
611 String badStr = str.replace("protocol", "protocol1");
613 isValid = listValidator.isValid(badStr, "credential", allDataTypes);
615 assertFalse("check valid value", isValid);
617 badStr = str.replace("55", "\"aa\"");
619 isValid = listValidator.isValid(badStr, "credential", allDataTypes);
621 assertFalse("check valid value", isValid);
625 private List<Object> buildListOf2CredentialObjects() {
626 List<Object> list = new ArrayList<>();
628 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
629 List<String> strList = Arrays.asList(strArr);
630 Credential credential1 = new Credential("protocol.,\":;<br>>", 5, "token_type", "token", null, "user", true,
632 City mycity1 = new City("myadd<br><<br>", 55);
633 credential1.setMycity(mycity1);
635 Credential credential2 = new Credential("protocol.,\":;<br>>", 5, "token_type", "token", null, "user", true,
637 City mycity2 = new City("myadd<br><<br>", 66);
638 credential2.setMycity(mycity2);
640 list.add(credential1);
641 list.add(credential2);
645 private void validateListOfCredential(Gson gson, String convertedValue) {
647 log.debug(convertedValue);
648 Type type = new TypeToken<List<Credential>>() {
651 List<Credential> fromJson = gson.fromJson(convertedValue, type);
653 assertEquals("check list size", 2, fromJson.size());
655 // Credential actualCredential1 = gson.fromJson(list.get(0).toString(),
656 // Credential.class);
657 Credential actualCredential1 = fromJson.get(0);
658 assertEquals("check sum", 5, actualCredential1.getSum().intValue());
659 assertEquals("check protocol", "protocol.,\":;>", actualCredential1.getProtocol());
660 String[] convertedStrArr = { "aaa", "bbb", "cdcc" };
661 List<String> convertedStrList = Arrays.asList(convertedStrArr);
662 assertEquals("check list", convertedStrList, actualCredential1.getMylist());
664 assertEquals("check city address", "myadd<", actualCredential1.getMycity().getAddress());
665 assertEquals("check city address", 55, actualCredential1.getMycity().getAge().intValue());
667 // Credential actualCredential2 = gson.fromJson(list.get(1).toString(),
668 // Credential.class);
669 Credential actualCredential2 = fromJson.get(1);
670 assertEquals("check city address", 66, actualCredential2.getMycity().getAge().intValue());
673 private DataTypeDefinition buildCredentialDataType() {
674 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
675 dataTypeDefinition.setName("datatype.1");
676 List<PropertyDefinition> properties = new ArrayList<>();
677 PropertyDefinition propertyDefinition1 = new PropertyDefinition();
678 propertyDefinition1.setName("sum");
679 propertyDefinition1.setType(ToscaPropertyType.INTEGER.getType());
680 PropertyDefinition propertyDefinition2 = new PropertyDefinition();
681 propertyDefinition2.setName("protocol");
682 propertyDefinition2.setType(ToscaPropertyType.STRING.getType());
683 PropertyDefinition propertyDefinition3 = new PropertyDefinition();
684 propertyDefinition3.setName("token_type");
685 propertyDefinition3.setType(ToscaPropertyType.STRING.getType());
686 PropertyDefinition propertyDefinition4 = new PropertyDefinition();
687 propertyDefinition4.setName("token");
688 propertyDefinition4.setType(ToscaPropertyType.STRING.getType());
689 PropertyDefinition propertyDefinition5 = new PropertyDefinition();
690 propertyDefinition5.setName("keys");
691 propertyDefinition5.setType(ToscaPropertyType.MAP.getType());
692 PropertyDefinition propertyDefinition6 = new PropertyDefinition();
693 propertyDefinition6.setName("mylist");
694 propertyDefinition6.setType(ToscaPropertyType.LIST.getType());
695 SchemaDefinition entrySchema = new SchemaDefinition();
696 PropertyDataDefinition property = new PropertyDataDefinition();
697 property.setType("string");
698 entrySchema.setProperty(property);
699 propertyDefinition6.setSchema(entrySchema);
700 PropertyDefinition propertyDefinition7 = new PropertyDefinition();
701 propertyDefinition7.setName("user");
702 propertyDefinition7.setType(ToscaPropertyType.STRING.getType());
703 PropertyDefinition propertyDefinition8 = new PropertyDefinition();
704 propertyDefinition8.setName("isMandatory");
705 propertyDefinition8.setType(ToscaPropertyType.BOOLEAN.getType());
707 PropertyDefinition propertyDefinition9 = new PropertyDefinition();
708 propertyDefinition9.setName("mycity");
709 propertyDefinition9.setType("city");
711 properties.add(propertyDefinition1);
712 properties.add(propertyDefinition2);
713 properties.add(propertyDefinition3);
714 properties.add(propertyDefinition4);
715 properties.add(propertyDefinition5);
716 properties.add(propertyDefinition6);
717 properties.add(propertyDefinition7);
718 properties.add(propertyDefinition8);
719 properties.add(propertyDefinition9);
721 dataTypeDefinition.setProperties(properties);
722 return dataTypeDefinition;
725 private static DataTypeDefinition buildCityDataType() {
726 DataTypeDefinition cityDataType = new DataTypeDefinition();
727 cityDataType.setName("city");
728 List<PropertyDefinition> cityProperties = new ArrayList<>();
729 PropertyDefinition cityPropertyDefinition1 = new PropertyDefinition();
730 cityPropertyDefinition1.setName("age");
731 cityPropertyDefinition1.setType(ToscaPropertyType.INTEGER.getType());
732 PropertyDefinition cityPropertyDefinition2 = new PropertyDefinition();
733 cityPropertyDefinition2.setName("address");
734 cityPropertyDefinition2.setType(ToscaPropertyType.STRING.getType());
736 cityProperties.add(cityPropertyDefinition1);
737 cityProperties.add(cityPropertyDefinition2);
739 cityDataType.setProperties(cityProperties);
743 private static DataTypeDefinition buildPersonDataType() {
744 DataTypeDefinition personDataType = new DataTypeDefinition();
745 personDataType.setName("person");
746 List<PropertyDefinition> personProperties = new ArrayList<>();
747 PropertyDefinition personPropertyDefinition1 = new PropertyDefinition();
748 personPropertyDefinition1.setName("age");
749 personPropertyDefinition1.setType("myinteger");
750 PropertyDefinition personPropertyDefinition2 = new PropertyDefinition();
751 personPropertyDefinition2.setName("address");
752 personPropertyDefinition2.setType(ToscaPropertyType.STRING.getType());
754 personProperties.add(personPropertyDefinition1);
755 personProperties.add(personPropertyDefinition2);
757 personDataType.setProperties(personProperties);
758 return personDataType;
761 private static DataTypeDefinition buildFileDataType() {
762 DataTypeDefinition fileDataType = new DataTypeDefinition();
763 fileDataType.setName("file");
764 List<PropertyDefinition> fileProperties = new ArrayList<>();
765 PropertyDefinition filePropertyDefinition1 = new PropertyDefinition();
766 filePropertyDefinition1.setName("age");
767 filePropertyDefinition1.setType("integer");
769 PropertyDefinition filePropertyDefinition2 = new PropertyDefinition();
770 filePropertyDefinition2.setName("attributes");
771 filePropertyDefinition2.setType(ToscaPropertyType.MAP.getType());
773 fileProperties.add(filePropertyDefinition1);
774 fileProperties.add(filePropertyDefinition2);
776 SchemaDefinition entrySchema = new SchemaDefinition();
777 PropertyDataDefinition property = new PropertyDataDefinition();
778 property.setType("city");
779 entrySchema.setProperty(property);
780 filePropertyDefinition2.setSchema(entrySchema);
782 fileDataType.setProperties(fileProperties);
786 private static DataTypeDefinition getPrimitiveDataType(String type) {
788 DataTypeDefinition derivedFrom = new DataTypeDefinition();
789 derivedFrom.setName(type);
795 private static DataTypeDefinition buildDerivedFromIntegerType() {
797 DataTypeDefinition derivedFrom = getPrimitiveDataType("integer");
799 DataTypeDefinition myIntegerDataType = new DataTypeDefinition();
800 myIntegerDataType.setDerivedFrom(derivedFrom);
802 myIntegerDataType.setName("myinteger");
804 return myIntegerDataType;
807 public static class MyFile {
811 Map<String, City> attributes;
813 public Integer getAge() {
817 public void setAge(Integer age) {
821 public Map<String, City> getAttributes() {
825 public void setAttributes(Map<String, City> attributes) {
826 this.attributes = attributes;
831 public static class City {
836 public City(String address, Integer age) {
838 this.address = address;
842 public String getAddress() {
846 public void setAddress(String address) {
847 this.address = address;
850 public Integer getAge() {
854 public void setAge(Integer age) {
860 public static class Person {
865 public Person(String address, Integer age) {
867 this.address = address;
871 public String getAddress() {
875 public void setAddress(String address) {
876 this.address = address;
879 public Integer getAge() {
883 public void setAge(Integer age) {
888 public String toString() {
889 return "Person [address=" + address + ", age=" + age + "]";
894 public static class Credential {
900 Map<String, String> keys;
906 public Credential(String protocol, Integer sum, String token_type, String token, Map<String, String> keys,
907 String user, Boolean isMandatory, List<String> mylist) {
909 this.protocol = protocol;
911 this.token_type = token_type;
915 this.isMandatory = isMandatory;
916 this.mylist = mylist;
919 public String getProtocol() {
923 public void setProtocol(String protocol) {
924 this.protocol = protocol;
927 public String getToken_type() {
931 public void setToken_type(String token_type) {
932 this.token_type = token_type;
935 public String getToken() {
939 public void setToken(String token) {
943 public Map<String, String> getKeys() {
947 public void setKeys(Map<String, String> keys) {
951 public String getUser() {
955 public void setUser(String user) {
959 public Boolean getIsMandatory() {
963 public void setIsMandatory(Boolean isMandatory) {
964 this.isMandatory = isMandatory;
967 public Integer getSum() {
971 public void setSum(Integer sum) {
975 public List<String> getMylist() {
979 public void setMylist(List<String> mylist) {
980 this.mylist = mylist;
983 public City getMycity() {
987 public void setMycity(City mycity) {
988 this.mycity = mycity;
992 public String toString() {
993 return "Credential [protocol=" + protocol + ", token_type=" + token_type + ", token=" + token + ", keys="
994 + keys + ", user=" + user + ", isMandatory=" + isMandatory + "]";