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.schema;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
27 import java.nio.file.Path;
28 import java.nio.file.Paths;
30 import java.util.stream.Collectors;
32 import javax.xml.parsers.DocumentBuilder;
33 import javax.xml.parsers.DocumentBuilderFactory;
34 import javax.xml.parsers.ParserConfigurationException;
35 import javax.xml.xpath.XPath;
36 import javax.xml.xpath.XPathConstants;
37 import javax.xml.xpath.XPathExpressionException;
38 import javax.xml.xpath.XPathFactory;
40 import org.apache.commons.io.FileUtils;
41 import org.apache.commons.io.filefilter.DirectoryFileFilter;
42 import org.apache.commons.io.filefilter.RegexFileFilter;
43 import org.json.simple.JSONArray;
44 import org.json.simple.JSONObject;
45 import org.json.simple.parser.JSONParser;
46 import org.json.simple.parser.ParseException;
47 import org.junit.Ignore;
48 import org.junit.Test;
50 import org.xml.sax.SAXException;
52 public class ValidateOXMTest {
54 private String DBEDGERULES_RULES = "rules";
55 private String DBEDGERULES_FROM = "from";
56 private String DBEDGERULES_TO = "to";
57 private String DBEDGERULES_DIRECTION = "direction";
58 private String DBEDGERULES_CONTAINS_OTHER_V = "contains-other-v";
59 private String DBEDGERULES_OUT = "OUT";
60 private String DBEDGERULES_IN = "IN";
61 private String XMLROOTELEMENT = "xml-root-element";
62 private String XMLPROPERTIES = "xml-properties";
63 private String ECOMP = "ecomp";
64 private String NARAD = "narad";
65 private String ONAP = "onap";
68 public void testFindXmlPropContainingSpace()
69 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
70 boolean foundIssue = false;
71 List<File> fileList = getLatestFiles();
73 StringBuilder msg = new StringBuilder();
74 for (File file : fileList) {
75 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
77 Document xmlDocument = getDocument(file);
78 XPath xPath = XPathFactory.newInstance().newXPath();
80 "/xml-bindings/java-types/java-type/xml-properties/xml-property[@name!='description' and contains(@value,' ')]";
82 (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
84 for (int i = 0; i < nodeList.getLength(); i++) {
87 msg.append(nodeList.item(i).getParentNode().getParentNode().getAttributes()
88 .getNamedItem("name").getNodeValue());
97 System.out.println(msg.toString());
98 fail("Node type xml-property should have space.");
104 * Verifies that all of the node types in the oxm's have their uri templates.
106 * @throws XPathExpressionException
107 * @throws IOException
108 * @throws SAXException
109 * @throws ParserConfigurationException
112 public void allNodeTypesHaveAAIUriTemplate()
113 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
114 boolean foundIssue = false;
115 List<File> fileList = getFiles();
117 StringBuilder msg = new StringBuilder();
118 for (File file : fileList) {
119 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
121 Document xmlDocument = getDocument(file);
122 XPath xPath = XPathFactory.newInstance().newXPath();
123 String expression = "/xml-bindings/java-types/java-type[" + "("
124 + "count(xml-properties/xml-property[@name='container']) > 0 "
125 + "or count(xml-properties/xml-property[@name='dependentOn']) > 0" + ") "
126 + "and count(xml-properties/xml-property[@name='uriTemplate']) = 0 " + "]";
128 (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
130 for (int i = 0; i < nodeList.getLength(); i++) {
131 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
132 if (name.equals("InstanceFilter") || name.equals("InventoryResponseItems")
133 || name.equals("InventoryResponseItem")) {
143 System.out.println(msg.toString());
144 fail("Missing uriTemplate in oxm.");
150 public void verifyAllIndexedPropertiesExistInObject()
151 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
153 boolean foundIssue = false;
154 List<File> fileList = getOxmSchemaFiles();
155 fileList.addAll(getOnapOxmSchemaFiles());
156 StringBuilder msg = new StringBuilder();
157 for (File file : fileList) {
158 Document xmlDocument = getDocument(file);
159 XPath xPath = XPathFactory.newInstance().newXPath();
161 "/xml-bindings/java-types/java-type[count(xml-properties/xml-property[@name='indexedProps']) > 0]";
163 (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
165 Map<String, List<String>> nodeTypeBadIndexProps = new HashMap<>();
166 for (int i = 0; i < nodeList.getLength(); i++) {
167 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
169 NodeList javaAttributesList =
170 ((Element) nodeList.item(i)).getElementsByTagName("java-attributes");
172 Set<String> properties = new HashSet<>();
174 for (int j = 0; j < javaAttributesList.getLength(); j++) {
175 NodeList elementList =
176 ((Element) javaAttributesList.item(j)).getElementsByTagName("xml-element");
177 for (int k = 0; k < elementList.getLength(); k++) {
178 properties.add(elementList.item(k).getAttributes().getNamedItem("name")
183 NodeList xmlPropertiesList =
184 ((Element) nodeList.item(i)).getElementsByTagName("xml-properties");
185 List<String> badIndexedProps = new ArrayList<>();
186 boolean foundIssueInNodeType = false;
188 for (int j = 0; j < xmlPropertiesList.getLength(); j++) {
189 NodeList xmlProperties =
190 ((Element) xmlPropertiesList.item(j)).getElementsByTagName("xml-property");
191 for (int k = 0; k < xmlProperties.getLength(); k++) {
192 String xmlProp = xmlProperties.item(k).getAttributes().getNamedItem("name")
194 if ("indexedProps".equals(xmlProp)) {
195 String xmlPropValue = xmlProperties.item(k).getAttributes()
196 .getNamedItem("value").getNodeValue();
198 List<String> indexProps =
199 Arrays.stream(xmlPropValue.split(",")).collect(Collectors.toList());
201 for (String indexProp : indexProps) {
202 if (!properties.contains(indexProp)) {
203 foundIssueInNodeType = true;
204 badIndexedProps.add(indexProp);
212 if (foundIssueInNodeType) {
214 nodeTypeBadIndexProps.put(name, badIndexedProps);
218 if (!nodeTypeBadIndexProps.isEmpty()) {
220 msg.append("File: " + file.getAbsolutePath().replaceAll(".*aai-schema", ""));
222 for (Map.Entry<String, List<String>> nodeTypeBadIndex : nodeTypeBadIndexProps
224 msg.append("NodeType: " + nodeTypeBadIndex.getKey());
226 " contains following indexed props that are not properties in object: ");
227 msg.append(String.join(",", nodeTypeBadIndex.getValue()));
235 fail(msg.toString());
240 public void verifyAllUniquePropertiesExistInObject()
241 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
243 boolean foundIssue = false;
244 List<File> fileList = getOxmSchemaFiles();
245 fileList.addAll(getOnapOxmSchemaFiles());
246 StringBuilder msg = new StringBuilder();
247 for (File file : fileList) {
248 Document xmlDocument = getDocument(file);
249 XPath xPath = XPathFactory.newInstance().newXPath();
251 "/xml-bindings/java-types/java-type[count(xml-properties/xml-property[@name='uniqueProps']) > 0]";
253 (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
255 Map<String, List<String>> nodeTypeBadUniqueProps = new HashMap<>();
256 for (int i = 0; i < nodeList.getLength(); i++) {
257 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
259 NodeList javaAttributesList =
260 ((Element) nodeList.item(i)).getElementsByTagName("java-attributes");
262 Set<String> properties = new HashSet<>();
264 for (int j = 0; j < javaAttributesList.getLength(); j++) {
265 NodeList elementList =
266 ((Element) javaAttributesList.item(j)).getElementsByTagName("xml-element");
267 for (int k = 0; k < elementList.getLength(); k++) {
268 properties.add(elementList.item(k).getAttributes().getNamedItem("name")
273 NodeList xmlPropertiesList =
274 ((Element) nodeList.item(i)).getElementsByTagName("xml-properties");
275 List<String> badUniqueProps = new ArrayList<>();
276 boolean foundIssueInNodeType = false;
278 for (int j = 0; j < xmlPropertiesList.getLength(); j++) {
279 NodeList xmlProperties =
280 ((Element) xmlPropertiesList.item(j)).getElementsByTagName("xml-property");
281 for (int k = 0; k < xmlProperties.getLength(); k++) {
282 String xmlProp = xmlProperties.item(k).getAttributes().getNamedItem("name")
284 if ("uniqueProps".equals(xmlProp)) {
285 String xmlPropValue = xmlProperties.item(k).getAttributes()
286 .getNamedItem("value").getNodeValue();
288 List<String> uniqueProps =
289 Arrays.stream(xmlPropValue.split(",")).collect(Collectors.toList());
291 for (String uniqueProp : uniqueProps) {
292 if (!properties.contains(uniqueProp)) {
293 foundIssueInNodeType = true;
294 badUniqueProps.add(uniqueProp);
302 if (foundIssueInNodeType) {
304 nodeTypeBadUniqueProps.put(name, badUniqueProps);
308 if (!nodeTypeBadUniqueProps.isEmpty()) {
310 msg.append("File: " + file.getAbsolutePath().replaceAll(".*aai-schema", ""));
312 for (Map.Entry<String, List<String>> nodeTypeBadUnique : nodeTypeBadUniqueProps
314 msg.append("NodeType: " + nodeTypeBadUnique.getKey());
316 " contains following unique props that are not properties in object: ");
317 msg.append(String.join(",", nodeTypeBadUnique.getValue()));
325 fail(msg.toString());
330 * Verifies that all of the top level node types in the oxm's have their namespace in uri
333 * @throws XPathExpressionException
334 * @throws IOException
335 * @throws SAXException
336 * @throws ParserConfigurationException
339 public void verifyAllUriTemplateHaveNamespace()
340 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
341 boolean foundIssue = false;
342 List<File> fileList = getOxmSchemaFiles();
343 fileList.addAll(getOnapOxmSchemaFiles());
344 StringBuilder msg = new StringBuilder();
345 for (File file : fileList) {
346 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
348 Document xmlDocument = getDocument(file);
349 XPath xPath = XPathFactory.newInstance().newXPath();
350 String expression = "/xml-bindings/java-types/java-type["
351 + "count(xml-properties/xml-property[@name='namespace']) > 0 " + "]";
353 (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
355 for (int i = 0; i < nodeList.getLength(); i++) {
356 String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
358 NodeList childNodeList = (NodeList) nodeList.item(i).getChildNodes();
359 for (int j = 0; j < childNodeList.getLength(); j++) {
361 String nodeName = childNodeList.item(j).getNodeName();
362 NodeList xmlPropertyNodeList = childNodeList.item(j).getChildNodes();
363 if (XMLPROPERTIES.equals(nodeName)) {
365 String namespaceVal = "";
366 String uriTemplateVal = "";
367 for (int k = 0; k < xmlPropertyNodeList.getLength(); k++) {
369 if ("xml-property".equals(xmlPropertyNodeList.item(k).getNodeName())) {
371 NamedNodeMap attributes =
372 xmlPropertyNodeList.item(k).getAttributes();
375 .equals(attributes.getNamedItem("name").getNodeValue())) {
376 namespaceVal = attributes.getNamedItem("value").getNodeValue();
379 .equals(attributes.getNamedItem("name").getNodeValue())) {
381 attributes.getNamedItem("value").getNodeValue();
388 if (!uriTemplateVal.startsWith("/" + namespaceVal + "/")) {
391 msg.append(uriTemplateVal);
401 System.out.println(msg.toString());
402 fail("uriTemplate doesnt start with /namespace/.");
408 * Verifies that all specified properties are indexed
409 * Currently set to check that "model-invariant-id","model-version-id" which are aliased are
412 * @throws XPathExpressionException
413 * @throws IOException
414 * @throws SAXException
415 * @throws ParserConfigurationException
418 public void aliasedIndexedPropsAreInIndexedListWithPropName()
419 throws XPathExpressionException, IOException, SAXException, ParserConfigurationException {
421 final List<String> props = Arrays.asList("model-invariant-id", "model-version-id");
423 boolean foundIssue = false;
424 List<File> fileList = getLatestFiles();
425 StringBuilder msg = new StringBuilder();
427 for (File file : fileList) {
428 msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", ""));
430 for (String prop : props) {
431 Document xmlDocument = getDocument(file);
432 XPath xPath = XPathFactory.newInstance().newXPath();
433 String expression = "/xml-bindings/java-types/java-type[" + "("
434 + "count(xml-properties/xml-property[@name='container']) > 0 "
435 + "or count(xml-properties/xml-property[@name='dependentOn']) > 0" + ") "
436 + "and count(xml-properties/xml-property[@name='indexedProps' and not(contains(@value,'"
437 + prop + "'))]) > 0 " + // prop is not in indexed props list
438 "and count(java-attributes/xml-element[@name='" + prop + "']) > 0 " + // prop is
444 NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument,
445 XPathConstants.NODESET);
447 if (nodeList.getLength() > 0) {
448 msg.append("\t").append(prop).append("\n");
450 for (int i = 0; i < nodeList.getLength(); i++) {
452 nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue();
453 if (name.equals("InstanceFilter") || name.equals("InventoryResponseItems")
454 || name.equals("InventoryResponseItem")) {
458 msg.append("\t\t").append(name).append("\n");
464 System.out.println(msg.toString());
465 fail("Missing index entry in oxm.");
471 * Check schema versions against their respective dbEdgeRules file and check if the
472 * dependentOn relationship matches what is listed in the edge rules.
477 public void testSchemaValidationAgainstEdgeRules() throws XPathExpressionException, IOException,
478 SAXException, ParserConfigurationException, ParseException {
479 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
481 Arrays.asList(currentRelativePath.toFile().listFiles(File::isDirectory));
482 boolean success = true;
483 for (File subDir : subDirs) {
484 List<String> oxmSchemaList = new ArrayList<>();
485 List<String> dbEdgeRulesList = new ArrayList<>();
486 String oxm = subDir.getAbsolutePath() + "/oxm";
487 File[] oxms = new File(oxm).listFiles(File::isDirectory);
488 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
489 public int compare(String o1, String o2) {
490 return extractInt(o1) - extractInt(o2);
493 int extractInt(String s) {
494 String num = s.replaceAll("\\D", "");
495 return num.isEmpty() ? 0 : Integer.parseInt(num);
497 }).ifPresent(oxmSchemaList::add);
499 String edgeRule = subDir.getAbsolutePath() + "/dbedgerules";
500 File[] edgeRules = new File(edgeRule).listFiles(File::isDirectory);
501 Arrays.stream(edgeRules).map(File::getAbsolutePath).max(new Comparator<String>() {
502 public int compare(String o1, String o2) {
503 return extractInt(o1) - extractInt(o2);
506 int extractInt(String s) {
507 String num = s.replaceAll("\\D", "");
508 return num.isEmpty() ? 0 : Integer.parseInt(num);
510 }).ifPresent(dbEdgeRulesList::add);
512 List<File> oxmSchemaFileList = new ArrayList<>();
513 List<File> dbEdgeRulesFileList = new ArrayList<>();
514 oxmSchemaList.forEach(s -> FileUtils
515 .listFiles(new File(s), new RegexFileFilter(".*\\.xml"),
516 DirectoryFileFilter.DIRECTORY)
517 .stream().filter(file -> file.getAbsolutePath().contains("oxm"))
518 .forEach(oxmSchemaFileList::add));
520 dbEdgeRulesList.forEach(s -> FileUtils
521 .listFiles(new File(s), new RegexFileFilter(".*\\.json"),
522 DirectoryFileFilter.DIRECTORY)
523 .stream().filter(file -> file.getAbsolutePath().contains("DbEdgeRules"))
524 .forEach(dbEdgeRulesFileList::add));
526 // Map the dbEdgeRules json file into a HashMap for reference
527 Map<String, Set<String>> dbEdgeRules = new HashMap<>();
528 JSONParser jsonParser = new JSONParser();
529 for (File file : dbEdgeRulesFileList) {
530 FileReader reader = new FileReader(file);
531 // Read JSON file. Expecting JSON file to read an object with a JSONArray names
533 JSONObject jsonObj = (JSONObject) jsonParser.parse(reader);
534 JSONArray rules = (JSONArray) jsonObj.get(DBEDGERULES_RULES);
535 for (int i = 0; i < rules.size(); i++) {
536 JSONObject rule = (JSONObject) rules.get(i);
537 String fromNode = rule.get(DBEDGERULES_FROM).toString();
538 String toNode = rule.get(DBEDGERULES_TO).toString();
539 String direction = rule.get(DBEDGERULES_DIRECTION).toString();
540 String containsOtherV = rule.get(DBEDGERULES_CONTAINS_OTHER_V).toString();
542 // special case - cvlan-tag should be replaced with cvlan-tag-entry
543 if (fromNode.equals("cvlan-tag"))
544 fromNode = "cvlan-tag-entry";
545 if (toNode.equals("cvlan-tag"))
546 toNode = "cvlan-tag-entry";
547 if (containsOtherV.equals("!${direction}")) {
548 if (direction.equals(DBEDGERULES_IN)) {
549 direction = DBEDGERULES_OUT;
550 } else if (direction.equals(DBEDGERULES_OUT)) {
551 direction = DBEDGERULES_IN;
554 // If this value is none, the edge rule is for cousin nodes. Ignore.
555 else if (containsOtherV.equals("NONE"))
557 dbEdgeRulesMapPut(dbEdgeRules, fromNode, toNode, direction);
561 // Iterate through the most recent oxm schema files. Map the parent child relationships
562 Map<String, Set<String>> oxmSchemaFile = new HashMap<>();
563 for (File file : oxmSchemaFileList) {
564 Document xmlDocument = getDocument(file);
565 XPath xPath = XPathFactory.newInstance().newXPath();
566 String parentNodeExpression =
567 "/xml-bindings/java-types/java-type/xml-properties/xml-property[@name='dependentOn']";
568 NodeList parentNodeList = (NodeList) xPath.compile(parentNodeExpression)
569 .evaluate(xmlDocument, XPathConstants.NODESET);
570 String childNodeExpression = "/xml-bindings/java-types/java-type[" + "("
571 + "count(xml-properties/xml-property[@name='dependentOn']) > 0" + ")]";
572 NodeList childNodeList = (NodeList) xPath.compile(childNodeExpression)
573 .evaluate(xmlDocument, XPathConstants.NODESET);
575 for (int i = 0; i < parentNodeList.getLength(); i++) {
577 // Obtain the xml-root-element field by tracing the childNodes from the
578 // java-type parent node
579 for (int j = 0; j < childNodeList.item(i).getChildNodes().getLength(); j++) {
580 if (childNodeList.item(i).getChildNodes().item(j).getNodeName()
581 .equals(XMLROOTELEMENT)) {
584 String dependentOn = parentNodeList.item(i).getAttributes()
585 .getNamedItem("value").getNodeValue();
588 String xmlRootElement = childNodeList.item(i).getChildNodes().item(j)
589 .getAttributes().getNamedItem("name").getNodeValue();
591 Set<String> childSet;
592 String[] parents = dependentOn.split(",");
593 for (int k = 0; k < parents.length; k++) {
594 String parent = parents[k];
595 if (oxmSchemaFile.containsKey(parent)) {
596 childSet = oxmSchemaFile.get(parent);
598 childSet = new HashSet<>();
600 childSet.add(xmlRootElement);
601 oxmSchemaFile.put(parent, childSet);
609 // Compare the OXM file against the dbEdgeRules file. check what is missing in
610 // dbEdgeRules from the oxm files.
611 Set<String> oxmKeySet = oxmSchemaFile.keySet();
612 for (String key : oxmKeySet) {
613 Set<String> oxmChildren = oxmSchemaFile.get(key);
614 Set<String> dbEdgeRulesChildren = dbEdgeRules.get(key);
616 // Check if the parent vertex exists at all in the dbEdgeRules file
617 if (dbEdgeRulesChildren == null || dbEdgeRulesChildren.isEmpty()) {
618 for (String oxmChild : oxmChildren) {
619 System.out.println("ERROR: dbEdgeRules under directory '"
620 + subDir.toString() + "' does not contain parent '" + key
621 + "' and child '" + oxmChild + "' relationship");
627 // Compare both parent-child relationships between both files
628 if (!oxmChildren.equals(dbEdgeRulesChildren)) {
629 for (String oxmChild : oxmChildren) {
630 if (!dbEdgeRulesChildren.contains(oxmChild)) {
631 System.out.println("ERROR: dbEdgeRules under directory '"
632 + subDir.toString() + "' does not contain parent '" + key
633 + "' and child '" + oxmChild + "' relationship");
640 // Compare the dbEdgeRules against the OXM File
641 Set<String> dbEdgeRuleKeySet = dbEdgeRules.keySet();
642 for (String key : dbEdgeRuleKeySet) {
643 Set<String> dbEdgeRulesChildren = dbEdgeRules.get(key);
644 Set<String> oxmChildren = oxmSchemaFile.get(key);
646 // Check if the parent vertex exists at all in the dbEdgeRules file
647 if (oxmChildren == null || oxmChildren.isEmpty()) {
648 for (String dbEdgeRuleChild : dbEdgeRulesChildren) {
649 System.out.println("ERROR: oxms under directory '" + subDir.toString()
650 + "' do not contain parent '" + key + "' and child '" + dbEdgeRuleChild
657 // Compare both parent-child relationships between both files
658 if (!dbEdgeRulesChildren.equals(oxmChildren)) {
659 for (String dbEdgeRuleChild : dbEdgeRulesChildren) {
660 if (!oxmChildren.contains(dbEdgeRuleChild)) {
661 System.out.println("ERROR: oxms under directory '" + subDir.toString()
662 + "' do not contain parent '" + key + "' and child '"
663 + dbEdgeRuleChild + "' relationship");
674 * Check dataOwner elements to ensure that they have ownerCheck side effect added to it.
678 public void testDataOwnerWithOwnerCheck() throws XPathExpressionException, IOException,
679 SAXException, ParserConfigurationException, ParseException {
680 List<File> fileList = getLatestFiles();
682 for (File file : fileList) {
683 Document xmlDocument = getDocument(file);
684 XPath xPath = XPathFactory.newInstance().newXPath();
686 "/xml-bindings/java-types/java-type/java-attributes/xml-element[@name='data-owner']";
688 (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET);
690 List<String> typeMissingOwnerCheck = new ArrayList<>();
692 for (int i = 0; i < nodeList.getLength(); i++) {
693 String type = nodeList.item(i).getParentNode().getParentNode().getAttributes()
694 .getNamedItem("name").getNodeValue();
695 NodeList xmlPropertiesList =
696 ((Element) nodeList.item(i)).getElementsByTagName("xml-properties");
698 boolean missingOwnerCheck = true;
699 for (int j = 0; j < xmlPropertiesList.getLength(); j++) {
700 NodeList xmlProperties =
701 ((Element) xmlPropertiesList.item(j)).getElementsByTagName("xml-property");
703 for (int k = 0; k < xmlProperties.getLength(); k++) {
704 String xmlProp = xmlProperties.item(k).getAttributes().getNamedItem("name")
707 if ("ownerCheck".equals(xmlProp)) {
708 missingOwnerCheck = false;
713 if (!missingOwnerCheck) {
718 if (missingOwnerCheck) {
719 typeMissingOwnerCheck.add(type);
723 if (!typeMissingOwnerCheck.isEmpty()) {
724 fail(file.getAbsolutePath().replaceAll(".*aai-schema", "") + ": "
725 + String.join(", ", typeMissingOwnerCheck));
731 * Null check for strings
736 private boolean isStringEmpty(String s) {
737 return (s == null || s.isEmpty()) ? true : false;
741 * Creating a hashmap to map what child nodes are associated to which parent nodes
742 * according to the dbEdgeRules json files. A HashMap was chosen for the value of the map for
745 * @param from this variable will act as the key or value depending on the direction
746 * @param to this variable will act as the key or value depending on the direction
747 * @param direction dictates the direction of which vertex is dependent on which
748 * @return The map returned will act as a dictionary to keep track of the parent nodes. Value of
749 * the map is a hashmap to help handle collision of multiple children to one parent
751 private Map<String, Set<String>> dbEdgeRulesMapPut(Map<String, Set<String>> dbEdgeRules,
752 String from, String to, String direction) {
753 if (isStringEmpty(from) || isStringEmpty(to) || isStringEmpty(direction))
756 // Assigning the strings to parent and child for readability
757 String parent = "", child = "";
758 if (direction.equals(DBEDGERULES_OUT)) {
761 } else if (direction.equals(DBEDGERULES_IN)) {
765 // Add to the dbEdgeRules mapping
766 Set<String> children;
767 if (!dbEdgeRules.containsKey(parent)) {
768 children = new HashSet<>();
770 dbEdgeRules.put(parent, children);
772 children = dbEdgeRules.get(parent);
774 dbEdgeRules.put(parent, children);
779 private List<File> getFiles() {
780 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
782 .listFiles(currentRelativePath.toFile(), new RegexFileFilter(".*\\.xml"),
783 DirectoryFileFilter.DIRECTORY)
784 .stream().filter(file -> file.getAbsolutePath().contains("oxm"))
785 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
786 .collect(Collectors.toList());
789 private List<File> getOxmSchemaFiles() {
791 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
793 .listFiles(currentRelativePath.toFile(), new RegexFileFilter(".*\\.xml"),
794 DirectoryFileFilter.DIRECTORY)
795 .stream().filter(file -> file.getAbsolutePath().contains("oxm"))
796 .filter(file -> file.getAbsolutePath().contains("aai_schema_oxm"))
797 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
798 .collect(Collectors.toList());
802 private List<File> getOnapOxmSchemaFiles() {
804 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
806 .listFiles(currentRelativePath.toFile(), new RegexFileFilter(".*\\.xml"),
807 DirectoryFileFilter.DIRECTORY)
808 .stream().filter(file -> file.getAbsolutePath().contains("oxm"))
809 .filter(file -> file.getAbsolutePath().contains("aai_oxm"))
810 .collect(Collectors.toList());
814 private List<File> getAaiSchemaOxmFiles() {
815 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
817 .listFiles(currentRelativePath.toFile(), new RegexFileFilter(".*\\.xml"),
818 DirectoryFileFilter.DIRECTORY)
819 .stream().filter(file -> file.getAbsolutePath().contains("oxm"))
820 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
821 .collect(Collectors.toList());
824 private List<File> getDbEdgeRulesFiles() {
825 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
827 .listFiles(currentRelativePath.toFile(), new RegexFileFilter(".*\\.json"),
828 DirectoryFileFilter.DIRECTORY)
829 .stream().filter(file -> file.getAbsolutePath().contains("DbEdgeRules"))
830 .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks
831 .collect(Collectors.toList());
835 * Finds all of the oxm files for the latest version.
837 * @return list of the latest version of the oxm files.
839 private List<File> getLatestDbEdgeRulesFiles(String fileDirectory) {
840 List<String> latest = new ArrayList<>();
841 String currentRelativePath =
842 Paths.get("../aai-schema/src/main/resources/" + fileDirectory + "/dbedgerules")
843 .toAbsolutePath().toString();
844 File[] oxms = new File(currentRelativePath).listFiles(File::isDirectory);
845 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
846 public int compare(String o1, String o2) {
847 return extractInt(o1) - extractInt(o2);
850 int extractInt(String s) {
851 String num = s.replaceAll("\\D", "");
852 return num.isEmpty() ? 0 : Integer.parseInt(num);
854 }).ifPresent(latest::add);
856 List<File> latestFiles = new ArrayList<>();
857 latest.forEach(s -> FileUtils
858 .listFiles(new File(s), new RegexFileFilter(".*\\.json"), DirectoryFileFilter.DIRECTORY)
859 .stream().filter(file -> file.getAbsolutePath().contains("DbEdgeRules"))
860 .forEach(latestFiles::add));
866 * Finds all of the oxm files for the latest version.
868 * @return list of the latest version of the oxm files.
870 private List<File> getLatestFiles() {
871 List<String> latest = new ArrayList<>();
872 Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath();
874 Arrays.asList(currentRelativePath.toFile().listFiles(File::isDirectory));
875 for (File subDir : subDirs) {
876 String oxm = subDir.getAbsolutePath() + "/oxm";
877 File[] oxms = new File(oxm).listFiles(File::isDirectory);
878 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
879 public int compare(String o1, String o2) {
880 return extractInt(o1) - extractInt(o2);
883 int extractInt(String s) {
884 String num = s.replaceAll("\\D", "");
885 return num.isEmpty() ? 0 : Integer.parseInt(num);
887 }).ifPresent(latest::add);
890 List<File> latestFiles = new ArrayList<>();
891 latest.forEach(s -> FileUtils
892 .listFiles(new File(s), new RegexFileFilter(".*\\.xml"), DirectoryFileFilter.DIRECTORY)
893 .stream().filter(file -> file.getAbsolutePath().contains("oxm"))
894 .forEach(latestFiles::add));
900 * Finds all of the oxm files for the latest version.
902 * @return list of the latest version of the oxm files.
904 private List<File> getLatestFiles(String fileDirectory) {
905 List<String> latest = new ArrayList<>();
906 String currentRelativePath =
907 Paths.get("../aai-schema/src/main/resources/" + fileDirectory + "/oxm").toAbsolutePath()
909 File[] oxms = new File(currentRelativePath).listFiles(File::isDirectory);
910 Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator<String>() {
911 public int compare(String o1, String o2) {
912 return extractInt(o1) - extractInt(o2);
915 int extractInt(String s) {
916 String num = s.replaceAll("\\D", "");
917 return num.isEmpty() ? 0 : Integer.parseInt(num);
919 }).ifPresent(latest::add);
921 List<File> latestFiles = new ArrayList<>();
922 latest.forEach(s -> FileUtils
923 .listFiles(new File(s), new RegexFileFilter(".*\\.xml"), DirectoryFileFilter.DIRECTORY)
924 .stream().filter(file -> file.getAbsolutePath().contains("oxm"))
925 .forEach(latestFiles::add));
930 // TODO test that all oxm xml are valid xml
932 public String printNodeList(NodeList nodeList, Document doc) throws IOException {
933 StringBuilder stringBuilder = new StringBuilder();
934 for (int i = 0; i < nodeList.getLength(); i++) {
935 stringBuilder.append(printNode(nodeList.item(i), doc)).append("\n");
937 return stringBuilder.toString();
940 public String printNode(Node node, Document document) throws IOException {
941 StringWriter stringWriter = new StringWriter();
942 return stringWriter.toString();
946 private Document getDocument(File file)
947 throws ParserConfigurationException, SAXException, IOException {
948 InputStream fileIS = new FileInputStream(file);
949 DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
950 DocumentBuilder builder = builderFactory.newDocumentBuilder();
951 return builder.parse(fileIS);