Add instructions to invoke the linter and code formatter plugins to the README and...
[aai/schema-service.git] / aai-schema-gen / src / test / java / org / onap / aai / schemagen / genxsd / XSDJavaTypeTest.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.aai.schemagen.genxsd;
22
23 import static org.hamcrest.CoreMatchers.equalTo;
24 import static org.junit.Assert.assertThat;
25
26 import java.util.HashMap;
27
28 import org.junit.Before;
29 import org.junit.Test;
30 import org.w3c.dom.Element;
31
32 public class XSDJavaTypeTest extends XSDElementTest {
33
34     @Before
35     public void setUp() throws Exception {
36         super.setUp();
37     }
38
39     @Test
40     public void testXSDJavaTypeElement() {
41         HashMap<String, String> map = new HashMap<String, String>();
42         HashMap<String, String> target = new HashMap<String, String>();
43         target.put("Customer", "global-customer-id");
44         target.put("Business", "customers");
45         target.put("Inventory", "business");
46         target.put("Customers", "customer");
47         target.put("ServiceSubscriptions", "service-subscription");
48         target.put("ServiceSubscription", "service-type");
49
50         for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
51             XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
52             XSDJavaType javaType = new XSDJavaType(javaTypeElement);
53             map.put(javaType.name(), javaType.getItemName());
54         }
55         for (String key : map.keySet()) {
56             assertThat("For key: " + key, map.get(key), equalTo(target.get(key)));
57         }
58     }
59
60     @Test
61     public void testGetItemName() {
62         HashMap<String, String> map = new HashMap<String, String>();
63         HashMap<String, String> target = new HashMap<String, String>();
64         target.put("Customer", "global-customer-id");
65         target.put("Business", "customers");
66         target.put("Inventory", "business");
67         target.put("Customers", "customer");
68         target.put("ServiceSubscriptions", "service-subscription");
69         target.put("ServiceSubscription", "service-type");
70
71         for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
72             XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
73             XSDJavaType javaType = new XSDJavaType(javaTypeElement);
74             map.put(javaType.name(), javaType.getItemName());
75         }
76         for (String key : map.keySet()) {
77             assertThat("For key: " + key, map.get(key), equalTo(target.get(key)));
78         }
79     }
80
81     @Test
82     public void testGetArrayType() {
83         HashMap<String, String> map = new HashMap<String, String>();
84         HashMap<String, String> target = new HashMap<String, String>();
85         target.put("Customer", null);
86         target.put("Business", null);
87         target.put("Inventory", null);
88         target.put("Customers", "customer");
89         target.put("ServiceSubscriptions", "service-subscription");
90         target.put("ServiceSubscription", null);
91
92         for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
93             XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
94             XSDJavaType javaType = new XSDJavaType(javaTypeElement);
95             map.put(javaType.name(), javaType.getArrayType());
96         }
97         for (String key : map.keySet()) {
98             assertThat(map.get(key), equalTo(target.get(key)));
99         }
100     }
101
102 }