2 * ============LICENSE_START=======================================================
3 * ================================================================================
4 * Copyright (C) 2019 Fujitsu Limited. All rights reserved.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 * ============LICENSE_END=========================================================
20 package org.onap.sdc.impl;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.onap.sdc.tosca.parser.api.ISdcCsarHelper;
25 import org.onap.sdc.tosca.parser.exceptions.SdcToscaParserException;
26 import org.onap.sdc.tosca.parser.impl.SdcToscaParserFactory;
27 import org.onap.sdc.toscaparser.api.elements.DataType;
28 import org.onap.sdc.toscaparser.api.elements.PropertyDef;
29 import org.onap.sdc.toscaparser.api.elements.constraints.Schema;
32 import java.util.HashSet;
33 import java.util.LinkedHashMap;
35 import static org.junit.Assert.assertThat;
36 import static org.hamcrest.CoreMatchers.is;
37 import static org.hamcrest.core.IsNull.notNullValue;
39 public class ToscaParserDataTypeTest {
41 private static ISdcCsarHelper helper = null;
42 private static final String TEST_DATATYPE_FILENAME = "csars/dataTypes-test-service.csar";
43 private static final String TEST_DATATYPE_TEST1 = "TestType1";
44 private static final String TEST_DATATYPE_TEST2 = "TestType2";
45 private static final String TEST_DATATYPE_PROPERTY_STR = "strdata";
46 private static final String TEST_DATATYPE_PROPERTY_INT = "intdata";
47 private static final String TEST_DATATYPE_PROPERTY_LIST = "listdata";
48 private static final String TEST_DATATYPE_PROPERTY_TYPE = "type";
49 private static final String TEST_DATATYPE_PROPERTY_ENTRY_SCHEMA = "entry_schema";
52 public static void setUpClass() {
54 URL resource = GetEntityPortMirroringTest.class.getClassLoader()
55 .getResource(TEST_DATATYPE_FILENAME);
56 if (resource != null) {
57 helper = SdcToscaParserFactory.getInstance().getSdcCsarHelper(resource.getFile());
60 } catch (SdcToscaParserException e) {
66 public void getDataTypes() {
67 HashSet<DataType> dataTypes = helper.getDataTypes();
68 assertThat(dataTypes, notNullValue());
69 assertThat(dataTypes.size(), is(2));
71 for(DataType dataType: dataTypes){
72 LinkedHashMap<String, PropertyDef> properties;
74 if(dataType.getType().equals(TEST_DATATYPE_TEST1)){
75 properties = dataType.getAllProperties();
76 property = properties.get(TEST_DATATYPE_PROPERTY_STR);
77 assertThat(property,notNullValue());
78 assertThat(property.getName(),is(TEST_DATATYPE_PROPERTY_STR));
79 assertThat( property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE),is(Schema.STRING));
81 if(dataType.getType().equals(TEST_DATATYPE_TEST2)) {
82 properties = dataType.getAllProperties();
83 property = properties.get(TEST_DATATYPE_PROPERTY_INT);
84 assertThat(property, notNullValue());
85 assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_INT));
86 assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.INTEGER));
88 property = properties.get(TEST_DATATYPE_PROPERTY_LIST);
89 assertThat(property, notNullValue());
90 assertThat(property.getName(), is(TEST_DATATYPE_PROPERTY_LIST));
91 assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_TYPE), is(Schema.LIST));
92 assertThat(property.getSchema().get(TEST_DATATYPE_PROPERTY_ENTRY_SCHEMA), is(TEST_DATATYPE_TEST1));