2 * ============LICENSE_START=======================================================
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
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.onap.aai.schemagen.genxsd;
23 import static org.hamcrest.CoreMatchers.both;
24 import static org.hamcrest.CoreMatchers.equalTo;
25 import static org.hamcrest.CoreMatchers.is;
26 import static org.hamcrest.collection.IsIn.in;
27 import static org.hamcrest.collection.IsIterableContainingInAnyOrder.containsInAnyOrder;
28 import static org.hamcrest.core.Every.everyItem;
29 import static org.junit.Assert.assertEquals;
30 import static org.junit.Assert.assertThat;
32 import java.io.IOException;
33 import java.io.StringReader;
34 import java.util.ArrayList;
35 import java.util.Arrays;
36 import java.util.HashMap;
37 import java.util.List;
38 import java.util.Vector;
40 import javax.xml.XMLConstants;
41 import javax.xml.parsers.DocumentBuilder;
42 import javax.xml.parsers.DocumentBuilderFactory;
43 import javax.xml.parsers.ParserConfigurationException;
45 import org.apache.commons.lang.StringUtils;
46 import org.junit.Before;
47 import org.junit.BeforeClass;
48 import org.junit.Test;
49 import org.slf4j.Logger;
50 import org.slf4j.LoggerFactory;
51 import org.w3c.dom.Document;
52 import org.w3c.dom.Element;
53 import org.w3c.dom.NodeList;
54 import org.xml.sax.InputSource;
55 import org.xml.sax.SAXException;
57 public class XSDElementTest {
58 private static final Logger logger = LoggerFactory.getLogger("XSDElementTest.class");
59 private static final int maxSizeForXml = 20000;
60 protected String testXML;
61 protected Document doc = null;
62 protected NodeList javaTypeNodes = null;
64 public String getTestXML() {
69 public static void setUpBeforeClass() throws Exception {
73 public void setUp() throws Exception {
77 public void setUp(int sbopt) throws Exception {
78 StringBuilder sb = new StringBuilder(maxSizeForXml);
85 addCustomerNoSubscriberType(sb);
86 addCustomerSubscriberType(sb);
88 addServiceSubscriptions(sb);
89 addServiceSubscription(sb);
91 testXML = sb.toString();
95 public void setUpRelationship() throws Exception {
96 StringBuilder sb = new StringBuilder(maxSizeForXml);
97 addNamespaceNoInventory(sb);
99 addRelationshipList(sb);
100 addRelatedToProperty(sb);
101 addRelationshipData(sb);
103 testXML = sb.toString();
107 private void addNamespace(StringBuilder sb) {
109 "<xml-bindings xmlns=\"http://www.eclipse.org/eclipselink/xsds/persistence/oxm\" package-name=\"inventory.aai.onap.org.v11\" xml-mapping-metadata-complete=\"true\">\n");
110 sb.append("<xml-schema element-form-default=\"QUALIFIED\">\n");
111 sb.append("<xml-ns namespace-uri=\"http://org.onap.aai.inventory/v11\" />\n");
112 sb.append("</xml-schema>\n");
113 sb.append("<java-types>\n");
114 sb.append("<java-type name=\"Inventory\">\n");
115 sb.append("<xml-root-element name=\"inventory\" />\n");
116 sb.append("<java-attributes>\n");
118 "<xml-element java-attribute=\"business\" name=\"business\" type=\"inventory.aai.onap.org.v11.Business\" />\n");
119 sb.append("</java-attributes>\n");
120 sb.append("</java-type>\n");
123 private void addNamespaceNoInventory(StringBuilder sb) {
125 "<xml-bindings xmlns=\"http://www.eclipse.org/eclipselink/xsds/persistence/oxm\" package-name=\"inventory.aai.onap.org.v11\" xml-mapping-metadata-complete=\"true\">\n");
126 sb.append("<xml-schema element-form-default=\"QUALIFIED\">\n");
127 sb.append("<xml-ns namespace-uri=\"http://org.onap.aai.inventory/v11\" />\n");
128 sb.append("</xml-schema>\n");
129 sb.append("<java-types>\n");
132 private void addBusiness(StringBuilder sb) {
133 sb.append("<java-type name=\"Business\">\n");
134 sb.append("<xml-properties>\n");
136 "<xml-property name=\"description\" value=\"Namespace for business related constructs\" />\n");
137 sb.append("</xml-properties>\n");
138 sb.append("<xml-root-element name=\"business\" />\n");
139 sb.append("<java-attributes>\n");
141 "<xml-element java-attribute=\"customers\" name=\"customers\" type=\"inventory.aai.onap.org.v11.Customers\" />\n");
142 sb.append("</java-attributes>\n");
143 sb.append("</java-type>\n");
146 private void addCustomers(StringBuilder sb) {
147 sb.append("<java-type name=\"Customers\">\n");
148 sb.append("<xml-properties>\n");
150 "<xml-property name=\"description\" value=\"Collection of customer identifiers to provide linkage back to BSS information.\" />\n");
151 sb.append("</xml-properties>\n");
152 sb.append("<xml-root-element name=\"customers\" />\n");
153 sb.append("<java-attributes>\n");
155 "<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"customer\" name=\"customer\" type=\"inventory.aai.onap.org.v11.Customer\" />\n");
156 sb.append("</java-attributes>\n");
157 sb.append("<xml-properties>\n");
158 sb.append("<xml-property name=\"maximumDepth\" value=\"0\" />\n");
159 sb.append("</xml-properties>\n");
160 sb.append("</java-type>\n");
163 private void addCustomer(StringBuilder sb) {
164 sb.append("<java-type name=\"Customer\">\n");
165 sb.append("<xml-root-element name=\"customer\" />\n");
166 sb.append("<java-attributes>\n");
168 "<xml-element java-attribute=\"globalCustomerId\" name=\"global-customer-id\" required=\"true\" type=\"java.lang.String\" xml-key=\"true\">\n");
169 sb.append("<xml-properties>\n");
171 "<xml-property name=\"description\" value=\"Global customer id used across to uniquely identify customer.\" />\n");
172 sb.append("</xml-properties>\n");
173 sb.append("</xml-element>\n");
175 "<xml-element java-attribute=\"subscriberName\" name=\"subscriber-name\" required=\"true\" type=\"java.lang.String\">\n");
176 sb.append("<xml-properties>\n");
178 "<xml-property name=\"description\" value=\"Subscriber name, an alternate way to retrieve a customer.\" />\n");
179 sb.append("</xml-properties>\n");
180 sb.append("</xml-element>\n");
182 "<xml-element java-attribute=\"subscriberType\" name=\"subscriber-type\" required=\"true\" type=\"java.lang.String\">\n");
183 sb.append("<xml-properties>\n");
185 "<xml-property name=\"description\" value=\"Subscriber type, a way to provide VID with only the INFRA customers.\" />\n");
186 sb.append("<xml-property name=\"defaultValue\" value=\"CUST\" />\n");
187 sb.append("</xml-properties>\n");
188 sb.append("</xml-element>\n");
190 "<xml-element java-attribute=\"resourceVersion\" name=\"resource-version\" type=\"java.lang.String\">\n");
191 sb.append("<xml-properties>\n");
193 "<xml-property name=\"description\" value=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\" />\n");
194 sb.append("</xml-properties>\n");
195 sb.append("</xml-element>\n");
197 "<xml-element java-attribute=\"serviceSubscriptions\" name=\"service-subscriptions\" type=\"inventory.aai.onap.org.v11.ServiceSubscriptions\" />\n");
198 // sb.append("<xml-element java-attribute=\"relationshipList\" name=\"relationship-list\"
199 // type=\"inventory.aai.onap.org.v11.RelationshipList\" />\n");
200 sb.append("</java-attributes>\n");
201 sb.append("<xml-properties>\n");
203 "<xml-property name=\"description\" value=\"customer identifiers to provide linkage back to BSS information.\" />\n");
204 sb.append("<xml-property name=\"nameProps\" value=\"subscriber-name\" />\n");
206 "<xml-property name=\"indexedProps\" value=\"subscriber-name,global-customer-id,subscriber-type\" />\n");
208 "<xml-property name=\"searchable\" value=\"global-customer-id,subscriber-name\" />\n");
209 sb.append("<xml-property name=\"uniqueProps\" value=\"global-customer-id\" />\n");
210 sb.append("<xml-property name=\"container\" value=\"customers\" />\n");
211 sb.append("<xml-property name=\"namespace\" value=\"business\" />\n");
212 sb.append("</xml-properties>\n");
213 sb.append("</java-type>\n");
216 private void addCustomerNoSubscriberType(StringBuilder sb) {
217 sb.append("<java-type name=\"Customer\">\n");
218 sb.append("<xml-root-element name=\"customer\" />\n");
219 sb.append("<java-attributes>\n");
221 "<xml-element java-attribute=\"globalCustomerId\" name=\"global-customer-id\" required=\"true\" type=\"java.lang.String\" xml-key=\"true\">\n");
222 sb.append("<xml-properties>\n");
224 "<xml-property name=\"description\" value=\"Global customer id used across to uniquely identify customer.\" />\n");
225 sb.append("</xml-properties>\n");
226 sb.append("</xml-element>\n");
228 "<xml-element java-attribute=\"subscriberName\" name=\"subscriber-name\" required=\"true\" type=\"java.lang.String\">\n");
229 sb.append("<xml-properties>\n");
231 "<xml-property name=\"description\" value=\"Subscriber name, an alternate way to retrieve a customer.\" />\n");
232 sb.append("</xml-properties>\n");
233 sb.append("</xml-element>\n");
235 "<xml-element java-attribute=\"resourceVersion\" name=\"resource-version\" type=\"java.lang.String\">\n");
236 sb.append("<xml-properties>\n");
238 "<xml-property name=\"description\" value=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\" />\n");
239 sb.append("</xml-properties>\n");
240 sb.append("</xml-element>\n");
242 "<xml-element java-attribute=\"serviceSubscriptions\" name=\"service-subscriptions\" type=\"inventory.aai.onap.org.v11.ServiceSubscriptions\" />\n");
243 sb.append("</java-attributes>\n");
244 sb.append("<xml-properties>\n");
246 "<xml-property name=\"description\" value=\"customer identifiers to provide linkage back to BSS information.\" />\n");
247 sb.append("<xml-property name=\"nameProps\" value=\"subscriber-name\" />\n");
249 "<xml-property name=\"indexedProps\" value=\"subscriber-name,global-customer-id\" />\n");
251 "<xml-property name=\"searchable\" value=\"global-customer-id,subscriber-name\" />\n");
252 sb.append("<xml-property name=\"uniqueProps\" value=\"global-customer-id\" />\n");
253 sb.append("<xml-property name=\"container\" value=\"customers\" />\n");
254 sb.append("<xml-property name=\"namespace\" value=\"business\" />\n");
255 sb.append("</xml-properties>\n");
256 sb.append("</java-type>\n");
259 private void addCustomerSubscriberType(StringBuilder sb) {
260 sb.append("<java-type name=\"Customer\">\n");
261 sb.append("<xml-root-element name=\"customer\" />\n");
262 sb.append("<java-attributes>\n");
264 "<xml-element java-attribute=\"subscriberType\" name=\"subscriber-type\" required=\"true\" type=\"java.lang.String\">\n");
265 sb.append("<xml-properties>\n");
267 "<xml-property name=\"description\" value=\"Subscriber type, a way to provide VID with only the INFRA customers.\" />\n");
268 sb.append("<xml-property name=\"defaultValue\" value=\"CUST\" />\n");
269 sb.append("</xml-properties>\n");
270 sb.append("</xml-element>\n");
271 sb.append("</java-attributes>\n");
272 sb.append("<xml-properties>\n");
273 sb.append("<xml-property name=\"indexedProps\" value=\"subscriber-type\" />\n");
274 sb.append("<xml-property name=\"container\" value=\"customers\" />\n");
275 sb.append("</xml-properties>\n");
276 sb.append("</java-type>\n");
279 private void addServiceSubscriptions(StringBuilder sb) {
280 sb.append("<java-type name=\"ServiceSubscriptions\">\n");
281 sb.append("<xml-properties>\n");
283 "<xml-property name=\"description\" value=\"Collection of objects that group service instances.\" />\n");
284 sb.append("</xml-properties>\n");
285 sb.append("<xml-root-element name=\"service-subscriptions\" />\n");
286 sb.append("<java-attributes>\n");
288 "<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"serviceSubscription\" name=\"service-subscription\" type=\"inventory.aai.onap.org.v11.ServiceSubscription\" />\n");
289 sb.append("</java-attributes>\n");
290 sb.append("</java-type>\n");
293 private void addServiceSubscription(StringBuilder sb) {
294 sb.append("<java-type name=\"ServiceSubscription\">\n");
295 sb.append("<xml-root-element name=\"service-subscription\" />\n");
296 sb.append("<java-attributes>\n");
298 "<xml-element java-attribute=\"serviceType\" name=\"service-type\" required=\"true\" type=\"java.lang.String\" xml-key=\"true\">\n");
299 sb.append("<xml-properties>\n");
301 "<xml-property name=\"description\" value=\"Value defined by orchestration to identify this service.\" />\n");
302 sb.append("</xml-properties>\n");
303 sb.append("</xml-element>\n");
305 "<xml-element java-attribute=\"tempUbSubAccountId\" name=\"temp-ub-sub-account-id\" type=\"java.lang.String\">\n");
306 sb.append("<xml-properties>\n");
308 "<xml-property name=\"description\" value=\"This property will be deleted from A&AI in the near future. Only stop gap solution.\" />\n");
309 sb.append("</xml-properties>\n");
310 sb.append("</xml-element>\n");
312 "<xml-element java-attribute=\"resourceVersion\" name=\"resource-version\" type=\"java.lang.String\">\n");
313 sb.append("<xml-properties>\n");
315 "<xml-property name=\"description\" value=\"Used for optimistic concurrency. Must be empty on create, valid on update and delete.\" />\n");
316 sb.append("</xml-properties>\n");
317 sb.append("</xml-element>\n");
318 // sb.append("<xml-element java-attribute=\"relationshipList\" name=\"relationship-list\"
319 // type=\"inventory.aai.onap.org.v11.RelationshipList\" />\n");
320 sb.append("</java-attributes>\n");
321 sb.append("<xml-properties>\n");
323 "<xml-property name=\"description\" value=\"Object that group service instances.\" />\n");
324 sb.append("<xml-property name=\"indexedProps\" value=\"service-type\" />\n");
325 sb.append("<xml-property name=\"dependentOn\" value=\"customer\" />\n");
326 sb.append("<xml-property name=\"container\" value=\"service-subscriptions\" />\n");
328 "<xml-property name=\"crossEntityReference\" value=\"service-instance,service-type\" />\n");
329 sb.append("</xml-properties>\n");
330 sb.append("</java-type>\n");
333 private void addRelationshipList(StringBuilder sb) {
334 sb.append("<java-type name=\"RelationshipList\">\n");
335 sb.append("<xml-root-element name=\"relationship-list\" />\n");
336 sb.append("<java-attributes>\n");
338 "<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"relationship\" name=\"relationship\" type=\"inventory.aai.onap.org.v11.Relationship\" />/n");
339 sb.append("</java-attributes>\n");
340 sb.append("</java-type>\n");
343 private void addRelationship(StringBuilder sb) {
344 sb.append("<java-type name=\"Relationship\">\n");
345 sb.append("<xml-root-element name=\"relationship\" />\n");
346 sb.append("<java-attributes>\n");
348 "<xml-element java-attribute=\"relatedTo\" name=\"related-to\" type=\"java.lang.String\">\n");
349 sb.append("<xml-properties>\n");
351 "<xml-property name=\"description\" value=\"A keyword provided by A&AI to indicate type of node.\" />\n");
352 sb.append("</xml-properties>\n");
353 sb.append("</xml-element>\n");
355 "<xml-element java-attribute=\"relatedLink\" name=\"related-link\" type=\"java.lang.String\">\n");
356 sb.append("<xml-properties>\n");
357 sb.append("<xml-property name=\"description\" value=\"URL to the object in A&AI.\" />");
358 sb.append("</xml-properties>\n");
359 sb.append("</xml-element>\n");
361 "<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"relationshipData\" name=\"relationship-data\" type=\"inventory.aai.onap.org.v11.RelationshipData\" />\n");
363 "<xml-element container-type=\"java.util.ArrayList\" java-attribute=\"relatedToProperty\" name=\"related-to-property\" type=\"inventory.aai.onap.org.v11.RelatedToProperty\" />\n");
364 sb.append("</java-attributes>\n");
365 sb.append("</java-type>\n");
368 private void addRelatedToProperty(StringBuilder sb) {
369 sb.append("<java-type name=\"RelatedToProperty\">\n");
370 sb.append("<xml-root-element name=\"related-to-property\" />\n");
371 sb.append("<java-attributes>\n");
373 "<xml-element java-attribute=\"propertyKey\" name=\"property-key\" type=\"java.lang.String\">\n");
374 sb.append("<xml-properties>\n");
375 sb.append("<xml-property name=\"description\" value=\"Key part of a key/value pair\" />\n");
376 sb.append("</xml-properties>\n");
377 sb.append("</xml-element>\n");
379 "<xml-element java-attribute=\"propertyValue\" name=\"property-value\" type=\"java.lang.String\">\n");
380 sb.append("<xml-properties>\n");
382 "<xml-property name=\"description\" value=\"Value part of a key/value pair\" />\n");
383 sb.append("</xml-properties>\n");
384 sb.append("</xml-element>\n");
385 sb.append("</java-attributes>\n");
386 sb.append("</java-type>\n");
389 private void addRelationshipData(StringBuilder sb) {
390 sb.append("<java-type name=\"RelationshipData\">\n");
391 sb.append("<xml-root-element name=\"relationship-data\" />\n");
392 sb.append("<java-attributes>\n");
394 "<xml-element java-attribute=\"relationshipKey\" name=\"relationship-key\" required=\"true\" type=\"java.lang.String\">\n");
395 sb.append("<xml-properties>\n");
397 "<xml-property name=\"description\" value=\"A keyword provided by A&AI to indicate an attribute.\" />\n");
398 sb.append("</xml-properties>\n");
399 sb.append("</xml-element>\n");
401 "<xml-element java-attribute=\"relationshipValue\" name=\"relationship-value\" required=\"true\" type=\"java.lang.String\">\n");
402 sb.append("<xml-properties>\n");
403 sb.append("<xml-property name=\"description\" value=\"Value of the attribute.\" />\n");
404 sb.append("</xml-properties>\n");
405 sb.append("</xml-element>\n");
406 sb.append("</java-attributes>\n");
407 sb.append("</java-type>\n");
410 private void addEndOfXML(StringBuilder sb) {
411 sb.append("</java-types>\n");
412 sb.append("</xml-bindings>\n");
415 public void init() throws ParserConfigurationException, SAXException, IOException {
416 DocumentBuilder dBuilder = null;
418 DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
419 dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
420 dBuilder = dbFactory.newDocumentBuilder();
421 } catch (ParserConfigurationException e) {
425 InputSource isInput = new InputSource(new StringReader(testXML));
426 doc = dBuilder.parse(isInput);
427 } catch (SAXException e) {
429 } catch (IOException e) {
433 NodeList bindingsNodes = doc.getElementsByTagName("xml-bindings");
434 Element bindingElement;
435 NodeList javaTypesNodes;
436 Element javaTypesElement;
438 if (bindingsNodes == null || bindingsNodes.getLength() == 0) {
439 throw new SAXException("OXM file error: missing <binding-nodes> in XML");
442 bindingElement = (Element) bindingsNodes.item(0);
443 javaTypesNodes = bindingElement.getElementsByTagName("java-types");
444 if (javaTypesNodes.getLength() < 1) {
445 throw new SAXException("OXM file error: missing <binding-nodes><java-types> in XML");
447 javaTypesElement = (Element) javaTypesNodes.item(0);
449 javaTypeNodes = javaTypesElement.getElementsByTagName("java-type");
450 if (javaTypeNodes.getLength() < 1) {
451 throw new SAXException(
452 "OXM file error: missing <binding-nodes><java-types><java-type> in XML");
454 logger.debug(testXML);
458 public void testXSDElement() {
459 // repeat of testGetIndexedProps() which uses the constructor
460 ArrayList<String> target = new ArrayList<String>();
461 target.add("subscriber-name");
462 target.add("global-customer-id");
463 target.add("subscriber-type");
464 target.add("service-type");
466 Vector<String> indexedProps = new Vector<String>();
467 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
468 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
469 indexedProps.addAll(javaTypeElement.getIndexedProps());
471 assertThat(new ArrayList<>(indexedProps),
472 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
476 public void testName() {
477 ArrayList<String> target = new ArrayList<String>();
478 target.add("ServiceSubscriptions");
479 target.add("ServiceSubscription");
480 target.add("Inventory");
481 target.add("Business");
482 target.add("Customers");
483 target.add("Customer");
484 ArrayList<String> names = new ArrayList<String>();
485 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
486 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
487 names.add(javaTypeElement.name());
489 logger.debug(String.join("|", names));
491 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
495 public void testGetAddTypes() {
496 HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
497 HashMap<String, ArrayList<String>> target = new HashMap<String, ArrayList<String>>();
498 target.put("Customer",
499 new ArrayList<>(Arrays.asList("ServiceSubscriptions", "RelationshipList")));
500 target.put("Customer", new ArrayList<>(Arrays.asList("ServiceSubscriptions")));
501 target.put("Business", new ArrayList<>(Arrays.asList("Customers")));
502 target.put("Inventory", new ArrayList<>(Arrays.asList("Business")));
503 target.put("Customers", new ArrayList<>(Arrays.asList("Customer")));
504 target.put("ServiceSubscription", new ArrayList<>(Arrays.asList("RelationshipList")));
505 target.put("ServiceSubscription", new ArrayList<>(Arrays.asList()));
506 target.put("ServiceSubscriptions", new ArrayList<>(Arrays.asList("ServiceSubscription")));
508 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
509 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
510 ArrayList<String> addTypes = new ArrayList<String>();
511 NodeList xmlElementNodes = javaTypeElement.getElementsByTagName("xml-element");
512 String name = javaTypeElement.name();
513 for (int j = 0; j < xmlElementNodes.getLength(); ++j) {
514 XSDElement xmlElement = new XSDElement((Element) xmlElementNodes.item(j));
515 addTypes.addAll(xmlElement.getAddTypes("v11"));
516 map.put(name, addTypes);
519 for (String key : map.keySet()) {
520 assertThat("Expected for key:" + key, map.get(key), equalTo(target.get(key)));
526 * public void testGetRequiredElements() {
527 * HashMap<String,ArrayList<String>> map = new HashMap<String,ArrayList<String>>();
528 * ArrayList<String> target = new ArrayList<String>();
529 * target.add("global-customer-id\n");
530 * target.add("subscriber-name\n");
531 * target.add("subscriber-type");
532 * for ( int i = 0; i < javaTypeNodes.getLength(); ++i ) {
533 * XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
534 * ArrayList<String> requiredItems = new ArrayList<String>();
535 * String name=javaTypeElement.name();
536 * requiredItems.addAll(javaTypeElement.getRequiredElements("v11"));
537 * map.put(name,requiredItems);
539 * for(String key : map.keySet()) {
540 * assertThat(map.get(key),equalTo(target));
545 public void testGetPathDescriptionProperty() {
546 ArrayList<String> target = new ArrayList<String>();
547 target.add("Namespace for business related constructs");
549 .add("Collection of customer identifiers to provide linkage back to BSS information.");
550 target.add("customer identifiers to provide linkage back to BSS information.");
551 target.add("Collection of objects that group service instances.");
552 target.add("Object that group service instances.");
553 List<String> descs = new ArrayList<String>();
554 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
555 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
556 if (javaTypeElement.getPathDescriptionProperty() != null)
557 descs.add(javaTypeElement.getPathDescriptionProperty());
559 logger.debug(String.join("|", descs));
560 assertThat(new ArrayList<>(descs),
561 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
565 public void testGetIndexedProps() {
566 ArrayList<String> target = new ArrayList<String>();
567 target.add("subscriber-name");
568 target.add("global-customer-id");
569 target.add("subscriber-type");
570 target.add("service-type");
572 Vector<String> indexedProps = new Vector<String>();
573 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
574 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
575 indexedProps.addAll(javaTypeElement.getIndexedProps());
577 assertThat(new ArrayList<>(indexedProps),
578 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
582 public void testGetContainerProperty() {
583 ArrayList<String> target = new ArrayList<String>();
584 target.add("service-subscriptions");
585 target.add("customers");
586 List<String> containers = new ArrayList<String>();
587 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
588 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
589 if (javaTypeElement.getContainerProperty() != null)
590 containers.add(javaTypeElement.getContainerProperty());
592 logger.debug(String.join("|", containers));
593 assertThat(new ArrayList<>(containers),
594 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
598 public void testGetQueryParamYAML() {
599 ArrayList<String> target = new ArrayList<String>();
601 " - name: global-customer-id\n in: query\n required: false\n type: string\n");
603 " - name: subscriber-name\n in: query\n required: false\n type: string\n");
605 " - name: subscriber-type\n in: query\n required: false\n type: string\n");
606 Vector<String> indexedProps = new Vector<String>();
607 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
608 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
609 if (javaTypeElement.getContainerProperty() != null) {
610 indexedProps.addAll(javaTypeElement.getIndexedProps());
611 String container = javaTypeElement.getContainerProperty();
612 Vector<String> containerProps = new Vector<String>();
613 NodeList xmlElementNodes = javaTypeElement.getElementsByTagName("xml-element");
614 for (int j = 0; j < xmlElementNodes.getLength(); ++j) {
615 XSDElement xmlElement = new XSDElement((Element) xmlElementNodes.item(j));
616 if (indexedProps.contains(xmlElement.name()))
617 containerProps.add(xmlElement.getQueryParamYAML());
619 GetOperation.addContainerProps(container, containerProps);
623 * List<String> queryParams = new ArrayList<String>();
624 * for ( int i = 0; i < javaTypeNodes.getLength(); ++ i ) {
625 * XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
626 * if(javaTypeElement.getQueryParamYAML() != null)
627 * queryParams.add(javaTypeElement.getQueryParamYAML());
630 assertThat(GetOperation.containers.get("customers"), equalTo(target));
634 public void testGetPathParamYAML() {
635 ArrayList<String> target = new ArrayList<String>();
637 " - name: Inventory\n in: path\n description: Inventory\n required: true\n");
639 " - name: Business\n in: path\n description: Business\n required: true\n");
641 " - name: Customers\n in: path\n description: Customers\n required: true\n");
643 " - name: Customer\n in: path\n description: Customer\n required: true\n");
645 " - name: ServiceSubscriptions\n in: path\n description: ServiceSubscriptions\n required: true\n");
647 " - name: ServiceSubscription\n in: path\n description: ServiceSubscription\n required: true\n");
648 List<String> pathParams = new ArrayList<String>();
649 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
650 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
651 if (javaTypeElement.getPathParamYAML(javaTypeElement.name()) != null)
652 pathParams.add(javaTypeElement.getPathParamYAML(javaTypeElement.name()));
654 logger.debug(String.join("|", pathParams));
655 assertThat(new ArrayList<>(pathParams),
656 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
660 public void testGetHTMLAnnotation() {
661 ArrayList<String> target = new ArrayList<String>();
662 target.add(" <xs:annotation>" + OxmFileProcessor.LINE_SEPARATOR + " <xs:appinfo>"
663 + OxmFileProcessor.LINE_SEPARATOR
664 + " <annox:annotate target=\"Business\">@org.onap.aai.annotations.Metadata(description=\"Namespace for business related constructs\")</annox:annotate>"
665 + OxmFileProcessor.LINE_SEPARATOR + " </xs:appinfo>"
666 + OxmFileProcessor.LINE_SEPARATOR + " </xs:annotation>"
667 + OxmFileProcessor.LINE_SEPARATOR);
668 target.add(" <xs:annotation>" + OxmFileProcessor.LINE_SEPARATOR + " <xs:appinfo>"
669 + OxmFileProcessor.LINE_SEPARATOR
670 + " <annox:annotate target=\"Customers\">@org.onap.aai.annotations.Metadata(description=\"Collection of customer identifiers to provide linkage back to BSS information.\")</annox:annotate>"
671 + OxmFileProcessor.LINE_SEPARATOR + " </xs:appinfo>"
672 + OxmFileProcessor.LINE_SEPARATOR + " </xs:annotation>"
673 + OxmFileProcessor.LINE_SEPARATOR);
674 target.add(" <xs:annotation>" + OxmFileProcessor.LINE_SEPARATOR + " <xs:appinfo>"
675 + OxmFileProcessor.LINE_SEPARATOR
676 + " <annox:annotate target=\"Customer\">@org.onap.aai.annotations.Metadata(description=\"customer identifiers to provide linkage back to BSS information.\",nameProps=\"subscriber-name\",indexedProps=\"subscriber-name,global-customer-id,subscriber-type\",searchable=\"global-customer-id,subscriber-name\",uniqueProps=\"global-customer-id\",container=\"customers\",namespace=\"business\")</annox:annotate>"
677 + OxmFileProcessor.LINE_SEPARATOR + " </xs:appinfo>"
678 + OxmFileProcessor.LINE_SEPARATOR + " </xs:annotation>"
679 + OxmFileProcessor.LINE_SEPARATOR);
680 target.add(" <xs:annotation>" + OxmFileProcessor.LINE_SEPARATOR + " <xs:appinfo>"
681 + OxmFileProcessor.LINE_SEPARATOR
682 + " <annox:annotate target=\"ServiceSubscriptions\">@org.onap.aai.annotations.Metadata(description=\"Collection of objects that group service instances.\")</annox:annotate>"
683 + OxmFileProcessor.LINE_SEPARATOR + " </xs:appinfo>"
684 + OxmFileProcessor.LINE_SEPARATOR + " </xs:annotation>"
685 + OxmFileProcessor.LINE_SEPARATOR);
686 target.add(" <xs:annotation>" + OxmFileProcessor.LINE_SEPARATOR + " <xs:appinfo>"
687 + OxmFileProcessor.LINE_SEPARATOR
688 + " <annox:annotate target=\"ServiceSubscription\">@org.onap.aai.annotations.Metadata(description=\"Object that group service instances.\",indexedProps=\"service-type\",dependentOn=\"customer\",container=\"service-subscriptions\",crossEntityReference=\"service-instance,service-type\")</annox:annotate>"
689 + OxmFileProcessor.LINE_SEPARATOR + " </xs:appinfo>"
690 + OxmFileProcessor.LINE_SEPARATOR + " </xs:annotation>"
691 + OxmFileProcessor.LINE_SEPARATOR);
692 List<String> annotes = new ArrayList<String>();
693 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
694 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
696 .isNotEmpty(javaTypeElement.getHTMLAnnotation(javaTypeElement.name(), "")))
697 annotes.add(javaTypeElement.getHTMLAnnotation(javaTypeElement.name(), " "));
699 logger.debug("result:");
700 logger.debug(String.join("|", annotes));
701 logger.debug("Expected:");
702 logger.debug(String.join("|", target));
703 assertThat(new ArrayList<>(annotes),
704 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
709 public void testGetTypePropertyYAML() {
710 ArrayList<String> target = new ArrayList<String>();
711 target.add(" Inventory:\n type: ");
713 " Business:\n type: description: Namespace for business related constructs\n");
715 " Customers:\n type: description: Collection of customer identifiers to provide linkage back to BSS information.\n");
717 " Customer:\n type: description: customer identifiers to provide linkage back to BSS information.\n");
719 " ServiceSubscriptions:\n type: description: Collection of objects that group service instances.\n");
721 " ServiceSubscription:\n type: description: Object that group service instances.\n");
722 StringBuilder sb = new StringBuilder(
723 " Customer:\n type: description: |\n customer identifiers to provide linkage back to BSS information.\n");
725 " *This property can be used as a filter to find the start node for a dsl query\n");
726 String yamlDesc = sb.toString();
727 List<String> types = new ArrayList<String>();
729 String customerDesc = null;
730 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
731 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
732 if (javaTypeElement.getTypePropertyYAML(false) != null)
733 types.add(javaTypeElement.getTypePropertyYAML(false));
734 container = javaTypeElement.getContainerProperty();
735 if ("customers".equals(container)) {
736 customerDesc = javaTypeElement.getTypePropertyYAML(true);
739 assertThat(new ArrayList<>(types),
740 both(everyItem(is(in(target.toArray())))).and(containsInAnyOrder(target.toArray())));
741 assertEquals(customerDesc, yamlDesc);
745 public void testIsStandardType() {
746 HashMap<String, ArrayList<String>> map = new HashMap<String, ArrayList<String>>();
747 HashMap<String, ArrayList<String>> target = new HashMap<String, ArrayList<String>>();
748 target.put("Customer", new ArrayList<>(Arrays.asList("global-customer-id",
749 "subscriber-name", "subscriber-type", "resource-version")));
750 target.put("Business", new ArrayList<>());
751 target.put("Inventory", new ArrayList<>());
752 target.put("Customers", new ArrayList<>());
753 target.put("ServiceSubscriptions", new ArrayList<>());
754 target.put("ServiceSubscription", new ArrayList<>(
755 Arrays.asList("service-type", "temp-ub-sub-account-id", "resource-version")));
757 for (int i = 0; i < javaTypeNodes.getLength(); ++i) {
758 XSDElement javaTypeElement = new XSDElement((Element) javaTypeNodes.item(i));
759 ArrayList<String> addTypes = new ArrayList<String>();
760 NodeList xmlElementNodes = javaTypeElement.getElementsByTagName("xml-element");
761 String name = javaTypeElement.name();
762 for (int j = 0; j < xmlElementNodes.getLength(); ++j) {
763 XSDElement xmlElement = new XSDElement((Element) xmlElementNodes.item(j));
764 if (xmlElement.isStandardType())
765 addTypes.add(xmlElement.name());
767 map.put(name, addTypes);
769 for (String key : map.keySet()) {
770 assertThat(map.get(key), equalTo(target.get(key)));