From bd6468173eec459beea471778d20a7ff0278aad0 Mon Sep 17 00:00:00 2001 From: Eric Santos Date: Wed, 27 Jan 2021 14:34:17 -0500 Subject: Unit test for ownerCheck Issue-ID: AAI-3256 Signed-off-by: Santos, Eric Change-Id: I02a8e2be8a3bac4f5986c03b9a4aa7e803f70d43 --- .../java/org/onap/aai/schema/ValidateOXMTest.java | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'aai-schema') diff --git a/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java b/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java index 79323aa..a65ddd9 100644 --- a/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java +++ b/aai-schema/src/test/java/org/onap/aai/schema/ValidateOXMTest.java @@ -627,6 +627,55 @@ public class ValidateOXMTest { assertTrue(success); } + /** + * Check dataOwner elements to ensure that they have ownerCheck side effect added to it. + * + */ + @Test + public void testDataOwnerWithOwnerCheck() throws XPathExpressionException, IOException, SAXException, ParserConfigurationException, ParseException { + List fileList = getLatestFiles(); + + for (File file : fileList) { + Document xmlDocument = getDocument(file); + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "/xml-bindings/java-types/java-type/java-attributes/xml-element[@name='data-owner']"; + NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); + + List typeMissingOwnerCheck = new ArrayList<>(); + + for (int i = 0; i < nodeList.getLength(); i++) { + String type = nodeList.item(i).getParentNode().getParentNode().getAttributes().getNamedItem("name").getNodeValue(); + NodeList xmlPropertiesList = ((Element) nodeList.item(i)).getElementsByTagName("xml-properties"); + + boolean missingOwnerCheck = true; + for (int j = 0; j < xmlPropertiesList.getLength(); j++) { + NodeList xmlProperties = ((Element) xmlPropertiesList.item(j)).getElementsByTagName("xml-property"); + + for (int k = 0; k < xmlProperties.getLength(); k++) { + String xmlProp = xmlProperties.item(k).getAttributes().getNamedItem("name").getNodeValue(); + + if ("ownerCheck".equals(xmlProp)) { + missingOwnerCheck = false; + break; + } + } + + if (!missingOwnerCheck) { + break; + } + } + + if (missingOwnerCheck) { + typeMissingOwnerCheck.add(type); + } + } + + if (!typeMissingOwnerCheck.isEmpty()) { + fail(file.getAbsolutePath().replaceAll(".*aai-schema", "") + ": " + String.join(", ", typeMissingOwnerCheck)); + } + } + } + /** * Null check for strings * @param s -- cgit 1.2.3-korg