From c20ee9965e16166f11a77a15b29204eebac4d08c Mon Sep 17 00:00:00 2001 From: "Threefoot, Jane (jt6620)" Date: Thu, 29 Mar 2018 12:54:05 -0400 Subject: [PATCH] added schema validation tools Issue-ID: AAI-879 Change-Id: I028547c97450372252b76286a8b10f4dbed4d2bf Signed-off-by: Threefoot, Jane (jt6620) --- aai-schema-ingest/.classpath | 36 --- .../main/java/org/onap/aai/edges/EdgeIngestor.java | 81 +----- .../src/main/java/org/onap/aai/edges/EdgeRule.java | 4 +- .../java/org/onap/aai/edges/EdgeRuleQuery.java | 9 +- .../main/java/org/onap/aai/edges/JsonIngestor.java | 88 ++++++ .../java/org/onap/aai/edges/TypeAlphabetizer.java | 67 +++++ .../org/onap/aai/edges/enums/AAIDirection.java | 4 +- .../onap/aai/edges/enums/DirectionNotation.java | 9 +- .../java/org/onap/aai/edges/enums/EdgeField.java | 5 +- .../org/onap/aai/edges/enums/EdgeProperty.java | 5 +- .../java/org/onap/aai/edges/enums/EdgeType.java | 4 +- .../org/onap/aai/edges/enums/MultiplicityRule.java | 4 +- .../exceptions/AmbiguousRuleChoiceException.java | 9 +- .../exceptions/EdgeRuleNotFoundException.java | 9 +- .../main/java/org/onap/aai/nodes/NodeIngestor.java | 58 +++- .../java/org/onap/aai/setup/ConfigTranslator.java | 9 +- .../org/onap/aai/setup/SchemaLocationsBean.java | 9 +- .../src/main/java/org/onap/aai/setup/Version.java | 5 +- .../validation/AAISchemaValidationException.java | 32 +++ .../aai/validation/CheckEverythingStrategy.java | 72 +++++ .../validation/DefaultVersionValidationModule.java | 78 ++++++ .../org/onap/aai/validation/FailFastStrategy.java | 63 +++++ .../onap/aai/validation/SchemaErrorStrategy.java | 61 +++++ .../aai/validation/VersionValidationModule.java | 40 +++ .../org/onap/aai/validation/VersionValidator.java | 55 ++++ .../edges/CousinDefaultingValidationModule.java | 87 ++++++ .../edges/DefaultEdgeFieldsValidationModule.java | 75 ++++++ .../edges/EdgeFieldsValidationModule.java | 56 ++++ .../aai/validation/edges/EdgeRuleValidator.java | 115 ++++++++ .../edges/NodeTypesValidationModule.java | 90 +++++++ .../edges/SingleContainmentValidationModule.java | 63 +++++ .../edges/UniqueLabelValidationModule.java | 73 +++++ ...ultDuplicateNodeDefinitionValidationModule.java | 106 ++++++++ .../DuplicateNodeDefinitionValidationModule.java | 49 ++++ .../onap/aai/validation/nodes/NodeValidator.java | 61 +++++ .../java/org/onap/aai/edges/EdgeIngestorTest.java | 9 +- .../org/onap/aai/edges/EdgeIngestorWiringTest.java | 9 +- .../java/org/onap/aai/edges/EdgeRuleQueryTest.java | 9 +- .../java/org/onap/aai/edges/JsonIngestorTest.java | 75 ++++++ .../org/onap/aai/edges/TypeAlphabetizerTest.java | 42 +++ .../java/org/onap/aai/nodes/NodeIngestorTest.java | 18 +- .../org/onap/aai/nodes/NodeIngestorWiringTest.java | 9 +- .../onap/aai/setup/ConfigTranslatorWiringTest.java | 9 +- .../SchemaLocationsBeanDefaultInjectionTest.java | 9 +- .../SchemaLocationsBeanEnvVarInjectionTest.java | 9 +- .../setup/SchemaLocationsBeanXMLSetterTest.java | 9 +- ...hemaLocationsBeanXMLSetterWithPropFileTest.java | 9 +- .../testutils/BadEdgeConfigForValidationTest.java | 62 +++++ .../testutils/BadNodeConfigForValidationTest.java | 63 +++++ .../testutils/ConfigTranslatorForWiringTest.java | 9 +- .../aai/testutils/GoodConfigForValidationTest.java | 68 +++++ .../aai/testutils/TestUtilConfigTranslator.java | 9 +- .../validation/CheckEverythingStrategyTest.java | 57 ++++ .../onap/aai/validation/FailFastStrategyTest.java | 52 ++++ .../validation/VersionValidatorRainyDayTest.java | 53 ++++ .../validation/VersionValidatorSunnyDayTest.java | 50 ++++ .../CousinDefaultingValidationModuleTest.java | 80 ++++++ .../DefaultEdgeFieldsValidationModuleTest.java | 65 +++++ .../edges/EdgeRuleValidatorRainyDayTest.java | 63 +++++ .../edges/EdgeRuleValidatorSunnyDayTest.java | 60 +++++ .../edges/NodeTypesValidationModuleTest.java | 67 +++++ .../SingleContainmentValidationModuleTest.java | 70 +++++ .../edges/UniqueLabelValidationModuleTest.java | 97 +++++++ .../nodes/NodeValidatorRainyDayTest.java | 58 ++++ .../nodes/NodeValidatorSunnyDayTest.java | 55 ++++ .../edgeRules/containsValidationTest.json | 64 +++++ .../edgeRules/cousinDefaultValidationTest.json | 112 ++++++++ .../resources/edgeRules/labelValidationTest1.json | 124 +++++++++ .../resources/edgeRules/labelValidationTest2.json | 52 ++++ .../src/test/resources/edgeRules/test3-butbad.json | 63 +++++ .../oxm/badConfigForValidationTest_oxm.xml | 208 +++++++++++++++ .../oxm/goodConfigForValidationTest_oxm.xml | 296 +++++++++++++++++++++ 72 files changed, 3593 insertions(+), 171 deletions(-) delete mode 100644 aai-schema-ingest/.classpath create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/edges/TypeAlphabetizer.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/AAISchemaValidationException.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/CheckEverythingStrategy.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/DefaultVersionValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/FailFastStrategy.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/SchemaErrorStrategy.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidator.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeFieldsValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeRuleValidator.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/NodeTypesValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DuplicateNodeDefinitionValidationModule.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/NodeValidator.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/edges/JsonIngestorTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/edges/TypeAlphabetizerTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadEdgeConfigForValidationTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadNodeConfigForValidationTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/testutils/GoodConfigForValidationTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/CheckEverythingStrategyTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/FailFastStrategyTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorRainyDayTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorSunnyDayTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/CousinDefaultingValidationModuleTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModuleTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorRainyDayTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorSunnyDayTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/NodeTypesValidationModuleTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/SingleContainmentValidationModuleTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/UniqueLabelValidationModuleTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorRainyDayTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSunnyDayTest.java create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/containsValidationTest.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/cousinDefaultValidationTest.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest1.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest2.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test3-butbad.json create mode 100644 aai-schema-ingest/src/test/resources/oxm/badConfigForValidationTest_oxm.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/goodConfigForValidationTest_oxm.xml diff --git a/aai-schema-ingest/.classpath b/aai-schema-ingest/.classpath deleted file mode 100644 index fae1a2b3..00000000 --- a/aai-schema-ingest/.classpath +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java index 642ede83..b424e840 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeIngestor.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges; import java.io.BufferedReader; @@ -55,7 +58,7 @@ import static com.jayway.jsonpath.Criteria.where; * information, including allowing various filters to extract particular rules. */ public class EdgeIngestor { - private Map> versionJsonFilesMap = new EnumMap<>(Version.class); + private Map> versionJsonFilesMap; private static final String READ_START = "$.rules.[?]"; private static final String READ_ALL_START = "$.rules.*"; @@ -69,38 +72,8 @@ public class EdgeIngestor { */ public EdgeIngestor(ConfigTranslator translator) { Map> filesToIngest = translator.getEdgeFiles(); - - for (Entry> verFile : filesToIngest.entrySet()) { - Version v = verFile.getKey(); - List files = verFile.getValue(); - - List docs = new ArrayList<>(); - - for (String rulesFilename : files) { - String fileContents = readInJsonFile(rulesFilename); - docs.add(JsonPath.parse(fileContents)); - } - versionJsonFilesMap.put(v, docs); - } - } - - /** - * Reads the json file at the given filename into an in-memory String. - * - * @param rulesFilename - json file to be read (must include path to the file) - * @return String json contents of the given file - */ - private String readInJsonFile(String rulesFilename) { - StringBuilder sb = new StringBuilder(); - try(BufferedReader br = new BufferedReader(new FileReader(rulesFilename))) { - String line; - while ((line = br.readLine()) != null) { - sb.append(line); - } - } catch (IOException e) { - throw new ExceptionInInitializerError(e); - } - return sb.toString(); + JsonIngestor ji = new JsonIngestor(); + versionJsonFilesMap = ji.ingest(filesToIngest); } //-----methods for getting rule info-----// @@ -533,46 +506,16 @@ public class EdgeIngestor { private Multimap convertToEdgeRules(List> allFound) { Multimap rules = ArrayListMultimap.create(); + TypeAlphabetizer alpher = new TypeAlphabetizer(); + if (!allFound.isEmpty()) { for (Map raw : allFound) { EdgeRule converted = new EdgeRule(raw); - String alphabetizedKey = buildAlphabetizedKey(raw.get(EdgeField.FROM.toString()), raw.get(EdgeField.TO.toString())); + String alphabetizedKey = alpher.buildAlphabetizedKey(raw.get(EdgeField.FROM.toString()), raw.get(EdgeField.TO.toString())); rules.put(alphabetizedKey, converted); } } return rules; } - - /** - * Builds the multimap key for the rules, where nodetypes are alphabetically sorted - * (ignoring dashes). - * - * @param nodeA - first nodetype - * @param nodeB - second nodetype - * @return {alphabetically first nodetype}|{alphabetically second nodetype} - * ex: buildAlphabetizedKey("l-interface", "logical-link") -> "l-interface|logical-link" - * buildAlphabetizedKey("logical-link", "l-interface") -> "l-interface|logical-link" - * - * This is alphabetical order to normalize the keys, as sometimes there will be multiple - * rules for a pair of node types but the from/to value in the json is flipped for some of them. - */ - private String buildAlphabetizedKey(String nodeA, String nodeB) { - //normalize - String normalizedNodeA = nodeA.replace("-", ""); - String normalizedNodeB = nodeB.replace("-", ""); - int cmp = normalizedNodeA.compareTo(normalizedNodeB); - - StringBuilder sb = new StringBuilder(); - if (cmp <= 0) { - sb.append(nodeA); - sb.append("|"); - sb.append(nodeB); - } else { - sb.append(nodeB); - sb.append("|"); - sb.append(nodeA); - } - return sb.toString(); - } } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java index bac217d1..f859aae6 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRule.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.edges; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java index 701977a6..3029685f 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/EdgeRuleQuery.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges; import org.onap.aai.edges.enums.AAIDirection; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java new file mode 100644 index 00000000..29a2e3b9 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/JsonIngestor.java @@ -0,0 +1,88 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.edges; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.onap.aai.setup.Version; + +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.JsonPath; + +/** + * JsonIngestor produces DocumentContexts from json files + */ +public class JsonIngestor { + + /** + * Reads in given json files to queryable DocumentContexts. + * + * @param Map> filesToIngest - map of filenames to ingest + * per Version + * @return Map> - map of DocumentContexts per Version + */ + public Map> ingest(Map> filesToIngest) { + Map> result = new EnumMap<>(Version.class); + + for (Entry> verFiles : filesToIngest.entrySet()) { + Version v = verFiles.getKey(); + List files = verFiles.getValue(); + + List docs = new ArrayList<>(); + + for (String rulesFilename : files) { + String fileContents = readInJsonFile(rulesFilename); + docs.add(JsonPath.parse(fileContents)); + } + result.put(v, docs); + } + + return result; + } + + /** + * Reads the json file at the given filename into an in-memory String. + * + * @param rulesFilename - json file to be read (must include path to the file) + * @return String json contents of the given file + */ + private String readInJsonFile(String rulesFilename) { + StringBuilder sb = new StringBuilder(); + try(BufferedReader br = new BufferedReader(new FileReader(rulesFilename))) { + String line; + while ((line = br.readLine()) != null) { + sb.append(line); + } + } catch (IOException e) { + throw new ExceptionInInitializerError(e); + } + return sb.toString(); + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/TypeAlphabetizer.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/TypeAlphabetizer.java new file mode 100644 index 00000000..2106d3a5 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/TypeAlphabetizer.java @@ -0,0 +1,67 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.edges; + +/** + * Helper class to produce alphabetized keys for EdgeIngestor and EdgeValidator + */ +public class TypeAlphabetizer { + /** + * Builds key for edge rules, where nodetypes are alphabetically sorted + * (ignoring dashes). + * + * @param nodeA - first nodetype + * @param nodeB - second nodetype + * @return {alphabetically first nodetype}|{alphabetically second nodetype} + * ex: buildAlphabetizedKey("l-interface", "logical-link") -> "l-interface|logical-link" + * buildAlphabetizedKey("logical-link", "l-interface") -> "l-interface|logical-link" + * + * This is alphabetical order to normalize the keys, as sometimes there will be multiple + * rules for a pair of node types but the from/to value in the json is flipped for some of them. + */ + public String buildAlphabetizedKey(String nodeA, String nodeB) { + if (nodeA == null) { + nodeA = ""; + } + if (nodeB == null) { + nodeB = ""; + } + + //normalize + String normalizedNodeA = nodeA.replace("-", ""); + String normalizedNodeB = nodeB.replace("-", ""); + int cmp = normalizedNodeA.compareTo(normalizedNodeB); + + StringBuilder sb = new StringBuilder(); + if (cmp <= 0) { + sb.append(nodeA); + sb.append("|"); + sb.append(nodeB); + } else { + sb.append(nodeB); + sb.append("|"); + sb.append(nodeA); + } + return sb.toString(); + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/AAIDirection.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/AAIDirection.java index 8ea5157b..3f748a50 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/AAIDirection.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/AAIDirection.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.edges.enums; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/DirectionNotation.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/DirectionNotation.java index 7e4a65c2..203249a4 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/DirectionNotation.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/DirectionNotation.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges.enums; public enum DirectionNotation { diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeField.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeField.java index e75a516d..3e896f61 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeField.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeField.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges.enums; /** diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeProperty.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeProperty.java index 4ec3f071..2f6afa47 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeProperty.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeProperty.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges.enums; /** diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeType.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeType.java index 4a921420..00dce0fd 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeType.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/EdgeType.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.edges.enums; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/MultiplicityRule.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/MultiplicityRule.java index 7f672c42..4fc8938d 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/MultiplicityRule.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/enums/MultiplicityRule.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,8 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.edges.enums; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/AmbiguousRuleChoiceException.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/AmbiguousRuleChoiceException.java index 9baf7902..ebb9739b 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/AmbiguousRuleChoiceException.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/AmbiguousRuleChoiceException.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges.exceptions; public class AmbiguousRuleChoiceException extends Exception { diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/EdgeRuleNotFoundException.java b/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/EdgeRuleNotFoundException.java index 0bf414fa..e1a8fe6b 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/EdgeRuleNotFoundException.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/edges/exceptions/EdgeRuleNotFoundException.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges.exceptions; public class EdgeRuleNotFoundException extends Exception { diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java b/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java index 849ad577..bafc6b32 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/nodes/NodeIngestor.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,21 +16,31 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.nodes; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.EnumMap; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import javax.xml.XMLConstants; import javax.xml.bind.JAXBException; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; import org.eclipse.persistence.jaxb.JAXBContextProperties; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; @@ -39,6 +49,11 @@ import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.Version; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.google.common.base.CaseFormat; @Component /** @@ -47,6 +62,7 @@ import org.springframework.stereotype.Component; public class NodeIngestor { private Map versionContextMap = new EnumMap<>(Version.class); + private Map> typesPerVersion = new EnumMap<>(Version.class); @Autowired /** @@ -64,8 +80,9 @@ public class NodeIngestor { List files = verFiles.getValue(); final DynamicJAXBContext ctx = ingest(files); versionContextMap.put(v, ctx); + typesPerVersion.put(v, getAllNodeTypes(files)); } - } catch (FileNotFoundException | JAXBException e) { + } catch (JAXBException | ParserConfigurationException | SAXException | IOException e) { throw new ExceptionInInitializerError(e); } } @@ -91,6 +108,28 @@ public class NodeIngestor { properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, streams); return DynamicJAXBContextFactory.createContextFromOXM(this.getClass().getClassLoader(), properties); } + + private Set getAllNodeTypes(List files) throws ParserConfigurationException, SAXException, IOException { + Set types = new HashSet<>(); + + final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + + for (String file : files) { + InputStream inputStream = new FileInputStream(file); + + final Document doc = docBuilder.parse(inputStream); + final NodeList list = doc.getElementsByTagName("java-type"); + + for (int i = 0; i < list.getLength(); i++) { + String type = list.item(i).getAttributes().getNamedItem("name").getNodeValue(); + types.add(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, type)); + } + } + + return types; + } /** * Gets the DynamicJAXBContext for the given version @@ -101,4 +140,15 @@ public class NodeIngestor { public DynamicJAXBContext getContextForVersion(Version v) { return versionContextMap.get(v); } + + /** + * Determines if the given version contains the given node type + * + * @param String nodeType - node type to check, must be in lower hyphen form (ie "type-name") + * @param v + * @return + */ + public boolean hasNodeType(String nodeType, Version v) { + return typesPerVersion.get(v).contains(nodeType); + } } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java index e22dcdc1..b34622de 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/ConfigTranslator.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.setup; import java.util.List; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java index 8cc09ddd..b5b878af 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaLocationsBean.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.setup; import org.springframework.beans.factory.annotation.Value; diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/Version.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Version.java index 81303f06..1fd1481d 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/Version.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Version.java @@ -2,7 +2,7 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,13 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ package org.onap.aai.setup; public enum Version { + V7, V8, V9, V10, diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/AAISchemaValidationException.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/AAISchemaValidationException.java new file mode 100644 index 00000000..a3784b77 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/AAISchemaValidationException.java @@ -0,0 +1,32 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + +/** + * Indicates that a fatal error in the A&AI schema has been found. + */ +public class AAISchemaValidationException extends IllegalStateException { + public AAISchemaValidationException(String msg) { + super(msg); + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/CheckEverythingStrategy.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/CheckEverythingStrategy.java new file mode 100644 index 00000000..d8b4eb39 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/CheckEverythingStrategy.java @@ -0,0 +1,72 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +/** + * + */ +package org.onap.aai.validation; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.lang.StringUtils; + +/** + * When an error is found, mark that it is NOT ok to + * continue with installation/whatever other caller function, + * and keep track of the message but + * keep validating so all issues are found in one run. + */ +public class CheckEverythingStrategy implements SchemaErrorStrategy { + private boolean isOK = true; + private List errorMsgs = new ArrayList<>(); + + /* (non-Javadoc) + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#isOK() + */ + @Override + public boolean isOK() { + return isOK; + } + + /* (non-Javadoc) + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#getErrorMsg() + */ + @Override + public String getErrorMsg() { + if (errorMsgs.isEmpty()) { + return "No errors found."; + } else { + return StringUtils.join(errorMsgs, "\n"); + } + } + + /* (non-Javadoc) + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#notifyOnError(java.lang.String) + */ + @Override + public void notifyOnError(String errorMsg) { + isOK = false; + errorMsgs.add(errorMsg); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/DefaultVersionValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/DefaultVersionValidationModule.java new file mode 100644 index 00000000..d1f5647b --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/DefaultVersionValidationModule.java @@ -0,0 +1,78 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +/** + * + */ +package org.onap.aai.validation; + +import java.util.List; +import java.util.Map; + +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.Version; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * By default, A&AI must have schema files for all current + * supported Versions in the Version enum + * + */ +@Component +public class DefaultVersionValidationModule implements VersionValidationModule { + private ConfigTranslator config; + + @Autowired + public DefaultVersionValidationModule(ConfigTranslator config) { + this.config = config; + } + + /* (non-Javadoc) + * @see org.onap.aai.validation.VersionValidationModule#validate(org.onap.aai.setup.ConfigTranslator) + */ + @Override + public String validate() { + Map> nodeConfig = config.getNodeFiles(); + Map> edgeConfig = config.getEdgeFiles(); + + StringBuilder missingVers = new StringBuilder().append("Missing schema for the following versions: "); + boolean isMissing = false; + for (Version v : Version.values()) { + if (nodeConfig.get(v) == null) { + isMissing = true; + missingVers.append(v.toString()).append(" has no OXM configured. "); + } + if (edgeConfig.get(v) == null) { + isMissing = true; + missingVers.append(v.toString()).append(" has no edge rules configured. "); + } + } + + if (isMissing) { + return missingVers.toString(); + } else { + return ""; + } + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/FailFastStrategy.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/FailFastStrategy.java new file mode 100644 index 00000000..07180855 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/FailFastStrategy.java @@ -0,0 +1,63 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +/** + * + */ +package org.onap.aai.validation; + +/** + * Fails out the validation process as soon as + * an error is found. Tells the validation's calling + * process to abort. + */ +public class FailFastStrategy implements SchemaErrorStrategy { + private boolean isOK = true; + private String errorMsg = "No errors found."; + + /* (non-Javadoc) + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#isOK() + */ + @Override + public boolean isOK() { + return isOK; + } + + /* (non-Javadoc) + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#getErrorMsg() + */ + @Override + public String getErrorMsg() { + return errorMsg; + } + + /* (non-Javadoc) + * @see org.onap.aai.edges.validation.SchemaErrorStrategy#notifyOnError(java.lang.String) + */ + @Override + public void notifyOnError(String errorMsg) { + isOK = false; + this.errorMsg = errorMsg; + throw new AAISchemaValidationException(errorMsg); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/SchemaErrorStrategy.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/SchemaErrorStrategy.java new file mode 100644 index 00000000..0f2f2673 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/SchemaErrorStrategy.java @@ -0,0 +1,61 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + +/** + * Controls response to finding problems in the schema files. + */ +public interface SchemaErrorStrategy { + /** + * Gives if it is OK to proceed with whatever process + * invoked the validation (probably the installation of + * the A&AI instance). + * + * @return boolean + */ + public boolean isOK(); + + /** + * Gets the error message(s) gathered in the course + * of validation. + * + * @return String error message or messages concatenated together + */ + public String getErrorMsg(); + + /** + * Invokes the ErrorStrategy to do whatever response to + * an issue in the schema having been found. + * + * Options: + * -Throw an exception if the whole process should be + * immediately aborted + * -Set OK status to false, store the message and allow the + * validation process to continue and find any other issues + * -Completely ignore that something is wrong + * etc. + * + * @param String errorMsg - the error message from the validator module + */ + public void notifyOnError(String errorMsg); +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidationModule.java new file mode 100644 index 00000000..e0b6e12a --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidationModule.java @@ -0,0 +1,40 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + + +/** + * Defines the behavior for what versions are required/optional. + * + * Constructor must take ConfigTranslator via autowiring. + */ +public interface VersionValidationModule { + + /** + * Validates that all required versions have schema + * configured for them. + * + * @return empty string if none missing or else an appropriate error + */ + public String validate(); +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidator.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidator.java new file mode 100644 index 00000000..24c05db0 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/VersionValidator.java @@ -0,0 +1,55 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Verifies that the schema config covers + * all required versions + */ +@Component +public class VersionValidator { + private SchemaErrorStrategy strat; + private VersionValidationModule verMod; + + @Autowired + public VersionValidator(SchemaErrorStrategy strategy, VersionValidationModule verMod) { + this.strat = strategy; + this.verMod = verMod; + } + + public boolean validate() { + String result = verMod.validate(); + if (!"".equals(result)) { + strat.notifyOnError(result); + } + + return strat.isOK(); + } + + public String getErrorMsg() { + return strat.getErrorMsg(); + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java new file mode 100644 index 00000000..85b4dc64 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java @@ -0,0 +1,87 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.onap.aai.edges.EdgeRuleQuery; +import org.onap.aai.edges.EdgeRuleQuery.Builder; +import org.onap.aai.edges.enums.EdgeField; +import org.onap.aai.edges.enums.EdgeType; + +import com.jayway.jsonpath.DocumentContext; + +/** + * Validates that in the collection of cousin rules between a given node type pair, + * there is exactly 1 set default=true. + */ +public class CousinDefaultingValidationModule { + + /** + * Validates that in the collection of cousin rules between a given node type pair, + * there is exactly 1 set default=true. + * + * @param String nodeTypePair - pair of A&AI node types in the form "typeA|typeB" + * @param List ctxs - the ingested json schema to validate + * @return empty string if ok, appropriate error message otherwise + */ + public String validate(String nodeTypePair, List ctxs) { + String[] types = nodeTypePair.split("\\|"); + EdgeRuleQuery lookup = new EdgeRuleQuery.Builder(types[0], types[1]).edgeType(EdgeType.COUSIN).build(); + List> rules = new ArrayList<>(); + for (DocumentContext ctx : ctxs) { + rules.addAll(ctx.read("$.rules.[?]", lookup.getFilter())); + } + + if (rules.isEmpty()) { + return ""; //bc irrelevant check + } + + int defaultCount = 0; + Set defLabels = new HashSet<>(); + for (Map rule : rules) { + if ("true".equals(rule.get(EdgeField.DEFAULT.toString()))) { + defaultCount++; + defLabels.add(rule.get(EdgeField.LABEL.toString())); + } + } + + StringBuilder errorBase = new StringBuilder().append("Pair ").append(nodeTypePair).append(" must have exactly one cousin rule set as default. "); + if (defaultCount == 1) { + return ""; + } else if (defaultCount == 0){ + errorBase.append("None set."); + return errorBase.toString(); + } else { + errorBase.append("Multiple set, see labels: "); + for (String label : defLabels) { + errorBase.append(label).append(" "); + } + return errorBase.toString(); + } + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java new file mode 100644 index 00000000..ff58e7dd --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModule.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +/** + * + */ +package org.onap.aai.validation.edges; + +import java.util.EnumSet; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.onap.aai.edges.enums.EdgeField; + +/** + * Default core A&AI edge field validation + * All fields in EdgeField enum are required EXCEPT description + * + */ +public class DefaultEdgeFieldsValidationModule implements EdgeFieldsValidationModule { + + /* (non-Javadoc) + * @see org.onap.aai.edges.EdgeFieldsValidator#verifyFields(java.util.Map) + */ + @Override + public String verifyFields(Map rule) { + EnumSet missingFields = EnumSet.complementOf(EnumSet.allOf(EdgeField.class)); + + for (EdgeField f : EdgeField.values()) { + if (!rule.containsKey(f.toString()) && (f != EdgeField.DESCRIPTION)) { //description is optional + missingFields.add(f); + } + } + + StringBuilder errorMsg = new StringBuilder(); + if (!missingFields.isEmpty()) { + errorMsg.append("Rule ").append(ruleToString(rule)).append(" missing required fields: "); + for (EdgeField mf : missingFields) { + errorMsg.append(mf.toString()).append(" "); + } + } + + return errorMsg.toString(); + } + + private String ruleToString(Map rule) { + StringBuilder sb = new StringBuilder(); + for (Entry fields : rule.entrySet()) { + sb.append(fields.getKey()).append(":").append(fields.getValue()).append(" "); + } + + return sb.toString(); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeFieldsValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeFieldsValidationModule.java new file mode 100644 index 00000000..b2d153fa --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeFieldsValidationModule.java @@ -0,0 +1,56 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import java.util.Map; + +/** + * Verifies that a given raw edge rule contains all required fields. + * + */ +public interface EdgeFieldsValidationModule { + + /** + * Verifies the given rule has all required fields. + * Implement to check for what you determine to be required. + * You may also throw an error on unexpected fields if you wish, + * whatever makes sense for your system. + * + * @param rule - Map that will look something like this: + * { + * "from": "foo", + * "to": "bar", + * "label": "tosca.relationships.network.BindsTo", + * "direction": "OUT", + * "multiplicity": "ONE2ONE", + * "contains-other-v": "NONE", + * "delete-other-v": "NONE", + * "prevent-delete": "NONE", + * "default": "true", + * "description":"An edge comment" + * } + * @return empty String if no errors found, or String with + * the appropriate error message + */ + public String verifyFields(Map rule); +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeRuleValidator.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeRuleValidator.java new file mode 100644 index 00000000..34c603aa --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/EdgeRuleValidator.java @@ -0,0 +1,115 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Set; + +import org.onap.aai.edges.JsonIngestor; +import org.onap.aai.edges.TypeAlphabetizer; +import org.onap.aai.edges.enums.EdgeField; +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.Version; +import org.onap.aai.validation.SchemaErrorStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import com.jayway.jsonpath.DocumentContext; + +/** + * Runs all validations against the ingested schema + */ +@Component +public class EdgeRuleValidator { + private Map> versionJsonFilesMap; + private final SchemaErrorStrategy strat; + protected final EdgeFieldsValidationModule fieldValidator; + protected final UniqueLabelValidationModule labelValidator; + protected final SingleContainmentValidationModule containsValidator; + protected final CousinDefaultingValidationModule defaultsValidator; + protected final NodeTypesValidationModule typeValidator; + + @Autowired + public EdgeRuleValidator(ConfigTranslator config, SchemaErrorStrategy strat, + EdgeFieldsValidationModule fieldValidator, UniqueLabelValidationModule labelValidator, + SingleContainmentValidationModule containsValidator, CousinDefaultingValidationModule defaultsValidator, + NodeTypesValidationModule typeValidator) { + this.versionJsonFilesMap = new JsonIngestor().ingest(config.getEdgeFiles()); + this.strat = strat; + this.fieldValidator = fieldValidator; + this.labelValidator = labelValidator; + this.containsValidator = containsValidator; + this.defaultsValidator = defaultsValidator; + this.typeValidator = typeValidator; + } + + public boolean validate() { + + for (Entry> verEntry : versionJsonFilesMap.entrySet()) { + Version v = verEntry.getKey(); + List ctxs = verEntry.getValue(); + List> rules = collectRules(ctxs); + Set nodeTypePairs = new HashSet<>(); + TypeAlphabetizer alpher = new TypeAlphabetizer(); + + for (Map rule : rules) { + handleResult(fieldValidator.verifyFields(rule)); + nodeTypePairs.add(alpher.buildAlphabetizedKey(rule.get(EdgeField.FROM.toString()), rule.get(EdgeField.TO.toString()))); + } + + for (String nodeTypePair : nodeTypePairs) { + handleResult(labelValidator.validate(nodeTypePair, ctxs)); + handleResult(containsValidator.validate(nodeTypePair, ctxs)); + handleResult(defaultsValidator.validate(nodeTypePair, ctxs)); + } + + handleResult(typeValidator.validate(nodeTypePairs, v)); + } + + return strat.isOK(); + } + + private List> collectRules(List ctxs) { + List> rules = new ArrayList<>(); + + for (DocumentContext ctx : ctxs) { + rules.addAll(ctx.read("$.rules.*")); + } + + return rules; + } + + private void handleResult(String result) { + if (!"".equals(result)) { + strat.notifyOnError(result); + } + } + + public String getErrorMsg() { + return strat.getErrorMsg(); + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/NodeTypesValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/NodeTypesValidationModule.java new file mode 100644 index 00000000..6d061245 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/NodeTypesValidationModule.java @@ -0,0 +1,90 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.Version; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +/** + * Validates that the node types appearing in the edge rules are valid + * against the ingested OXM. + * + * (This is why the node validation has to be run before the edge validation) + */ +@Component +public class NodeTypesValidationModule { + private NodeIngestor ni; + + @Autowired + public NodeTypesValidationModule(NodeIngestor ni) { + this.ni = ni; + } + + /** + * Validate that every node type in the given set is defined in + * the OXM for the given version + * + * @param Collection nodeTypes - all the node types in + * the edge rules for the given version being validated + * @param Version v - the version being validated + * @return empty string if all types are present in the given version's ingested OXM, else + * appropriate error message + */ + public String validate(Collection nodeTypePairs, Version v) { + //setup + Set nodeTypes = new HashSet<>(); + for (String pair : nodeTypePairs) { + String[] types = pair.split("\\|"); + + for (String type : types) { + if (!"".equals(type)) { + nodeTypes.add(type); + } + } + } + + //validation + Set badTypes = new HashSet<>(); + for (String type : nodeTypes) { + if (!ni.hasNodeType(type, v)) { + badTypes.add(type); + } + } + + if (badTypes.isEmpty()) { + return ""; + } else { + StringBuilder errorBase = new StringBuilder().append("Invalid node type(s) found: "); + for (String bt : badTypes) { + errorBase.append(bt).append(" "); + } + return errorBase.toString(); + } + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java new file mode 100644 index 00000000..15e1c2aa --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/SingleContainmentValidationModule.java @@ -0,0 +1,63 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +import org.onap.aai.edges.EdgeRuleQuery; +import org.onap.aai.edges.enums.EdgeType; + +import com.jayway.jsonpath.DocumentContext; + +/** + * Validates that the given node type pair has at most one containment relationship + * in their edge rules. + * + */ +public class SingleContainmentValidationModule { + + /** + * Validates that the given node type pair has at most one containment relationship + * in their edge rules. + * + * @param String nodeTypePair - pair of A&AI node types in the form "typeA|typeB" + * @param List ctxs - the ingested json to validate + * @return empty string if passes, else appropriate error message + */ + public String validate(String nodeTypePair, List ctxs) { + String[] types = nodeTypePair.split("\\|"); + EdgeRuleQuery lookup = new EdgeRuleQuery.Builder(types[0], types[1]).edgeType(EdgeType.TREE).build(); + List> rules = new ArrayList<>(); + for (DocumentContext ctx : ctxs) { + rules.addAll(ctx.read("$.rules.[?]", lookup.getFilter())); + } + + if (rules.isEmpty() || rules.size() == 1) { + return ""; + } else { //had more than one containment relationship for the pair + return "Pair " + nodeTypePair + " has multiple containment rules. Only one allowed."; + } + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java new file mode 100644 index 00000000..bed6cadd --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/UniqueLabelValidationModule.java @@ -0,0 +1,73 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.onap.aai.edges.EdgeRuleQuery; +import org.onap.aai.edges.EdgeRuleQuery.Builder; +import org.onap.aai.edges.enums.EdgeField; + +import com.jayway.jsonpath.DocumentContext; + +/** + * Applies label validation rules + * + */ +public class UniqueLabelValidationModule { + + /** + * Validates that the given pair of node types have no duplicate labels in + * their edge rules + * + * @param String nodeTypePair - of the form "typeA|typeB" + * @param List ctxs - the edge rule json to pull rules from + * (ie all files for one version) + * @return empty string if no errors, else string error message + */ + public String validate(String nodeTypePair, List ctxs) { + String[] types = nodeTypePair.split("\\|"); + EdgeRuleQuery lookup = new EdgeRuleQuery.Builder(types[0], types[1]).build(); + + List> rules = new ArrayList<>(); + for (DocumentContext ctx : ctxs) { + rules.addAll(ctx.read("$.rules.[?]", lookup.getFilter())); + } + + Set labelsSeen = new HashSet<>(); + for (Map rule : rules) { + String label = rule.get(EdgeField.LABEL.toString()); + if (labelsSeen.contains(label)) { + return "Pair " + nodeTypePair + " has multiple rules using the same label: " + label + + ". Every rule between the same node type pair must have a unique label."; + } else { + labelsSeen.add(label); + } + } + return ""; + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java new file mode 100644 index 00000000..f8536684 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DefaultDuplicateNodeDefinitionValidationModule.java @@ -0,0 +1,106 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.nodes; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.List; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; + +import org.onap.aai.setup.Version; +import org.w3c.dom.Document; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; + +/** + * Default duplicate rules for A&AI - + * node types may never have a duplicate definition + * within the same Version's file set. + * + * Finds all duplicates and what files they're in. + * + */ +public class DefaultDuplicateNodeDefinitionValidationModule implements DuplicateNodeDefinitionValidationModule { + + /* (non-Javadoc) + * @see org.onap.aai.nodes.validation.DuplicateNodeDefinitionValidationModule#findDuplicates(java.util.List) + */ + @Override + public String findDuplicates(List files, Version v) { + try { + final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + + Multimap types = ArrayListMultimap.create(); + boolean foundDups = false; + for (String file : files) { + InputStream inputStream = new FileInputStream(file); + final Document doc = docBuilder.parse(inputStream); + final NodeList list = doc.getElementsByTagName("java-type"); + + for (int i = 0; i < list.getLength(); i++) { + String type = list.item(i).getAttributes().getNamedItem("name").getNodeValue(); + if (types.containsKey(type)) { + foundDups = true; + } + types.put(type, file); + } + } + + if (foundDups) { + return buildErrorMsg(types, v); + } else { + return ""; + } + } catch (ParserConfigurationException | SAXException | IOException e) { + // TODO something useful with this information + return e.getMessage(); + } + } + + private String buildErrorMsg(Multimap types, Version v) { + StringBuilder errorMsg = new StringBuilder().append("Duplicates found in version ").append(v.toString()).append(". "); + for (String nodeType : types.keySet()) { + Collection files = types.get(nodeType); + if (files.size() == 1) { + continue; //only record the duplicated ones + } + errorMsg.append(nodeType).append(" has definitions in "); + for (String file : files) { + errorMsg.append(file).append(" "); + } + } + return errorMsg.toString(); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DuplicateNodeDefinitionValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DuplicateNodeDefinitionValidationModule.java new file mode 100644 index 00000000..b7cd4a07 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/DuplicateNodeDefinitionValidationModule.java @@ -0,0 +1,49 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.nodes; + +import java.util.List; + +import org.onap.aai.setup.Version; + +/** + * Defines rules for duplicate node definitions in a set of files + * (where the intent is the set of files is all the OXM for one version). + * + * Example Options: + * -Any duplicated definition found is an error + * -Duplicates within a namespace are OK but not across namespaces + * -Anything goes + * etc. + */ +public interface DuplicateNodeDefinitionValidationModule { + /** + * Finds any duplicates according to the defined rules + * + * @param files - the OXM files to use with full directory + * @return empty String if none found, else a String + * with appropriate information about what node types + * were found + */ + public String findDuplicates(List files, Version v); +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/NodeValidator.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/NodeValidator.java new file mode 100644 index 00000000..f8089a19 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/validation/nodes/NodeValidator.java @@ -0,0 +1,61 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.nodes; + +import java.util.List; +import java.util.Map.Entry; + +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.Version; +import org.onap.aai.validation.SchemaErrorStrategy; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class NodeValidator { + private ConfigTranslator translator; + private SchemaErrorStrategy strat; + private DuplicateNodeDefinitionValidationModule dupChecker; + + @Autowired + public NodeValidator(ConfigTranslator translator, SchemaErrorStrategy strategy, DuplicateNodeDefinitionValidationModule dupChecker) { + this.translator = translator; + this.strat = strategy; + this.dupChecker = dupChecker; + } + + public boolean validate() { + + for(Entry> entry : translator.getNodeFiles().entrySet()) { + String result = dupChecker.findDuplicates(entry.getValue(), entry.getKey()); + if (!"".equals(result)) { + strat.notifyOnError(result); + } + } + return strat.isOK(); + } + + public String getErrorMsg() { + return strat.getErrorMsg(); + } +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorTest.java index fe43de09..9f6d67a1 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorWiringTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorWiringTest.java index ac0c302f..74aceb51 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorWiringTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorWiringTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeRuleQueryTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeRuleQueryTest.java index 19aa0ce4..f21246cb 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeRuleQueryTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeRuleQueryTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.edges; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/edges/JsonIngestorTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/edges/JsonIngestorTest.java new file mode 100644 index 00000000..4bc23542 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/edges/JsonIngestorTest.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.edges; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; +import org.onap.aai.setup.Version; + +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.Filter; +import static com.jayway.jsonpath.Criteria.where; +import static com.jayway.jsonpath.Filter.filter; + +public class JsonIngestorTest { + + @Test + public void test() { + //setup + List files = new ArrayList<>(); + files.add("src/test/resources/edgeRules/test.json"); + files.add("src/test/resources/edgeRules/test2.json"); + files.add("src/test/resources/edgeRules/otherTestRules.json"); + Map> input = new EnumMap<>(Version.class); + input.put(Version.getLatest(), files); + + List files2 = new ArrayList<>(); + files2.add("src/test/resources/edgeRules/test.json"); + input.put(Version.V10, files2); + + List files3 = new ArrayList<>(); + files3.add("src/test/resources/edgeRules/test3.json"); + files3.add("src/test/resources/edgeRules/defaultEdgesTest.json"); + input.put(Version.V11, files3); + + //test + JsonIngestor ji = new JsonIngestor(); + Map> results = ji.ingest(input); + + assertTrue(results.entrySet().size() == 3); + assertTrue(results.get(Version.getLatest()).size() == 3); + assertTrue(results.get(Version.V11).size() == 2); + assertTrue(results.get(Version.V10).size() == 1); + + Filter f = filter(where("from").is("foo").and("contains-other-v").is("NONE")); + List> filterRes = results.get(Version.V10).get(0).read("$.rules.[?]",f); + assertTrue(filterRes.size() == 2); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/edges/TypeAlphabetizerTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/edges/TypeAlphabetizerTest.java new file mode 100644 index 00000000..6c99a489 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/edges/TypeAlphabetizerTest.java @@ -0,0 +1,42 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.edges; + +import static org.junit.Assert.*; + +import org.junit.Test; + +public class TypeAlphabetizerTest { + + @Test + public void test() { + TypeAlphabetizer alpher = new TypeAlphabetizer(); + assertTrue("aaa|bbb".equals(alpher.buildAlphabetizedKey("aaa", "bbb"))); + assertTrue("l-interface|logical-link".equals(alpher.buildAlphabetizedKey("l-interface", "logical-link"))); + assertTrue("l-interface|logical-link".equals(alpher.buildAlphabetizedKey("logical-link", "l-interface"))); + assertTrue("|foo".equals(alpher.buildAlphabetizedKey(null, "foo"))); + assertTrue("|foo".equals(alpher.buildAlphabetizedKey("foo", null))); + assertTrue("|".equals(alpher.buildAlphabetizedKey(null, null))); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java index f5135571..bcd58732 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.nodes; import static org.junit.Assert.*; @@ -48,7 +51,7 @@ public class NodeIngestorTest { public ExpectedException thrown = ExpectedException.none(); @Test - public void test() { + public void testGetContextForVersion() { DynamicJAXBContext ctx10 = ni.getContextForVersion(Version.V10); //should work bc Foo is valid in test_network_v10 schema @@ -78,4 +81,11 @@ public class NodeIngestorTest { //should fail bc Quux not in v10 test schema ctx10.newDynamicEntity("Quux"); } + + @Test + public void testHasNodeType() { + assertTrue(ni.hasNodeType("foo", Version.V11)); + assertTrue(ni.hasNodeType("quux", Version.V11)); + assertFalse(ni.hasNodeType("quux", Version.V10)); + } } diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorWiringTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorWiringTest.java index 92500d05..e62cc6ab 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorWiringTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorWiringTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.nodes; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/setup/ConfigTranslatorWiringTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/setup/ConfigTranslatorWiringTest.java index f0371b91..9d66551b 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/setup/ConfigTranslatorWiringTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/setup/ConfigTranslatorWiringTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.setup; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanDefaultInjectionTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanDefaultInjectionTest.java index 3d7b589c..5074f913 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanDefaultInjectionTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanDefaultInjectionTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.setup; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanEnvVarInjectionTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanEnvVarInjectionTest.java index 3be939f3..f9d6b620 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanEnvVarInjectionTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanEnvVarInjectionTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.setup; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterTest.java index a96ca854..0a22bbb0 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.setup; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterWithPropFileTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterWithPropFileTest.java index 7c96b9a6..4604b045 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterWithPropFileTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaLocationsBeanXMLSetterWithPropFileTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.setup; import static org.junit.Assert.*; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadEdgeConfigForValidationTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadEdgeConfigForValidationTest.java new file mode 100644 index 00000000..d6aee9a2 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadEdgeConfigForValidationTest.java @@ -0,0 +1,62 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.testutils; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.Version; + +/** + * Good oxm, bad edge rules for rainy day edge rule validation testing + */ +public class BadEdgeConfigForValidationTest extends ConfigTranslator { + + public BadEdgeConfigForValidationTest(SchemaLocationsBean bean) { + super(bean); + } + + @Override + public Map> getNodeFiles() { + List files = new ArrayList<>(); + files.add("src/test/resources/oxm/goodConfigForValidationTest_oxm.xml"); + Map> input = new EnumMap<>(Version.class); + input.put(Version.getLatest(), files); + return input; + } + + @Override + public Map> getEdgeFiles() { + Map> input = new EnumMap<>(Version.class); + List files = new ArrayList<>(); + files.add("src/test/resources/edgeRules/test3-butbad.json"); + input.put(Version.getLatest(), files); + return input; + } + + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadNodeConfigForValidationTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadNodeConfigForValidationTest.java new file mode 100644 index 00000000..a778e48a --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/BadNodeConfigForValidationTest.java @@ -0,0 +1,63 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.testutils; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.Version; + +/** + * All schema files here are valid for sunny day validator testing + */ +public class BadNodeConfigForValidationTest extends ConfigTranslator { + + public BadNodeConfigForValidationTest(SchemaLocationsBean bean) { + super(bean); + } + + @Override + public Map> getNodeFiles() { + List files = new ArrayList<>(); + files.add("src/test/resources/oxm/goodConfigForValidationTest_oxm.xml"); + files.add("src/test/resources/oxm/badConfigForValidationTest_oxm.xml"); + Map> input = new EnumMap<>(Version.class); + input.put(Version.getLatest(), files); + return input; + } + + @Override + public Map> getEdgeFiles() { + Map> input = new EnumMap<>(Version.class); + List files = new ArrayList<>(); + files.add("src/test/resources/edgeRules/test3.json"); + input.put(Version.getLatest(), files); + return input; + } + + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java index b69e3ac3..5e1b6c82 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/ConfigTranslatorForWiringTest.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.testutils; import java.util.ArrayList; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/GoodConfigForValidationTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/GoodConfigForValidationTest.java new file mode 100644 index 00000000..5efa2654 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/GoodConfigForValidationTest.java @@ -0,0 +1,68 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.testutils; + +import java.util.ArrayList; +import java.util.EnumMap; +import java.util.List; +import java.util.Map; + +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.Version; + +/** + * All schema files here are valid for sunny day validator testing + */ +public class GoodConfigForValidationTest extends ConfigTranslator { + + public GoodConfigForValidationTest(SchemaLocationsBean bean) { + super(bean); + } + + @Override + public Map> getNodeFiles() { + List files = new ArrayList<>(); + files.add("src/test/resources/oxm/goodConfigForValidationTest_oxm.xml"); + Map> input = new EnumMap<>(Version.class); + //input.put(Version.getLatest(), files); + for (Version v : Version.values()) { + input.put(v, files); + } + return input; + } + + @Override + public Map> getEdgeFiles() { + Map> input = new EnumMap<>(Version.class); + List files = new ArrayList<>(); + files.add("src/test/resources/edgeRules/test3.json"); + //input.put(Version.getLatest(), files); + for (Version v : Version.values()) { + input.put(v, files); + } + return input; + } + + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslator.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslator.java index f69ba29f..785b7403 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslator.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslator.java @@ -1,14 +1,14 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, @@ -16,7 +16,10 @@ * See the License for the specific language governing permissions and * limitations under the License. * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. */ + package org.onap.aai.testutils; import java.util.ArrayList; diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/CheckEverythingStrategyTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/CheckEverythingStrategyTest.java new file mode 100644 index 00000000..7078ac3a --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/CheckEverythingStrategyTest.java @@ -0,0 +1,57 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.onap.aai.validation.CheckEverythingStrategy; + +public class CheckEverythingStrategyTest { + + @Test + public void test() { + CheckEverythingStrategy strat = new CheckEverythingStrategy(); + //no issues so nothing notified, should be fine + assertTrue(strat.isOK()); + assertTrue("No errors found.".equals(strat.getErrorMsg())); + + //simulate post one error + String testError1 = "oh noes a problem with the gooble-gobble edge rule!"; + strat.notifyOnError(testError1); + assertFalse(strat.isOK()); + assertTrue(testError1.equals(strat.getErrorMsg())); + + //simulate multiple found + String testError2 = "error 2"; + String testError3 = "duplicate labels not everything is a fork"; + strat.notifyOnError(testError2); + strat.notifyOnError(testError3); + assertFalse(strat.isOK()); + System.out.println(strat.getErrorMsg()); + assertTrue(strat.getErrorMsg().contains(testError1)); + assertTrue(strat.getErrorMsg().contains(testError2)); + assertTrue(strat.getErrorMsg().contains(testError3)); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/FailFastStrategyTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/FailFastStrategyTest.java new file mode 100644 index 00000000..69f56007 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/FailFastStrategyTest.java @@ -0,0 +1,52 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + +import static org.junit.Assert.*; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.onap.aai.validation.AAISchemaValidationException; +import org.onap.aai.validation.FailFastStrategy; + +public class FailFastStrategyTest { + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void test() { + FailFastStrategy strat = new FailFastStrategy(); + + //simulate no issues found + assertTrue(strat.isOK()); + assertTrue("No errors found.".equals(strat.getErrorMsg())); + + //simulate an issue found + String testError = "hi i'm a problem"; + thrown.expect(AAISchemaValidationException.class); + thrown.expectMessage(testError); + strat.notifyOnError(testError); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorRainyDayTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorRainyDayTest.java new file mode 100644 index 00000000..f0d13d2e --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorRainyDayTest.java @@ -0,0 +1,53 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.Version; +import org.onap.aai.testutils.BadNodeConfigForValidationTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SchemaLocationsBean.class, BadNodeConfigForValidationTest.class, NodeIngestor.class, + CheckEverythingStrategy.class, DefaultVersionValidationModule.class, VersionValidator.class}) +@SpringBootTest +public class VersionValidatorRainyDayTest { + @Autowired + VersionValidator validator; + + @Test + public void test() { + assertFalse(validator.validate()); + assertTrue(validator.getErrorMsg().contains(Version.V12.toString())); + assertTrue(validator.getErrorMsg().contains(Version.V11.toString())); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorSunnyDayTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorSunnyDayTest.java new file mode 100644 index 00000000..f1950dd6 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/VersionValidatorSunnyDayTest.java @@ -0,0 +1,50 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.testutils.GoodConfigForValidationTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SchemaLocationsBean.class, GoodConfigForValidationTest.class, NodeIngestor.class, + CheckEverythingStrategy.class, DefaultVersionValidationModule.class, VersionValidator.class}) +@SpringBootTest +public class VersionValidatorSunnyDayTest { + @Autowired + VersionValidator validator; + + @Test + public void test() { + assertTrue(validator.validate()); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/CousinDefaultingValidationModuleTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/CousinDefaultingValidationModuleTest.java new file mode 100644 index 00000000..86aa61d3 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/CousinDefaultingValidationModuleTest.java @@ -0,0 +1,80 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.aai.edges.JsonIngestor; +import org.onap.aai.setup.Version; +import org.onap.aai.validation.edges.CousinDefaultingValidationModule; + +import com.jayway.jsonpath.DocumentContext; + +public class CousinDefaultingValidationModuleTest { + private static List ctxs; + private static CousinDefaultingValidationModule validator; + + @BeforeClass + public static void setUpBeforeClass() { + Map> testRules = new HashMap<>(); + List testFiles = new ArrayList<>(); + testFiles.add("src/test/resources/edgeRules/cousinDefaultValidationTest.json"); + testRules.put(Version.getLatest(), testFiles); + + JsonIngestor ji = new JsonIngestor(); + ctxs = ji.ingest(testRules).get(Version.getLatest()); + validator = new CousinDefaultingValidationModule(); + } + + @Test + public void testValidCousins() { + assertTrue("".equals(validator.validate("boop|beep", ctxs))); + } + + @Test + public void testValidBoth() { + assertTrue("".equals(validator.validate("monster|human", ctxs))); + } + + @Test + public void testValidSingleContains() { + assertTrue("".equals(validator.validate("family|baby", ctxs))); + } + + @Test + public void testInvalidTooManyDefaults() { + assertTrue(validator.validate("sheep|wool", ctxs).contains("Multiple set")); + } + + @Test + public void testInvalidNoDefaults() { + assertTrue(validator.validate("cloth|thread", ctxs).contains("None set")); + } +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModuleTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModuleTest.java new file mode 100644 index 00000000..39f2a019 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/DefaultEdgeFieldsValidationModuleTest.java @@ -0,0 +1,65 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import static org.junit.Assert.*; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.edges.enums.EdgeField; +import org.onap.aai.validation.edges.DefaultEdgeFieldsValidationModule; +import org.onap.aai.validation.edges.EdgeFieldsValidationModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {DefaultEdgeFieldsValidationModule.class}) +@SpringBootTest +public class DefaultEdgeFieldsValidationModuleTest { + @Autowired + EdgeFieldsValidationModule validator; + + @Test + public void test() { + Map test = new HashMap<>(); + for (EdgeField f : EdgeField.values()) { + test.put(f.toString(), "test"); + } + assertTrue("".equals(validator.verifyFields(test))); + + test.remove(EdgeField.DESCRIPTION.toString()); + assertTrue("".equals(validator.verifyFields(test))); //bc description is optional + + test.remove(EdgeField.CONTAINS.toString()); + assertTrue(validator.verifyFields(test).contains("missing required fields: contains-other-v")); + + test.remove(EdgeField.FROM.toString()); + assertTrue(validator.verifyFields(test).contains("missing required fields: from contains-other-v")); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorRainyDayTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorRainyDayTest.java new file mode 100644 index 00000000..5a3a4334 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorRainyDayTest.java @@ -0,0 +1,63 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.testutils.BadEdgeConfigForValidationTest; +import org.onap.aai.validation.CheckEverythingStrategy; +import org.onap.aai.validation.edges.CousinDefaultingValidationModule; +import org.onap.aai.validation.edges.DefaultEdgeFieldsValidationModule; +import org.onap.aai.validation.edges.EdgeRuleValidator; +import org.onap.aai.validation.edges.NodeTypesValidationModule; +import org.onap.aai.validation.edges.SingleContainmentValidationModule; +import org.onap.aai.validation.edges.UniqueLabelValidationModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SchemaLocationsBean.class, BadEdgeConfigForValidationTest.class, NodeIngestor.class, + CheckEverythingStrategy.class, DefaultEdgeFieldsValidationModule.class, UniqueLabelValidationModule.class, + SingleContainmentValidationModule.class, CousinDefaultingValidationModule.class, NodeTypesValidationModule.class, + EdgeRuleValidator.class}) +@SpringBootTest +public class EdgeRuleValidatorRainyDayTest { + @Autowired + EdgeRuleValidator validator; + + @Test + public void test() { + assertNotNull(validator); //verify spring wiring OK + assertFalse(validator.validate()); + String errors = validator.getErrorMsg(); + assertTrue(errors.contains("missing required fields: delete-other-v")); + assertTrue(errors.contains("has multiple rules using the same label: org.onap.relationships.inventory.Source")); + assertTrue(errors.contains("Invalid node type(s) found: gooble")); + } +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorSunnyDayTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorSunnyDayTest.java new file mode 100644 index 00000000..20885894 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/EdgeRuleValidatorSunnyDayTest.java @@ -0,0 +1,60 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.testutils.GoodConfigForValidationTest; +import org.onap.aai.validation.CheckEverythingStrategy; +import org.onap.aai.validation.edges.CousinDefaultingValidationModule; +import org.onap.aai.validation.edges.DefaultEdgeFieldsValidationModule; +import org.onap.aai.validation.edges.EdgeRuleValidator; +import org.onap.aai.validation.edges.NodeTypesValidationModule; +import org.onap.aai.validation.edges.SingleContainmentValidationModule; +import org.onap.aai.validation.edges.UniqueLabelValidationModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SchemaLocationsBean.class, GoodConfigForValidationTest.class, NodeIngestor.class, + CheckEverythingStrategy.class, DefaultEdgeFieldsValidationModule.class, UniqueLabelValidationModule.class, + SingleContainmentValidationModule.class, CousinDefaultingValidationModule.class, NodeTypesValidationModule.class, + EdgeRuleValidator.class}) +@SpringBootTest +public class EdgeRuleValidatorSunnyDayTest { + @Autowired + EdgeRuleValidator validator; + + @Test + public void test() { + assertNotNull(validator); //verify spring wiring OK + assertTrue(validator.validate()); + assertTrue("No errors found.".equals(validator.getErrorMsg())); + } +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/NodeTypesValidationModuleTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/NodeTypesValidationModuleTest.java new file mode 100644 index 00000000..a7cb9c2e --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/NodeTypesValidationModuleTest.java @@ -0,0 +1,67 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.Version; +import org.onap.aai.testutils.TestUtilConfigTranslator; +import org.onap.aai.validation.edges.NodeTypesValidationModule; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SchemaLocationsBean.class, TestUtilConfigTranslator.class, NodeIngestor.class, NodeTypesValidationModule.class}) +@SpringBootTest +public class NodeTypesValidationModuleTest { + @Autowired + NodeTypesValidationModule validator; + + @Test + public void test() { + List testPairs = new ArrayList<>(); + testPairs.add("bar|foo"); + testPairs.add("foo|foo"); + testPairs.add("foo|quux"); + assertTrue("".equals(validator.validate(testPairs, Version.V11))); + assertTrue(validator.validate(testPairs, Version.V10).contains("Invalid node type(s) found: quux")); //bc no quux in v10 + } + + @Test + public void testWeirdCases() { + List testPairs = new ArrayList<>(); + testPairs.add("bar|"); + testPairs.add("|foo"); + testPairs.add("|"); + assertTrue("".equals(validator.validate(testPairs, Version.V11))); //bc empty just ignored + } +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/SingleContainmentValidationModuleTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/SingleContainmentValidationModuleTest.java new file mode 100644 index 00000000..caf73cb5 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/SingleContainmentValidationModuleTest.java @@ -0,0 +1,70 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.aai.edges.JsonIngestor; +import org.onap.aai.setup.Version; +import org.onap.aai.validation.edges.SingleContainmentValidationModule; + +import com.jayway.jsonpath.DocumentContext; + +public class SingleContainmentValidationModuleTest { + private static List ctxs; + private static SingleContainmentValidationModule validator; + + @BeforeClass + public static void setUpBeforeClass() { + Map> testRules = new HashMap<>(); + List testFiles = new ArrayList<>(); + testFiles.add("src/test/resources/edgeRules/containsValidationTest.json"); + testRules.put(Version.getLatest(), testFiles); + + JsonIngestor ji = new JsonIngestor(); + ctxs = ji.ingest(testRules).get(Version.getLatest()); + validator = new SingleContainmentValidationModule(); + } + + @Test + public void testValid() { + assertTrue("".equals(validator.validate("human|monster", ctxs))); + } + + @Test + public void testValidWithNone() { + assertTrue("".equals(validator.validate("bread|cheese", ctxs))); + } + + @Test + public void testInvalid() { + assertTrue(validator.validate("box|cat", ctxs).contains("has multiple containment rules")); + } +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/UniqueLabelValidationModuleTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/UniqueLabelValidationModuleTest.java new file mode 100644 index 00000000..7f51a6fb --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/edges/UniqueLabelValidationModuleTest.java @@ -0,0 +1,97 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.edges; + +import static org.junit.Assert.*; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.BeforeClass; +import org.junit.Test; +import org.onap.aai.edges.JsonIngestor; +import org.onap.aai.setup.Version; +import org.onap.aai.validation.edges.UniqueLabelValidationModule; + +import com.jayway.jsonpath.DocumentContext; + +public class UniqueLabelValidationModuleTest { + private static List ctxs; + private static UniqueLabelValidationModule validator; + + @BeforeClass + public static void setup() { + Map> testRules = new HashMap<>(); + List testFiles = new ArrayList<>(); + testFiles.add("src/test/resources/edgeRules/labelValidationTest1.json"); + testFiles.add("src/test/resources/edgeRules/labelValidationTest2.json"); + testRules.put(Version.getLatest(), testFiles); + + JsonIngestor ji = new JsonIngestor(); + ctxs = ji.ingest(testRules).get(Version.getLatest()); + validator = new UniqueLabelValidationModule(); + } + + @Test + public void testValidSetOneFile() { + assertTrue("".equals(validator.validate("human|monster", ctxs))); + assertTrue("".equals(validator.validate("monster|human", ctxs))); + } + + @Test + public void testValidDupLabelButDiffPairs() { + assertTrue("".equals(validator.validate("human|strange-and-interesting-plant", ctxs))); + assertTrue("".equals(validator.validate("strange-and-interesting-plant|human", ctxs))); + } + + @Test + public void testValidAcrossFiles() { + assertTrue("".equals(validator.validate("human|toaster", ctxs))); + assertTrue("".equals(validator.validate("toaster|human", ctxs))); + } + + @Test + public void testInvalidSetOneFileBothTypes() { + assertTrue(validator.validate("sphinx|monster", ctxs).contains("has multiple rules using the same label")); + assertTrue(validator.validate("monster|sphinx", ctxs).contains("has multiple rules using the same label")); + } + + @Test + public void testInvalidSetOneFileJustCousins() { + assertTrue(validator.validate("griffin|hippogriff", ctxs).contains("has multiple rules using the same label")); + assertTrue(validator.validate("hippogriff|griffin", ctxs).contains("has multiple rules using the same label")); + } + + @Test + public void testInvalidSetMultipleFiles() { + assertTrue(validator.validate("lava|floor", ctxs).contains("has multiple rules using the same label")); + assertTrue(validator.validate("floor|lava", ctxs).contains("has multiple rules using the same label")); + } + + @Test + public void testInvalidCopyInOtherFile() { + assertTrue(validator.validate("badger|mushroom", ctxs).contains("has multiple rules using the same label")); + } +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorRainyDayTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorRainyDayTest.java new file mode 100644 index 00000000..d1a60dd8 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorRainyDayTest.java @@ -0,0 +1,58 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.nodes; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.testutils.BadNodeConfigForValidationTest; +import org.onap.aai.validation.CheckEverythingStrategy; +import org.onap.aai.validation.nodes.DefaultDuplicateNodeDefinitionValidationModule; +import org.onap.aai.validation.nodes.NodeValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SchemaLocationsBean.class, BadNodeConfigForValidationTest.class, NodeIngestor.class, + CheckEverythingStrategy.class, DefaultDuplicateNodeDefinitionValidationModule.class, NodeValidator.class}) +@SpringBootTest +public class NodeValidatorRainyDayTest { + @Autowired + NodeValidator validator; + + @Test + public void test() { + assertNotNull(validator); //check spring wiring ok + assertFalse(validator.validate()); + String result = validator.getErrorMsg(); + assertTrue(result.contains("LogicalLink")); + assertTrue(result.contains("LagInterface")); + assertFalse(result.contains("LInterface")); + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSunnyDayTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSunnyDayTest.java new file mode 100644 index 00000000..6233dfe1 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSunnyDayTest.java @@ -0,0 +1,55 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + * + * ECOMP is a trademark and service mark of AT&T Intellectual Property. + */ + +package org.onap.aai.validation.nodes; + +import static org.junit.Assert.*; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.testutils.GoodConfigForValidationTest; +import org.onap.aai.validation.CheckEverythingStrategy; +import org.onap.aai.validation.nodes.DefaultDuplicateNodeDefinitionValidationModule; +import org.onap.aai.validation.nodes.NodeValidator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = {SchemaLocationsBean.class, GoodConfigForValidationTest.class, NodeIngestor.class, + CheckEverythingStrategy.class, DefaultDuplicateNodeDefinitionValidationModule.class, NodeValidator.class}) +@SpringBootTest +public class NodeValidatorSunnyDayTest { + @Autowired + NodeValidator validator; + + @Test + public void test() { + assertNotNull(validator); //check spring wiring ok + assertTrue(validator.validate()); + assertTrue("No errors found.".equals(validator.getErrorMsg())); + } + +} diff --git a/aai-schema-ingest/src/test/resources/edgeRules/containsValidationTest.json b/aai-schema-ingest/src/test/resources/edgeRules/containsValidationTest.json new file mode 100644 index 00000000..06e599b1 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/containsValidationTest.json @@ -0,0 +1,64 @@ +{ + "rules" : [ + { + "from": "human", + "to": "monster", + "label": "fights", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "${direction}", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"valid set with one containment" + }, + { + "from": "human", + "to": "monster", + "label": "avoids", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"valid set with one containment" + }, + { + "from": "cheese", + "to": "bread", + "label": "eatenWith", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"valid set with no containment" + }, + { + "from": "box", + "to": "cat", + "label": "contains", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "${direction}", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"invalid set with more than one containment" + }, + { + "from": "box", + "to": "cat", + "label": "encapsulates", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "IN", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"invalid set with more than one containment" + } + ] +} \ No newline at end of file diff --git a/aai-schema-ingest/src/test/resources/edgeRules/cousinDefaultValidationTest.json b/aai-schema-ingest/src/test/resources/edgeRules/cousinDefaultValidationTest.json new file mode 100644 index 00000000..1a5b8a9b --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/cousinDefaultValidationTest.json @@ -0,0 +1,112 @@ +{ + "rules" : [ + { + "from": "human", + "to": "monster", + "label": "fights", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"valid set as cousin/contains have separate defaulting" + }, + { + "from": "human", + "to": "monster", + "label": "builds", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"valid set as cousin/contains have separate defaulting" + }, + { + "from": "boop", + "to": "beep", + "label": "isTransformedByRobotsInto", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"valid set with exactly 1 default" + }, + { + "from": "boop", + "to": "beep", + "label": "yields", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "false", + "description":"valid set with exactly 1 default" + }, + { + "from": "sheep", + "to": "wool", + "label": "produces", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"invalid set with multiple defaults" + }, + { + "from": "wool", + "to": "sheep", + "label": "isShearedFrom", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"invalid set with multiple defaults" + }, + { + "from": "cloth", + "to": "thread", + "label": "isWovenFrom", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "false", + "description":"invalid set with no defaults" + }, + { + "from": "cloth", + "to": "thread", + "label": "unravelsTo", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "false", + "description":"invalid set with no defaults" + }, + { + "from": "family", + "to": "baby", + "label": "raises", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"vacuously valid set (ie no cousin so doesn't even matter)" + } + ] +} \ No newline at end of file diff --git a/aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest1.json b/aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest1.json new file mode 100644 index 00000000..1a5bd487 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest1.json @@ -0,0 +1,124 @@ +{ + "rules": [ + { + "from": "human", + "to": "monster", + "label": "fights", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of valid set" + }, + { + "from": "monster", + "to": "human", + "label": "ignores", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of valid set" + }, + { + "from": "human", + "to": "monster", + "label": "tames", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of valid set" + }, + { + "from": "sphinx", + "to": "monster", + "label": "isA", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of invalid set - dup label, cousin and containment, from/to flipped" + }, + { + "from": "sphinx", + "to": "monster", + "label": "isA", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of invalid set - dup label, cousin and containment, from/to flipped" + }, + { + "from": "griffin", + "to": "hippogriff", + "label": "fliesPast", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "false", + "description":"will be part of invalid set - dup label, both cousins, from/to flipped" + }, + { + "from": "hippogriff", + "to": "griffin", + "label": "fliesPast", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of invalid set - dup label, both cousins, from/to flipped" + }, + { + "from": "human", + "to": "toaster", + "label": "owns", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of valid set (dup label (human owns) but on different pair so ok)" + }, + { + "from": "badger", + "to": "mushroom", + "label": "onap.whatever.BindsTo", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of invalid set - full copy in file2" + }, + { + "from": "lava", + "to": "floor", + "label": "is", + "direction": "IN", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of invalid set - dup in file2, contains and cousin, from/to flipped" + } + ] +} \ No newline at end of file diff --git a/aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest2.json b/aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest2.json new file mode 100644 index 00000000..5743fbb9 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/labelValidationTest2.json @@ -0,0 +1,52 @@ +{ + "rules": [ + { + "from": "human", + "to": "strange-and-interesting-plant", + "label": "owns", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of valid set (dup label (human owns) to stuff in file1, but different pair so ok)" + }, + { + "from": "badger", + "to": "mushroom", + "label": "onap.whatever.BindsTo", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of invalid set - full copy in file2" + }, + { + "from": "floor", + "to": "lava", + "label": "is", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of invalid set - dup in file2, contains and cousin, from/to flipped" + }, + { + "from": "human", + "to": "toaster", + "label": "builds", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"will be part of valid set across both files" + } + ] +} \ No newline at end of file diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test3-butbad.json b/aai-schema-ingest/src/test/resources/edgeRules/test3-butbad.json new file mode 100644 index 00000000..f20caebb --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test3-butbad.json @@ -0,0 +1,63 @@ +{ + "rules": [ + { + "from": "l-interface", + "to": "logical-link", + "label": "tosca.relationships.network.LinksTo", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"" + }, + { + "from": "logical-link", + "to": "l-interface", + "label": "org.onap.relationships.inventory.Source", + "direction": "OUT", + "multiplicity": "ONE2MANY", + "contains-other-v": "NONE", + "delete-other-v": "!${direction}", + "prevent-delete": "NONE", + "default": "false", + "description":"" + }, + { + "from": "logical-link", + "to": "l-interface", + "label": "org.onap.relationships.inventory.Source", + "direction": "OUT", + "multiplicity": "ONE2MANY", + "contains-other-v": "NONE", + "delete-other-v": "!${direction}", + "prevent-delete": "NONE", + "default": "false", + "description":"" + }, + { + "from": "l-interface", + "to": "lag-interface", + "label": "org.onap.relationships.inventory.BelongsTo", + "direction": "OUT", + "multiplicity": "MANY2ONE", + "contains-other-v": "!${direction}", + "delete-other-v": "!${direction}", + "prevent-delete": "NONE", + "default": "true", + "description":"" + }, + { + "from": "gooble", + "to": "logical-link", + "label": "org.onap.relationships.inventory.Uses", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "default": "true", + "description":"" + } + ] +} \ No newline at end of file diff --git a/aai-schema-ingest/src/test/resources/oxm/badConfigForValidationTest_oxm.xml b/aai-schema-ingest/src/test/resources/oxm/badConfigForValidationTest_oxm.xml new file mode 100644 index 00000000..7b13262a --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/badConfigForValidationTest_oxm.xml @@ -0,0 +1,208 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/aai-schema-ingest/src/test/resources/oxm/goodConfigForValidationTest_oxm.xml b/aai-schema-ingest/src/test/resources/oxm/goodConfigForValidationTest_oxm.xml new file mode 100644 index 00000000..b3da71d8 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/goodConfigForValidationTest_oxm.xml @@ -0,0 +1,296 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file -- 2.16.6