From 5948f878fa0ee735e81f1cf648d5d3bdb35048cd Mon Sep 17 00:00:00 2001 From: "Kajur, Harish (vk250x)" Date: Tue, 4 Dec 2018 23:19:04 -0500 Subject: Update schema ingest library call schema service Issue-ID: AAI-1994 Change-Id: Icc9910db0371eeb8289abd4381ae1936a281a5df Signed-off-by: Kajur, Harish (vk250x) --- aai-schema-ingest/pom.xml | 62 +- .../org/onap/aai/config/ConfigConfiguration.java | 46 + .../org/onap/aai/config/EdgesConfiguration.java | 77 + .../org/onap/aai/config/NodesConfiguration.java | 82 + .../org/onap/aai/config/RestConfiguration.java | 82 + .../aai/config/SchemaServiceConfiguration.java | 54 + .../onap/aai/config/TranslatorConfiguration.java | 36 + .../main/java/org/onap/aai/edges/EdgeIngestor.java | 788 ++-- .../src/main/java/org/onap/aai/edges/EdgeRule.java | 67 +- .../java/org/onap/aai/edges/EdgeRuleQuery.java | 21 +- .../main/java/org/onap/aai/edges/JsonIngestor.java | 125 +- .../exceptions/AmbiguousRuleChoiceException.java | 6 +- .../exceptions/EdgeRuleNotFoundException.java | 6 +- .../main/java/org/onap/aai/nodes/NodeIngestor.java | 428 +- .../aai/restclient/SchemaServiceNoAuthClient.java | 75 + .../aai/restclient/SchemaServiceOneWayClient.java | 87 + .../aai/restclient/SchemaServiceRestClient.java | 102 + .../org/onap/aai/setup/AAIConfigTranslator.java | 9 +- .../java/org/onap/aai/setup/ConfigTranslator.java | 66 +- .../org/onap/aai/setup/SchemaLocationsBean.java | 1 - .../onap/aai/setup/SchemaServiceTranslator.java | 105 + .../org/onap/aai/setup/SchemaServiceVersions.java | 48 + .../java/org/onap/aai/setup/SchemaVersion.java | 2 - .../java/org/onap/aai/setup/SchemaVersions.java | 120 +- .../org/onap/aai/setup/SchemaVersionsBean.java | 83 + .../main/java/org/onap/aai/setup/Translator.java | 67 + .../validation/DefaultVersionValidationModule.java | 56 +- .../edges/CousinDefaultingValidationModule.java | 9 +- .../edges/DefaultEdgeFieldsValidationModule.java | 5 +- .../aai/validation/edges/EdgeRuleValidator.java | 41 +- .../edges/NodeTypesValidationModule.java | 7 +- .../edges/SingleContainmentValidationModule.java | 9 +- .../edges/UniqueLabelValidationModule.java | 9 +- .../onap/aai/validation/nodes/NodeValidator.java | 7 +- .../org/onap/aai/edges/EdgeIngestorLocalTest.java | 369 ++ .../java/org/onap/aai/edges/EdgeIngestorTest.java | 197 +- .../org/onap/aai/edges/EdgeIngestorWiringTest.java | 10 +- .../java/org/onap/aai/edges/EdgeRuleQueryTest.java | 1 + .../java/org/onap/aai/edges/JsonIngestorTest.java | 1 - .../org/onap/aai/edges/TypeAlphabetizerTest.java | 1 - .../org/onap/aai/nodes/NodeIngestorLocalTest.java | 176 + .../java/org/onap/aai/nodes/NodeIngestorTest.java | 96 +- .../org/onap/aai/nodes/NodeIngestorWiringTest.java | 10 +- .../java/org/onap/aai/restclient/MockProvider.java | 58 + .../org/onap/aai/restclient/MockRestClient.java | 295 ++ .../org/onap/aai/restclient/RestClientTest.java | 24 + .../onap/aai/restclient/SchemaRestClientTest.java | 67 + .../onap/aai/setup/ConfigTranslatorWiringTest.java | 13 +- .../SchemaLocationsBeanDefaultInjectionTest.java | 5 +- .../SchemaLocationsBeanEnvVarInjectionTest.java | 5 +- .../setup/SchemaLocationsBeanXMLSetterTest.java | 5 +- ...hemaLocationsBeanXMLSetterWithPropFileTest.java | 5 +- .../org/onap/aai/setup/SchemaVersionsBeanTest.java | 87 + .../testutils/BadEdgeConfigForValidationTest.java | 8 +- .../testutils/BadNodeConfigForValidationTest.java | 10 +- .../testutils/ConfigTranslatorForWiringTest.java | 11 +- .../aai/testutils/GoodConfigForValidationTest.java | 7 +- .../aai/testutils/SchemaIncompleteTranslator.java | 11 +- .../aai/testutils/TestUtilConfigTranslator.java | 16 +- .../TestUtilConfigTranslatorforBusiness.java | 11 +- .../validation/VersionValidatorRainyDayTest.java | 9 +- .../validation/VersionValidatorSunnyDayTest.java | 12 +- .../DefaultEdgeFieldsValidationModuleTest.java | 2 - .../edges/EdgeRuleValidatorRainyDayTest.java | 16 +- .../edges/EdgeRuleValidatorSunnyDayTest.java | 16 +- .../edges/NodeTypesValidationModuleTest.java | 10 +- .../nodes/NodeValidatorRainyDayTest.java | 14 +- .../nodes/NodeValidatorSchemaIncompleteTest.java | 22 +- .../nodes/NodeValidatorSunnyDayTest.java | 12 +- .../src/test/resources/edgeRules/test_v10.json | 48 + .../src/test/resources/edgeRules/test_v11.json | 124 + .../src/test/resources/edgeRules/test_v12.json | 71 + .../src/test/resources/edgeRules/test_v13.json | 71 + .../src/test/resources/edgeRules/test_v14.json | 71 + .../src/test/resources/edgeRules/test_v15.json | 275 ++ .../src/test/resources/edgeRules/test_v8.json | 71 + .../src/test/resources/edgeRules/test_v9.json | 4 + .../src/test/resources/edgerequests.json | 50 + .../test/resources/forWiringTests/aai_oxm_v13.xml | 3 +- .../schema-ingest-ss-wiring-test.properties | 20 + ...schema-ingest-wiring-test-local-node.properties | 14 + .../schema-ingest-wiring-test-local.properties | 15 + .../schema-ingest-wiring-test.properties | 16 +- .../src/test/resources/mockrequests.json | 52 + .../src/test/resources/oxm/test_business_v10.xml | 6 +- .../oxm/test_combined_network_business_v10.xml | 83 + .../oxm/test_combined_network_business_v11.xml | 101 + .../oxm/test_combined_network_business_v12.xml | 101 + .../oxm/test_combined_network_business_v13.xml | 101 + .../oxm/test_combined_network_business_v14.xml | 101 + .../oxm/test_combined_network_business_v15.xml | 101 + .../oxm/test_combined_network_business_v8.xml | 101 + .../oxm/test_combined_network_business_v9.xml | 101 + .../src/test/resources/oxm/test_combined_v13.xml | 4629 ++++++++++++++++++++ .../src/test/resources/oxm/test_network_v10.xml | 6 +- .../src/test/resources/payload/versions.json | 18 + .../test/resources/schemaservice-endpoints.json | 9 + 97 files changed, 9683 insertions(+), 1080 deletions(-) create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/config/ConfigConfiguration.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/config/TranslatorConfiguration.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceNoAuthClient.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceOneWayClient.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceRestClient.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java create mode 100644 aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorLocalTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockProvider.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockRestClient.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/restclient/RestClientTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/restclient/SchemaRestClientTest.java create mode 100644 aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaVersionsBeanTest.java create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v10.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v11.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v12.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v13.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v14.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v15.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v8.json create mode 100644 aai-schema-ingest/src/test/resources/edgeRules/test_v9.json create mode 100644 aai-schema-ingest/src/test/resources/edgerequests.json create mode 100644 aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-ss-wiring-test.properties create mode 100644 aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local-node.properties create mode 100644 aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties create mode 100644 aai-schema-ingest/src/test/resources/mockrequests.json create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v10.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v11.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v12.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v13.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v14.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v15.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v8.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v9.xml create mode 100644 aai-schema-ingest/src/test/resources/oxm/test_combined_v13.xml create mode 100644 aai-schema-ingest/src/test/resources/payload/versions.json create mode 100644 aai-schema-ingest/src/test/resources/schemaservice-endpoints.json (limited to 'aai-schema-ingest') diff --git a/aai-schema-ingest/pom.xml b/aai-schema-ingest/pom.xml index d2f93694..55210d7c 100644 --- a/aai-schema-ingest/pom.xml +++ b/aai-schema-ingest/pom.xml @@ -25,13 +25,17 @@ org.onap.aai.aai-common aai-common - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT aai-schema-ingest aai-schema-ingest - 1.4.0-SNAPSHOT + 1.4.1-SNAPSHOT jar + + 1.0.0 + 4.5.5 + @@ -70,6 +74,17 @@ 2.4.15 indy + + + commons-io + commons-io + 2.6 + + + org.onap.aai.aai-common + aai-rest + ${project.version} + org.apache.tinkerpop gremlin-core @@ -80,11 +95,31 @@ json-path 2.2.0 + + javax.ws.rs + javax.ws.rs-api + 2.0.1 + org.springframework spring-context 4.3.18.RELEASE + + org.springframework + spring-web + 4.3.18.RELEASE + + + org.springframework.boot + spring-boot-starter-web + 1.5.12.RELEASE + + + org.apache.httpcomponents + httpclient + ${httpclient.version} + org.springframework spring-test @@ -108,6 +143,29 @@ 1.10.19 test + + com.att.eelf + eelf-core + ${eelf.core.version} + + + com.google.code.gson + gson + 2.8.5 + test + + + com.google.code.gson + gson + 2.8.5 + test + + + com.google.code.gson + gson + 2.8.5 + compile + diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/ConfigConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/ConfigConfiguration.java new file mode 100644 index 00000000..9f28cf8f --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/ConfigConfiguration.java @@ -0,0 +1,46 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ + * 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========================================================= + */ +package org.onap.aai.config; + +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersions; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@ConditionalOnProperty(prefix = "schema.translator.list", value = "config", matchIfMissing = true) +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) +public class ConfigConfiguration { + + @Bean(name = "schemaVersions") + public SchemaVersions schemaVersions() { + return new SchemaVersions(); + } + + @Bean(name = "schemaLocationsBean") + public SchemaLocationsBean schemaLocationsBean() { + return new SchemaLocationsBean(); + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java new file mode 100644 index 00000000..e492d213 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/EdgesConfiguration.java @@ -0,0 +1,77 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ + * 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========================================================= + */ +package org.onap.aai.config; + +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.Translator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Import({SchemaServiceConfiguration.class, ConfigConfiguration.class, TranslatorConfiguration.class}) +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) +@Configuration +public class EdgesConfiguration { + + private static final String CONFIG_TRANSLATOR = "config"; + private static final String SCHEMA_SERVICE_TRANSLATOR = "schema-service"; + + @Autowired(required = false) + SchemaServiceConfiguration schemaConfiguration; + + @Autowired(required = false) + ConfigConfiguration configConfiguration; + + @Autowired(required = false) + TranslatorConfiguration translatorConfiguration; + + @Value("${schema.translator.list}") + private String[] translatorArray; + + public Set translators() { + Set translators = new HashSet<>(); + + List translatorList = Arrays.asList(translatorArray); + if (translatorList.contains(SCHEMA_SERVICE_TRANSLATOR)) { + translators.add(schemaConfiguration.schemaServiceTranslator()); + } else { + translators.add(translatorConfiguration.configTranslator); + } + return translators; + } + + @Bean(name = "edgeIngestor") + public EdgeIngestor edgeIngestor() { + return new EdgeIngestor(translators()); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java new file mode 100644 index 00000000..94bc6da5 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/NodesConfiguration.java @@ -0,0 +1,82 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ + * 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========================================================= + */ +package org.onap.aai.config; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.Translator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.context.annotation.PropertySource; + +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +@Import({SchemaServiceConfiguration.class, ConfigConfiguration.class, TranslatorConfiguration.class}) +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) +@Configuration +public class NodesConfiguration { + + private static final String CONFIG_TRANSLATOR = "config"; + private static final String SCHEMA_SERVICE_TRANSLATOR = "schema-service"; + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(NodesConfiguration.class); + + @Autowired(required = false) + SchemaServiceConfiguration schemaConfiguration; + + @Autowired(required = false) + ConfigConfiguration configConfiguration; + + @Autowired(required = false) + TranslatorConfiguration translatorConfiguration; + + @Value("${schema.translator.list}") + private String[] translatorArray; + + public Set translators() { + Set translators = new HashSet<>(); + + List translatorList = Arrays.asList(translatorArray); + if (translatorList.contains(SCHEMA_SERVICE_TRANSLATOR)) { + LOGGER.info("Translator is SchemaServiceTranslator"); + translators.add(schemaConfiguration.schemaServiceTranslator()); + } else { + LOGGER.info("Translator is SchemaServiceTranslator"); + translators.add(translatorConfiguration.configTranslator); + } + return translators; + } + + @Bean(name = "nodeIngestor") + public NodeIngestor nodeIngestor() { + return new NodeIngestor(translators()); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java new file mode 100644 index 00000000..0a3dbf5e --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/RestConfiguration.java @@ -0,0 +1,82 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ + * 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========================================================= + */ +package org.onap.aai.config; + +import org.onap.aai.restclient.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@ConditionalOnExpression("'${schema.translator.list}'.contains('schema-service')") +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) +public class RestConfiguration { + + private static final String TWO_WAY_SSL = "two-way-ssl"; + private static final String ONE_WAY_SSL = "one-way-ssl"; + private static final String NO_AUTH = "no-auth"; + + @Value("${schema.service.client:two-way-ssl}") + private String schemaServiceClient; + + @Autowired + private RestClient restClient; + + @Bean + public RestClientFactory restClientFactory() { + + return new RestClientFactory() { + @Override + public RestClient getRestClient(String clientType) { + return restClient; + + } + }; + } + + /* + In the below cases bean name and method names are different because all of them qualify as restClient + */ + @Bean(name="restClient") + @ConditionalOnProperty(name = "schema.service.client", havingValue = "two-way-ssl", matchIfMissing = true) + public RestClient getSchemaServiceTwoWayClient() { + return new SchemaServiceRestClient(); + } + + @Bean(name="restClient") + @ConditionalOnProperty(name = "schema.service.client", havingValue = "no-auth") + public RestClient getSchemaServiceNoAuthClient() { + return new SchemaServiceNoAuthClient(); + } + + @Bean(name="restClient") + @ConditionalOnProperty(name = "schema.service.client", havingValue = "one-way-ssl") + public RestClient getSchemaServiceOneWayClient() { + return new SchemaServiceOneWayClient(); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java new file mode 100644 index 00000000..81ef02a8 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/SchemaServiceConfiguration.java @@ -0,0 +1,54 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ + * 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========================================================= + */ +package org.onap.aai.config; + +import org.onap.aai.setup.SchemaServiceTranslator; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersionsBean; +import org.onap.aai.setup.Translator; +import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@ConditionalOnExpression("'${schema.translator.list}'.contains('schema-service')") +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) +public class SchemaServiceConfiguration { + + @Bean(name = "schemaVersionsBean") + public SchemaVersionsBean schemaVersionsBean() { + return new SchemaVersionsBean(); + } + + @Bean(name = "schemaVersions") + public SchemaVersions schemaVersions() { + return schemaVersionsBean().getSchemaVersions(); + } + + @Bean(name = "schemaServiceTranslator") + public Translator schemaServiceTranslator() { + return new SchemaServiceTranslator(schemaVersions()); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/config/TranslatorConfiguration.java b/aai-schema-ingest/src/main/java/org/onap/aai/config/TranslatorConfiguration.java new file mode 100644 index 00000000..941e03d9 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/config/TranslatorConfiguration.java @@ -0,0 +1,36 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ + * 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========================================================= + */ +package org.onap.aai.config; + +import org.onap.aai.setup.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Configuration; + +@Configuration +@ConditionalOnProperty(prefix = "schema.translator.list", value = "config", matchIfMissing = true) +public class TranslatorConfiguration { + //TODO check if you can put dependsOn to reduce number of config files + @Autowired(required = false) + ConfigTranslator configTranslator; + +} 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 c2c58d5f..71225340 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 @@ -20,37 +20,37 @@ package org.onap.aai.edges; -import java.util.*; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; -import java.util.stream.Collectors; - -import com.google.common.cache.Cache; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; import com.google.common.cache.CacheBuilder; import com.google.common.cache.CacheLoader; import com.google.common.cache.LoadingCache; +import com.google.common.collect.ArrayListMultimap; +import com.google.common.collect.Multimap; +import com.jayway.jsonpath.Criteria; +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.Filter; import org.apache.tinkerpop.gremlin.structure.Direction; import org.onap.aai.edges.enums.DirectionNotation; import org.onap.aai.edges.enums.EdgeField; import org.onap.aai.edges.enums.EdgeType; import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; -import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.onap.aai.setup.Translator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.google.common.collect.ArrayListMultimap; -import com.google.common.collect.Multimap; -import com.jayway.jsonpath.Criteria; -import com.jayway.jsonpath.DocumentContext; -import com.jayway.jsonpath.Filter; -import static com.jayway.jsonpath.Filter.filter; +import javax.annotation.PostConstruct; +import java.io.IOException; +import java.util.*; +import java.util.Map.Entry; +import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; + import static com.jayway.jsonpath.Criteria.where; +import static com.jayway.jsonpath.Filter.filter; /** * EdgeIngestor - ingests A&AI edge rule schema files per given config, serves that edge rule @@ -58,34 +58,73 @@ import static com.jayway.jsonpath.Criteria.where; */ @Component public class EdgeIngestor { + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(EdgeIngestor.class); + private Map> versionJsonFilesMap; + private static final String READ_START = "$.rules.[?]"; + private static final String READ_ALL_START = "$.rules.*"; + private SchemaVersions schemaVersions; - private static final Logger LOG = LoggerFactory.getLogger(EdgeIngestor.class); + Map> filesToIngest; - private Map> versionJsonFilesMap; - private static final String READ_START = "$.rules.[?]"; - private static final String READ_ALL_START = "$.rules.*"; + private Set multipleLabelKeys; - private SchemaVersions schemaVersions; + private LoadingCache> cacheFilterStore; - private Set multipleLabelKeys; + private LoadingCache cousinLabelStore; - private final LoadingCache> cacheFilterStore; + private Set translators; - private final LoadingCache cousinLabelStore; + @Autowired + public EdgeIngestor(Set translatorSet) { + LOGGER.debug("Local Schema files will be fetched"); + this.translators = translatorSet; + } + + @PostConstruct + public void initialize() { + + for (Translator translator : translators) { + try { + LOGGER.debug("Processing the translator"); + translateAll(translator); + + } catch (Exception e) { + LOGGER.debug("Error while Processing the translator" + e.getMessage()); + continue; + } + } + if (versionJsonFilesMap.isEmpty() || schemaVersions==null ) { + throw new ExceptionInInitializerError(); + } + } + + public void translateAll(Translator translator) { + /* + Use SchemaVersions from the Translator + */ + this.schemaVersions = translator.getSchemaVersions(); + List schemaVersionList = this.schemaVersions.getVersions(); + List jsonPayloads = null; + JsonIngestor ji = new JsonIngestor(); + Map> edgeRulesToIngest = new HashMap<>(); // Obtain a map of schema versions to a list of strings. One List per key + + // Add to the map the JSON file per version. + for (SchemaVersion version : schemaVersionList) { + LOGGER.debug("Version being processed" + version); + // If the flag is set to not use the local files, obtain the Json from the service. + try { + jsonPayloads = translator.getJsonPayload(version); // need to change this - need to receive the json files. + } catch (IOException e) { + LOGGER.info("Exception in retrieving the JSON Payload"+e.getMessage()); + } + if (jsonPayloads == null || jsonPayloads.isEmpty()) { + continue; + } + LOGGER.debug("Retrieved json from SchemaService"); + edgeRulesToIngest.put(version, jsonPayloads); + } + versionJsonFilesMap = ji.ingestContent(edgeRulesToIngest); - //-----ingest-----// - /** - * Instantiates the EdgeIngestor bean. - * - * @param translator - ConfigTranslator autowired in by Spring framework which - * contains the configuration information needed to ingest the desired files. - */ - @Autowired - public EdgeIngestor(ConfigTranslator translator, SchemaVersions schemaVersions) { - Map> filesToIngest = translator.getEdgeFiles(); - JsonIngestor ji = new JsonIngestor(); - this.schemaVersions = schemaVersions; - versionJsonFilesMap = ji.ingest(filesToIngest); this.cacheFilterStore = CacheBuilder.newBuilder() .maximumSize(2000) .build( @@ -107,27 +146,27 @@ public class EdgeIngestor { } } ); - } - - //-----methods for getting rule info-----// + } - /** - * Gets list of all edge rules defined in the latest version's schema - * - * @return Multimap of node names keys to the EdgeRules associated with those types - * where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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. - * @throws EdgeRuleNotFoundException if none found - */ - public Multimap getAllCurrentRules() throws EdgeRuleNotFoundException { - return getAllRules(schemaVersions.getDefaultVersion()); - } +// //-----methods for getting rule info-----// +// + /** + * Gets list of all edge rules defined in the latest version's schema + * + * @return Multimap of node names keys to the EdgeRules associated with those types + * where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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. + * @throws EdgeRuleNotFoundException if none found + */ + public Multimap getAllCurrentRules() throws EdgeRuleNotFoundException { + return getAllRules(schemaVersions.getDefaultVersion()); + } /** * Retrieves all the nodes that contain multiple edge labels @@ -137,81 +176,83 @@ public class EdgeIngestor { * @return a set containing a list of strings where each string is * concatenated by a pipe (|) character such as aNodeType|bNodeType */ - public Set getMultipleLabelKeys(){ + public Set getMultipleLabelKeys(){ - if(multipleLabelKeys == null){ + if(multipleLabelKeys == null){ multipleLabelKeys = new HashSet<>(); try { final Multimap edges = this.getAllCurrentRules(); if(edges == null || edges.isEmpty()){ - LOG.warn("Unable to find any edge rules for the latest version"); + LOGGER.warn("Unable to find any edge rules for the latest version"); + return multipleLabelKeys; } - edges.keySet().forEach((key) -> { + edges.keySet().forEach(key -> { Collection rules = edges.get(key); if(rules.size() > 1){ multipleLabelKeys.add(key); } }); } catch (EdgeRuleNotFoundException e) { - LOG.info("For the latest schema version, unable to find any edges with multiple keys"); + LOGGER.info("For the latest schema version, unable to find any edges with multiple keys"); } } return multipleLabelKeys; } - /** - * Gets list of all edge rules defined in the given version's schema - * - * @return Multimap of node names keys to the EdgeRules associated with those types - * where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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. - * @throws EdgeRuleNotFoundException if none found - */ - public Multimap getAllRules(SchemaVersion v) throws EdgeRuleNotFoundException { - Multimap found = extractRules(null, v); - if (found.isEmpty()) { - throw new EdgeRuleNotFoundException("No rules found for version " + v.toString() + "."); - } else { - return found; - } - } + /** + * Gets list of all edge rules defined in the given version's schema + * + * @return Multimap of node names keys to the EdgeRules associated with those types + * where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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. + * @throws EdgeRuleNotFoundException if none found + */ + public Multimap getAllRules(SchemaVersion v) throws EdgeRuleNotFoundException { + Multimap found = extractRules(null, v); + if (found.isEmpty()) { + throw new EdgeRuleNotFoundException("No rules found for version " + v.toString() + "."); + } else { + return found; + } + } - /** - * Finds the rules (if any) matching the given query criteria. If none, the returned Multimap - * will be empty. - * - * @param q - EdgeRuleQuery with filter criteria set - * - * @return Multimap of node names keys to the EdgeRules where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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. - * @throws EdgeRuleNotFoundException if none found - */ - public Multimap getRules(EdgeRuleQuery q) throws EdgeRuleNotFoundException { - Multimap found = null; - if(q.getVersion().isPresent()){ - found = extractRules(q.getFilter(), q.getVersion().get()); - } else { - found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion()); - } - if (found.isEmpty()) { - throw new EdgeRuleNotFoundException("No rules found for " + q.toString()); - } else { - Multimap copy = ArrayListMultimap.create(); - found.entries().stream().forEach((entry) -> { - EdgeRule rule = new EdgeRule(entry.getValue()); - if(!q.getFromType().equals(rule.getFrom())){ + /** + * Finds the rules (if any) matching the given query criteria. If none, the returned Multimap + * will be empty. + * + * @param q - EdgeRuleQuery with filter criteria set + * + * @return Multimap of node names keys to the EdgeRules where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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. + * @throws EdgeRuleNotFoundException if none found + */ + + public Multimap getRules(EdgeRuleQuery q) throws EdgeRuleNotFoundException { + Multimap found = null; + if(q.getVersion().isPresent()){ + found = extractRules(q.getFilter(), q.getVersion().get()); + } else { + found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion()); + } + if (found.isEmpty()) { + throw new EdgeRuleNotFoundException("No rules found for " + q.toString()); + } else { + Multimap copy = ArrayListMultimap.create(); + found.entries().stream().forEach((entry) -> { + EdgeRule rule = new EdgeRule(entry.getValue()); + if (!q.getFromType().equals(rule.getFrom())) { /* To maintain backwards compatibility with old EdgeRules API, * where the direction of the returned EdgeRule would be * flipped (if necessary) to match the directionality of @@ -220,296 +261,293 @@ public class EdgeIngestor { * if the user asked (A,B) the direction would be OUT, * if they asked (B,A), it would be IN to match. */ - rule.flipDirection(); + rule.flipDirection(); } - copy.put(entry.getKey(), rule); + copy.put(entry.getKey(), rule); }); - return copy; - } - } - - /** - * Gets the rule satisfying the given filter criteria. If there are more than one - * that match, return the default rule. If there is no clear default to return, or - * no rules match at all, error. - * - * @param q - EdgeRuleQuery with filter criteria set - * @return EdgeRule satisfying given criteria - * @throws EdgeRuleNotFoundException if none found that match - * @throws AmbiguousRuleChoiceException if multiple match but no way to choice one from them - * Specifically, if multiple node type pairs come back (ie bar|foo and asdf|foo, - * no way to know which is appropriate over the others), - * or if there is a mix of Tree and Cousin edges because again there is no way to - * know which is "defaulter" than the other. - * The default property only clarifies among multiple cousin edges of the same node pair, - * ex: which l-interface|logical-link rule to default to. - */ - public EdgeRule getRule(EdgeRuleQuery q) throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { - Multimap found = null; - if(q.getVersion().isPresent()){ - found = extractRules(q.getFilter(), q.getVersion().get()); - } else { - found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion()); - } - - if (found.isEmpty()) { - throw new EdgeRuleNotFoundException("No rule found for " + q.toString() + "."); - } - - EdgeRule rule = null; - if (found.keys().size() == 1) { //only one found, cool we're done - for (Entry e : found.entries()) { - rule = e.getValue(); - } - } else { - rule = getDefaultRule(found); - } + return copy; + } + } - if (rule == null) { //should never get here though - throw new EdgeRuleNotFoundException("No rule found for " + q.toString() + "."); - } else { - rule = new EdgeRule(rule); - if (!q.getFromType().equals(rule.getFrom())) { - /* To maintain backwards compatibility with old EdgeRules API, - * where the direction of the returned EdgeRule would be - * flipped (if necessary) to match the directionality of - * the input params. - * ie, If the rule is from=A,to=B,direction=OUT, - * if the user asked (A,B) the direction would be OUT, - * if they asked (B,A), it would be IN to match. - */ - rule.flipDirection(); - } - return rule; - } - } + /** + * Gets the rule satisfying the given filter criteria. If there are more than one + * that match, return the default rule. If there is no clear default to return, or + * no rules match at all, error. + * + * @param q - EdgeRuleQuery with filter criteria set + * @return EdgeRule satisfying given criteria + * @throws EdgeRuleNotFoundException if none found that match + * @throws AmbiguousRuleChoiceException if multiple match but no way to choice one from them + * Specifically, if multiple node type pairs come back (ie bar|foo and asdf|foo, + * no way to know which is appropriate over the others), + * or if there is a mix of Tree and Cousin edges because again there is no way to + * know which is "defaulter" than the other. + * The default property only clarifies among multiple cousin edges of the same node pair, + * ex: which l-interface|logical-link rule to default to. + */ + public EdgeRule getRule(EdgeRuleQuery q) throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + Multimap found = null; + if(q.getVersion().isPresent()){ + found = extractRules(q.getFilter(), q.getVersion().get()); + } else { + found = extractRules(q.getFilter(), schemaVersions.getDefaultVersion()); + } + if (found.isEmpty()) { + throw new EdgeRuleNotFoundException("No rule found for " + q.toString() + "."); + } - private EdgeRule getDefaultRule(Multimap found) throws AmbiguousRuleChoiceException { - if (found.keySet().size() > 1) { //ie multiple node pairs (a|c and b|c not just all a|c) case - StringBuilder sb = new StringBuilder(); - for (String k : found.keySet()) { - sb.append(k).append(" "); - } - throw new AmbiguousRuleChoiceException("No way to select single rule from these pairs: " + sb.toString() + "."); - } + EdgeRule rule = null; + if (found.keys().size() == 1) { //only one found, cool we're done + for (Entry e : found.entries()) { + rule = e.getValue(); + } + } else { + rule = getDefaultRule(found); + } - int defaultCount = 0; - EdgeRule defRule = null; - for (Entry e : found.entries()) { - EdgeRule rule = e.getValue(); - if (rule.isDefault()) { - defaultCount++; - defRule = rule; - } - } - if (defaultCount > 1) { - throw new AmbiguousRuleChoiceException("Multiple defaults found."); - } else if (defaultCount == 0) { - throw new AmbiguousRuleChoiceException("No default found."); - } + if (rule == null) { //should never get here though + throw new EdgeRuleNotFoundException("No rule found for " + q.toString() + "."); + } else { + rule = new EdgeRule(rule); + if (!q.getFromType().equals(rule.getFrom())) { + /* To maintain backwards compatibility with old EdgeRules API, + * where the direction of the returned EdgeRule would be + * flipped (if necessary) to match the directionality of + * the input params. + * ie, If the rule is from=A,to=B,direction=OUT, + * if the user asked (A,B) the direction would be OUT, + * if they asked (B,A), it would be IN to match. + */ + rule.flipDirection(); + } + return rule; + } + } - return defRule; - } + private EdgeRule getDefaultRule(Multimap found) throws AmbiguousRuleChoiceException { + if (found.keySet().size() > 1) { //ie multiple node pairs (a|c and b|c not just all a|c) case + StringBuilder sb = new StringBuilder(); + for (String k : found.keySet()) { + sb.append(k).append(" "); + } + throw new AmbiguousRuleChoiceException("No way to select single rule from these pairs: " + sb.toString() + "."); + } - /** - * Checks if there exists any rule that satisfies the given filter criteria. - * - * @param q - EdgeRuleQuery with filter criteria set - * @return boolean - */ - public boolean hasRule(EdgeRuleQuery q) { - if(q.getVersion().isPresent()){ - return !extractRules(q.getFilter(), q.getVersion().get()).isEmpty(); - } else { - return !extractRules(q.getFilter(), schemaVersions.getDefaultVersion()).isEmpty(); - } - } + int defaultCount = 0; + EdgeRule defRule = null; + for (Entry e : found.entries()) { + EdgeRule rule = e.getValue(); + if (rule.isDefault()) { + defaultCount++; + defRule = rule; + } + } + if (defaultCount > 1) { + throw new AmbiguousRuleChoiceException("Multiple defaults found."); + } else if (defaultCount == 0) { + throw new AmbiguousRuleChoiceException("No default found."); + } - /** - * Gets all cousin rules for the given node type in the latest schema version. - * - * @param nodeType - * @return Multimap of node names keys to the EdgeRules where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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 Multimap getCousinRules(String nodeType) { - return getCousinRules(nodeType, schemaVersions.getDefaultVersion()); //default to latest - } + return defRule; + } + /** + * Checks if there exists any rule that satisfies the given filter criteria. + * + * @param q - EdgeRuleQuery with filter criteria set + * @return boolean + */ + public boolean hasRule(EdgeRuleQuery q) { + if(q.getVersion().isPresent()){ + return !extractRules(q.getFilter(), q.getVersion().get()).isEmpty(); + } else { + return !extractRules(q.getFilter(), schemaVersions.getDefaultVersion()).isEmpty(); + } + } + /** + * Gets all cousin rules for the given node type in the latest schema version. + * + * @param nodeType + * @return Multimap of node names keys to the EdgeRules where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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 Multimap getCousinRules(String nodeType) { + return getCousinRules(nodeType, schemaVersions.getDefaultVersion()); //default to latest + } - public String[] retrieveCousinLabels(String nodeType){ + public String[] retrieveCousinLabels(String nodeType){ - Multimap cousinRules = getCousinRules(nodeType); - String[] cousinLabels = new String[cousinRules.size()]; + Multimap cousinRules = getCousinRules(nodeType); + String[] cousinLabels = new String[cousinRules.size()]; - return cousinRules.entries() - .stream() - .map((entry) -> entry.getValue().getLabel()) - .collect(Collectors.toList()) - .toArray(cousinLabels); + return cousinRules.entries() + .stream() + .map(entry -> entry.getValue().getLabel()) + .collect(Collectors.toList()) + .toArray(cousinLabels); } public String[] retrieveCachedCousinLabels(String nodeType) throws ExecutionException { - return cousinLabelStore.get(nodeType); + return cousinLabelStore.get(nodeType); } - /** - * Gets all cousin rules for the given node type in the given schema version. - * - * @param nodeType - * @param v - the version of the edge rules to query - * @return Multimap of node names keys to the EdgeRules where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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 Multimap getCousinRules(String nodeType, SchemaVersion v) { - return extractRules(new EdgeRuleQuery.Builder(nodeType).edgeType(EdgeType.COUSIN).build().getFilter(), v); - } + /** + * Gets all cousin rules for the given node type in the given schema version. + * + * @param nodeType + * @param v - the version of the edge rules to query + * @return Multimap of node names keys to the EdgeRules where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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 Multimap getCousinRules(String nodeType, SchemaVersion v) { + return extractRules(new EdgeRuleQuery.Builder(nodeType).edgeType(EdgeType.COUSIN).build().getFilter(), v); + } - /** - * Returns if the given node type has any cousin relationships in the current version. - * @param nodeType - * @return boolean - */ - public boolean hasCousinRule(String nodeType) { - return hasCousinRule(nodeType, schemaVersions.getDefaultVersion()); - } + /** + * Returns if the given node type has any cousin relationships in the current version. + * @param nodeType + * @return boolean + */ + public boolean hasCousinRule(String nodeType) { + return hasCousinRule(nodeType, schemaVersions.getDefaultVersion()); + } - /** - * Returns if the given node type has any cousin relationships in the given version. - * @param nodeType - * @return boolean - */ - public boolean hasCousinRule(String nodeType, SchemaVersion v) { - return !getCousinRules(nodeType, v).isEmpty(); - } + /** + * Returns if the given node type has any cousin relationships in the given version. + * @param nodeType + * @return boolean + */ + public boolean hasCousinRule(String nodeType, SchemaVersion v) { + return !getCousinRules(nodeType, v).isEmpty(); + } - /** - * Gets all rules where "{given nodeType} contains {otherType}" in the latest schema version. - * - * @param nodeType - node type that is the container in the returned relationships - * @return Multimap of node names keys to the EdgeRules where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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 Multimap getChildRules(String nodeType) { - return getChildRules(nodeType, schemaVersions.getDefaultVersion()); - } + /** + * Gets all rules where "{given nodeType} contains {otherType}" in the latest schema version. + * + * @param nodeType - node type that is the container in the returned relationships + * @return Multimap of node names keys to the EdgeRules where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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 Multimap getChildRules(String nodeType) { + return getChildRules(nodeType, schemaVersions.getDefaultVersion()); + } - /** - * Gets all rules where "{given nodeType} contains {otherType}" in the given schema version. - * - * @param nodeType - node type that is the container in the returned relationships - * @return Multimap of node names keys to the EdgeRules where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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 Multimap getChildRules(String nodeType, SchemaVersion v) { - Filter from = assembleFilterSegments(where(EdgeField.FROM.toString()).is(nodeType), getSameDirectionContainmentCriteria()); - Filter to = assembleFilterSegments(where(EdgeField.TO.toString()).is(nodeType), getOppositeDirectionContainmentCriteria()); - Filter total = from.or(to); + /** + * Gets all rules where "{given nodeType} contains {otherType}" in the given schema version. + * + * @param nodeType - node type that is the container in the returned relationships + * @return Multimap of node names keys to the EdgeRules where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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 Multimap getChildRules(String nodeType, SchemaVersion v) { + Filter from = assembleFilterSegments(where(EdgeField.FROM.toString()).is(nodeType), getSameDirectionContainmentCriteria()); + Filter to = assembleFilterSegments(where(EdgeField.TO.toString()).is(nodeType), getOppositeDirectionContainmentCriteria()); + Filter total = from.or(to); - return extractRules(total, v); - } + return extractRules(total, v); + } - /** - * Returns if the given node type has any child relationships (ie it contains another node type) in the current version. - * @param nodeType - * @return boolean - */ - public boolean hasChildRule(String nodeType) { - return hasChildRule(nodeType, schemaVersions.getDefaultVersion()); - } + /** + * Returns if the given node type has any child relationships (ie it contains another node type) in the current version. + * @param nodeType + * @return boolean + */ + public boolean hasChildRule(String nodeType) { + return hasChildRule(nodeType, schemaVersions.getDefaultVersion()); + } - /** - * Returns if the given node type has any child relationships (ie it contains another node type) in the given version. - * @param nodeType - * @return boolean - */ - public boolean hasChildRule(String nodeType, SchemaVersion v) { - return !getChildRules(nodeType, v).isEmpty(); - } + /** + * Returns if the given node type has any child relationships (ie it contains another node type) in the given version. + * @param nodeType + * @return boolean + */ + public boolean hasChildRule(String nodeType, SchemaVersion v) { + return !getChildRules(nodeType, v).isEmpty(); + } - /** - * Gets all rules where "{given nodeType} is contained by {otherType}" in the latest schema version. - * - * @param nodeType - node type that is the containee in the returned relationships - * @return Multimap of node names keys to the EdgeRules where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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 Multimap getParentRules(String nodeType) { - return getParentRules(nodeType, schemaVersions.getDefaultVersion()); - } + /** + * Gets all rules where "{given nodeType} is contained by {otherType}" in the latest schema version. + * + * @param nodeType - node type that is the containee in the returned relationships + * @return Multimap of node names keys to the EdgeRules where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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 Multimap getParentRules(String nodeType) { + return getParentRules(nodeType, schemaVersions.getDefaultVersion()); + } - /** - * Gets all rules where "{given nodeType} is contained by {otherType}" in the given schema version. - * - * @param nodeType - node type that is the containee in the returned relationships - * @return Multimap of node names keys to the EdgeRules where the key takes the form of - * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if - * no rules are found. - * 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 Multimap getParentRules(String nodeType, SchemaVersion v) { - Filter from = assembleFilterSegments(where(EdgeField.FROM.toString()).is(nodeType), getOppositeDirectionContainmentCriteria()); - Filter to = assembleFilterSegments(where(EdgeField.TO.toString()).is(nodeType), getSameDirectionContainmentCriteria()); - Filter total = from.or(to); + /** + * Gets all rules where "{given nodeType} is contained by {otherType}" in the given schema version. + * + * @param nodeType - node type that is the containee in the returned relationships + * @return Multimap of node names keys to the EdgeRules where the key takes the form of + * {alphabetically first nodetype}|{alphabetically second nodetype}. Map will be empty if + * no rules are found. + * 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 Multimap getParentRules(String nodeType, SchemaVersion v) { + Filter from = assembleFilterSegments(where(EdgeField.FROM.toString()).is(nodeType), getOppositeDirectionContainmentCriteria()); + Filter to = assembleFilterSegments(where(EdgeField.TO.toString()).is(nodeType), getSameDirectionContainmentCriteria()); + Filter total = from.or(to); - return extractRules(total, v); - } + return extractRules(total, v); + } - /** - * Returns if the given node type has any parent relationships (ie it is contained by another node type) in the current version. - * @param nodeType - * @return boolean - */ - public boolean hasParentRule(String nodeType) { - return hasParentRule(nodeType, schemaVersions.getDefaultVersion()); - } + /** + * Returns if the given node type has any parent relationships (ie it is contained by another node type) in the current version. + * @param nodeType + * @return boolean + */ + public boolean hasParentRule(String nodeType) { + return hasParentRule(nodeType, schemaVersions.getDefaultVersion()); + } - /** - * Returns if the given node type has any parent relationships (ie it is contained by another node type) in the given version. - * @param nodeType - * @return boolean - */ - public boolean hasParentRule(String nodeType, SchemaVersion v) { - return !getParentRules(nodeType, v).isEmpty(); - } + /** + * Returns if the given node type has any parent relationships (ie it is contained by another node type) in the given version. + * @param nodeType + * @return boolean + */ + public boolean hasParentRule(String nodeType, SchemaVersion v) { + return !getParentRules(nodeType, v).isEmpty(); + } /** * Applies the given filter to the DocumentContext(s) for the given version to extract @@ -527,17 +565,17 @@ public class EdgeIngestor { * 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 Multimap extractRules(Filter filter, SchemaVersion v) { - SchemaFilter schemaFilter = new SchemaFilter(filter, v); + private Multimap extractRules(Filter filter, SchemaVersion v) { + SchemaFilter schemaFilter = new SchemaFilter(filter, v); try { return cacheFilterStore.get(schemaFilter); } catch (ExecutionException e) { - LOG.info("Encountered exception during the retrieval of the rules"); + LOGGER.info("Encountered exception during the retrieval of the rules"); return ArrayListMultimap.create(); } } - public Multimap extractRules(SchemaFilter schemaFilter){ + public Multimap extractRules(SchemaFilter schemaFilter){ List> foundRules = new ArrayList<>(); List docs = versionJsonFilesMap.get(schemaFilter.getSchemaVersion()); if (docs != null) { 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 f914f6cb..f8f8caca 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 @@ -20,13 +20,8 @@ package org.onap.aai.edges; import org.apache.tinkerpop.gremlin.structure.Direction; -import org.onap.aai.edges.enums.AAIDirection; -import org.onap.aai.edges.enums.DirectionNotation; -import org.onap.aai.edges.enums.EdgeField; -import org.onap.aai.edges.enums.EdgeProperty; -import org.onap.aai.edges.enums.MultiplicityRule; +import org.onap.aai.edges.enums.*; -import java.util.Collections; import java.util.EnumMap; import java.util.HashMap; import java.util.Map; @@ -45,52 +40,52 @@ public class EdgeRule { private String description; private boolean isPrivateEdge = false; - /** + /** * Instantiates a new edge rule. - * + * * @param fieldVals - Map where first string is - * an EdgeField value and second string is the + * an EdgeField value and second string is the * value of that field */ public EdgeRule(Map fieldVals) { edgeFields = new EnumMap<>(EdgeProperty.class); - + from = fieldVals.get(EdgeField.FROM.toString()); to = fieldVals.get(EdgeField.TO.toString()); label = fieldVals.get(EdgeField.LABEL.toString()); direction = Direction.valueOf(fieldVals.get(EdgeField.DIRECTION.toString())); multiplicityRule = MultiplicityRule.getValue(fieldVals.get(EdgeField.MULTIPLICITY.toString())); isPrivateEdge = Boolean.valueOf(fieldVals.getOrDefault(EdgeField.PRIVATE.toString(), "false")); - for (EdgeProperty prop : EdgeProperty.values()) { + + for (EdgeProperty prop : EdgeProperty.values()) { String rawVal = fieldVals.get(prop.toString()); edgeFields.put(prop, convertNotation(direction, rawVal)); } - + isDefaultEdge = Boolean.valueOf(fieldVals.get(EdgeField.DEFAULT.toString())); - - description = fieldVals.get(EdgeField.DESCRIPTION.toString()); + description = fieldVals.get(EdgeField.DESCRIPTION.toString()); if (description == null) { //bc description is optional and not in v12 and earlier description = ""; } } - // Copy Constructor - public EdgeRule(EdgeRule edgeRule){ - this.from = edgeRule.from; - this.to = edgeRule.to; - this.label = edgeRule.label; - this.direction = Direction.valueOf(edgeRule.direction.toString()); - this.multiplicityRule = MultiplicityRule.valueOf(edgeRule.multiplicityRule.toString()); + // Copy Constructor + public EdgeRule(EdgeRule edgeRule){ + this.from = edgeRule.from; + this.to = edgeRule.to; + this.label = edgeRule.label; + this.direction = Direction.valueOf(edgeRule.direction.toString()); + this.multiplicityRule = MultiplicityRule.valueOf(edgeRule.multiplicityRule.toString()); this.edgeFields = new HashMap<>(edgeRule.edgeFields); - this.isDefaultEdge = edgeRule.isDefaultEdge; - this.description = edgeRule.description; - this.isPrivateEdge = edgeRule.isPrivateEdge; + this.isDefaultEdge = edgeRule.isDefaultEdge; + this.description = edgeRule.description; + this.isPrivateEdge = edgeRule.isPrivateEdge; } /** * Converts whatever string was in the json for an edge property value into * the appropriate AAIDirection - * + * * @param Direction dir - the edge direction * @param String rawVal - property value from the json, may be * IN, OUT, BOTH, NONE, ${direction}, or !${direction} @@ -107,7 +102,7 @@ public class EdgeRule { } else if (AAIDirection.IN.toString().equalsIgnoreCase(rawVal)) { return AAIDirection.IN; } - + DirectionNotation rawDN = DirectionNotation.getValue(rawVal); if (DirectionNotation.DIRECTION.equals(rawDN)) { return AAIDirection.getValue(dir); @@ -115,7 +110,7 @@ public class EdgeRule { return AAIDirection.getValue(dir.opposite()); } } - + /** * Gets the name of the node type in the "from" field * @return String nodetype @@ -140,7 +135,7 @@ public class EdgeRule { public String getLabel() { return label; } - + /** * Gets the multiplicity rule. * @@ -149,7 +144,7 @@ public class EdgeRule { public MultiplicityRule getMultiplicityRule() { return multiplicityRule; } - + /** * Gets the edge direction * @@ -158,7 +153,7 @@ public class EdgeRule { public Direction getDirection() { return direction; } - + /** * Gets the value of contains-other-v * @@ -167,7 +162,7 @@ public class EdgeRule { public String getContains() { return edgeFields.get(EdgeProperty.CONTAINS).toString(); } - + /** * Gets the value of delete-other-v * @@ -176,10 +171,10 @@ public class EdgeRule { public String getDeleteOtherV() { return edgeFields.get(EdgeProperty.DELETE_OTHER_V).toString(); } - + /** * Gets the value of the prevent-delete property - * + * * @return String prevent-delete property value */ public String getPreventDelete() { @@ -188,13 +183,13 @@ public class EdgeRule { /** * Returns if this rule is a default or not - * + * * @return boolean */ public boolean isDefault() { return isDefaultEdge; } - + /** * Gets the description on the edge rule (if there is one) * @return String description @@ -202,7 +197,7 @@ public class EdgeRule { public String getDescription() { return this.description; } - + /** * Flips the direction value * IN -> OUT 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 58c8c546..d6fec83d 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 @@ -170,7 +170,7 @@ public class EdgeRuleQuery { List criteriaFromTo = new ArrayList<>(); //Special logic to allow for A to B case only if(("FromOnly").equals(builder.getSecondNodeType())) { - criteriaFromTo.add(buildToFromPart(builder.getFirstNodeType(), null)); + criteriaFromTo.add(buildToFromPart(builder.getFirstNodeType(), null)); } else { criteriaFromTo.add(buildToFromPart(builder.getFirstNodeType(), builder.getSecondNodeType())); } @@ -245,16 +245,16 @@ public class EdgeRuleQuery { } private Predicate addDirection(AAIDirection direction) { - if (direction == AAIDirection.OUT) { - return where(EdgeField.DIRECTION.toString()).in(AAIDirection.OUT.toString(), AAIDirection.BOTH.toString()); - } else if (direction == AAIDirection.IN) { - return where(EdgeField.DIRECTION.toString()).in(AAIDirection.IN.toString(), AAIDirection.BOTH.toString()); - } else if (direction == AAIDirection.BOTH) { - return where(EdgeField.DIRECTION.toString()).is(AAIDirection.BOTH.toString()); - } else if (direction == AAIDirection.NONE) { - return where(EdgeField.DIRECTION.toString()).is(AAIDirection.NONE.toString()); - } + if (direction == AAIDirection.OUT) { + return where(EdgeField.DIRECTION.toString()).in(AAIDirection.OUT.toString(), AAIDirection.BOTH.toString()); + } else if (direction == AAIDirection.IN) { + return where(EdgeField.DIRECTION.toString()).in(AAIDirection.IN.toString(), AAIDirection.BOTH.toString()); + } else if (direction == AAIDirection.BOTH) { + return where(EdgeField.DIRECTION.toString()).is(AAIDirection.BOTH.toString()); + } else if (direction == AAIDirection.NONE) { return where(EdgeField.DIRECTION.toString()).is(AAIDirection.NONE.toString()); + } + return where(EdgeField.DIRECTION.toString()).is(AAIDirection.NONE.toString()); } /** @@ -345,4 +345,3 @@ public class EdgeRuleQuery { } - 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 index 16562756..713103a0 100644 --- 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 @@ -1,4 +1,4 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -20,64 +20,85 @@ package org.onap.aai.edges; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.jayway.jsonpath.DocumentContext; +import com.jayway.jsonpath.JsonPath; +import org.onap.aai.setup.SchemaVersion; + import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import java.util.Map.Entry; -import org.onap.aai.setup.SchemaVersion; - -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 filesToIngest - map of filenames to ingest - * per Version - * @return Map> - map of DocumentContexts per Version - */ - public Map> ingest(Map> filesToIngest) { - Map> result = new HashMap<>(); - - for (Entry> verFiles : filesToIngest.entrySet()) { - SchemaVersion 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(); - } + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(JsonIngestor.class); + + /** + * Reads in given json files to queryable DocumentContexts. + * + * @param filesToIngest - map of filenames to ingest + * per Version + * @return Map> - map of DocumentContexts per Version + */ + public Map> ingest(Map> filesToIngest) { + Map> result = new HashMap<>(); + + for (Entry> verFiles : filesToIngest.entrySet()) { + SchemaVersion 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; + } + + public Map> ingestContent(Map> filesToIngest) { + Map> result = new HashMap<>(); + + for (Entry> verFiles : filesToIngest.entrySet()) { + SchemaVersion v = verFiles.getKey(); + List files = verFiles.getValue(); + + List docs = new ArrayList<>(); + for (String jsonPayload : files) { + docs.add(JsonPath.parse(jsonPayload)); + } + 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 + */ + public 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) { + LOGGER.warn("Exception in file"+e.getMessage()); + throw new ExceptionInInitializerError(e); + } + return sb.toString(); + } } 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 3ddced9a..da79d9c7 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,4 +1,4 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -25,7 +25,7 @@ public class AmbiguousRuleChoiceException extends Exception { super(msg); } - public AmbiguousRuleChoiceException(Throwable throwable){ - super(throwable); + public AmbiguousRuleChoiceException(Throwable throwable){ + super(throwable); } } 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 de022bc5..f9b9b643 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,4 +1,4 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -25,7 +25,7 @@ public class EdgeRuleNotFoundException extends Exception { super(msg); } - public EdgeRuleNotFoundException(Throwable throwable){ - super(throwable); + public EdgeRuleNotFoundException(Throwable throwable){ + super(throwable); } } 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 95232386..1945a1ef 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 @@ -2,13 +2,15 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-18 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. * ================================================================================ * 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, @@ -20,210 +22,256 @@ 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.*; -import java.io.ByteArrayInputStream; -import java.nio.charset.StandardCharsets; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -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 com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import com.google.common.base.CaseFormat; import org.eclipse.persistence.jaxb.JAXBContextProperties; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContextFactory; - import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.Translator; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import com.google.common.base.CaseFormat; +import javax.annotation.PostConstruct; +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 java.io.*; +import java.nio.charset.StandardCharsets; +import java.util.*; +import java.util.regex.Matcher; +import java.util.regex.Pattern; @Component -/** - * NodeIngestor - ingests A&AI OXM files per given config, serves DynamicJAXBContext per version +/* + NodeIngestor - ingests A&AI OXM files per given config, serves DynamicJAXBContext per version */ +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound=true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound=true) public class NodeIngestor { + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(NodeIngestor.class); + private static final Pattern classNamePattern = Pattern.compile("\\.(v\\d+)\\."); + Map> filesToIngest; + private Map versionContextMap = new TreeMap<>(); + private Map> typesPerVersion = new TreeMap<>(); + private Map schemaPerVersion = new TreeMap<>(); + private String localSchema; + private SchemaVersions schemaVersions; + private Set translators; + + //TODO : See if you can get rid of InputStream resets + /** + * Instantiates the NodeIngestor bean. + * + * @param - ConfigTranslator autowired in by Spring framework which + * contains the configuration information needed to ingest the desired files. + */ - private Map versionContextMap = new TreeMap<>(); - private Map> typesPerVersion = new TreeMap<>(); - private Map schemaPerVersion = new TreeMap<>(); - private static final Pattern classNamePattern = Pattern.compile("\\.(v\\d+)\\."); - - private ConfigTranslator translator; - - - @Autowired - /** - * Instantiates the NodeIngestor bean. - * - * @param translator - ConfigTranslator autowired in by Spring framework which - * contains the configuration information needed to ingest the desired files. - */ - public NodeIngestor(ConfigTranslator translator) { - this.translator = translator; - Map> filesToIngest = translator.getNodeFiles(); - - try { - for (Entry> verFiles : filesToIngest.entrySet()) { - SchemaVersion v = verFiles.getKey(); - List files = verFiles.getValue(); - final DynamicJAXBContext ctx = ingest(files); - versionContextMap.put(v, ctx); - typesPerVersion.put(v, getAllNodeTypes(files)); - schemaPerVersion.put(v, createCombinedSchema(files, v)); - } - } catch (JAXBException | ParserConfigurationException | SAXException | IOException e) { - throw new ExceptionInInitializerError(e); - } - } - - /** - * Ingests the given OXM files into DynamicJAXBContext - * - * @param files - List of full filenames (ie including the path) to be ingested - * - * @return DynamicJAXBContext including schema information from all given files - * - * @throws FileNotFoundException if an OXM file can't be found - * @throws JAXBException if there's an error creating the DynamicJAXBContext - */ - private DynamicJAXBContext ingest(List files) throws FileNotFoundException, JAXBException { - List streams = new ArrayList<>(); - - for (String name : files) { - streams.add(new FileInputStream(new File(name))); - } - - Map properties = new HashMap<>(); - 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(); - - ArrayList javaTypes = new ArrayList(); - 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(); - javaTypes.add(list.item(i)); - types.add(CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, type)); - } - } - - return types; - } - - private Document createCombinedSchema(List files,SchemaVersion v) throws ParserConfigurationException, SAXException, IOException { - final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); - docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); - final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); - DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder(); - Document combinedDoc = masterDocBuilder.parse(getShell(v)); - NodeList masterList = combinedDoc.getElementsByTagName("java-types"); - Node javaTypesContainer = masterList.getLength() == 0 ? combinedDoc.getDocumentElement() : masterList.item(0); - 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++) { - Node copy = combinedDoc.importNode(list.item(i),true); - javaTypesContainer.appendChild(copy); - } - } - return combinedDoc; - } - - /** - * Gets the DynamicJAXBContext for the given version - * - * @param v - * @return DynamicJAXBContext - */ - public DynamicJAXBContext getContextForVersion(SchemaVersion v) { - return versionContextMap.get(v); - } - - /** - * Determines if the given version contains the given node type - * - * @param nodeType - node type to check, must be in lower hyphen form (ie "type-name") - * @param v - schema version to check against - * @return - */ - public boolean hasNodeType(String nodeType, SchemaVersion v) { - return typesPerVersion.get(v).contains(nodeType); - } - - public Set getObjectsInVersion(SchemaVersion v){ - return typesPerVersion.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 Document getSchema(SchemaVersion v) { - return schemaPerVersion.get(v); - } - - private InputStream getShell(SchemaVersion v) { - String source = "\n" + - "\n" + - " \n" + - " \n" + - " \n" + - " \n" + - " \\n" + - ""; -// source.rep.replace("v11", v.toString()); - return new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)); - } - - - public SchemaVersion getVersionFromClassName (String classname) { - Matcher m = classNamePattern.matcher(classname); - String version = null; - if (m.find()) { - version = m.group(1); - return new SchemaVersion(version); - } else { - return translator.getSchemaVersions().getDefaultVersion(); - } - } -} + @Autowired + public NodeIngestor(Set translatorSet) { + LOGGER.debug("Local Schema files will be fetched"); + this.translators = translatorSet; + } + @PostConstruct + public void initialize() { + + for (Translator translator : translators) { + try { + LOGGER.debug("Processing the translator"); + translateAll(translator); + + } catch (Exception e) { + LOGGER.info("Error while Processing the translator" + e.getMessage()); + continue; + } + } + if (versionContextMap.isEmpty() || schemaPerVersion.isEmpty() || typesPerVersion.isEmpty()) { + throw new ExceptionInInitializerError(); + } + } + + private void translateAll(Translator translator) throws ExceptionInInitializerError { + if (translator instanceof ConfigTranslator) { + this.localSchema = "true"; + } + + Boolean retrieveLocalSchema = Boolean.parseBoolean(this.localSchema); + /* + * Set this to default schemaVersion + */ + this.schemaVersions = translator.getSchemaVersions(); + List schemaVersionList = translator.getSchemaVersions().getVersions(); + + try { + for (SchemaVersion version : schemaVersionList) { + LOGGER.debug("Version being processed" + version); + List inputStreams = retrieveOXM(version, translator); + LOGGER.debug("Retrieved OXMs from SchemaService"); + /* + IOUtils.copy and copy the inputstream + */ + if (inputStreams.isEmpty()) { + continue; + } + + final DynamicJAXBContext ctx = ingest(inputStreams); + versionContextMap.put(version, ctx); + typesPerVersion.put(version, getAllNodeTypes(inputStreams)); + schemaPerVersion.put(version, createCombinedSchema(inputStreams, version, retrieveLocalSchema)); + } + } catch (JAXBException | ParserConfigurationException | SAXException | IOException e) { + throw new ExceptionInInitializerError(e); + } + } + + /** + * Ingests the given OXM files into DynamicJAXBContext + * + * @param inputStreams - inputStrean of oxms from SchemaService to be ingested + * + * @return DynamicJAXBContext including schema information from all given files + * + * @throws JAXBException if there's an error creating the DynamicJAXBContext + */ + private DynamicJAXBContext ingest(List inputStreams) throws JAXBException { + Map properties = new HashMap<>(); + properties.put(JAXBContextProperties.OXM_METADATA_SOURCE, inputStreams); + LOGGER.debug("Ingested the InputStream"); + return DynamicJAXBContextFactory.createContextFromOXM(this.getClass().getClassLoader(), properties); + } + + private Set getAllNodeTypes(List inputStreams) throws ParserConfigurationException, SAXException, IOException { + //Reset the InputStream to reset the offset to inital position + Set types = new HashSet<>(); + final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + + for (InputStream inputStream : inputStreams) { + //TODO Change this + inputStream.reset(); + 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)); + } + } + + LOGGER.debug("Types size" + types.size()); + return types; + } + + private Document createCombinedSchema(List inputStreams, SchemaVersion version, boolean localSchema) throws ParserConfigurationException, SAXException, IOException { + if (localSchema) { + return createCombinedSchema(inputStreams, version); + } + + InputStream inputStream = inputStreams.get(0); + inputStream.reset(); + final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder(); + return masterDocBuilder.parse(inputStream); + } + + private Document createCombinedSchema(List inputStreams, SchemaVersion version) throws ParserConfigurationException, SAXException, IOException { + final DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); + docFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + final DocumentBuilder docBuilder = docFactory.newDocumentBuilder(); + DocumentBuilder masterDocBuilder = docFactory.newDocumentBuilder(); + Document combinedDoc = masterDocBuilder.parse(getShell(version)); + NodeList masterList = combinedDoc.getElementsByTagName("java-types"); + Node javaTypesContainer = masterList.getLength() == 0 ? combinedDoc.getDocumentElement() : masterList.item(0); + + for (InputStream inputStream : inputStreams) { + inputStream.reset(); + final Document doc = docBuilder.parse(inputStream); + final NodeList list = doc.getElementsByTagName("java-type"); + for (int i = 0; i < list.getLength(); i++) { + Node copy = combinedDoc.importNode(list.item(i), true); + javaTypesContainer.appendChild(copy); + } + } + return combinedDoc; + } + + /** + * Gets the DynamicJAXBContext for the given version + * + * @param v - schema version to retrieve the context + * @return DynamicJAXBContext + */ + public DynamicJAXBContext getContextForVersion(SchemaVersion v) { + return versionContextMap.get(v); + } + + /** + * Determines if the given version contains the given node type + * + * @param nodeType - node type to check, must be in lower hyphen form (ie "type-name") + * @param v - schema version to check against + * @return boolean + */ + public boolean hasNodeType(String nodeType, SchemaVersion v) { + return typesPerVersion.get(v).contains(nodeType); + } + + public Set getObjectsInVersion(SchemaVersion v) { + return typesPerVersion.get(v); + } + + /** + * Determines if the given version contains the given node type + * + * @param v - Schemaversion to retrieve the schema + * @return Document + */ + public Document getSchema(SchemaVersion v) { + return schemaPerVersion.get(v); + } + + + public SchemaVersion getVersionFromClassName(String classname) { + Matcher m = classNamePattern.matcher(classname); + if (m.find()) { + String version = m.group(1); + return new SchemaVersion(version); + } else { + return this.schemaVersions.getDefaultVersion(); + } + } + + private List retrieveOXM(SchemaVersion version, Translator translator) throws IOException { + /* + Call Schema MS to get versions using RestTemplate or Local + */ + return translator.getVersionNodeStream(version); + + } + + private InputStream getShell(SchemaVersion v) { + String source = "\n" + + "\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + ""; + return new ByteArrayInputStream(source.getBytes(StandardCharsets.UTF_8)); + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceNoAuthClient.java b/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceNoAuthClient.java new file mode 100644 index 00000000..07f522b4 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceNoAuthClient.java @@ -0,0 +1,75 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2018-19 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========================================================= + */ +package org.onap.aai.restclient; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.util.MultiValueMap; + +import javax.annotation.PostConstruct; +import java.util.Collections; +import java.util.Map; +import java.util.UUID; + +@Component(value="no-auth-service-rest-client") +public class SchemaServiceNoAuthClient extends NoAuthRestClient{ + + private static EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceNoAuthClient.class); + + @Value("${schema.service.base.url}") + private String baseUrl; + + @PostConstruct + public void init () throws Exception { + super.init(); + } + + @Override + public String getBaseUrl() { + return baseUrl; + } + + @Override + public MultiValueMap getHeaders(Map headers) { + HttpHeaders httpHeaders = new HttpHeaders(); + + String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString()); + String defaultContentType = headers.getOrDefault(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString()); + + if(headers.isEmpty()){ + httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType(defaultAccept))); + httpHeaders.setContentType(MediaType.parseMediaType(defaultContentType)); + } + + httpHeaders.add("X-FromAppId", appName); + httpHeaders.add("X-TransactionId", UUID.randomUUID().toString()); + headers.forEach(httpHeaders::add); + return httpHeaders; + } + + @Override + public EELFLogger getLogger() { + return logger; + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceOneWayClient.java b/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceOneWayClient.java new file mode 100644 index 00000000..3aa3b1da --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceOneWayClient.java @@ -0,0 +1,87 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2018-19 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========================================================= + */ +package org.onap.aai.restclient; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.util.MultiValueMap; + +import javax.annotation.PostConstruct; +import java.util.Collections; +import java.util.Map; +import java.util.UUID; + +@Component(value="schema-service-one-way-rest-client") +public class SchemaServiceOneWayClient extends OneWaySSLRestClient{ + + private static EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceOneWayClient.class); + + @Value("${schema.service.base.url}") + private String baseUrl; + + @Value("${schema.service.ssl.trust-store}") + private String truststorePath; + + @Value("${schema.service.ssl.trust-store-password}") + private String truststorePassword; + + @Override + public String getBaseUrl() { + return baseUrl; + } + + @Override + protected String getTruststorePath() { + return truststorePath; + } + + @Override + protected char[] getTruststorePassword() { + return truststorePassword.toCharArray(); + } + + @Override + public MultiValueMap getHeaders(Map headers) { + HttpHeaders httpHeaders = new HttpHeaders(); + + String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString()); + String defaultContentType = headers.getOrDefault(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString()); + + if(headers.isEmpty()){ + httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType(defaultAccept))); + httpHeaders.setContentType(MediaType.parseMediaType(defaultContentType)); + } + + httpHeaders.add("X-FromAppId", appName); + httpHeaders.add("X-TransactionId", UUID.randomUUID().toString()); + httpHeaders.add("X-TransactionId", appName); + headers.forEach(httpHeaders::add); + return httpHeaders; + } + + @Override + public EELFLogger getLogger() { + return logger; + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceRestClient.java b/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceRestClient.java new file mode 100644 index 00000000..db1a50b5 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/restclient/SchemaServiceRestClient.java @@ -0,0 +1,102 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Modifications Copyright © 2018 IBM. + * ================================================================================ + * 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========================================================= + */ +package org.onap.aai.restclient; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.stereotype.Component; +import org.springframework.util.MultiValueMap; + +import java.util.Collections; +import java.util.Map; +import java.util.UUID; + +@Component(value = "schema-service-rest-client") +public class SchemaServiceRestClient extends TwoWaySSLRestClient { + private static EELFLogger logger = EELFManager.getInstance().getLogger(SchemaServiceRestClient.class); + + @Value("${schema.service.base.url}") + private String baseUrl; + + @Value("${schema.service.ssl.key-store}") + private String keystorePath; + + @Value("${schema.service.ssl.trust-store}") + private String truststorePath; + + @Value("${schema.service.ssl.key-store-password}") + private String keystorePassword; + + @Value("${schema.service.ssl.trust-store-password}") + private String truststorePassword; + + @Override + public String getBaseUrl() { + return baseUrl; + } + + @Override + protected String getKeystorePath() { + return keystorePath; + } + + @Override + protected String getTruststorePath() { + return truststorePath; + } + + @Override + protected char[] getKeystorePassword() { + return keystorePassword.toCharArray(); + } + + @Override + protected char[] getTruststorePassword() { + return truststorePassword.toCharArray(); + } + + @Override + public MultiValueMap getHeaders(Map headers) { + HttpHeaders httpHeaders = new HttpHeaders(); + + String defaultAccept = headers.getOrDefault(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON.toString()); + String defaultContentType = headers.getOrDefault(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON.toString()); + + if (headers.isEmpty()) { + httpHeaders.setAccept(Collections.singletonList(MediaType.parseMediaType(defaultAccept))); + httpHeaders.setContentType(MediaType.parseMediaType(defaultContentType)); + } + + httpHeaders.add("X-FromAppId", appName); + httpHeaders.add("X-TransactionId", UUID.randomUUID().toString()); + headers.forEach(httpHeaders::add); + return httpHeaders; + } + + @Override + public EELFLogger getLogger() { + return logger; + } +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java index 2cb0c99b..899a520d 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/AAIConfigTranslator.java @@ -20,7 +20,10 @@ package org.onap.aai.setup; import java.io.File; -import java.util.*; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; import java.util.function.Supplier; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -43,7 +46,7 @@ public class AAIConfigTranslator extends ConfigTranslator { */ @Override public Map> getNodeFiles() { - + Map> files = new TreeMap<>(); for (SchemaVersion v : schemaVersions.getVersions()) { List container = getVersionNodeFiles(v); @@ -55,7 +58,6 @@ public class AAIConfigTranslator extends ConfigTranslator { private List getVersionNodeFiles(SchemaVersion v) { - return getVersionFiles( bean.getNodeDirectory(), v, @@ -99,7 +101,6 @@ public class AAIConfigTranslator extends ConfigTranslator { List container; final String directoryName = startDirectory + FILESEP + schemaVersion.toString() + FILESEP; - container = Arrays.stream(new File(directoryName).listFiles()) .map(File::getName) .filter(name -> inclusionPattern.get().anyMatch(name::matches)) 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 ccbe7065..4e6a6bdf 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 @@ -20,25 +20,35 @@ package org.onap.aai.setup; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.apache.commons.io.IOUtils; +import org.onap.aai.edges.JsonIngestor; +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.*; +import java.nio.charset.Charset; +import java.util.ArrayList; import java.util.List; import java.util.Map; -import org.springframework.beans.factory.annotation.Autowired; - /** * Converts the contents of the schema config file * (which lists which schema files to be loaded) to * the format the Ingestors can work with. * */ -public abstract class ConfigTranslator { +public abstract class ConfigTranslator extends Translator{ + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(ConfigTranslator.class); + protected SchemaLocationsBean bean; - protected SchemaVersions schemaVersions; + @Autowired public ConfigTranslator(SchemaLocationsBean schemaLocationbean, SchemaVersions schemaVersions) { + super(schemaVersions); this.bean = schemaLocationbean; - this.schemaVersions = schemaVersions; + } /** @@ -49,6 +59,49 @@ public abstract class ConfigTranslator { * ingested for that version */ public abstract Map> getNodeFiles(); + + public List getVersionNodeStream(SchemaVersion version) { + + Map> filesToIngest = getNodeFiles(); + List streams = new ArrayList<>(); + + if(!filesToIngest.containsKey(version)) { + return streams; + } + List versionFiles = filesToIngest.get(version); + + for (String name : versionFiles) { + try { + InputStream stream = new FileInputStream(new File(name)); + String value = IOUtils.toString(stream, Charset.defaultCharset()); + InputStream bis =(IOUtils.toInputStream(value, Charset.defaultCharset())); + streams.add(bis); + } catch (FileNotFoundException e) { + //TODO This may have to be cascaded + LOGGER.warn("File Not Found"+e.getMessage()); + } catch (IOException e) { + LOGGER.warn("IOException while reading files"+e.getMessage()); + } + } + return streams; + } + + @Override + public List getJsonPayload(SchemaVersion version) { + Map> filesToIngest = getEdgeFiles(); + List jsonPayloads = new ArrayList<>(); + if(!filesToIngest.containsKey(version)) { + return jsonPayloads; + } + List versionFiles = filesToIngest.get(version); + JsonIngestor ji = new JsonIngestor(); + for (String rulesFilename : versionFiles) { + jsonPayloads.add(ji.readInJsonFile(rulesFilename)); + + } + + return jsonPayloads; + } /** * Translates the contents of the schema config file @@ -59,7 +112,4 @@ public abstract class ConfigTranslator { */ public abstract Map> getEdgeFiles(); - public SchemaVersions getSchemaVersions(){ - return schemaVersions; - } } 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 e3cd7236..9e740a8c 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 @@ -26,7 +26,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.PropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; -import java.util.Collections; import java.util.List; @Configuration diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java new file mode 100644 index 00000000..21082fa1 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceTranslator.java @@ -0,0 +1,105 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 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========================================================= + */ +package org.onap.aai.setup; + +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; +import org.onap.aai.restclient.RestClient; +import org.onap.aai.restclient.RestClientFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.core.io.Resource; +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; + +import javax.ws.rs.HttpMethod; +import java.io.*; +import java.util.*; + +/** + * AAIConfigTranslator is responsible for looking at the schema files and + * edge files based on the available versions Also has the ability to exclude + * them based on the node.exclusion.pattern + */ +public class SchemaServiceTranslator extends Translator { + + private static final EELFLogger LOGGER = EELFManager.getInstance().getLogger(SchemaServiceTranslator.class); + + private static final String SchemaServiceClientType = "schema.service"; + + @Value("${schema.service.nodes.endpoint}") + private String nodeSchemaUri; + + @Value("${schema.service.edges.endpoint}") + private String edgeSchemaUri; + + @Autowired + private RestClientFactory restClientFactory; + + public SchemaServiceTranslator(SchemaVersions schemaVersions) { + super(schemaVersions); + } + + /* + * (non-Javadoc) + * + * @see org.onap.aai.setup.ConfigTranslator#getNodeFiles() + */ + + @Override + public List getVersionNodeStream(SchemaVersion version) throws IOException { + + List inputStreams = new ArrayList<>(); + String content = ""; + String uri = nodeSchemaUri + version.toString(); + Map headersMap = new HashMap<>(); + + headersMap.put(HttpHeaders.ACCEPT, MediaType.APPLICATION_XML.toString()); + headersMap.put(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_XML.toString()); + RestClient restClient = restClientFactory.getRestClient(SchemaServiceClientType); + ResponseEntity schemaResponse = restClient.getGetResource(content, uri, + headersMap); + LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode()); + inputStreams.add(schemaResponse.getBody().getInputStream()); + return inputStreams; + } + + @Override + public List getJsonPayload(SchemaVersion version) throws IOException { + /* + * Call Schema MS to get versions using RestTemplate + */ + List inputStreams = new ArrayList<>(); + String content = ""; + String uri = edgeSchemaUri + version.toString(); + Map headersMap = new HashMap<>(); + + RestClient restClient = restClientFactory.getRestClient(SchemaServiceClientType); + + ResponseEntity schemaResponse = restClient.getGetRequest(content, uri, + headersMap); + LOGGER.debug("SchemaResponse Status code" + schemaResponse.getStatusCode()); + inputStreams.add(schemaResponse.getBody()); + return inputStreams; + + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java new file mode 100644 index 00000000..6594f232 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaServiceVersions.java @@ -0,0 +1,48 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-18 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========================================================= + */ +package org.onap.aai.setup; + +import javax.annotation.PostConstruct; +import java.util.List; +import java.util.stream.Collectors; + +public class SchemaServiceVersions extends SchemaVersions { + private List versions; + private String edgeVersion; + private String defaultVersion; + private String depthVersion; + private String appRootVersion; + private String relatedLinkVersion; + private String namespaceChangeVersion; + + + @PostConstruct + public void initializeFromSchemaService() { + versionsValue = versions.stream().map(SchemaVersion::new).collect(Collectors.toList()); + edgeLabelVersionValue = new SchemaVersion(edgeVersion); + defaultVersionValue = new SchemaVersion(defaultVersion); + depthVersionValue = new SchemaVersion(depthVersion); + appRootVersionValue = new SchemaVersion(appRootVersion); + relatedLinkVersionValue = new SchemaVersion(relatedLinkVersion); + namespaceChangeVersionValue = new SchemaVersion(namespaceChangeVersion); + this.validate(); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java index c744c5a3..a1a40e69 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersion.java @@ -21,7 +21,6 @@ package org.onap.aai.setup; import org.onap.aai.validation.AAISchemaValidationException; -import java.util.Comparator; import java.util.regex.Pattern; public class SchemaVersion implements Comparable { @@ -31,7 +30,6 @@ public class SchemaVersion implements Comparable { private final String value; public SchemaVersion(String value){ - if(!VERSION_PATTERN.matcher(value).matches()){ throw new AAISchemaValidationException("Invalid Schema Version " + value + ", value doesn't match the expected regex: " + VERSION_PATTERN); } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java index 2205b14b..028ebdeb 100644 --- a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersions.java @@ -2,13 +2,13 @@ * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. + * Copyright © 2017-18 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, @@ -25,7 +25,6 @@ import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Component; import javax.annotation.PostConstruct; -import javax.xml.validation.Schema; import java.util.List; import java.util.stream.Collectors; @@ -36,124 +35,99 @@ public class SchemaVersions { @Value("#{'${schema.version.list}'.split(',')}") private List apiVersions; - @Value("${schema.version.api.default}") private String defaultApiVersion; - @Value("${schema.version.edge.label.start}") private String edgeLabelStartVersion; - @Value("${schema.version.depth.start}") private String depthStartVersion; - @Value("${schema.version.app.root.start}") private String appRootStartVersion; - @Value("${schema.version.related.link.start}") private String relatedLinkStartVersion; - @Value("${schema.version.namespace.change.start}") - private String namespaceChangeStartVersion; - private List versions; - - private SchemaVersion edgeLabelVersion; - private SchemaVersion defaultVersion; - private SchemaVersion depthVersion; - private SchemaVersion appRootVersion; - private SchemaVersion relatedLinkVersion; - private SchemaVersion namespaceChangeVersion; + protected String namespaceChangeStartVersion; + protected List versionsValue; + protected SchemaVersion edgeLabelVersionValue; + protected SchemaVersion defaultVersionValue; + protected SchemaVersion depthVersionValue; + protected SchemaVersion appRootVersionValue; + protected SchemaVersion relatedLinkVersionValue; + protected SchemaVersion namespaceChangeVersionValue; @PostConstruct public void initialize() { - versions = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList()); - - edgeLabelVersion = new SchemaVersion(edgeLabelStartVersion); - defaultVersion = new SchemaVersion(defaultApiVersion); - depthVersion = new SchemaVersion(depthStartVersion); - appRootVersion = new SchemaVersion(appRootStartVersion); - relatedLinkVersion = new SchemaVersion(relatedLinkStartVersion); - namespaceChangeVersion = new SchemaVersion(namespaceChangeStartVersion); - - if (!versions.contains(edgeLabelVersion)) { - throw new AAISchemaValidationException( - "Invalid, edge label version is not in the api versions list" + versionsValue = apiVersions.stream().map(SchemaVersion::new).collect(Collectors.toList()); + edgeLabelVersionValue = new SchemaVersion(edgeLabelStartVersion); + defaultVersionValue = new SchemaVersion(defaultApiVersion); + depthVersionValue = new SchemaVersion(depthStartVersion); + appRootVersionValue = new SchemaVersion(appRootStartVersion); + relatedLinkVersionValue = new SchemaVersion(relatedLinkStartVersion); + namespaceChangeVersionValue = new SchemaVersion(namespaceChangeStartVersion); + this.validate(); + } + + + protected void validate() { + String errorMessage = "Invalid, edge label version is not in the api versions list" + ", please check schema.version.list and ensure that the" - + " schema.version.edge.label.start is in that list" - ); + + " schema.version.edge.label.start is in that list"; + if (!versionsValue.contains(edgeLabelVersionValue)) { + throw new AAISchemaValidationException(errorMessage); } - if (!versions.contains(defaultVersion)) { - throw new AAISchemaValidationException( - "Invalid, default version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.api.default is in that list" - ); + if (!versionsValue.contains(defaultVersionValue)) { + throw new AAISchemaValidationException(errorMessage); } - if (!versions.contains(depthVersion)) { - throw new AAISchemaValidationException( - "Invalid, depth version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.depth.start is in that list" - ); + if (!versionsValue.contains(depthVersionValue)) { + throw new AAISchemaValidationException(errorMessage); } - if(!versions.contains(appRootVersion)){ - throw new AAISchemaValidationException( - "Invalid, app root version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.app.root.start is in that list" - ); + if (!versionsValue.contains(appRootVersionValue)) { + throw new AAISchemaValidationException(errorMessage); } - if(!versions.contains(relatedLinkVersion)){ - throw new AAISchemaValidationException( - "Invalid, related link version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.related.link.start is in that list" - ); + if (!versionsValue.contains(relatedLinkVersionValue)) { + throw new AAISchemaValidationException(errorMessage); } - if(!versions.contains(namespaceChangeVersion)){ - throw new AAISchemaValidationException( - "Invalid, namespace change start version is not in the api versions list" - + ", please check schema.version.list and ensure that the" - + " schema.version.related.link.start is in that list" - ); + if (!versionsValue.contains(namespaceChangeVersionValue)) { + throw new AAISchemaValidationException(errorMessage); } } - + public List getVersions() { - return versions; + return versionsValue; } public SchemaVersion getEdgeLabelVersion() { - return edgeLabelVersion; + return edgeLabelVersionValue; } public SchemaVersion getDefaultVersion() { - return defaultVersion; + return defaultVersionValue; } public SchemaVersion getDepthVersion() { - return depthVersion; + return depthVersionValue; } - public SchemaVersion getAppRootVersion(){ - return appRootVersion; + public SchemaVersion getAppRootVersion() { + return appRootVersionValue; } - public SchemaVersion getRelatedLinkVersion(){ - return relatedLinkVersion; + public SchemaVersion getRelatedLinkVersion() { + return relatedLinkVersionValue; } public SchemaVersion getNamespaceChangeVersion() { - return namespaceChangeVersion; + return namespaceChangeVersionValue; } public void setNamespaceChangeVersion(SchemaVersion namespaceChangeVersion) { - this.namespaceChangeVersion = namespaceChangeVersion; + this.namespaceChangeVersionValue = namespaceChangeVersion; } } diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java new file mode 100644 index 00000000..119669d3 --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/SchemaVersionsBean.java @@ -0,0 +1,83 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-18 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========================================================= + */ +package org.onap.aai.setup; + +import com.google.gson.FieldNamingPolicy; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.onap.aai.restclient.RestClient; +import org.onap.aai.restclient.RestClientFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; + +import javax.annotation.PostConstruct; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class SchemaVersionsBean { + + private String SCHEMA_SERVICE = "schema-service"; + private SchemaServiceVersions schemaVersions; + + @Value("${schema.service.versions.endpoint}") + private String versionsUri; + + @Autowired + private RestClientFactory restClientFactory; + + @PostConstruct + public void initialize() { + //Call SchemaService to get versions + retrieveAllSchemaVersions(); + } + + public void retrieveAllSchemaVersions() { + /* + Call Schema MS to get versions using RestTemplate + */ + String content = ""; + Map headersMap = new HashMap<>(); + RestClient restClient = restClientFactory + .getRestClient(SCHEMA_SERVICE); + + ResponseEntity schemaResponse = restClient.getGetRequest( content, versionsUri, headersMap); + Gson gson = new GsonBuilder() + .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) + .create(); + schemaVersions = gson.fromJson(schemaResponse.getBody(), SchemaServiceVersions.class); + schemaVersions.initializeFromSchemaService(); + + } + + public SchemaServiceVersions getSchemaVersions() { + return schemaVersions; + } + + public void setSchemaVersions(SchemaServiceVersions schemaVersions) { + this.schemaVersions = schemaVersions; + } + + public List getVersions() { + return getSchemaVersions().getVersions(); + } + +} diff --git a/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java new file mode 100644 index 00000000..09062e1c --- /dev/null +++ b/aai-schema-ingest/src/main/java/org/onap/aai/setup/Translator.java @@ -0,0 +1,67 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-18 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========================================================= + */ + +package org.onap.aai.setup; + +import org.springframework.beans.factory.annotation.Autowired; + +import java.io.*; +import java.util.List; +/** + * Converts the contents of the schema config file + * (which lists which schema files to be loaded) to + * the format the Ingestors can work with. + * + */ +public abstract class Translator { + + protected SchemaVersions schemaVersions; + + public Translator(SchemaVersions schemaVersions) { + this.schemaVersions = schemaVersions; + } + + /** + * Translates the contents of the schema config file + * into the input for the NodeIngestor + * + * @return Map of Version to the list of (string) filenames to be + * ingested for that version + */ + + + public abstract List getVersionNodeStream(SchemaVersion version) throws IOException; + + public abstract List + getJsonPayload(SchemaVersion version) throws IOException; + + /** + * Translates the contents of the schema config file + * into the input for the EdgeIngestor + * + * @return Map of Version to the List of (String) filenames to be + * ingested for that version + */ + + + public SchemaVersions getSchemaVersions(){ + return this.schemaVersions; + } +} 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 index 7eae7508..36176587 100644 --- 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 @@ -38,39 +38,41 @@ import org.springframework.stereotype.Component; */ @Component public class DefaultVersionValidationModule implements VersionValidationModule { - private ConfigTranslator config; - + + private ConfigTranslator config; + @Autowired public DefaultVersionValidationModule(ConfigTranslator config) { - this.config = 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 (SchemaVersion v : config.getSchemaVersions().getVersions()) { - 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 ""; - } - } + @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 (SchemaVersion v : config.getSchemaVersions().getVersions()) { + 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/edges/CousinDefaultingValidationModule.java b/aai-schema-ingest/src/main/java/org/onap/aai/validation/edges/CousinDefaultingValidationModule.java index 05b79753..d4ab7aeb 100644 --- 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 @@ -20,18 +20,13 @@ 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 com.jayway.jsonpath.DocumentContext; 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; +import java.util.*; /** * Validates that in the collection of cousin rules between a given node type pair, 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 index 01e9e296..9a7288b0 100644 --- 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 @@ -23,12 +23,11 @@ */ package org.onap.aai.validation.edges; +import org.onap.aai.edges.enums.EdgeField; + 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 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 index 309d8945..38dcbb7e 100644 --- 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 @@ -20,22 +20,18 @@ 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 com.jayway.jsonpath.DocumentContext; 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.SchemaVersion; import org.onap.aai.validation.SchemaErrorStrategy; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; -import com.jayway.jsonpath.DocumentContext; +import java.util.*; /** * Runs all validations against the ingested schema @@ -49,21 +45,22 @@ public class EdgeRuleValidator { 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; - } - + + @Autowired + public EdgeRuleValidator(ConfigTranslator config, SchemaErrorStrategy strat, + EdgeFieldsValidationModule fieldValidator, UniqueLabelValidationModule labelValidator, + SingleContainmentValidationModule containsValidator, CousinDefaultingValidationModule defaultsValidator, + NodeTypesValidationModule typeValidator) { + //TODO - Need to change this to use files/schemaservice + 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 (Map.Entry> verEntry : versionJsonFilesMap.entrySet()) { 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 index b4ed3782..e8c45063 100644 --- 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 @@ -20,15 +20,16 @@ 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.SchemaVersion; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Component; +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; + /** * Validates that the node types appearing in the edge rules are valid * against the ingested OXM. 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 index 4586ccce..ad2cffeb 100644 --- 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 @@ -20,14 +20,13 @@ package org.onap.aai.validation.edges; -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - +import com.jayway.jsonpath.DocumentContext; import org.onap.aai.edges.EdgeRuleQuery; import org.onap.aai.edges.enums.EdgeType; -import com.jayway.jsonpath.DocumentContext; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * Validates that the given node type pair has at most one containment relationship 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 index 103baaba..35d74667 100644 --- 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 @@ -20,17 +20,12 @@ 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 com.jayway.jsonpath.DocumentContext; 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; +import java.util.*; /** * Applies label validation rules 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 index 27a69f9b..38b3a70c 100644 --- 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 @@ -31,13 +31,14 @@ import org.springframework.stereotype.Component; @Component public class NodeValidator { - private ConfigTranslator translator; + + private ConfigTranslator translator; private SchemaErrorStrategy strat; private DuplicateNodeDefinitionValidationModule dupChecker; @Autowired - public NodeValidator(ConfigTranslator translator, SchemaErrorStrategy strategy, DuplicateNodeDefinitionValidationModule dupChecker) { - this.translator = translator; + public NodeValidator( ConfigTranslator translator, SchemaErrorStrategy strategy, DuplicateNodeDefinitionValidationModule dupChecker) { + this.translator = translator; this.strat = strategy; this.dupChecker = dupChecker; } diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorLocalTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorLocalTest.java new file mode 100644 index 00000000..3ed7bb79 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/edges/EdgeIngestorLocalTest.java @@ -0,0 +1,369 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-18 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========================================================= + */ + +package org.onap.aai.edges; + +import com.google.common.collect.Multimap; +import org.apache.tinkerpop.gremlin.structure.Direction; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.onap.aai.restclient.MockProvider; +import org.onap.aai.config.EdgesConfiguration; +import org.onap.aai.edges.enums.AAIDirection; +import org.onap.aai.edges.enums.MultiplicityRule; +import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.testutils.TestUtilConfigTranslator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.Collection; + +import static org.junit.Assert.*; + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(classes = { EdgesConfiguration.class, TestUtilConfigTranslator.class}) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) + +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) +//@TestPropertySource(locations = "/schema-service-rest.properties" ) +@SpringBootTest +public class EdgeIngestorLocalTest { + @Autowired + EdgeIngestor edgeIngestor; + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Test + public void getRulesTest1() throws EdgeRuleNotFoundException { + EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build(); + Multimap results = edgeIngestor.getRules(q); + assertTrue(results.size() == 5); + assertTrue(results.containsKey("bar|foo")); + + assertTrue(2 == results.get("bar|foo").size()); + boolean seenLabel1 = false; + boolean seenLabel2 = false; + for(EdgeRule r : results.get("bar|foo")) { + if ("eats".equals(r.getLabel())) { + seenLabel1 = true; + } + if ("eatz".equals(r.getLabel())) { + seenLabel2 = true; + } + } + assertTrue(seenLabel1 && seenLabel2); + + assertTrue(results.containsKey("baz|foo")); + assertTrue(results.containsKey("foo|quux")); + assertTrue(results.containsKey("dog|foo")); + } + + @Test + public void getRulesTest2() throws EdgeRuleNotFoundException { + EdgeRuleQuery q = new EdgeRuleQuery.Builder("dog", "puppy").build(); + Multimap results = edgeIngestor.getRules(q); + assertTrue(results.size() == 1); + assertTrue(results.containsKey("dog|puppy")); + Collection cr = results.get("dog|puppy"); + for (EdgeRule r : cr) { + assertTrue("dog".equals(r.getFrom())); + assertTrue("puppy".equals(r.getTo())); + assertTrue("caresFor".equals(r.getLabel())); + assertTrue(Direction.OUT.equals(r.getDirection())); + assertTrue("One2Many".equalsIgnoreCase(r.getMultiplicityRule().toString())); + assertTrue("NONE".equals(r.getContains())); + assertTrue("OUT".equals(r.getDeleteOtherV())); + assertTrue("NONE".equals(r.getPreventDelete())); + assertTrue(r.isDefault()); + } + } + + @Test + public void getRulesFlippedTypesTest() throws EdgeRuleNotFoundException { + EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface", "logical-link").version(new SchemaVersion("v11")).build(); + Multimap results = edgeIngestor.getRules(q); + assertTrue(results.size() == 3); + for (EdgeRule r : results.get("l-interface|logical-link")) { + if ("org.onap.relationships.inventory.Source".equals(r.getLabel()) || + "org.onap.relationships.inventory.Destination".equals(r.getLabel())) { + //these are defined with from=logical-link, to=l-interface, so they must be flipped + assertTrue(Direction.IN.equals(r.getDirection())); + } else if ("tosca.relationships.network.LinksTo".equals(r.getLabel())) { + //this is defined with from=l-interface, to=logical-link, so it shouldn't be flipped + assertTrue(Direction.OUT.equals(r.getDirection())); + } else { + fail("how did you get here"); + } + } + } + + @Test + public void fromToSameFlipTests() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + //getRules, setting from and to + EdgeRuleQuery q = new EdgeRuleQuery.Builder("bloop","bloop").version(new SchemaVersion("v11")).build(); + Multimap results = edgeIngestor.getRules(q); + assertTrue(results.size() == 1); + for (EdgeRule r : results.get("bloop|bloop")) { + assertTrue(Direction.IN.equals(r.getDirection())); + } + + //getRule, setting just from + EdgeRuleQuery q2 = new EdgeRuleQuery.Builder("bloop").version(new SchemaVersion("v11")).build(); + assertTrue(Direction.IN.equals(edgeIngestor.getRule(q2).getDirection())); + + //getChildRules + Multimap child = edgeIngestor.getChildRules("bloop", new SchemaVersion("v11")); + assertTrue(child.size() == 1); + for (EdgeRule r : child.get("bloop|bloop")) { + assertTrue(Direction.IN.equals(r.getDirection())); + } + } + + @Test + public void getRulesTest3() throws EdgeRuleNotFoundException { + EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build(); + Multimap results = edgeIngestor.getRules(q); + assertTrue(results.size() == 4); + assertTrue(results.containsKey("lag-interface|l-interface")); + assertTrue(results.containsKey("l-interface|logical-link")); + assertTrue(results.get("l-interface|logical-link").size() == 3); + } + + @Test + public void getRulesNoneFound() throws EdgeRuleNotFoundException { + thrown.expect(EdgeRuleNotFoundException.class); + thrown.expectMessage("No rules found for"); + EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").build(); + edgeIngestor.getRules(q); + } + + @Test + public void getRuleSimpleTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + EdgeRuleQuery q = new EdgeRuleQuery.Builder("parent", "notation").build(); + EdgeRule result = edgeIngestor.getRule(q); + assertTrue("parent".equals(result.getFrom())); + assertTrue("notation".equals(result.getTo())); + assertTrue("has".equals(result.getLabel())); + assertTrue(Direction.OUT.equals(result.getDirection())); + assertTrue(MultiplicityRule.MANY2MANY.equals(result.getMultiplicityRule())); + assertTrue(AAIDirection.OUT.toString().equals(result.getContains())); + assertTrue(AAIDirection.NONE.toString().equals(result.getDeleteOtherV())); + assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete())); + assertTrue("parent contains notation".equals(result.getDescription())); + } + + @Test + public void getRuleFlippedTypesTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + EdgeRuleQuery q = new EdgeRuleQuery.Builder("notation", "parent").build(); + EdgeRule result = edgeIngestor.getRule(q); + assertTrue("parent".equals(result.getFrom())); + assertTrue("notation".equals(result.getTo())); + assertTrue("has".equals(result.getLabel())); + //direction flipped to match input order per old EdgeRules.java API + assertTrue(Direction.IN.equals(result.getDirection())); + assertTrue(MultiplicityRule.MANY2MANY.equals(result.getMultiplicityRule())); + assertTrue(AAIDirection.OUT.toString().equals(result.getContains())); + assertTrue(AAIDirection.NONE.toString().equals(result.getDeleteOtherV())); + assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete())); + assertTrue("parent contains notation".equals(result.getDescription())); + } + +// @Test +// public void getRuleWithDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { +// +// EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").version(new SchemaVersion("v11")).build(); +// EdgeRule res = edgeIngestor.getRule(q); +// assertTrue(res.isDefault()); +// assertTrue("tosca.relationships.network.LinksTo".equals(res.getLabel())); +// } +// +// @Test +// public void getRuleWithNonDefault() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { +// EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").label("org.onap.relationships.inventory.Source").version(new SchemaVersion("v11")).build(); +// EdgeRule res = edgeIngestor.getRule(q); +// assertFalse(res.isDefault()); +// assertTrue("org.onap.relationships.inventory.Source".equals(res.getLabel())); +// } + + @Test + public void getRuleNoneFoundTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + thrown.expect(EdgeRuleNotFoundException.class); + thrown.expectMessage("No rule found for"); + EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","nonexistent").build(); + edgeIngestor.getRule(q); + } + +// @Test +// public void getRuleTooManyPairsTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { +// thrown.expect(AmbiguousRuleChoiceException.class); +// thrown.expectMessage("No way to select single rule from these pairs:"); +// EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build(); +// edgeIngestor.getRule(q); +// } + + @Test + public void getRuleAmbiguousDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + thrown.expect(AmbiguousRuleChoiceException.class); + thrown.expectMessage("Multiple defaults found."); + EdgeRuleQuery q = new EdgeRuleQuery.Builder("seed","plant").version(new SchemaVersion("v11")).build(); + edgeIngestor.getRule(q); + } + + @Test + public void getRuleNoDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { + thrown.expect(AmbiguousRuleChoiceException.class); + thrown.expectMessage("No default found."); + EdgeRuleQuery q = new EdgeRuleQuery.Builder("apple", "orange").version(new SchemaVersion("v11")).build(); + edgeIngestor.getRule(q); + } + +// @Test +// public void hasRuleTest() { +// assertTrue(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build())); +// assertFalse(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").build())); +// } +// +// @Test +// public void getCousinRulesTest() { +// Multimap results = edgeIngestor.getCousinRules("dog"); +// assertTrue(results.size() == 2); +// assertTrue(results.containsKey("dog|puppy")); +// assertTrue(results.containsKey("dog|foo")); +// } + + @Test + public void getCousinRulesWithVersionTest() { + Multimap results = edgeIngestor.getCousinRules("foo", new SchemaVersion("v10")); + assertTrue(results.size() == 2); + assertTrue(results.containsKey("bar|foo")); + assertTrue(results.get("bar|foo").size() == 2); + } + + @Test + public void getCousinsNoneInVersionTest() { + Multimap results = edgeIngestor.getCousinRules("foo", new SchemaVersion("v11")); + assertTrue(results.isEmpty()); + } + +// @Test +// public void hasCousinTest() { +// assertTrue(edgeIngestor.hasCousinRule("foo")); +// assertTrue(edgeIngestor.hasCousinRule("foo", new SchemaVersion("v10"))); +// assertFalse(edgeIngestor.hasCousinRule("parent")); +// assertFalse(edgeIngestor.hasCousinRule("foo", new SchemaVersion("v11"))); +// } + + @Test + public void getChildRulesTest() { + Multimap results = edgeIngestor.getChildRules("parent"); + assertTrue(results.size() == 6); + assertTrue(results.containsKey("notation|parent")); + assertTrue(results.containsKey("not-notation|parent")); + assertTrue(results.containsKey("out-out|parent")); + assertTrue(results.containsKey("in-in|parent")); + assertTrue(results.containsKey("in-out|parent")); + assertTrue(results.containsKey("out-in|parent")); + } + + @Test + public void getChildRulesWithVersionTest() { + Multimap results = edgeIngestor.getChildRules("foo", new SchemaVersion("v10")); + assertTrue(results.size() == 2); + assertTrue(results.containsKey("baz|foo")); + assertTrue(results.containsKey("foo|quux")); + } + + @Test + public void getChildRulesNoneInVersionTest() { + Multimap results = edgeIngestor.getChildRules("foo", new SchemaVersion("v11")); + assertTrue(results.isEmpty()); + } + +// @Test +// public void hasChildTest() { +// assertTrue(edgeIngestor.hasChildRule("foo")); +// assertTrue(edgeIngestor.hasChildRule("foo", new SchemaVersion("v10"))); +// assertFalse(edgeIngestor.hasChildRule("puppy")); +// assertFalse(edgeIngestor.hasChildRule("foo", new SchemaVersion("v11"))); +// } + + @Test + public void getParentRulesTest() { + Multimap results = edgeIngestor.getParentRules("parent"); + assertTrue(results.size() == 6); + assertTrue(results.containsKey("grandparent1|parent")); + assertTrue(results.containsKey("grandparent2|parent")); + assertTrue(results.containsKey("grandparent3|parent")); + assertTrue(results.containsKey("grandparent4|parent")); + assertTrue(results.containsKey("grandparent5|parent")); + assertTrue(results.containsKey("grandparent6|parent")); + } + + @Test + public void getParentRulesWithVersionTest() { + Multimap results = edgeIngestor.getParentRules("baz", new SchemaVersion("v10")); + assertTrue(results.size() == 1); + assertTrue(results.containsKey("baz|foo")); + } + + @Test + public void getParentRulesNoneInVersionTest() { + Multimap results = edgeIngestor.getParentRules("baz", new SchemaVersion("v11")); + assertTrue(results.isEmpty()); + } + + @Test + public void hasParentTest() { + assertTrue(edgeIngestor.hasParentRule("parent")); + assertTrue(edgeIngestor.hasParentRule("quux", new SchemaVersion("v10"))); + assertFalse(edgeIngestor.hasParentRule("puppy")); + assertFalse(edgeIngestor.hasParentRule("foo", new SchemaVersion("v11"))); + } + +// @Test +// public void getAllCurrentRulesTest() throws EdgeRuleNotFoundException { +// Multimap res = edgeIngestor.getAllCurrentRules(); +// assertTrue(res.size() == 18); +// } + + @Test + public void getAllRulesTest() throws EdgeRuleNotFoundException { + Multimap res = edgeIngestor.getAllRules(new SchemaVersion("v10")); + assertTrue(res.size() == 4); + assertTrue(res.containsKey("bar|foo")); + assertTrue(res.get("bar|foo").size() == 2); + assertTrue(res.containsKey("baz|foo")); + assertTrue(res.containsKey("foo|quux")); + + thrown.expect(EdgeRuleNotFoundException.class); + thrown.expectMessage("No rules found for version v9."); + edgeIngestor.getAllRules(new SchemaVersion("v9")); + } +} 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 6292da71..ab83e196 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,4 +1,4 @@ -/** +/** * ============LICENSE_START======================================================= * org.onap.aai * ================================================================================ @@ -25,20 +25,22 @@ import static org.junit.Assert.*; import java.util.Collection; import org.apache.tinkerpop.gremlin.structure.Direction; +import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import org.onap.aai.restclient.MockProvider; +import org.onap.aai.restclient.MockRestClient; +import org.onap.aai.config.EdgesConfiguration; import org.onap.aai.edges.enums.AAIDirection; import org.onap.aai.edges.enums.MultiplicityRule; import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; -import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; -import org.onap.aai.testutils.TestUtilConfigTranslator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -46,23 +48,29 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.google.common.collect.Multimap; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, TestUtilConfigTranslator.class, EdgeIngestor.class}) +@ContextConfiguration(classes = {MockProvider.class, EdgesConfiguration.class}) @TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) + +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) @SpringBootTest public class EdgeIngestorTest { @Autowired - EdgeIngestor ei; - + EdgeIngestor edgeIngestor; + @Rule public ExpectedException thrown = ExpectedException.none(); - + @Test public void getRulesTest1() throws EdgeRuleNotFoundException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build(); - Multimap results = ei.getRules(q); + Multimap results = edgeIngestor.getRules(q); + System.out.println(results.size()); + for (String key : results.keySet()) { + System.out.println(key); + } assertTrue(results.size() == 5); assertTrue(results.containsKey("bar|foo")); - + assertTrue(2 == results.get("bar|foo").size()); boolean seenLabel1 = false; boolean seenLabel2 = false; @@ -75,16 +83,16 @@ public class EdgeIngestorTest { } } assertTrue(seenLabel1 && seenLabel2); - + assertTrue(results.containsKey("baz|foo")); assertTrue(results.containsKey("foo|quux")); assertTrue(results.containsKey("dog|foo")); } - + @Test public void getRulesTest2() throws EdgeRuleNotFoundException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("dog", "puppy").build(); - Multimap results = ei.getRules(q); + Multimap results = edgeIngestor.getRules(q); assertTrue(results.size() == 1); assertTrue(results.containsKey("dog|puppy")); Collection cr = results.get("dog|puppy"); @@ -100,11 +108,11 @@ public class EdgeIngestorTest { assertTrue(r.isDefault()); } } - + @Test public void getRulesFlippedTypesTest() throws EdgeRuleNotFoundException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface", "logical-link").version(new SchemaVersion("v11")).build(); - Multimap results = ei.getRules(q); + Multimap results = edgeIngestor.getRules(q); assertTrue(results.size() == 3); for (EdgeRule r : results.get("l-interface|logical-link")) { if ("org.onap.relationships.inventory.Source".equals(r.getLabel()) || @@ -119,51 +127,51 @@ public class EdgeIngestorTest { } } } - + @Test public void fromToSameFlipTests() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { //getRules, setting from and to EdgeRuleQuery q = new EdgeRuleQuery.Builder("bloop","bloop").version(new SchemaVersion("v11")).build(); - Multimap results = ei.getRules(q); + Multimap results = edgeIngestor.getRules(q); assertTrue(results.size() == 1); for (EdgeRule r : results.get("bloop|bloop")) { assertTrue(Direction.IN.equals(r.getDirection())); } - + //getRule, setting just from EdgeRuleQuery q2 = new EdgeRuleQuery.Builder("bloop").version(new SchemaVersion("v11")).build(); - assertTrue(Direction.IN.equals(ei.getRule(q2).getDirection())); - + assertTrue(Direction.IN.equals(edgeIngestor.getRule(q2).getDirection())); + //getChildRules - Multimap child = ei.getChildRules("bloop", new SchemaVersion("v11")); + Multimap child = edgeIngestor.getChildRules("bloop", new SchemaVersion("v11")); assertTrue(child.size() == 1); for (EdgeRule r : child.get("bloop|bloop")) { assertTrue(Direction.IN.equals(r.getDirection())); } } - + @Test public void getRulesTest3() throws EdgeRuleNotFoundException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build(); - Multimap results = ei.getRules(q); + Multimap results = edgeIngestor.getRules(q); assertTrue(results.size() == 4); assertTrue(results.containsKey("lag-interface|l-interface")); assertTrue(results.containsKey("l-interface|logical-link")); assertTrue(results.get("l-interface|logical-link").size() == 3); } - + @Test public void getRulesNoneFound() throws EdgeRuleNotFoundException { thrown.expect(EdgeRuleNotFoundException.class); thrown.expectMessage("No rules found for"); - EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface").build(); - ei.getRules(q); + EdgeRuleQuery q = new EdgeRuleQuery.Builder("bogus-value").build(); + edgeIngestor.getRules(q); } - + @Test public void getRuleSimpleTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("parent", "notation").build(); - EdgeRule result = ei.getRule(q); + EdgeRule result = edgeIngestor.getRule(q); assertTrue("parent".equals(result.getFrom())); assertTrue("notation".equals(result.getTo())); assertTrue("has".equals(result.getLabel())); @@ -174,11 +182,30 @@ public class EdgeIngestorTest { assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete())); assertTrue("parent contains notation".equals(result.getDescription())); } - +// @Test +// public void getRuleSimpleTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { +// EdgeRuleQuery q = new EdgeRuleQuery.Builder("parent", "notation").build(); +// Multimap results = edgeIngestor.getRules(q); +// assertTrue(results.size() == 1); +// // EdgeRule result = edgeIngestor.getRule(q); +// for (EdgeRule result : results.get("parent|notation")) { +// assertTrue("parent".equals(result.getFrom())); +// assertTrue("notation".equals(result.getTo())); +// assertTrue("has".equals(result.getLabel())); +// assertTrue(Direction.OUT.equals(result.getDirection())); +// assertTrue(MultiplicityRule.MANY2MANY.equals(result.getMultiplicityRule())); +// assertTrue(AAIDirection.OUT.toString().equals(result.getContains())); +// assertTrue(AAIDirection.NONE.toString().equals(result.getDeleteOtherV())); +// assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete())); +// assertTrue("parent contains notation".equals(result.getDescription())); +// } +// } + + @Test public void getRuleFlippedTypesTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("notation", "parent").build(); - EdgeRule result = ei.getRule(q); + EdgeRule result = edgeIngestor.getRule(q); assertTrue("parent".equals(result.getFrom())); assertTrue("notation".equals(result.getTo())); assertTrue("has".equals(result.getLabel())); @@ -190,95 +217,97 @@ public class EdgeIngestorTest { assertTrue(AAIDirection.NONE.toString().equals(result.getPreventDelete())); assertTrue("parent contains notation".equals(result.getDescription())); } - + @Test public void getRuleWithDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").version(new SchemaVersion("v11")).build(); - EdgeRule res = ei.getRule(q); + EdgeRule res = edgeIngestor.getRule(q); assertTrue(res.isDefault()); assertTrue("tosca.relationships.network.LinksTo".equals(res.getLabel())); } - + @Test public void getRuleWithNonDefault() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","logical-link").label("org.onap.relationships.inventory.Source").version(new SchemaVersion("v11")).build(); - EdgeRule res = ei.getRule(q); + EdgeRule res = edgeIngestor.getRule(q); assertFalse(res.isDefault()); assertTrue("org.onap.relationships.inventory.Source".equals(res.getLabel())); } - + @Test public void getRuleNoneFoundTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { thrown.expect(EdgeRuleNotFoundException.class); thrown.expectMessage("No rule found for"); EdgeRuleQuery q = new EdgeRuleQuery.Builder("l-interface","nonexistent").build(); - ei.getRule(q); + edgeIngestor.getRule(q); } - + @Test public void getRuleTooManyPairsTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { thrown.expect(AmbiguousRuleChoiceException.class); thrown.expectMessage("No way to select single rule from these pairs:"); EdgeRuleQuery q = new EdgeRuleQuery.Builder("foo").build(); - ei.getRule(q); + edgeIngestor.getRule(q); } - + @Test public void getRuleAmbiguousDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { thrown.expect(AmbiguousRuleChoiceException.class); thrown.expectMessage("Multiple defaults found."); EdgeRuleQuery q = new EdgeRuleQuery.Builder("seed","plant").version(new SchemaVersion("v11")).build(); - ei.getRule(q); + edgeIngestor.getRule(q); } - + @Test public void getRuleNoDefaultTest() throws EdgeRuleNotFoundException, AmbiguousRuleChoiceException { thrown.expect(AmbiguousRuleChoiceException.class); thrown.expectMessage("No default found."); EdgeRuleQuery q = new EdgeRuleQuery.Builder("apple", "orange").version(new SchemaVersion("v11")).build(); - ei.getRule(q); + edgeIngestor.getRule(q); } - + @Test public void hasRuleTest() { - assertTrue(ei.hasRule(new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build())); - assertFalse(ei.hasRule(new EdgeRuleQuery.Builder("l-interface").build())); + assertTrue(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v11")).build())); + assertFalse(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").version(new SchemaVersion("v10")).build())); + assertTrue(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").build())); +// assertFalse(edgeIngestor.hasRule(new EdgeRuleQuery.Builder("l-interface").build())); } - + @Test public void getCousinRulesTest() { - Multimap results = ei.getCousinRules("dog"); + Multimap results = edgeIngestor.getCousinRules("dog"); assertTrue(results.size() == 2); assertTrue(results.containsKey("dog|puppy")); assertTrue(results.containsKey("dog|foo")); } - + @Test public void getCousinRulesWithVersionTest() { - Multimap results = ei.getCousinRules("foo", new SchemaVersion("v10")); + Multimap results = edgeIngestor.getCousinRules("foo", new SchemaVersion("v10")); assertTrue(results.size() == 2); assertTrue(results.containsKey("bar|foo")); assertTrue(results.get("bar|foo").size() == 2); } - + @Test public void getCousinsNoneInVersionTest() { - Multimap results = ei.getCousinRules("foo", new SchemaVersion("v11")); + Multimap results = edgeIngestor.getCousinRules("foo", new SchemaVersion("v11")); assertTrue(results.isEmpty()); } - + @Test public void hasCousinTest() { - assertTrue(ei.hasCousinRule("foo")); - assertTrue(ei.hasCousinRule("foo", new SchemaVersion("v10"))); - assertFalse(ei.hasCousinRule("parent")); - assertFalse(ei.hasCousinRule("foo", new SchemaVersion("v11"))); + assertTrue(edgeIngestor.hasCousinRule("foo")); + assertTrue(edgeIngestor.hasCousinRule("foo", new SchemaVersion("v10"))); + assertFalse(edgeIngestor.hasCousinRule("parent")); + assertFalse(edgeIngestor.hasCousinRule("foo", new SchemaVersion("v11"))); } @Test public void getChildRulesTest() { - Multimap results = ei.getChildRules("parent"); + Multimap results = edgeIngestor.getChildRules("parent"); assertTrue(results.size() == 6); assertTrue(results.containsKey("notation|parent")); assertTrue(results.containsKey("not-notation|parent")); @@ -287,32 +316,32 @@ public class EdgeIngestorTest { assertTrue(results.containsKey("in-out|parent")); assertTrue(results.containsKey("out-in|parent")); } - + @Test public void getChildRulesWithVersionTest() { - Multimap results = ei.getChildRules("foo", new SchemaVersion("v10")); + Multimap results = edgeIngestor.getChildRules("foo", new SchemaVersion("v10")); assertTrue(results.size() == 2); assertTrue(results.containsKey("baz|foo")); assertTrue(results.containsKey("foo|quux")); } - + @Test public void getChildRulesNoneInVersionTest() { - Multimap results = ei.getChildRules("foo", new SchemaVersion("v11")); + Multimap results = edgeIngestor.getChildRules("foo", new SchemaVersion("v11")); assertTrue(results.isEmpty()); } - + @Test public void hasChildTest() { - assertTrue(ei.hasChildRule("foo")); - assertTrue(ei.hasChildRule("foo", new SchemaVersion("v10"))); - assertFalse(ei.hasChildRule("puppy")); - assertFalse(ei.hasChildRule("foo", new SchemaVersion("v11"))); + assertTrue(edgeIngestor.hasChildRule("foo")); + assertTrue(edgeIngestor.hasChildRule("foo", new SchemaVersion("v10"))); + assertFalse(edgeIngestor.hasChildRule("puppy")); + assertFalse(edgeIngestor.hasChildRule("foo", new SchemaVersion("v11"))); } - + @Test public void getParentRulesTest() { - Multimap results = ei.getParentRules("parent"); + Multimap results = edgeIngestor.getParentRules("parent"); assertTrue(results.size() == 6); assertTrue(results.containsKey("grandparent1|parent")); assertTrue(results.containsKey("grandparent2|parent")); @@ -321,45 +350,45 @@ public class EdgeIngestorTest { assertTrue(results.containsKey("grandparent5|parent")); assertTrue(results.containsKey("grandparent6|parent")); } - + @Test public void getParentRulesWithVersionTest() { - Multimap results = ei.getParentRules("baz", new SchemaVersion("v10")); + Multimap results = edgeIngestor.getParentRules("baz", new SchemaVersion("v10")); assertTrue(results.size() == 1); assertTrue(results.containsKey("baz|foo")); } - + @Test public void getParentRulesNoneInVersionTest() { - Multimap results = ei.getParentRules("baz", new SchemaVersion("v11")); + Multimap results = edgeIngestor.getParentRules("baz", new SchemaVersion("v11")); assertTrue(results.isEmpty()); } - + @Test public void hasParentTest() { - assertTrue(ei.hasParentRule("parent")); - assertTrue(ei.hasParentRule("quux", new SchemaVersion("v10"))); - assertFalse(ei.hasParentRule("puppy")); - assertFalse(ei.hasParentRule("foo", new SchemaVersion("v11"))); + assertTrue(edgeIngestor.hasParentRule("parent")); + assertTrue(edgeIngestor.hasParentRule("quux", new SchemaVersion("v10"))); + assertFalse(edgeIngestor.hasParentRule("puppy")); + assertFalse(edgeIngestor.hasParentRule("foo", new SchemaVersion("v11"))); } - + @Test public void getAllCurrentRulesTest() throws EdgeRuleNotFoundException { - Multimap res = ei.getAllCurrentRules(); - assertTrue(res.size() == 18); + Multimap res = edgeIngestor.getAllCurrentRules(); + assertTrue(res.size() == 24); } - + @Test public void getAllRulesTest() throws EdgeRuleNotFoundException { - Multimap res = ei.getAllRules(new SchemaVersion("v10")); + Multimap res = edgeIngestor.getAllRules(new SchemaVersion("v10")); assertTrue(res.size() == 4); assertTrue(res.containsKey("bar|foo")); assertTrue(res.get("bar|foo").size() == 2); assertTrue(res.containsKey("baz|foo")); assertTrue(res.containsKey("foo|quux")); - + thrown.expect(EdgeRuleNotFoundException.class); thrown.expectMessage("No rules found for version v9."); - ei.getAllRules(new SchemaVersion("v9")); + edgeIngestor.getAllRules(new SchemaVersion("v9")); } } 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 cae3bf78..395c9cc7 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 @@ -22,12 +22,14 @@ package org.onap.aai.edges; import static org.junit.Assert.*; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.aai.config.EdgesConfiguration; import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; -import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersionsBean; + import org.onap.aai.testutils.ConfigTranslatorForWiringTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -38,8 +40,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import com.google.common.collect.Multimap; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, ConfigTranslatorForWiringTest.class, EdgeIngestor.class}) -@TestPropertySource(properties = {"schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties"}) +@ContextConfiguration(classes = {EdgesConfiguration.class, ConfigTranslatorForWiringTest.class}) +@TestPropertySource(properties = {"schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties"}) @SpringBootTest public class EdgeIngestorWiringTest { @Autowired 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 856ebb70..27c8d6e1 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 @@ -33,6 +33,7 @@ import org.onap.aai.edges.enums.EdgeType; import com.jayway.jsonpath.DocumentContext; import com.jayway.jsonpath.JsonPath; + public class EdgeRuleQueryTest { private DocumentContext testRules; private String readStart = "$.rules.[?]"; 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 index b718c0fd..4475b3f2 100644 --- 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 @@ -23,7 +23,6 @@ package org.onap.aai.edges; import static org.junit.Assert.*; import java.util.*; - import org.junit.Test; import org.onap.aai.setup.SchemaVersion; 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 index 4e3d61dd..3f49428f 100644 --- 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 @@ -21,7 +21,6 @@ package org.onap.aai.edges; import static org.junit.Assert.*; - import org.junit.Test; public class TypeAlphabetizerTest { diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java new file mode 100644 index 00000000..cec3f9d8 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/nodes/NodeIngestorLocalTest.java @@ -0,0 +1,176 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-18 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========================================================= + */ + +package org.onap.aai.nodes; + +import org.eclipse.persistence.dynamic.DynamicEntity; +import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.onap.aai.restclient.MockProvider; +import org.onap.aai.config.NodesConfiguration; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.testutils.TestUtilConfigTranslator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; +import org.w3c.dom.Document; + +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + +@RunWith(SpringRunner.class) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local-node.properties" }) +@ContextConfiguration(classes = {TestUtilConfigTranslator.class, NodesConfiguration.class}) + +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) + +@SpringBootTest +public class NodeIngestorLocalTest { + + //set thrown.expect to whatever a specific test needs + //this establishes a default of expecting no exceptions to be thrown + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Autowired + NodeIngestor nodeIngestor; + + public static void printDocument(Document doc, OutputStream out) throws IOException, TransformerException { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer transformer = tf.newTransformer(); + transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "no"); + transformer.setOutputProperty(OutputKeys.METHOD, "xml"); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); + transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); + + transformer.transform(new DOMSource(doc), + new StreamResult(new OutputStreamWriter(out, "UTF-8"))); + } + + @Test + public void testGetContextForVersion11() { + DynamicJAXBContext ctx10 = nodeIngestor.getContextForVersion(new SchemaVersion("v10")); + + //should work bc Foo is valid in test_network_v10 schema + DynamicEntity foo10 = ctx10.newDynamicEntity("Foo"); + + foo10.set("fooId", "bar"); + assertTrue("bar".equals(foo10.get("fooId"))); + + //should work bc Bar is valid in test_business_v10 schema + DynamicEntity bar10 = ctx10.newDynamicEntity("Bar"); + bar10.set("barId", "bar2"); + assertTrue("bar2".equals(bar10.get("barId"))); + XSDOutputResolver outputResolver10 = new XSDOutputResolver(); + ctx10.generateSchema(outputResolver10); + + DynamicJAXBContext ctx11 = nodeIngestor.getContextForVersion(new SchemaVersion("v11")); + + //should work bc Foo.quantity is valid in test_network_v11 schema + DynamicEntity foo11 = ctx11.newDynamicEntity("Foo"); + foo11.set("quantity", "12"); + assertTrue("12".equals(foo11.get("quantity"))); + + DynamicEntity quux11 = ctx11.newDynamicEntity("Quux"); + quux11.set("qManagerName", "some guy"); + assertTrue("some guy".equals(quux11.get("qManagerName"))); + XSDOutputResolver outputResolver11 = new XSDOutputResolver(); + ctx11.generateSchema(outputResolver11); + + + thrown.expect(IllegalArgumentException.class); + //should fail bc Quux not in v10 test schema + ctx10.newDynamicEntity("Quux"); + } + + @Test + public void testHasNodeType() { + assertTrue(nodeIngestor.hasNodeType("foo", new SchemaVersion("v11"))); + assertTrue(nodeIngestor.hasNodeType("quux", new SchemaVersion("v11"))); + assertFalse(nodeIngestor.hasNodeType("quux", new SchemaVersion("v10"))); + } + + @Test + public void testGetVersionFromClassName() { + assertEquals(nodeIngestor.getVersionFromClassName("inventory.aai.onap.org.v13.Evc"), new SchemaVersion("v13")); + + } + + @Test + public void testGetVersionFromClassNameNull() { + assertEquals(nodeIngestor.getVersionFromClassName("blah"), new SchemaVersion("v15")); + + } + + @Test + public void testGetObjectsInVersion() { + assertEquals(nodeIngestor.getObjectsInVersion(new SchemaVersion("v13")).size(), 148); + + } + + @Test + public void testCombinedSchema() throws TransformerException, IOException { + DynamicJAXBContext ctx13 = nodeIngestor.getContextForVersion(new SchemaVersion("v13")); + XSDOutputResolver outputResolver13 = new XSDOutputResolver(); + ctx13.generateSchema(outputResolver13); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + printDocument(nodeIngestor.getSchema(new SchemaVersion("v13")), buffer); + String content = new String(Files.readAllBytes(Paths.get("src/test/resources/forWiringTests/aai_oxm_v13.xml"))); + content = content.replaceAll("\\s+", ""); + String expected = buffer.toString().replaceAll("\\s+", ""); + + assertThat("OXM:\n" + expected, expected, is(content)); + } + + private class XSDOutputResolver extends SchemaOutputResolver { + + @Override + public Result createOutput(String namespaceUri, String suggestedFileName) + throws IOException { + + // create new file + // create stream result + File temp = File.createTempFile("schema", ".xsd"); + StreamResult result = new StreamResult(temp); + System.out.println("Schema file: " + temp.getAbsolutePath()); + + // set system id + result.setSystemId(temp.toURI().toURL().toString()); + + // return result + return result; + } + } +} 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 2de5847e..ec529f9d 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 @@ -20,54 +20,45 @@ package org.onap.aai.nodes; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.*; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.nio.file.Files; -import java.nio.file.Paths; - -import javax.xml.bind.SchemaOutputResolver; -import javax.xml.transform.OutputKeys; -import javax.xml.transform.Result; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - import org.eclipse.persistence.dynamic.DynamicEntity; -import org.eclipse.persistence.jaxb.JAXBContext; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; -import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.restclient.MockProvider; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; -import org.onap.aai.testutils.TestUtilConfigTranslator; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.w3c.dom.Document; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; + +import javax.xml.bind.SchemaOutputResolver; +import javax.xml.transform.*; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.*; + @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, TestUtilConfigTranslator.class, NodeIngestor.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-ss-wiring-test.properties" }) + +@ContextConfiguration(classes = { MockProvider.class, NodesConfiguration.class}) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) @SpringBootTest public class NodeIngestorTest { @Autowired - NodeIngestor ni; - + NodeIngestor nodeIngestor; + //set thrown.expect to whatever a specific test needs //this establishes a default of expecting no exceptions to be thrown @Rule @@ -75,7 +66,7 @@ public class NodeIngestorTest { @Test public void testGetContextForVersion() { - DynamicJAXBContext ctx10 = ni.getContextForVersion(new SchemaVersion("v10")); + DynamicJAXBContext ctx10 = nodeIngestor.getContextForVersion(new SchemaVersion("v10")); //should work bc Foo is valid in test_network_v10 schema DynamicEntity foo10 = ctx10.newDynamicEntity("Foo"); @@ -90,7 +81,7 @@ public class NodeIngestorTest { XSDOutputResolver outputResolver10 = new XSDOutputResolver(); ctx10.generateSchema(outputResolver10); - DynamicJAXBContext ctx11 = ni.getContextForVersion(new SchemaVersion("v11")); + DynamicJAXBContext ctx11 = nodeIngestor.getContextForVersion(new SchemaVersion("v11")); //should work bc Foo.quantity is valid in test_network_v11 schema DynamicEntity foo11 = ctx11.newDynamicEntity("Foo"); @@ -108,23 +99,47 @@ public class NodeIngestorTest { //should fail bc Quux not in v10 test schema ctx10.newDynamicEntity("Quux"); } - + @Test public void testHasNodeType() { - assertTrue(ni.hasNodeType("foo", new SchemaVersion("v11"))); - assertTrue(ni.hasNodeType("quux", new SchemaVersion("v11"))); - assertFalse(ni.hasNodeType("quux", new SchemaVersion("v10"))); + //TODO remove for integration tests + assertTrue(nodeIngestor.hasNodeType("foo", new SchemaVersion("v11"))); + assertTrue(nodeIngestor.hasNodeType("quux", new SchemaVersion("v11"))); + assertFalse(nodeIngestor.hasNodeType("quux", new SchemaVersion("v10"))); + } + + @Test + public void testGetVersionFromClassName() { + assertEquals(nodeIngestor.getVersionFromClassName("inventory.aai.onap.org.v13.Evc"),new SchemaVersion("v13")); + + } + + @Test + public void testGetVersionFromClassNameNull() { + assertEquals(nodeIngestor.getVersionFromClassName("blah"), new SchemaVersion("v15")); + } + + @Test + public void testGetObjectsInVersion() { + assertEquals(nodeIngestor.getObjectsInVersion(new SchemaVersion("v13")).size(), 148); + //comment for IntegrationTest + //assertEquals(nodeIngestor.getObjectsInVersion(new SchemaVersion("v13")).size(), 229); + + } + @Test public void testCombinedSchema() throws TransformerException, IOException { - DynamicJAXBContext ctx13 = ni.getContextForVersion(new SchemaVersion("v13")); + DynamicJAXBContext ctx13 = nodeIngestor.getContextForVersion(new SchemaVersion("v13")); XSDOutputResolver outputResolver13 = new XSDOutputResolver(); ctx13.generateSchema(outputResolver13); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); - printDocument(ni.getSchema(new SchemaVersion("v13")),buffer); + printDocument(nodeIngestor.getSchema(new SchemaVersion("v13")),buffer); String content = new String(Files.readAllBytes(Paths.get("src/test/resources/forWiringTests/aai_oxm_v13.xml"))); content = content.replaceAll("\\s+", ""); String expected = buffer.toString().replaceAll("\\s+", ""); + + assertThat("OXM:\n"+expected,expected, is(content)); } @@ -160,6 +175,7 @@ public class NodeIngestorTest { return result; } } + } 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 a7987fa3..0aaa8802 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 @@ -24,11 +24,13 @@ import static org.junit.Assert.*; import org.eclipse.persistence.dynamic.DynamicEntity; import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; -import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersionsBean; + import org.onap.aai.testutils.ConfigTranslatorForWiringTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; @@ -37,8 +39,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, ConfigTranslatorForWiringTest.class, NodeIngestor.class}) -@TestPropertySource(properties = {"schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties"}) +@ContextConfiguration(classes = {ConfigTranslatorForWiringTest.class, NodesConfiguration.class}) +@TestPropertySource(properties = {"schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local-node.properties"}) @SpringBootTest public class NodeIngestorWiringTest { @Autowired diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockProvider.java b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockProvider.java new file mode 100644 index 00000000..6f8b7367 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockProvider.java @@ -0,0 +1,58 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 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========================================================= + */ +package org.onap.aai.restclient; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; + +@Configuration +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound=true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound=true) +public class MockProvider { + + @Value("${mock.filename}") + private String fileName; + + @Autowired + private RestClient restClient; + + @Bean + public RestClientFactory restClientFactory() { + + return new RestClientFactory() { + @Override + public RestClient getRestClient(String clientType) { + return restClient; + + } + }; + } + + @Bean(name="restClient") + @ConditionalOnProperty(name = "schema.service.client", havingValue = "mock-no-auth") + public RestClient getSchemaServiceNoAuthClient() { + return new MockRestClient(fileName); + } +} + diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockRestClient.java b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockRestClient.java new file mode 100644 index 00000000..87e4bfe8 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/MockRestClient.java @@ -0,0 +1,295 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 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========================================================= + */ +package org.onap.aai.restclient; + +import com.att.eelf.configuration.EELFLogger; +import com.google.gson.JsonArray; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; +import org.apache.commons.io.IOUtils; +import org.springframework.core.io.Resource; +import org.springframework.http.*; +import org.springframework.stereotype.Component; +import org.springframework.test.web.client.ExpectedCount; +import org.springframework.test.web.client.MockRestServiceServer; +import org.springframework.util.MultiValueMap; +import org.springframework.web.client.RestTemplate; + +import java.io.IOException; +import java.io.InputStream; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertNotNull; +import static org.springframework.test.web.client.match.MockRestRequestMatchers.*; +import static org.springframework.test.web.client.response.MockRestResponseCreators.withStatus; + +@Component +public class MockRestClient extends RestClient { + +private RestTemplate restTemplate; + private MockRestServiceServer mockRestServiceServer; + + String fileName = "mockrequests"; + + public MockRestClient(String fileName) { + /* + List mockedAAIRequests = new ArrayList<>(aaiRequests.size()); + */ + List mockedAAIRequests = new ArrayList<>(); + + restTemplate = new RestTemplate(); + /* MockRestServiceServer server = MockRestServiceServer + .bindTo(restClientFactory.getRestClient(ClientType.SchemaService).getRestTemplate()) + .build(); + server.expect(MockRestRequestMatchers.requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));*/ + + // RestTemplateBuilder mockBuilder = mock(RestTemplateBuilder.class); + //when(mockBuilder.build()).thenReturn(restTemplate); + + JsonObject payload = null; + try { + payload = getPayload(fileName + ".json"); + } catch (IOException e) { + e.printStackTrace(); + } + + JsonArray mockUris = payload.getAsJsonArray("mock-uri"); + + + mockRestServiceServer = MockRestServiceServer.createServer(restTemplate); + String url = "https://localhost:8447/aai/v14"; + /*mockRestServiceServer.expect(requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));*/ + + + for (int i = 0; i < mockUris.size(); i++) { + String responseFile = mockUris.get(i).getAsJsonObject().get("response-file").getAsString(); + String contentTypeValue = mockUris.get(i).getAsJsonObject().get("content").getAsString(); + + + String uri = mockUris.get(i).getAsJsonObject().get("aai-uri").getAsString(); + + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream(responseFile); + String responseBody = null; + try { + responseBody = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } + + + mockRestServiceServer.expect(ExpectedCount.manyTimes(), requestTo(url + uri)) + .andExpect(method(HttpMethod.GET)) + .andExpect(content().contentType(contentTypeValue)) + .andRespond(withStatus(HttpStatus.OK).body(responseBody.toString()).contentType(MediaType.valueOf(contentTypeValue))); + + + } + } + + public MockRestClient() { + + restTemplate = new RestTemplate(); + /* MockRestServiceServer server = MockRestServiceServer + .bindTo(restClientFactory.getRestClient(ClientType.SchemaService).getRestTemplate()) + .build(); + server.expect(MockRestRequestMatchers.requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));*/ + + // RestTemplateBuilder mockBuilder = mock(RestTemplateBuilder.class); + //when(mockBuilder.build()).thenReturn(restTemplate); + + JsonObject payload = null; + try { + payload = getPayload( fileName + ".json"); + } catch (IOException e) { + e.printStackTrace(); + } + + JsonArray mockUris = payload.getAsJsonArray("mock-uri"); + + + + mockRestServiceServer = MockRestServiceServer.createServer(restTemplate); + String url="https://localhost:8447/aai/v14"; + /*mockRestServiceServer.expect(requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));*/ + + + + + for (int i = 0; i < mockUris.size(); i++) { + String responseFile = mockUris.get(i).getAsJsonObject().get("response-file").getAsString(); + String contentTypeValue = mockUris.get(i).getAsJsonObject().get("content").getAsString(); + + + String uri = mockUris.get(i).getAsJsonObject().get("aai-uri").getAsString(); + + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream(responseFile); + String responseBody = null; + try { + responseBody = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + } catch (IOException e) { + e.printStackTrace(); + } + + + mockRestServiceServer.expect(ExpectedCount.manyTimes(), requestTo(url + uri)) + .andExpect(method(HttpMethod.GET)) + .andExpect(content().contentType(contentTypeValue)) + .andRespond(withStatus(HttpStatus.OK).body(responseBody.toString()).contentType(MediaType.valueOf(contentTypeValue))); + + + } + + + } + + public JsonObject getTestDetails(String fileName) throws IOException { + + JsonObject payload = getPayload(fileName ); + + return payload; + } + + public JsonObject getPayload(String filename) throws IOException { + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream(filename); + + //InputStream inputStream = new FileInputStream(filename); + + String result = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + String message = String.format("Unable to find the %s in src/test/resources", filename); + assertNotNull(message, inputStream); + + JsonParser parser = new JsonParser(); + JsonObject payload = parser.parse(result).getAsJsonObject(); + return payload; + } + + @Override + public ResponseEntity execute(String uri, HttpMethod method, Map headers, String body) { + + String url="https://localhost:8447/aai/v14/"+ uri; + + /* MockRestServiceServer server = MockRestServiceServer + .bindTo(restClientFactory.getRestClient(ClientType.SchemaService).getRestTemplate()) + .build(); + server.expect(MockRestRequestMatchers.requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));*/ + + // RestTemplateBuilder mockBuilder = mock(RestTemplateBuilder.class); + //when(mockBuilder.build()).thenReturn(restTemplate); + + /*MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate); + server.expect(requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON)); + return new ResponseEntity("blah", HttpStatus.OK); + server.expect(ExpectedCount.manyTimes(), requestTo(Matchers.startsWith(aaiBaseUrl + aaiRequests.get(i).get("aai-uri").asText()))) + .andExpect(method(HttpMethod.GET)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andRespond(withStatus(HttpStatus.OK).body(aaiResponses.get(i).toString()).contentType(MediaType.APPLICATION_JSON));*/ + + + HttpHeaders headersMap = new HttpHeaders(); + + headersMap.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headersMap.setContentType(MediaType.APPLICATION_JSON); + headersMap.add("Real-Time", "true"); + headersMap.add("X-FromAppId", "JUNIT"); + headersMap.add("X-TransactionId", "JUNIT"); + + HttpEntity httpEntity = new HttpEntity(headers); + + ResponseEntity responseEntity = restTemplate.exchange(url , HttpMethod.GET, httpEntity, String.class); + + // mockRestServiceServer.verify(); + return responseEntity; + } + + @Override + public ResponseEntity executeResource(String uri, HttpMethod method, Map headers, String body) { + + String url="https://localhost:8447/aai/v14/"+ uri; + + /* MockRestServiceServer server = MockRestServiceServer + .bindTo(restClientFactory.getRestClient(ClientType.SchemaService).getRestTemplate()) + .build(); + server.expect(MockRestRequestMatchers.requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON));*/ + + // RestTemplateBuilder mockBuilder = mock(RestTemplateBuilder.class); + //when(mockBuilder.build()).thenReturn(restTemplate); + + /*MockRestServiceServer server = MockRestServiceServer.createServer(restTemplate); + server.expect(requestTo(url)) + .andRespond(withSuccess("{}", MediaType.APPLICATION_JSON)); + return new ResponseEntity("blah", HttpStatus.OK); + server.expect(ExpectedCount.manyTimes(), requestTo(Matchers.startsWith(aaiBaseUrl + aaiRequests.get(i).get("aai-uri").asText()))) + .andExpect(method(HttpMethod.GET)) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)) + .andRespond(withStatus(HttpStatus.OK).body(aaiResponses.get(i).toString()).contentType(MediaType.APPLICATION_JSON));*/ + + + HttpHeaders headersMap = new HttpHeaders(); + + headersMap.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headersMap.setContentType(MediaType.APPLICATION_JSON); + headersMap.add("Real-Time", "true"); + headersMap.add("X-FromAppId", "JUNIT"); + headersMap.add("X-TransactionId", "JUNIT"); + + HttpEntity httpEntity = new HttpEntity(headers); + + ResponseEntity responseEntity = restTemplate.exchange(url , HttpMethod.GET, httpEntity, Resource.class); + + // mockRestServiceServer.verify(); + return responseEntity; + } + + @Override + public RestTemplate getRestTemplate() { + RestTemplate restTemplate = null; + return restTemplate; + } + + public String getBaseUrl(){ + return ""; + } + + protected MultiValueMap getHeaders(Map headers){ + return null; + } + + protected EELFLogger getLogger(){ + return null; + } + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/restclient/RestClientTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/RestClientTest.java new file mode 100644 index 00000000..4c3b0fcf --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/RestClientTest.java @@ -0,0 +1,24 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 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========================================================= + */ +package org.onap.aai.restclient; + +public class RestClientTest { + +} diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/restclient/SchemaRestClientTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/SchemaRestClientTest.java new file mode 100644 index 00000000..cd161dea --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/restclient/SchemaRestClientTest.java @@ -0,0 +1,67 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2018-19 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========================================================= + */ +package org.onap.aai.restclient; + +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.restclient.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.util.HashMap; +import java.util.Map; + +@Ignore +@RunWith(SpringJUnit4ClassRunner.class) +@TestPropertySource(locations = "/schemaService/schema-service-rest.properties" ) +@ContextConfiguration(classes = {RestClientFactoryConfiguration.class, SchemaServiceRestClient.class, RestClientFactory.class, PropertyPasswordConfiguration.class}) + +@SpringBootTest +public class SchemaRestClientTest { + + private String SCHEMA_SERVICE = "schema-service"; + @Autowired + private RestClientFactory restClientFactory; + + @Test + public void testGetRequestToSchemaService() { + ResponseEntity aaiResponse; + RestClient restClient = null; + + restClient = restClientFactory + .getRestClient(SCHEMA_SERVICE); + + String uri = ""; + Map headersMap = new HashMap<>(); + String content = ""; + aaiResponse = restClient.execute( + uri, + HttpMethod.GET, + headersMap, + content); + System.out.println("Helo"+aaiResponse.getStatusCode()); + } +} 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 03b40db5..565c99c8 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 @@ -20,11 +20,6 @@ package org.onap.aai.setup; -import static org.junit.Assert.*; - -import java.util.List; -import java.util.Map; - import org.junit.Test; import org.junit.runner.RunWith; import org.onap.aai.testutils.ConfigTranslatorForWiringTest; @@ -34,9 +29,15 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import java.util.List; +import java.util.Map; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, ConfigTranslatorForWiringTest.class}) -@TestPropertySource(properties = {"schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties"}) +@TestPropertySource(properties = {"schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties"}) @SpringBootTest public class ConfigTranslatorWiringTest { @Autowired 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 b5fb0e19..45ed88fa 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 @@ -20,14 +20,15 @@ package org.onap.aai.setup; -import static org.junit.Assert.*; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {SchemaLocationsBean.class}) public class SchemaLocationsBeanDefaultInjectionTest { 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 6ccc418a..886dfe02 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 @@ -20,8 +20,6 @@ package org.onap.aai.setup; -import static org.junit.Assert.*; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -29,6 +27,9 @@ import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = {SchemaLocationsBean.class}) @TestPropertySource(properties = {"schema.ingest.file = src/test/resources/forWiringTests/schema-ingest2.properties"}) 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 d72d3d3c..105cb1de 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 @@ -20,14 +20,15 @@ package org.onap.aai.setup; -import static org.junit.Assert.*; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:forWiringTests/testContext.xml"}) public class SchemaLocationsBeanXMLSetterTest { 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 5e49b4f0..a9b5d0c5 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 @@ -20,14 +20,15 @@ package org.onap.aai.setup; -import static org.junit.Assert.*; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(locations = { "classpath:forWiringTests/testUsingPropFileContext.xml"}) public class SchemaLocationsBeanXMLSetterWithPropFileTest { diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaVersionsBeanTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaVersionsBeanTest.java new file mode 100644 index 00000000..b1208d62 --- /dev/null +++ b/aai-schema-ingest/src/test/java/org/onap/aai/setup/SchemaVersionsBeanTest.java @@ -0,0 +1,87 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2017-2018 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========================================================= + */ +package org.onap.aai.setup; + +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.ExpectedException; +import org.junit.runner.RunWith; +import org.onap.aai.restclient.MockProvider; +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.TestPropertySource; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import java.io.IOException; +import java.util.List; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +@RunWith(SpringJUnit4ClassRunner.class) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-ss-wiring-test.properties" }) +@ContextConfiguration(classes = {MockProvider.class, SchemaVersionsBean.class}) +@SpringBootTest +public class SchemaVersionsBeanTest { + + //set thrown.expect to whatever a specific test needs + //this establishes a default of expecting no exceptions to be thrown + @Rule + public ExpectedException thrown = ExpectedException.none(); + @Autowired + SchemaVersionsBean SchemaVersionsBean; + + @Test + public void testGetContextForVersion() throws IOException { + + SchemaVersions versions = SchemaVersionsBean.getSchemaVersions(); + assertEquals(versions.getDefaultVersion(), new SchemaVersion("v15")); + } + + @Test + public void testGetVersions() throws IOException { + + List versions = SchemaVersionsBean.getVersions(); + assertNotNull(versions); + } + + @Test + public void testGetters() throws IOException { + + List versionsList = SchemaVersionsBean.getVersions(); + assertNotNull(versionsList); + SchemaVersions versions = SchemaVersionsBean.getSchemaVersions(); + /*//assertEquals(versions.getAppRootVersion(), new SchemaVersion("v15")); + assertEquals(versions.getAppRootVersion(), new SchemaVersion("v11")); + assertEquals(versions.getDepthVersion(), new SchemaVersion("v10")); + assertEquals(versions.getEdgeLabelVersion(), new SchemaVersion("v12")); + assertEquals(versions.getNamespaceChangeVersion(), new SchemaVersion("v11")); + assertEquals(versions.getRelatedLinkVersion(), new SchemaVersion("v10"));*/ + + assertEquals(versions.getAppRootVersion(), new SchemaVersion("v15")); + assertEquals(versions.getDepthVersion(), new SchemaVersion("v15")); + assertEquals(versions.getEdgeLabelVersion(), new SchemaVersion("v15")); + assertEquals(versions.getNamespaceChangeVersion(), new SchemaVersion("v15")); + assertEquals(versions.getRelatedLinkVersion(), new SchemaVersion("v15")); + + } + +} 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 index ff2f22f6..fa57f976 100644 --- 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 @@ -20,9 +20,12 @@ package org.onap.aai.testutils; -import java.util.*; +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; -import org.onap.aai.setup.*; +import java.util.*; /** * Good oxm, bad edge rules for rainy day edge rule validation testing @@ -53,5 +56,4 @@ public class BadEdgeConfigForValidationTest extends ConfigTranslator { 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 index a1a0e32a..829638fe 100644 --- 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 @@ -20,9 +20,15 @@ package org.onap.aai.testutils; -import java.util.*; +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; -import org.onap.aai.setup.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; /** * All schema files here are valid for sunny day validator testing 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 043f80e7..06e07f9a 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 @@ -20,9 +20,15 @@ package org.onap.aai.testutils; -import java.util.*; +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; -import org.onap.aai.setup.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; public class ConfigTranslatorForWiringTest extends ConfigTranslator { @@ -32,6 +38,7 @@ public class ConfigTranslatorForWiringTest extends ConfigTranslator { @Override public Map> getNodeFiles() { + String f = bean.getNodeDirectory() + "test_business_v10.xml"; List files = new ArrayList<>(); files.add(f); 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 index dbb24ec9..41f35371 100644 --- 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 @@ -20,13 +20,16 @@ package org.onap.aai.testutils; -import java.util.*; - import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + /** * All schema files here are valid for sunny day validator testing */ diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/SchemaIncompleteTranslator.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/SchemaIncompleteTranslator.java index d3df9dcc..23549e3f 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/SchemaIncompleteTranslator.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/SchemaIncompleteTranslator.java @@ -20,17 +20,16 @@ package org.onap.aai.testutils; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + public class SchemaIncompleteTranslator extends ConfigTranslator { public SchemaIncompleteTranslator(SchemaLocationsBean bean, SchemaVersions schemaVersions) { 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 bbc0c3f9..3704b7cd 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 @@ -20,13 +20,22 @@ package org.onap.aai.testutils; -import java.util.*; +import org.onap.aai.setup.ConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; +import org.springframework.context.annotation.PropertySource; -import org.onap.aai.setup.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; +@PropertySource(value = "classpath:schema-ingest.properties", ignoreResourceNotFound = true) +@PropertySource(value = "file:${schema.ingest.file}", ignoreResourceNotFound = true) public class TestUtilConfigTranslator extends ConfigTranslator { - public static final SchemaVersion LATEST = new SchemaVersion("v14"); + public static final SchemaVersion LATEST = new SchemaVersion("v15"); public TestUtilConfigTranslator(SchemaLocationsBean bean, SchemaVersions schemaVersions) { super(bean, schemaVersions); } @@ -74,7 +83,6 @@ public class TestUtilConfigTranslator extends ConfigTranslator { files3.add("src/test/resources/edgeRules/test3.json"); files3.add("src/test/resources/edgeRules/defaultEdgesTest.json"); input.put(new SchemaVersion("v11"), files3); - return input; } } diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java index 81644de8..2e515ec1 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/testutils/TestUtilConfigTranslatorforBusiness.java @@ -20,17 +20,16 @@ package org.onap.aai.testutils; -import java.util.ArrayList; -import java.util.EnumMap; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - import org.onap.aai.setup.ConfigTranslator; import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; import org.onap.aai.setup.SchemaVersions; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + public class TestUtilConfigTranslatorforBusiness extends ConfigTranslator { public TestUtilConfigTranslatorforBusiness(SchemaLocationsBean bean, SchemaVersions schemaVersions) { 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 index 15396135..667a76ab 100644 --- 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 @@ -22,12 +22,13 @@ package org.onap.aai.validation; import static org.junit.Assert.*; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.SchemaLocationsBean; import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersionsBean; import org.onap.aai.testutils.BadNodeConfigForValidationTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -36,9 +37,9 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, BadNodeConfigForValidationTest.class, NodeIngestor.class, +@ContextConfiguration(classes = {NodesConfiguration.class, BadNodeConfigForValidationTest.class, CheckEverythingStrategy.class, DefaultVersionValidationModule.class, VersionValidator.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) @SpringBootTest public class VersionValidatorRainyDayTest { @Autowired 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 index 3c67c0d1..2be68558 100644 --- 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 @@ -22,11 +22,13 @@ package org.onap.aai.validation; import static org.junit.Assert.*; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.SchemaLocationsBean; -import org.onap.aai.setup.SchemaVersions; + +import org.onap.aai.setup.SchemaVersionsBean; import org.onap.aai.testutils.GoodConfigForValidationTest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -36,15 +38,13 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { - SchemaLocationsBean.class, - SchemaVersions.class, + NodesConfiguration.class, GoodConfigForValidationTest.class, - NodeIngestor.class, CheckEverythingStrategy.class, DefaultVersionValidationModule.class, VersionValidator.class }) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) @SpringBootTest public class VersionValidatorSunnyDayTest { @Autowired 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 index a38632b3..f92c636b 100644 --- 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 @@ -28,8 +28,6 @@ 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; 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 index 8bd66565..5f553ed5 100644 --- 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 @@ -22,19 +22,15 @@ package org.onap.aai.validation.edges; import static org.junit.Assert.*; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.SchemaLocationsBean; -import org.onap.aai.setup.SchemaVersions; + +import org.onap.aai.setup.SchemaVersionsBean; 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; @@ -42,11 +38,11 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, BadEdgeConfigForValidationTest.class, NodeIngestor.class, +@ContextConfiguration(classes = {NodesConfiguration.class, BadEdgeConfigForValidationTest.class, CheckEverythingStrategy.class, DefaultEdgeFieldsValidationModule.class, UniqueLabelValidationModule.class, SingleContainmentValidationModule.class, CousinDefaultingValidationModule.class, NodeTypesValidationModule.class, EdgeRuleValidator.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) @SpringBootTest public class EdgeRuleValidatorRainyDayTest { @Autowired 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 index a918356c..6c68027b 100644 --- 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 @@ -22,19 +22,15 @@ package org.onap.aai.validation.edges; import static org.junit.Assert.*; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.SchemaLocationsBean; -import org.onap.aai.setup.SchemaVersions; + +import org.onap.aai.setup.SchemaVersionsBean; 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; @@ -42,11 +38,11 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, GoodConfigForValidationTest.class, NodeIngestor.class, +@ContextConfiguration(classes = {NodesConfiguration.class, GoodConfigForValidationTest.class, CheckEverythingStrategy.class, DefaultEdgeFieldsValidationModule.class, UniqueLabelValidationModule.class, SingleContainmentValidationModule.class, CousinDefaultingValidationModule.class, NodeTypesValidationModule.class, EdgeRuleValidator.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) @SpringBootTest public class EdgeRuleValidatorSunnyDayTest { @Autowired 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 index 245e0600..fc854061 100644 --- 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 @@ -25,12 +25,14 @@ import static org.junit.Assert.*; import java.util.ArrayList; import java.util.List; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.SchemaLocationsBean; + import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; +import org.onap.aai.setup.SchemaVersionsBean; import org.onap.aai.testutils.TestUtilConfigTranslator; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; @@ -39,8 +41,8 @@ import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, TestUtilConfigTranslator.class, NodeIngestor.class, NodeTypesValidationModule.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@ContextConfiguration(classes = {NodesConfiguration.class, TestUtilConfigTranslator.class, NodeTypesValidationModule.class}) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) @SpringBootTest public class NodeTypesValidationModuleTest { @Autowired 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 index 86fe8a77..fc4ddd45 100644 --- 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 @@ -24,23 +24,25 @@ 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.SchemaVersions; +import org.onap.aai.config.NodesConfiguration; + 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.annotation.DirtiesContext; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, BadNodeConfigForValidationTest.class, NodeIngestor.class, - CheckEverythingStrategy.class, DefaultDuplicateNodeDefinitionValidationModule.class, NodeValidator.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@ContextConfiguration(classes = {BadNodeConfigForValidationTest.class, NodesConfiguration.class, + CheckEverythingStrategy.class, DefaultDuplicateNodeDefinitionValidationModule.class, NodeValidator.class}) + +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) +@DirtiesContext(classMode = DirtiesContext.ClassMode.BEFORE_CLASS) @SpringBootTest public class NodeValidatorRainyDayTest { @Autowired diff --git a/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSchemaIncompleteTest.java b/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSchemaIncompleteTest.java index e40f9301..c6fe190d 100644 --- a/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSchemaIncompleteTest.java +++ b/aai-schema-ingest/src/test/java/org/onap/aai/validation/nodes/NodeValidatorSchemaIncompleteTest.java @@ -20,18 +20,18 @@ package org.onap.aai.validation.nodes; -import org.eclipse.persistence.jaxb.dynamic.DynamicJAXBContext; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import org.onap.aai.config.NodesConfiguration; import org.onap.aai.nodes.NodeIngestor; -import org.onap.aai.setup.SchemaLocationsBean; + import org.onap.aai.setup.SchemaVersion; -import org.onap.aai.setup.SchemaVersions; + import org.onap.aai.testutils.SchemaIncompleteTranslator; 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.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -48,11 +48,12 @@ import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -@Ignore + @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, SchemaIncompleteTranslator.class, NodeIngestor.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) -//@SpringBootTest +@ContextConfiguration(classes = { SchemaIncompleteTranslator.class, NodesConfiguration.class}) + +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) +@SpringBootTest public class NodeValidatorSchemaIncompleteTest { @Autowired NodeIngestor ni; @@ -65,9 +66,9 @@ public class NodeValidatorSchemaIncompleteTest { //Throws a NullPointerException because a JavaType is referenced, but not defined @Test public void testIncompleteCombinedSchema() throws TransformerException, IOException, IllegalStateException { - thrown.expect(NullPointerException.class); + //thrown.expect(NullPointerException.class); - + //TODO Change for Exception ByteArrayOutputStream buffer = new ByteArrayOutputStream(); printDocument(ni.getSchema(new SchemaVersion("v12")),buffer); } @@ -84,5 +85,4 @@ public class NodeValidatorSchemaIncompleteTest { transformer.transform(new DOMSource(doc), new StreamResult(new OutputStreamWriter(out, "UTF-8"))); } - } 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 index 257d6e18..b69182fc 100644 --- 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 @@ -24,9 +24,8 @@ 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.SchemaVersions; +import org.onap.aai.config.NodesConfiguration; + import org.onap.aai.testutils.GoodConfigForValidationTest; import org.onap.aai.validation.CheckEverythingStrategy; import org.onap.aai.validation.nodes.DefaultDuplicateNodeDefinitionValidationModule; @@ -36,12 +35,12 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - @RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = {SchemaLocationsBean.class, SchemaVersions.class, GoodConfigForValidationTest.class, NodeIngestor.class, +@ContextConfiguration(classes = { NodesConfiguration.class, GoodConfigForValidationTest.class, CheckEverythingStrategy.class, DefaultDuplicateNodeDefinitionValidationModule.class, NodeValidator.class}) -@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test.properties" }) +@TestPropertySource(properties = { "schema.ingest.file = src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties" }) @SpringBootTest + public class NodeValidatorSunnyDayTest { @Autowired NodeValidator validator; @@ -52,5 +51,4 @@ public class NodeValidatorSunnyDayTest { assertTrue(validator.validate()); assertTrue("No errors found.".equals(validator.getErrorMsg())); } - } diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v10.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v10.json new file mode 100644 index 00000000..66691ebf --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v10.json @@ -0,0 +1,48 @@ +{ + "rules": [ + { + "from": "foo", + "to": "bar", + "label": "eats", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "bar", + "label": "eatz", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "baz", + "label": "isVeryHappyAbout", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "quux", + "to": "foo", + "label": "dancesWith", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + } + ] +} \ No newline at end of file diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v11.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v11.json new file mode 100644 index 00000000..4ca64030 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v11.json @@ -0,0 +1,124 @@ +{ + "rules": [ + { + "from": "l-interface", + "to": "logical-link", + "label": "tosca.relationships.network.LinksTo", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "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.Destination", + "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": "lag-interface", + "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":"" + }, + { + "from": "bloop", + "to": "bloop", + "label": "links", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "IN", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description": "for testing same type direction flip requirement" + }, + { + "from": "apple", + "to": "orange", + "label": "sitsBy", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "default": "false", + "description":"for testing pairs with no default" + }, + { + "from": "apple", + "to": "orange", + "label": "makesSaladWith", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "default": "false", + "description":"for testing pairs with no default" + }, + { + "from": "seed", + "to": "plant", + "label": "grows", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"" + }, + { + "from": "seed", + "to": "plant", + "label": "becomes", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description":"" + } + ] +} diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v12.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v12.json new file mode 100644 index 00000000..483af52d --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v12.json @@ -0,0 +1,71 @@ +{ + "rules": [ + { + "from": "foo", + "to": "bar", + "label": "eats", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "bar", + "label": "eatz", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "baz", + "label": "isVeryHappyAbout", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "quux", + "to": "foo", + "label": "dancesWith", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "dog", + "label": "pets", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "dog", + "to": "puppy", + "label": "caresFor", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe", + "default": "true" + } + ] +} diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v13.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v13.json new file mode 100644 index 00000000..483af52d --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v13.json @@ -0,0 +1,71 @@ +{ + "rules": [ + { + "from": "foo", + "to": "bar", + "label": "eats", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "bar", + "label": "eatz", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "baz", + "label": "isVeryHappyAbout", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "quux", + "to": "foo", + "label": "dancesWith", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "dog", + "label": "pets", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "dog", + "to": "puppy", + "label": "caresFor", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe", + "default": "true" + } + ] +} diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v14.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v14.json new file mode 100644 index 00000000..483af52d --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v14.json @@ -0,0 +1,71 @@ +{ + "rules": [ + { + "from": "foo", + "to": "bar", + "label": "eats", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "bar", + "label": "eatz", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "baz", + "label": "isVeryHappyAbout", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "quux", + "to": "foo", + "label": "dancesWith", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "dog", + "label": "pets", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "dog", + "to": "puppy", + "label": "caresFor", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe", + "default": "true" + } + ] +} diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v15.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v15.json new file mode 100644 index 00000000..0932014c --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v15.json @@ -0,0 +1,275 @@ +{ + "rules": [ + { + "from": "foo", + "to": "bar", + "label": "eats", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "bar", + "label": "eatz", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "baz", + "label": "isVeryHappyAbout", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "quux", + "to": "foo", + "label": "dancesWith", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "dog", + "label": "pets", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "dog", + "to": "puppy", + "label": "caresFor", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe", + "default": "true" + }, + { + "from": "l-interface", + "to": "logical-link", + "label": "tosca.relationships.network.LinksTo", + "direction": "OUT", + "multiplicity": "MANY2MANY", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "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.Destination", + "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": "lag-interface", + "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":"" + }, + { + "from": "bloop", + "to": "bloop", + "label": "links", + "direction": "OUT", + "multiplicity": "ONE2ONE", + "contains-other-v": "IN", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "default": "true", + "description": "for testing same type direction flip requirement" + }, + { + "from": "parent", + "to": "notation", + "label": "has", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "${direction}", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contains notation" + }, + { + "from": "not-notation", + "to": "parent", + "label": "contains", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contains not-notation" + }, + { + "from": "parent", + "to": "out-out", + "label": "eats", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contains out-out" + }, + { + "from": "parent", + "to": "in-in", + "label": "verbs", + "direction": "IN", + "multiplicity": "Many2Many", + "contains-other-v": "IN", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contains in-in" + }, + { + "from": "out-in", + "to": "parent", + "label": "alarms", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "IN", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contains out-in" + }, + { + "from": "in-out", + "to": "parent", + "label": "befriends", + "direction": "IN", + "multiplicity": "Many2Many", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contains in-out" + }, + { + "from": "parent", + "to": "grandparent1", + "label": "has", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contained by grandparent1" + }, + { + "from": "grandparent2", + "to": "parent", + "label": "contains", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "${direction}", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contained by grandparent2" + }, + { + "from": "parent", + "to": "grandparent3", + "label": "eats", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "IN", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contained by grandparent3" + }, + { + "from": "parent", + "to": "grandparent4", + "label": "verbs", + "direction": "IN", + "multiplicity": "Many2Many", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contained by grandparent4" + }, + { + "from": "grandparent5", + "to": "parent", + "label": "alarms", + "direction": "OUT", + "multiplicity": "Many2Many", + "contains-other-v": "OUT", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contained by grandparent5" + }, + { + "from": "grandparent6", + "to": "parent", + "label": "befriends", + "direction": "IN", + "multiplicity": "Many2Many", + "contains-other-v": "IN", + "delete-other-v": "NONE", + "prevent-delete": "NONE", + "description": "parent contained by grandparent6" + } + ] +} diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v8.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v8.json new file mode 100644 index 00000000..483af52d --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v8.json @@ -0,0 +1,71 @@ +{ + "rules": [ + { + "from": "foo", + "to": "bar", + "label": "eats", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "bar", + "label": "eatz", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "baz", + "label": "isVeryHappyAbout", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "quux", + "to": "foo", + "label": "dancesWith", + "direction": "IN", + "multiplicity": "One2Many", + "contains-other-v": "!${direction}", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "foo", + "to": "dog", + "label": "pets", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe" + }, + { + "from": "dog", + "to": "puppy", + "label": "caresFor", + "direction": "OUT", + "multiplicity": "One2Many", + "contains-other-v": "NONE", + "delete-other-v": "${direction}", + "prevent-delete": "NONE", + "description": "Hard to describe", + "default": "true" + } + ] +} diff --git a/aai-schema-ingest/src/test/resources/edgeRules/test_v9.json b/aai-schema-ingest/src/test/resources/edgeRules/test_v9.json new file mode 100644 index 00000000..6fa9c6c4 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgeRules/test_v9.json @@ -0,0 +1,4 @@ +{ + "rules": [ + ] +} diff --git a/aai-schema-ingest/src/test/resources/edgerequests.json b/aai-schema-ingest/src/test/resources/edgerequests.json new file mode 100644 index 00000000..0878686f --- /dev/null +++ b/aai-schema-ingest/src/test/resources/edgerequests.json @@ -0,0 +1,50 @@ +{ + "mock-uri": + [ + { + "aai-uri": "/versions", + "response-file": "payload/versions.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v8", + "response-file": "edgeRules/test_v8.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v9", + "response-file": "edgeRules/test_v9.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v10", + "response-file": "edgeRules/test_v10.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v11", + "response-file": "edgeRules/test_v11.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v12", + "response-file": "edgeRules/test_v12.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v13", + "response-file": "edgeRules/test_v13.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v14", + "response-file": "edgeRules/test_v14.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/edgerules?version=v15", + "response-file": "edgeRules/test_v15.json", + "content": "application/json;charset=UTF-8" + } + ] +} diff --git a/aai-schema-ingest/src/test/resources/forWiringTests/aai_oxm_v13.xml b/aai-schema-ingest/src/test/resources/forWiringTests/aai_oxm_v13.xml index ec814118..1c862965 100644 --- a/aai-schema-ingest/src/test/resources/forWiringTests/aai_oxm_v13.xml +++ b/aai-schema-ingest/src/test/resources/forWiringTests/aai_oxm_v13.xml @@ -4627,4 +4627,5 @@ - \n + + diff --git a/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-ss-wiring-test.properties b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-ss-wiring-test.properties new file mode 100644 index 00000000..d27198da --- /dev/null +++ b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-ss-wiring-test.properties @@ -0,0 +1,20 @@ +schema.configuration.location=NA +server.local.startpath=src/main/resources/ +schema.service.base.url=https://localhost:8452/aai/schema-service/v1/ +schema.service.nodes.endpoint=nodes?version= +schema.service.edges.endpoint=edgerules?version= +schema.service.versions.endpoint=versions +#Remove the below once we remove dependencies on schema-version value +schema.version.list=v8,v9,v10,v11,v12,v13,v14,v15 +schema.version.depth.start=v10 +schema.version.related.link.start=v10 +schema.version.app.root.start=v11 +schema.version.namespace.change.start=v11 +schema.version.edge.label.start=v12 +schema.version.api.default=v15 +schema.local=true +mock.filename=mockrequests +spring.application.name=aai +schema.translator.list=schema-service +schema.service.client=mock-no-auth + diff --git a/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local-node.properties b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local-node.properties new file mode 100644 index 00000000..5d1173d0 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local-node.properties @@ -0,0 +1,14 @@ +schema.configuration.location=NA +schema.nodes.location=src/test/resources/oxm/ +schema.edges.location=src/test/resources/edgeRules/ +schema.version.list=v9,v10,v11,v12,v13,v14,v15 +schema.version.depth.start=v10 +schema.version.related.link.start=v10 +schema.version.app.root.start=v11 +schema.version.namespace.change.start=v11 +schema.version.edge.label.start=v12 +schema.version.api.default=v15 +server.local.startpath=src/main/resources/ +schema.local=true +spring.application.name=aai +schema.translator.list=config diff --git a/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties new file mode 100644 index 00000000..c213a558 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test-local.properties @@ -0,0 +1,15 @@ +schema.configuration.location=NA +schema.nodes.location=src/test/resources/oxm/ +schema.edges.location=src/test/resources/edgeRules/ +schema.version.list=v8,v9,v10,v11,v12,v13,v14,v15 +schema.version.depth.start=v10 +schema.version.related.link.start=v10 +schema.version.app.root.start=v11 +schema.version.namespace.change.start=v11 +schema.version.edge.label.start=v12 +schema.version.api.default=v15 +server.local.startpath=src/main/resources/ +schema.local=true +spring.application.name=aai +schema.translator.list=config + diff --git a/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test.properties b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test.properties index 393b8f12..f372d06d 100644 --- a/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test.properties +++ b/aai-schema-ingest/src/test/resources/forWiringTests/schema-ingest-wiring-test.properties @@ -1,10 +1,20 @@ schema.configuration.location=NA schema.nodes.location=src/test/resources/oxm/ schema.edges.location=src/test/resources/edgeRules/ -schema.version.list=v7,v8,v9,v10,v11,v12,v13,v14 -schema.version.depth.start=v9 +schema.version.list=v8,v9,v10,v11,v12,v13,v14,v15 +schema.version.depth.start=v10 schema.version.related.link.start=v10 schema.version.app.root.start=v11 schema.version.namespace.change.start=v11 schema.version.edge.label.start=v12 -schema.version.api.default=v14 \ No newline at end of file +schema.version.api.default=v15 +server.local.startpath=src/main/resources/ +schema.service.base.url=https://localhost:8452/aai/schema-service/v1 +schema.service.nodes.endpoint=node-schema?version= +schema.service.edges.endpoint=edgerules?version= +schema.service.versions.endpoint=versions +schema.local=false +mock.filename=edgerequests +spring.application.name=aai +schema.translator.list=schema-service +schema.service.client=mock-no-auth diff --git a/aai-schema-ingest/src/test/resources/mockrequests.json b/aai-schema-ingest/src/test/resources/mockrequests.json new file mode 100644 index 00000000..7d669007 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/mockrequests.json @@ -0,0 +1,52 @@ +{ + "mock-uri": + [ + { + "aai-uri": "/versions", + "response-file": "payload/versions.json", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v8", + "response-file": "oxm/test_combined_network_business_v8.xml", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v9", + "response-file": "oxm/test_combined_network_business_v9.xml", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v10", + "response-file": "oxm/test_combined_network_business_v10.xml", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v11", + "response-file": "oxm/test_combined_network_business_v11.xml", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v12", + "response-file": "oxm/test_combined_network_business_v12.xml", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v13", + "response-file": "oxm/test_combined_v13.xml", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v14", + "response-file": "oxm/test_combined_network_business_v14.xml", + "content": "application/json;charset=UTF-8" + }, + { + "aai-uri": "/nodes?version=v15", + "response-file": "oxm/test_combined_network_business_v15.xml", + "content": "application/json;charset=UTF-8" + } + ] + + +} diff --git a/aai-schema-ingest/src/test/resources/oxm/test_business_v10.xml b/aai-schema-ingest/src/test/resources/oxm/test_business_v10.xml index 5ead4178..c3b60dbd 100644 --- a/aai-schema-ingest/src/test/resources/oxm/test_business_v10.xml +++ b/aai-schema-ingest/src/test/resources/oxm/test_business_v10.xml @@ -19,9 +19,9 @@ ============LICENSE_END========================================================= --> - + - + @@ -47,4 +47,4 @@ - \ No newline at end of file + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v10.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v10.xml new file mode 100644 index 00000000..a0fd77ca --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v10.xml @@ -0,0 +1,83 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v11.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v11.xml new file mode 100644 index 00000000..17ae17af --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v11.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v12.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v12.xml new file mode 100644 index 00000000..d59cd5a9 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v12.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v13.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v13.xml new file mode 100644 index 00000000..f3fef9a5 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v13.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v14.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v14.xml new file mode 100644 index 00000000..a0cc0ed4 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v14.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v15.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v15.xml new file mode 100644 index 00000000..b1c5519c --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v15.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v8.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v8.xml new file mode 100644 index 00000000..06c7c4e5 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v8.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v9.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v9.xml new file mode 100644 index 00000000..838a728a --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_network_business_v9.xml @@ -0,0 +1,101 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_combined_v13.xml b/aai-schema-ingest/src/test/resources/oxm/test_combined_v13.xml new file mode 100644 index 00000000..14da0168 --- /dev/null +++ b/aai-schema-ingest/src/test/resources/oxm/test_combined_v13.xml @@ -0,0 +1,4629 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-schema-ingest/src/test/resources/oxm/test_network_v10.xml b/aai-schema-ingest/src/test/resources/oxm/test_network_v10.xml index e7d77ac9..e52a58c2 100644 --- a/aai-schema-ingest/src/test/resources/oxm/test_network_v10.xml +++ b/aai-schema-ingest/src/test/resources/oxm/test_network_v10.xml @@ -19,9 +19,9 @@ ============LICENSE_END========================================================= --> - + - + @@ -48,4 +48,4 @@ - \ No newline at end of file + diff --git a/aai-schema-ingest/src/test/resources/payload/versions.json b/aai-schema-ingest/src/test/resources/payload/versions.json new file mode 100644 index 00000000..a1b608ba --- /dev/null +++ b/aai-schema-ingest/src/test/resources/payload/versions.json @@ -0,0 +1,18 @@ +{ +"versions": [ +"v8", +"v9", +"v10", + "v11", + "v12", + "v13", + "v14", + "v15" +], +"edge-version": "v15", +"default-version": "v15", +"depth-version": "v15", +"app-root-version": "v15", +"related-link-version": "v15", +"namespace-change-version": "v15" +} diff --git a/aai-schema-ingest/src/test/resources/schemaservice-endpoints.json b/aai-schema-ingest/src/test/resources/schemaservice-endpoints.json new file mode 100644 index 00000000..07d637dd --- /dev/null +++ b/aai-schema-ingest/src/test/resources/schemaservice-endpoints.json @@ -0,0 +1,9 @@ +"schema-service-endpoints" : { + "version-endpoint": { + "uri": "/versions", + "response" : { + "versions" : ["v9", "v10", "v11"], + "default" : "v14", + } + } +} -- cgit 1.2.3-korg