From 009a574339ba0bccca7c786c18af24203e4cecf3 Mon Sep 17 00:00:00 2001 From: "Kajur, Harish (vk250x)" Date: Sun, 14 Apr 2019 21:32:42 -0400 Subject: Add missing model invariant indexes Some of the properties in the schema are missing the indexes for the dbalias properties and if they are missing it could potentially cause issues when the application runs the create db schema Adding a junit to ensure that in the future that such properties are properly highlighted to ensure that this doesn't happen Issue-ID: AAI-2374 Change-Id: I01efba764a61881056892458bdf705d94d458650 Signed-off-by: Kajur, Harish (vk250x) --- aai-annotations/pom.xml | 4 +- aai-queries/pom.xml | 4 +- aai-schema-gen/pom.xml | 4 +- aai-schema-service/pom.xml | 4 +- aai-schema/pom.xml | 4 +- .../main/resources/onap/oxm/v16/aai_oxm_v16.xml | 14 +-- .../java/org/onap/aai/schema/ValidateOXMTest.java | 119 +++++++++++++++++++-- pom.xml | 4 +- version.properties | 2 +- 9 files changed, 130 insertions(+), 29 deletions(-) diff --git a/aai-annotations/pom.xml b/aai-annotations/pom.xml index 13443be..edd99cf 100644 --- a/aai-annotations/pom.xml +++ b/aai-annotations/pom.xml @@ -27,12 +27,12 @@ org.onap.aai.schema-service schema-service - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT aai-annotations aai-annotations jar - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT https://nexus.onap.org diff --git a/aai-queries/pom.xml b/aai-queries/pom.xml index a807229..a70da3f 100644 --- a/aai-queries/pom.xml +++ b/aai-queries/pom.xml @@ -27,11 +27,11 @@ org.onap.aai.schema-service schema-service - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT aai-queries aai-queries - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT https://nexus.onap.org diff --git a/aai-schema-gen/pom.xml b/aai-schema-gen/pom.xml index 2b5175e..2fcce4c 100644 --- a/aai-schema-gen/pom.xml +++ b/aai-schema-gen/pom.xml @@ -27,11 +27,11 @@ org.onap.aai.schema-service schema-service - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT aai-schema-gen aai-schema-gen - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT https://nexus.onap.org diff --git a/aai-schema-service/pom.xml b/aai-schema-service/pom.xml index b35f751..1c6a1d3 100644 --- a/aai-schema-service/pom.xml +++ b/aai-schema-service/pom.xml @@ -25,11 +25,11 @@ 4.0.0 org.onap.aai.schema-service aai-schema-service - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT org.onap.aai.schema-service schema-service - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT 1.8 diff --git a/aai-schema/pom.xml b/aai-schema/pom.xml index 34f4a26..127aa25 100644 --- a/aai-schema/pom.xml +++ b/aai-schema/pom.xml @@ -27,11 +27,11 @@ org.onap.aai.schema-service schema-service - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT aai-schema aai-schema - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT https://nexus.onap.org diff --git a/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml b/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml index aaf9e5c..78f71f5 100644 --- a/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml +++ b/aai-schema/src/main/resources/onap/oxm/v16/aai_oxm_v16.xml @@ -3845,7 +3845,7 @@ - + @@ -7718,7 +7718,7 @@ - + @@ -7863,7 +7863,7 @@ - + @@ -8188,7 +8188,7 @@ - + @@ -8291,7 +8291,7 @@ - + @@ -8410,7 +8410,7 @@ - + @@ -8555,7 +8555,7 @@ - + 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 cd8c76f..0dcf1b3 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 @@ -20,10 +20,10 @@ package org.onap.aai.schema; -//import org.junit.Test; - import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.DirectoryFileFilter; +import org.apache.commons.io.filefilter.FileFileFilter; +import org.apache.commons.io.filefilter.FileFilterUtils; import org.apache.commons.io.filefilter.RegexFileFilter; import org.junit.Test; import org.w3c.dom.Document; @@ -39,14 +39,12 @@ import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathFactory; import java.io.*; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; +import java.util.*; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; public class ValidateOXMTest { @@ -54,7 +52,7 @@ public class ValidateOXMTest { @Test public void testFindXmlPropContainingSpace() throws XPathExpressionException, IOException, SAXException, ParserConfigurationException { boolean foundIssue = false; - List fileList = getFiles(); + List fileList = getLatestFiles(); StringBuilder msg = new StringBuilder(); for (File file : fileList) { @@ -101,7 +99,13 @@ public class ValidateOXMTest { msg.append("\n"); Document xmlDocument = getDocument(file); XPath xPath = XPathFactory.newInstance().newXPath(); - String expression = "/xml-bindings/java-types/java-type[count(xml-properties/xml-property[@name='container']) > 0 and count(xml-properties/xml-property[@name='uriTemplate']) = 0 ]"; + String expression = "/xml-bindings/java-types/java-type[" + + "(" + + "count(xml-properties/xml-property[@name='container']) > 0 " + + "or count(xml-properties/xml-property[@name='dependentOn']) > 0" + + ") " + + "and count(xml-properties/xml-property[@name='uriTemplate']) = 0 " + + "]"; NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); for (int i = 0; i < nodeList.getLength(); i++) { @@ -122,16 +126,113 @@ public class ValidateOXMTest { } + + /** + * Verifies that all specified properties are indexed + * Currently set to check that "model-invariant-id","model-version-id" which are aliased are indexed + * @throws XPathExpressionException + * @throws IOException + * @throws SAXException + * @throws ParserConfigurationException + */ + @Test + public void aliasedIndexedPropsAreInIndexedListWithPropName() throws XPathExpressionException, IOException, SAXException, ParserConfigurationException { + + final List props = Arrays.asList("model-invariant-id","model-version-id"); + + boolean foundIssue = false; + List fileList = getLatestFiles(); + StringBuilder msg = new StringBuilder(); + + for (File file : fileList) { + msg.append(file.getAbsolutePath().replaceAll(".*aai-schema", "")); + msg.append("\n"); + for (String prop : props) { + Document xmlDocument = getDocument(file); + XPath xPath = XPathFactory.newInstance().newXPath(); + String expression = "/xml-bindings/java-types/java-type[" + + "(" + + "count(xml-properties/xml-property[@name='container']) > 0 " + + "or count(xml-properties/xml-property[@name='dependentOn']) > 0" + + ") " + + "and count(xml-properties/xml-property[@name='indexedProps' and not(contains(@value,'" + prop + "'))]) > 0 " + //prop is not in indexed props list + "and count(java-attributes/xml-element[@name='" + prop + "']) > 0 " + // prop is a property on obj + "]"; + + NodeList nodeList = (NodeList) xPath.compile(expression).evaluate(xmlDocument, XPathConstants.NODESET); + + if (nodeList.getLength() > 0) { + msg.append("\t") + .append(prop) + .append("\n"); + } + for (int i = 0; i < nodeList.getLength(); i++) { + String name = nodeList.item(i).getAttributes().getNamedItem("name").getNodeValue(); + if (name.equals("InstanceFilter") || name.equals("InventoryResponseItems") || name.equals("InventoryResponseItem")) { + continue; + } + foundIssue = true; + msg.append("\t\t") + .append(name) + .append("\n"); + } + } + } + + if (foundIssue) { + System.out.println(msg.toString()); + fail("Missing index entry in oxm."); + } + + } + private List getFiles() { Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath(); return FileUtils.listFiles( currentRelativePath.toFile(), new RegexFileFilter(".*\\.xml"), DirectoryFileFilter.DIRECTORY) - .stream().filter(file -> file.getAbsolutePath().contains("oxm")) + .stream() + .filter(file -> file.getAbsolutePath().contains("oxm")) + .filter(file -> !file.getAbsolutePath().contains("onap")) // skips onap for checks .collect(Collectors.toList()); } + /** + * Finds all of the oxm files for the latest version. + * @return list of the latest version of the oxm files. + */ + private List getLatestFiles() { + List latest = new ArrayList<>(); + Path currentRelativePath = Paths.get("../aai-schema/src/main/resources/").toAbsolutePath(); + List subDirs = Arrays.asList(currentRelativePath.toFile().listFiles(File::isDirectory)); + for (File subDir : subDirs) { + String oxm = subDir.getAbsolutePath() + "/oxm"; + File[] oxms = new File(oxm).listFiles(File::isDirectory); + Arrays.stream(oxms).map(File::getAbsolutePath).max(new Comparator() { + public int compare(String o1, String o2) { + return extractInt(o1) - extractInt(o2); + } + int extractInt(String s) { + String num = s.replaceAll("\\D", ""); + return num.isEmpty() ? 0 : Integer.parseInt(num); + } + }).ifPresent(latest::add); + } + + List latestFiles = new ArrayList<>(); + latest.forEach(s -> + FileUtils.listFiles( + new File(s), + new RegexFileFilter(".*\\.xml"), + DirectoryFileFilter.DIRECTORY) + .stream() + .filter(file -> file.getAbsolutePath().contains("oxm")) + .forEach(latestFiles::add)); + + return latestFiles; + } + //TODO test that all oxm xml are valid xml diff --git a/pom.xml b/pom.xml index baaeddf..2262c3b 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ org.onap.aai.schema-service schema-service - 1.0.2-SNAPSHOT + 1.0.3-SNAPSHOT aai-schema-service pom @@ -126,7 +126,7 @@ src/test/java/** pom.xml - false + true false
LICENSE_ALT1.txt
diff --git a/version.properties b/version.properties index 7c09f12..88f8ce6 100644 --- a/version.properties +++ b/version.properties @@ -4,7 +4,7 @@ # because they are used in Jenkins, whose plug-in doesn't support major_version=1 minor_version=0 -patch_version=2 +patch_version=3 base_version=${major_version}.${minor_version}.${patch_version} # Release must be completed with GIT information # in Jenkins release_version=${base_version} -- cgit 1.2.3-korg