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.assertTrue;
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertEquals;
26 import static org.junit.Assert.assertNull;
27 import static org.junit.Assert.assertNotNull;
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 java.util.Map.Entry;
38 import org.apache.commons.lang3.tuple.ImmutablePair;
39 import org.junit.Test;
40 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
41 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
42 import org.openecomp.sdc.be.model.DataTypeDefinition;
43 import org.openecomp.sdc.be.model.PropertyDefinition;
44 import org.openecomp.sdc.be.model.tosca.ToscaPropertyType;
45 import org.openecomp.sdc.be.model.tosca.converters.ListConverter;
46 import org.openecomp.sdc.be.model.tosca.converters.MapConverter;
47 import org.openecomp.sdc.be.model.tosca.validators.DataTypeValidatorConverter;
48 import org.openecomp.sdc.be.model.tosca.validators.ListValidator;
49 import org.openecomp.sdc.be.model.tosca.validators.MapValidator;
51 import com.google.gson.Gson;
52 import com.google.gson.GsonBuilder;
53 import com.google.gson.JsonElement;
54 import com.google.gson.JsonObject;
55 import com.google.gson.JsonParser;
56 import com.google.gson.reflect.TypeToken;
58 import fj.data.Either;
59 import org.slf4j.Logger;
60 import org.slf4j.LoggerFactory;
62 public class DataTypeValidatorTest {
63 private static Logger log = LoggerFactory.getLogger(DataTypeValidatorTest.class.getName());
64 private static Gson gson = new Gson();
66 DataTypeValidatorConverter dataTypeValidator = DataTypeValidatorConverter.getInstance();
69 public void testDerivedFromPrimitiveEmptyValue() {
71 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
72 allDataTypes.put("integer", getPrimitiveDataType("integer"));
74 DataTypeDefinition fromIntegerType = buildDerivedFromIntegerType();
75 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate("", fromIntegerType,
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(null, fromIntegerType, allDataTypes);
83 assertTrue("check result is valid", validate.right.booleanValue());
84 assertEquals("check value is the same as sent", null, validate.left);
86 validate = dataTypeValidator.validateAndUpdate("88", fromIntegerType, allDataTypes);
88 assertTrue("check result is valid", validate.right.booleanValue());
89 assertEquals("check value is the same as sent", "88", validate.left.toString());
94 public void testCompositeWithParameterDerivedFromPrimitiveEmptyValue() {
96 DataTypeDefinition derivedFromIntegerType = buildDerivedFromIntegerType();
97 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
98 allDataTypes.put("myinteger", derivedFromIntegerType);
100 DataTypeDefinition personDataType = buildPersonDataType();
102 Person person = new Person("my address", 32);
103 String json = gson.toJson(person);
106 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, personDataType,
108 assertTrue("check valid value", validate.right.booleanValue());
110 person = new Person("my address", 32);
111 json = gson.toJson(person);
112 json = json.replace("32", "32a");
115 validate = dataTypeValidator.validateAndUpdate(json, personDataType, allDataTypes);
116 assertFalse("check valid value", validate.right.booleanValue());
121 public void testCompositeWithEmptyListValue() {
123 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
125 String[] strArr = {};
126 List<String> strList = Arrays.asList(strArr);
129 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, strList);
130 City mycity = new City("myadd<br><<br>", 55);
131 credential.setMycity(mycity);
133 String json = gson.toJson(credential);
136 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
137 DataTypeDefinition cityDataType = buildCityDataType();
138 allDataTypes.put("city", cityDataType);
140 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
142 assertTrue("check valid value", validate.right.booleanValue());
144 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
145 assertEquals("check empty list", 0, credentialRes.getMylist().size());
147 log.debug("Result is = {}", validate.left.toString());
152 public void testCompositeWithListNullValue() {
153 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
155 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
156 DataTypeDefinition cityDataType = buildCityDataType();
157 allDataTypes.put("city", cityDataType);
159 // Check list is NULL
160 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, null);
161 City mycity = new City("myadd<br><<br>", 55);
162 credential.setMycity(mycity);
164 String json = gson.toJson(credential);
166 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
168 assertTrue("check valid value", validate.right.booleanValue());
170 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
171 assertNull("check list is null", credentialRes.getMylist());
172 log.debug("Result is = {}", validate.left.toString());
177 public void testCompositeWithUserNullValue() {
178 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
180 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
181 DataTypeDefinition cityDataType = buildCityDataType();
182 allDataTypes.put("city", cityDataType);
184 // Check user is null
185 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, null, true, null);
186 City mycity = new City("myadd<br><<br>", 55);
187 credential.setMycity(mycity);
189 String json = gson.toJson(credential);
191 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
193 assertTrue("check valid value", validate.right.booleanValue());
195 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
196 assertNull("check list is null", credentialRes.getUser());
197 log.debug("Result is = {}", validate.left.toString());
201 public void testCompositeWithEmptyUserValue() {
203 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
205 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
206 DataTypeDefinition cityDataType = buildCityDataType();
207 allDataTypes.put("city", cityDataType);
208 // Check user is empty
209 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "", true, null);
210 City mycity = new City("myadd<br><<br>", 55);
211 credential.setMycity(mycity);
213 String json = gson.toJson(credential);
216 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
218 assertTrue("check valid value", validate.right.booleanValue());
220 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
221 assertNotNull("check list is not null", credentialRes.getUser());
222 assertEquals("check user is empty", "", credentialRes.getUser());
223 log.debug("Result is = {}", validate.left.toString());
228 public void testCompositeWithSumNullValue() {
229 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
231 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
232 DataTypeDefinition cityDataType = buildCityDataType();
233 allDataTypes.put("city", cityDataType);
235 // Check user is null
236 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
237 City mycity = new City("myadd<br><<br>", 55);
238 credential.setMycity(mycity);
240 String json = gson.toJson(credential);
242 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
244 assertTrue("check valid value", validate.right.booleanValue());
246 Credential credentialRes = gson.fromJson(validate.left.toString(), Credential.class);
247 assertNull("check list is null", credentialRes.getSum());
248 log.debug("Result is = {}", validate.left.toString());
252 public void testInvalidJson() {
253 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
255 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
256 DataTypeDefinition cityDataType = buildCityDataType();
257 allDataTypes.put("city", cityDataType);
259 // Check user is null
260 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
261 City mycity = new City("myadd<br><<br>", 55);
262 credential.setMycity(mycity);
264 String json = gson.toJson(credential);
268 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
270 assertFalse("check valid value", validate.right.booleanValue());
275 public void testInvalidInnerValue() {
277 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
279 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
280 DataTypeDefinition cityDataType = buildCityDataType();
281 allDataTypes.put("city", cityDataType);
283 // Check user is null
284 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
285 City mycity = new City("myadd<br><<br>", 55);
286 credential.setMycity(mycity);
288 String json = gson.toJson(credential);
290 json = json.replace("55", "a55b");
292 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
294 assertFalse("check valid value", validate.right.booleanValue());
299 public void testInvalidInnerJson() {
301 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
303 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
304 DataTypeDefinition cityDataType = buildCityDataType();
305 allDataTypes.put("city", cityDataType);
307 // Check user is null
308 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
309 City mycity = new City("", null);
311 credential.setMycity(mycity);
313 String json = gson.toJson(credential);
315 json = json.replace("{\"address\":\"\"}", "scalar");
317 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
319 assertFalse("check valid value", validate.right.booleanValue());
324 public void testInvalidPropertyJson() {
326 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
328 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
329 DataTypeDefinition cityDataType = buildCityDataType();
330 allDataTypes.put("city", cityDataType);
332 // Check user is null
333 Credential credential = new Credential("protcol<br>>", null, "token_type", "token", null, null, true, null);
334 City mycity = new City("myadd<br><<br>", 55);
335 credential.setMycity(mycity);
337 String json = gson.toJson(credential);
339 json = json.replace("55", "a55b");
341 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
343 assertFalse("check valid value", validate.right.booleanValue());
348 public void testCompositeDataTypeWithInternalComposite() {
350 DataTypeDefinition dataTypeDefinition = buildCredentialDataType();
352 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
353 List<String> strList = Arrays.asList(strArr);
355 Credential credential = new Credential("protcol<br>>", 5, "token_type", "token", null, "user", true, strList);
356 City mycity = new City("myadd<br><<br>", 55);
357 credential.setMycity(mycity);
359 String json = gson.toJson(credential);
361 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
362 DataTypeDefinition cityDataType = buildCityDataType();
363 allDataTypes.put("city", cityDataType);
365 ImmutablePair<JsonElement, Boolean> validate = dataTypeValidator.validateAndUpdate(json, dataTypeDefinition,
367 assertTrue("check valid value", validate.right.booleanValue());
369 log.debug("Result is = {}", validate.left.toString());
374 public void testMapValidator() {
376 MapValidator validator = new MapValidator();
377 Gson gson = new Gson();
379 // 1 - Map<String,Integer> check OK
380 Map<String, Integer> map_1 = new HashMap<>();
381 map_1.put("key1", 2);
382 map_1.put("key2", 3);
383 String value = gson.toJson(map_1);
384 String innerType = "integer";
385 assertTrue("Test Map validation with inner integer type", validator.isValid(value, innerType, null));
387 // 2 - Map<String,Boolean> check OK
388 Map<String, Boolean> map_2 = new HashMap<>();
389 map_2.put("key1", true);
390 map_2.put("key2", false);
391 value = gson.toJson(map_2);
392 innerType = "boolean";
393 assertTrue("Test Map validation with inner boolean type", validator.isValid(value, innerType, null));
395 // 3 - give integer with quotes
396 innerType = "integer";
397 value = "{\"key1\":\"5\",\"key2\":\"7\"}";
398 assertTrue("Test Map validation with inner integer type, but qouted values",
399 validator.isValid(value, innerType, null));
401 // 4 - empty default value
404 assertTrue("Test Map validation with inner float type", validator.isValid(value, innerType, null));
407 // 5 - mismatch in data type
408 value = gson.toJson(map_1);
409 innerType = "boolean";
410 assertFalse("Test Map faulty validation with inner boolean type", validator.isValid(value, innerType, null));
411 // 6 - mismatch in data type
412 value = gson.toJson(map_2);
413 innerType = "integer";
414 assertFalse("Test Map faulty validation with inner integer type", validator.isValid(value, innerType, null));
419 public void testMapConverter() {
421 MapConverter converter = new MapConverter();
422 Gson gson = new Gson();
424 Map<String, String> map_1 = new HashMap<>();
425 Map<String, String> resMap_1 = new HashMap<>();
427 // 1 - check Spaces eliminated + html square brackets eliminated
428 map_1.put("key1", "<b>test</b>");
429 map_1.put("key2", " test");
430 resMap_1.put("key1", "test");
431 resMap_1.put("key2", " test");
432 String value = gson.toJson(map_1);
433 String expectedVal = gson.toJson(resMap_1);
434 String innerType = "string";
435 assertEquals("Test Map validation with inner string type", expectedVal,
436 converter.convert(value, innerType, null));
438 // 2 - float converter
440 value = "{\"key1\":0.4545,\"key2\":0.2f}";
441 expectedVal = "{\"key1\":0.4545,\"key2\":0.2}";
442 assertEquals("Test Map validation with inner float type", expectedVal,
443 converter.convert(value, innerType, null));
445 // 3 - check default empty value converter
449 assertEquals("Test Map validation with inner float type", expectedVal,
450 converter.convert(value, innerType, null));
453 // 3 - check default empty value converter
455 value = "{1345234556@#(";
457 assertEquals("Test Map validation with inner float type", expectedVal,
458 converter.convert(value, innerType, null));
463 public void testCompositeDataTypeWithMapComposite() {
465 DataTypeDefinition fileDataTypeDefinition = buildFileDataType();
466 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
467 DataTypeDefinition cityDataType = buildCityDataType();
468 allDataTypes.put("city", cityDataType);
470 MyFile myFile = new MyFile();
472 Map<String, City> attributes = new HashMap<>();
473 attributes.put("key1", new City("address1<br>", 11));
474 attributes.put("key2", new City("address2<br>", 22));
475 myFile.setAttributes(attributes);
477 String str = gson.toJson(myFile);
480 ImmutablePair<JsonElement, Boolean> convert = dataTypeValidator.validateAndUpdate(str, fileDataTypeDefinition,
483 assertTrue("check map converter succeed", convert.right);
485 JsonElement convertedValue = convert.left;
487 log.debug("{}", convertedValue);
488 MyFile fromJson = gson.fromJson(convertedValue, MyFile.class);
490 assertEquals("check age", 88, fromJson.getAge().intValue());
491 assertEquals("check address 1", "address1", fromJson.getAttributes().get("key1").getAddress());
492 assertEquals("check address 2", "address2", fromJson.getAttributes().get("key2").getAddress());
497 public void testMapConverterWithComplexInnerType() {
499 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
500 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
501 DataTypeDefinition cityDataType = buildCityDataType();
502 allDataTypes.put("city", cityDataType);
503 allDataTypes.put("credential", credentialDataTypeDefinition);
505 Gson gson = new Gson();
507 Map<String, Object> map_1 = new HashMap<>();
509 // 1 - check Spaces eliminated + html square brackets eliminated
511 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
512 List<String> strList = Arrays.asList(strArr);
513 Credential credential1 = new Credential("protocol;:,.\"<br>>", 5, "token_type", "token", null, "user", true,
515 City mycity1 = new City("myadd<br><<br>", 55);
516 credential1.setMycity(mycity1);
518 Credential credential2 = new Credential("protocol;:,.\"<br>>", 5, "token_type", "token", null, "user", true,
520 City mycity2 = new City("myadd<br><<br>", 66);
521 credential2.setMycity(mycity2);
523 map_1.put("key1", credential1);
524 map_1.put("key2", credential2);
526 String str = gson.toJson(map_1);
529 MapConverter mapConverter = new MapConverter();
530 Either<String, Boolean> convert = mapConverter.convertWithErrorResult(str, "credential", allDataTypes);
532 assertTrue("check map converter succeed", convert.isLeft());
534 String convertedValue = convert.left().value();
536 Type type = new TypeToken<Map<String, Credential>>() {
539 Map<String, Credential> fromJson = gson.fromJson(convertedValue, type);
541 Credential actualCredential1 = fromJson.get("key1");
542 assertEquals("check sum", 5, actualCredential1.getSum().intValue());
543 assertEquals("check protocol", "protocol;:,.\">", actualCredential1.getProtocol());
544 String[] convertedStrArr = { "aaa", "bbb", "cdcc" };
545 List<String> convertedStrList = Arrays.asList(convertedStrArr);
546 assertEquals("check list", convertedStrList, actualCredential1.getMylist());
548 assertEquals("check city address", "myadd<", actualCredential1.getMycity().getAddress());
549 assertEquals("check city address", 55, actualCredential1.getMycity().getAge().intValue());
551 Credential actualCredential2 = fromJson.get("key2");
552 assertEquals("check city address", 66, actualCredential2.getMycity().getAge().intValue());
557 public void testListConverterWithComplexInnerType() {
559 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
560 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
561 DataTypeDefinition cityDataType = buildCityDataType();
562 allDataTypes.put("city", cityDataType);
563 allDataTypes.put("credential", credentialDataTypeDefinition);
565 Gson gson = new Gson();
567 List<Object> list = buildListOf2CredentialObjects();
569 String str = gson.toJson(list);
572 ListConverter listConverter = new ListConverter();
574 Either<String, Boolean> convert = listConverter.convertWithErrorResult(str, "credential", allDataTypes);
576 assertTrue("check map converter succeed", convert.isLeft());
578 String convertedValue = convert.left().value();
580 validateListOfCredential(gson, convertedValue);
584 str = gson.toJson(list);
587 convert = listConverter.convertWithErrorResult(str, "credential", allDataTypes);
589 assertTrue("check map converter succeed", convert.isLeft());
591 validateListOfCredential(gson, convertedValue);
595 public void testListValidatorWithComplexInnerType() {
597 Map<String, DataTypeDefinition> allDataTypes = new HashMap<String, DataTypeDefinition>();
598 DataTypeDefinition credentialDataTypeDefinition = buildCredentialDataType();
599 DataTypeDefinition cityDataType = buildCityDataType();
600 allDataTypes.put("city", cityDataType);
601 allDataTypes.put("credential", credentialDataTypeDefinition);
603 Gson gson = new Gson();
605 List<Object> list = buildListOf2CredentialObjects();
607 String str = gson.toJson(list);
610 ListValidator listValidator = new ListValidator();
612 boolean isValid = listValidator.isValid(str, "credential", allDataTypes);
614 assertTrue("check valid value", isValid);
616 String badStr = str.replace("protocol", "protocol1");
618 isValid = listValidator.isValid(badStr, "credential", allDataTypes);
620 assertFalse("check valid value", isValid);
622 badStr = str.replace("55", "\"aa\"");
624 isValid = listValidator.isValid(badStr, "credential", allDataTypes);
626 assertFalse("check valid value", isValid);
630 private List<Object> buildListOf2CredentialObjects() {
631 List<Object> list = new ArrayList<>();
633 String[] strArr = { "aaa", "bbb", "c<br>dcc" };
634 List<String> strList = Arrays.asList(strArr);
635 Credential credential1 = new Credential("protocol.,\":;<br>>", 5, "token_type", "token", null, "user", true,
637 City mycity1 = new City("myadd<br><<br>", 55);
638 credential1.setMycity(mycity1);
640 Credential credential2 = new Credential("protocol.,\":;<br>>", 5, "token_type", "token", null, "user", true,
642 City mycity2 = new City("myadd<br><<br>", 66);
643 credential2.setMycity(mycity2);
645 list.add(credential1);
646 list.add(credential2);
650 private void validateListOfCredential(Gson gson, String convertedValue) {
652 log.debug(convertedValue);
653 Type type = new TypeToken<List<Credential>>() {
656 List<Credential> fromJson = gson.fromJson(convertedValue, type);
658 assertEquals("check list size", 2, fromJson.size());
660 // Credential actualCredential1 = gson.fromJson(list.get(0).toString(),
661 // Credential.class);
662 Credential actualCredential1 = fromJson.get(0);
663 assertEquals("check sum", 5, actualCredential1.getSum().intValue());
664 assertEquals("check protocol", "protocol.,\":;>", actualCredential1.getProtocol());
665 String[] convertedStrArr = { "aaa", "bbb", "cdcc" };
666 List<String> convertedStrList = Arrays.asList(convertedStrArr);
667 assertEquals("check list", convertedStrList, actualCredential1.getMylist());
669 assertEquals("check city address", "myadd<", actualCredential1.getMycity().getAddress());
670 assertEquals("check city address", 55, actualCredential1.getMycity().getAge().intValue());
672 // Credential actualCredential2 = gson.fromJson(list.get(1).toString(),
673 // Credential.class);
674 Credential actualCredential2 = fromJson.get(1);
675 assertEquals("check city address", 66, actualCredential2.getMycity().getAge().intValue());
678 private DataTypeDefinition buildCredentialDataType() {
679 DataTypeDefinition dataTypeDefinition = new DataTypeDefinition();
680 dataTypeDefinition.setName("datatype.1");
681 List<PropertyDefinition> properties = new ArrayList<>();
682 PropertyDefinition propertyDefinition1 = new PropertyDefinition();
683 propertyDefinition1.setName("sum");
684 propertyDefinition1.setType(ToscaPropertyType.INTEGER.getType());
685 PropertyDefinition propertyDefinition2 = new PropertyDefinition();
686 propertyDefinition2.setName("protocol");
687 propertyDefinition2.setType(ToscaPropertyType.STRING.getType());
688 PropertyDefinition propertyDefinition3 = new PropertyDefinition();
689 propertyDefinition3.setName("token_type");
690 propertyDefinition3.setType(ToscaPropertyType.STRING.getType());
691 PropertyDefinition propertyDefinition4 = new PropertyDefinition();
692 propertyDefinition4.setName("token");
693 propertyDefinition4.setType(ToscaPropertyType.STRING.getType());
694 PropertyDefinition propertyDefinition5 = new PropertyDefinition();
695 propertyDefinition5.setName("keys");
696 propertyDefinition5.setType(ToscaPropertyType.MAP.getType());
697 PropertyDefinition propertyDefinition6 = new PropertyDefinition();
698 propertyDefinition6.setName("mylist");
699 propertyDefinition6.setType(ToscaPropertyType.LIST.getType());
700 SchemaDefinition entrySchema = new SchemaDefinition();
701 PropertyDataDefinition property = new PropertyDataDefinition();
702 property.setType("string");
703 entrySchema.setProperty(property);
704 propertyDefinition6.setSchema(entrySchema);
705 PropertyDefinition propertyDefinition7 = new PropertyDefinition();
706 propertyDefinition7.setName("user");
707 propertyDefinition7.setType(ToscaPropertyType.STRING.getType());
708 PropertyDefinition propertyDefinition8 = new PropertyDefinition();
709 propertyDefinition8.setName("isMandatory");
710 propertyDefinition8.setType(ToscaPropertyType.BOOLEAN.getType());
712 PropertyDefinition propertyDefinition9 = new PropertyDefinition();
713 propertyDefinition9.setName("mycity");
714 propertyDefinition9.setType("city");
716 properties.add(propertyDefinition1);
717 properties.add(propertyDefinition2);
718 properties.add(propertyDefinition3);
719 properties.add(propertyDefinition4);
720 properties.add(propertyDefinition5);
721 properties.add(propertyDefinition6);
722 properties.add(propertyDefinition7);
723 properties.add(propertyDefinition8);
724 properties.add(propertyDefinition9);
726 dataTypeDefinition.setProperties(properties);
727 return dataTypeDefinition;
730 private static DataTypeDefinition buildCityDataType() {
731 DataTypeDefinition cityDataType = new DataTypeDefinition();
732 cityDataType.setName("city");
733 List<PropertyDefinition> cityProperties = new ArrayList<>();
734 PropertyDefinition cityPropertyDefinition1 = new PropertyDefinition();
735 cityPropertyDefinition1.setName("age");
736 cityPropertyDefinition1.setType(ToscaPropertyType.INTEGER.getType());
737 PropertyDefinition cityPropertyDefinition2 = new PropertyDefinition();
738 cityPropertyDefinition2.setName("address");
739 cityPropertyDefinition2.setType(ToscaPropertyType.STRING.getType());
741 cityProperties.add(cityPropertyDefinition1);
742 cityProperties.add(cityPropertyDefinition2);
744 cityDataType.setProperties(cityProperties);
748 private static DataTypeDefinition buildPersonDataType() {
749 DataTypeDefinition personDataType = new DataTypeDefinition();
750 personDataType.setName("person");
751 List<PropertyDefinition> personProperties = new ArrayList<>();
752 PropertyDefinition personPropertyDefinition1 = new PropertyDefinition();
753 personPropertyDefinition1.setName("age");
754 personPropertyDefinition1.setType("myinteger");
755 PropertyDefinition personPropertyDefinition2 = new PropertyDefinition();
756 personPropertyDefinition2.setName("address");
757 personPropertyDefinition2.setType(ToscaPropertyType.STRING.getType());
759 personProperties.add(personPropertyDefinition1);
760 personProperties.add(personPropertyDefinition2);
762 personDataType.setProperties(personProperties);
763 return personDataType;
766 private static DataTypeDefinition buildFileDataType() {
767 DataTypeDefinition fileDataType = new DataTypeDefinition();
768 fileDataType.setName("file");
769 List<PropertyDefinition> fileProperties = new ArrayList<>();
770 PropertyDefinition filePropertyDefinition1 = new PropertyDefinition();
771 filePropertyDefinition1.setName("age");
772 filePropertyDefinition1.setType("integer");
774 PropertyDefinition filePropertyDefinition2 = new PropertyDefinition();
775 filePropertyDefinition2.setName("attributes");
776 filePropertyDefinition2.setType(ToscaPropertyType.MAP.getType());
778 fileProperties.add(filePropertyDefinition1);
779 fileProperties.add(filePropertyDefinition2);
781 SchemaDefinition entrySchema = new SchemaDefinition();
782 PropertyDataDefinition property = new PropertyDataDefinition();
783 property.setType("city");
784 entrySchema.setProperty(property);
785 filePropertyDefinition2.setSchema(entrySchema);
787 fileDataType.setProperties(fileProperties);
791 private static DataTypeDefinition getPrimitiveDataType(String type) {
793 DataTypeDefinition derivedFrom = new DataTypeDefinition();
794 derivedFrom.setName(type);
800 private static DataTypeDefinition buildDerivedFromIntegerType() {
802 DataTypeDefinition derivedFrom = getPrimitiveDataType("integer");
804 DataTypeDefinition myIntegerDataType = new DataTypeDefinition();
805 myIntegerDataType.setDerivedFrom(derivedFrom);
807 myIntegerDataType.setName("myinteger");
809 return myIntegerDataType;
812 public static class MyFile {
816 Map<String, City> attributes;
818 public Integer getAge() {
822 public void setAge(Integer age) {
826 public Map<String, City> getAttributes() {
830 public void setAttributes(Map<String, City> attributes) {
831 this.attributes = attributes;
836 public static class City {
841 public City(String address, Integer age) {
843 this.address = address;
847 public String getAddress() {
851 public void setAddress(String address) {
852 this.address = address;
855 public Integer getAge() {
859 public void setAge(Integer age) {
865 public static class Person {
870 public Person(String address, Integer age) {
872 this.address = address;
876 public String getAddress() {
880 public void setAddress(String address) {
881 this.address = address;
884 public Integer getAge() {
888 public void setAge(Integer age) {
893 public String toString() {
894 return "Person [address=" + address + ", age=" + age + "]";
899 public static class Credential {
905 Map<String, String> keys;
911 public Credential(String protocol, Integer sum, String token_type, String token, Map<String, String> keys,
912 String user, Boolean isMandatory, List<String> mylist) {
914 this.protocol = protocol;
916 this.token_type = token_type;
920 this.isMandatory = isMandatory;
921 this.mylist = mylist;
924 public String getProtocol() {
928 public void setProtocol(String protocol) {
929 this.protocol = protocol;
932 public String getToken_type() {
936 public void setToken_type(String token_type) {
937 this.token_type = token_type;
940 public String getToken() {
944 public void setToken(String token) {
948 public Map<String, String> getKeys() {
952 public void setKeys(Map<String, String> keys) {
956 public String getUser() {
960 public void setUser(String user) {
964 public Boolean getIsMandatory() {
968 public void setIsMandatory(Boolean isMandatory) {
969 this.isMandatory = isMandatory;
972 public Integer getSum() {
976 public void setSum(Integer sum) {
980 public List<String> getMylist() {
984 public void setMylist(List<String> mylist) {
985 this.mylist = mylist;
988 public City getMycity() {
992 public void setMycity(City mycity) {
993 this.mycity = mycity;
997 public String toString() {
998 return "Credential [protocol=" + protocol + ", token_type=" + token_type + ", token=" + token + ", keys="
999 + keys + ", user=" + user + ", isMandatory=" + isMandatory + "]";