From 86e7411b128bd7db440eceff7265533844e577bb Mon Sep 17 00:00:00 2001 From: "LaMont, William(wl2432)" Date: Tue, 14 Apr 2020 14:00:00 -0400 Subject: schema-service processing for v19 Issue-ID: AAI-2864 Change-Id: I41a430ec9c9fd69be75bd9d01693249895e0928b Signed-off-by: LaMont, William(wl2432) --- .../test/java/org/onap/aai/queries/AAISetup.java | 132 ++++++++++++ .../java/org/onap/aai/queries/OnapQueryTest.java | 230 +++++++++++++++++++++ .../aai/queries/VnfToEsrSystemInfoQueryTest.java | 96 +++++++++ .../resources/application-onap-test.properties | 33 +++ .../src/test/resources/application-test.properties | 34 +++ aai-queries/src/test/resources/logback.xml | 81 ++++++++ .../src/test/resources/schema-ingest.properties | 10 + 7 files changed, 616 insertions(+) create mode 100644 aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java create mode 100644 aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java create mode 100644 aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java create mode 100644 aai-queries/src/test/resources/application-onap-test.properties create mode 100644 aai-queries/src/test/resources/application-test.properties create mode 100644 aai-queries/src/test/resources/logback.xml create mode 100644 aai-queries/src/test/resources/schema-ingest.properties (limited to 'aai-queries/src/test') diff --git a/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java b/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java new file mode 100644 index 0000000..551c10d --- /dev/null +++ b/aai-queries/src/test/java/org/onap/aai/queries/AAISetup.java @@ -0,0 +1,132 @@ +/** + * ============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.queries; + +import org.apache.commons.io.IOUtils; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.onap.aai.config.IntrospectionConfig; +import org.onap.aai.config.RestBeanConfig; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.MoxyLoader; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.rest.db.HttpEntry; +import org.onap.aai.serialization.db.EdgeSerializer; +import org.onap.aai.setup.AAIConfigTranslator; +import org.onap.aai.setup.SchemaLocationsBean; +import org.onap.aai.setup.SchemaVersion; +import org.onap.aai.setup.SchemaVersions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import static org.junit.Assert.assertNotNull; + +@ContextConfiguration(classes = { + SchemaLocationsBean.class, + SchemaVersions.class, + AAIConfigTranslator.class, + EdgeIngestor.class, + EdgeSerializer.class, + NodeIngestor.class, + SpringContextAware.class, + IntrospectionConfig.class , + RestBeanConfig.class, + GremlinServerSingleton.class +}) +@TestPropertySource(properties = { + "schema.uri.base.path = /aai", + "schema.ingest.file = src/test/resources/application-test.properties" +}) +public abstract class AAISetup { + @Autowired + protected NodeIngestor nodeIngestor; + + @Autowired + protected LoaderFactory loaderFactory; + + @Autowired + protected Map moxyLoaderInstance; + + @Autowired + protected HttpEntry traversalHttpEntry; + + @Autowired + protected HttpEntry traversalUriHttpEntry; + + @Autowired + protected EdgeSerializer edgeSer; + + @Autowired + protected EdgeIngestor edgeIngestor; + + @Autowired + protected SchemaVersions schemaVersions; + + @Autowired + protected GremlinServerSingleton gremlinServerSingleton; + + @Value("${schema.uri.base.path}") + protected String basePath; + + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + @BeforeClass + public static void setupBundleconfig() throws Exception { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + + } + + public String getPayload(String filename) throws IOException { + + InputStream inputStream = getClass() + .getClassLoader() + .getResourceAsStream(filename); + + String message = String.format("Unable to find the %s in src/test/resources", filename); + assertNotNull(message, inputStream); + + String resource = IOUtils.toString(inputStream); + return resource; + } +} + + + + + + + + diff --git a/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java b/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java new file mode 100644 index 0000000..d25aff6 --- /dev/null +++ b/aai-queries/src/test/java/org/onap/aai/queries/OnapQueryTest.java @@ -0,0 +1,230 @@ +/** + * ============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.queries; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import com.google.gson.Gson; +import com.google.gson.stream.JsonReader; +import com.jayway.jsonpath.JsonPath; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.Graph; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; +import org.json.JSONObject; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aai.config.IntrospectionConfig; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.edges.exceptions.AmbiguousRuleChoiceException; +import org.onap.aai.edges.exceptions.EdgeRuleNotFoundException; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.introspection.Loader; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.introspection.ModelType; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.queries.GremlinServerSingleton; +import org.onap.aai.query.builder.GremlinTraversal; +import org.onap.aai.restcore.search.GremlinGroovyShell; +import org.onap.aai.restcore.search.GroovyQueryBuilder; +import org.onap.aai.serialization.db.EdgeSerializer; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; +import org.onap.aai.serialization.engines.QueryStyle; +import org.onap.aai.serialization.engines.TransactionalGraphEngine; +import org.onap.aai.setup.*; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.core.env.Environment; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.rules.SpringClassRule; +import org.springframework.test.context.junit4.rules.SpringMethodRule; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileReader; +import java.io.IOException; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.util.*; +import java.util.stream.Collectors; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.when; + +@RunWith(Parameterized.class) +@ContextConfiguration(classes = { + SchemaLocationsBean.class, + SchemaConfigVersions.class, + AAIConfigTranslator.class, + EdgeIngestor.class, + EdgeSerializer.class, + NodeIngestor.class, + SpringContextAware.class, + GremlinServerSingleton.class, + IntrospectionConfig.class +}) +@TestPropertySource(properties = { + "schema.uri.base.path = /aai", + "schema.source.name = onap", + "schema.ingest.file = src/test/resources/application-test.properties" +}) +public abstract class OnapQueryTest { + + @ClassRule + public static final SpringClassRule springClassRule = new SpringClassRule(); + + @Rule + public final SpringMethodRule springMethodRule = new SpringMethodRule(); + + protected Logger logger; + protected Graph graph; + protected GremlinGroovyShell shell; + @Mock protected TransactionalGraphEngine dbEngine; + protected final List expectedResult = new ArrayList<>(); + + @Autowired + protected EdgeIngestor edgeRules; + + @Autowired + protected EdgeSerializer rules; + + @Autowired + protected LoaderFactory loaderFactory; + + @Autowired + protected SchemaVersions schemaVersions; + + protected Loader loader; + protected GraphTraversalSource gts; + + @Autowired + protected GremlinServerSingleton gremlinServerSingleton; + + @Parameterized.Parameter(value = 0) + public SchemaVersion version; + + @Parameterized.Parameters(name = "Version.{0}") + public static Collection data() { + return Arrays.asList(new Object[][]{ + {new SchemaVersion("v11")}, + {new SchemaVersion("v12")}, + {new SchemaVersion("v13")}, + {new SchemaVersion("v14")}, + {new SchemaVersion("v15")}, + {new SchemaVersion("v16")}, + {new SchemaVersion("v17")}, + {new SchemaVersion("v18")}, + {new SchemaVersion("v19")} + }); + } + + protected String query; + + LinkedHashMap params; + + @Autowired + private Environment env; + + @BeforeClass + public static void setupBundleconfig() { + System.setProperty("AJSC_HOME", "./"); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources/"); + } + + @Before + public void setUp() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException, IOException { + System.setProperty("AJSC_HOME", "."); + System.setProperty("BUNDLECONFIG_DIR", "src/main/resources"); + logger = LoggerFactory.getLogger(getClass()); + MockitoAnnotations.initMocks(this); + graph = TinkerGraph.open(); + gts = graph.traversal(); + createGraph(); + shell = new GremlinGroovyShell(); + loader = loaderFactory.createLoaderForVersion(ModelType.MOXY, version); + setUpQuery(); + } + + + protected void setUpQuery() { + query = gremlinServerSingleton.getStoredQueryFromConfig(getQueryName()); + params = new LinkedHashMap <>(); + addParam(params); + when(dbEngine.getQueryBuilder(any(QueryStyle.class))).thenReturn(new GremlinTraversal<>(loader, graph.traversal())); + logger.info("Stored query in abstraction form {}", query); + query = new GroovyQueryBuilder().executeTraversal(dbEngine, query, params); + logger.info("After converting to gremlin query {}", query); + query = "g" + query; + GraphTraversal g = graph.traversal().V(); + addStartNode(g); + params.put("g", g); + } + + public void run() { + + GraphTraversal result = (GraphTraversal)shell.executeTraversal(query, params); + + List vertices = result.toList(); + + logger.info("Expected result set of vertexes [{}]", convert(expectedResult)); + logger.info("Actual Result set of vertexes [{}]", convert(vertices)); + + List nonDuplicateExpectedResult = new ArrayList<>(new HashSet<>(expectedResult)); + vertices = new ArrayList<>(new HashSet<>(vertices)); + + nonDuplicateExpectedResult.sort(Comparator.comparing(vertex -> vertex.id().toString())); + vertices.sort(Comparator.comparing(vertex -> vertex.id().toString())); + + + // Use this instead of the assertTrue as this provides more useful + // debugging information such as this when expected and actual differ: + // java.lang.AssertionError: Expected all the vertices to be found + // Expected :[v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12]] + // Actual :[v[1], v[2], v[3], v[4], v[5], v[6], v[7], v[8], v[9], v[10], v[11], v[12]] + assertEquals("Expected all the vertices to be found", nonDuplicateExpectedResult, vertices); + + } + + protected String convert(List vertices){ + return vertices + .stream() + .map(vertex -> vertex.property("aai-node-type").value().toString()) + .collect(Collectors.joining(",")); + } + + protected abstract void createGraph() throws AAIException, NoEdgeRuleFoundException, EdgeRuleNotFoundException, AmbiguousRuleChoiceException; + + protected abstract String getQueryName(); + + protected abstract void addStartNode(GraphTraversal g); + + protected abstract void addParam(Map params); + +} diff --git a/aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java b/aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java new file mode 100644 index 0000000..9b6a0e8 --- /dev/null +++ b/aai-queries/src/test/java/org/onap/aai/queries/VnfToEsrSystemInfoQueryTest.java @@ -0,0 +1,96 @@ +/** + * ============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.queries; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.apache.tinkerpop.gremlin.structure.T; +import org.apache.tinkerpop.gremlin.structure.Vertex; +import org.junit.Test; +import org.onap.aai.exceptions.AAIException; +import org.onap.aai.serialization.db.exceptions.NoEdgeRuleFoundException; + +import java.util.Map; + +public class VnfToEsrSystemInfoQueryTest extends OnapQueryTest { + public VnfToEsrSystemInfoQueryTest() { + super(); + } + + @Test + public void run() { + super.run(); + } + + @Override + protected void createGraph() throws AAIException, NoEdgeRuleFoundException { + + + Vertex gnvf = graph.addVertex(T.label, "generic-vnf", T.id, "2", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-1"); + Vertex vserver = graph.addVertex(T.label, "vserver", T.id, "3", "aai-node-type", "vserver", "vserver-id", "vserver-id-1","vserver-name","vserver-name-1"); + Vertex tenant = graph.addVertex(T.label, "tenant", T.id, "4", "aai-node-type", "tenant", "tenant-id", "tenantid01", "tenant-name", "tenantName01"); + Vertex cloudregion = graph.addVertex(T.label, "cloud-region", T.id, "5", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-1", "cloud-region-owner", "cloud-owner-name-1"); + Vertex esr = graph.addVertex(T.label, "esr-system-info", T.id, "6", "aai-node-type", "esr-system-info", "esr-system-info-id", "esr-system-info-1"); + + Vertex gnvf1 = graph.addVertex(T.label, "generic-vnf", T.id, "8", "aai-node-type", "generic-vnf", "vnf-id", "vnf-id-2"); + Vertex vserver1 = graph.addVertex(T.label, "vserver", T.id, "9", "aai-node-type", "vserver", "vserver-id", "vserver-id-2","vserver-name","vserver-name-2"); + Vertex tenant1 = graph.addVertex(T.label, "tenant", T.id, "10", "aai-node-type", "tenant", "tenant-id", "tenantid02", "tenant-name", "tenantName02"); + Vertex cloudregion1 = graph.addVertex(T.label, "cloud-region", T.id, "11", "aai-node-type", "cloud-region", "cloud-region-id", "cloud-region-id-2", "cloud-region-owner", "cloud-owner-name-2"); + Vertex esr1 = graph.addVertex(T.label, "esr-system-info", T.id, "12", "aai-node-type", "esr-system-info", "esr-system-info-id", "esr-system-info-2"); + + + + + GraphTraversalSource g = graph.traversal(); + rules.addEdge(g, gnvf, vserver); + rules.addTreeEdge(g, vserver,tenant); + rules.addTreeEdge(g, tenant,cloudregion); + rules.addTreeEdge(g, cloudregion, esr); + + //Not expected in result + rules.addEdge(g, gnvf1, vserver1); + rules.addTreeEdge(g, vserver1,tenant1); + rules.addTreeEdge(g, tenant1,cloudregion1); + rules.addTreeEdge(g, cloudregion1, esr1); + //Not expected in result + + expectedResult.add(gnvf); + expectedResult.add(vserver); + expectedResult.add(tenant); + expectedResult.add(cloudregion); + expectedResult.add(esr); + + + } + + @Override + protected String getQueryName() { + return "vnf-to-esr-system-info"; + } + @Override + protected void addStartNode(GraphTraversal g) { + g.has("aai-node-type", "generic-vnf").has("vnf-id", "vnf-id-1"); + + } + @Override + protected void addParam(Map params) { + return; + } +} diff --git a/aai-queries/src/test/resources/application-onap-test.properties b/aai-queries/src/test/resources/application-onap-test.properties new file mode 100644 index 0000000..697c4a8 --- /dev/null +++ b/aai-queries/src/test/resources/application-onap-test.properties @@ -0,0 +1,33 @@ +server.local.startpath=src/main/resources/ +# Schema related attributes for the oxm and edges +# Any additional schema related attributes should start with prefix schema +schema.configuration.location=N/A +# Choose if the oxm schema is onap or other system +schema.source.name=onap +# Location of where the oxm files are +schema.nodes.location=${server.local.startpath}/schema/${schema.source.name}/oxm/ +# Location of where the dbedgerules files are +schema.edges.location=${server.local.startpath}/schema/${schema.source.name}/dbedgerules/ +# Location of where the stored queries are +schema.queries.location=${server.local.startpath}/schema/${schema.source.name}/query/ + +schema.ingest.file=${server.local.startpath}/application-test.properties + +# Schema Version Related Attributes +schema.uri.base.path=/aai +# Lists all of the versions in the schema +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17 +# Specifies from which version should the depth parameter to default to zero +schema.version.depth.start=v10 +# Specifies from which version should the related link be displayed in response payload +schema.version.related.link.start=v10 +# Specifies from which version should the client see only the uri excluding host info +# Before this version server base will also be included +schema.version.app.root.start=v11 +# Specifies from which version should the namespace be changed +schema.version.namespace.change.start=v12 +# Specifies from which version should the client start seeing the edge label in payload +schema.version.edge.label.start=v12 +# Specifies the version that the application should default to +schema.version.api.default=v17 +schema.translator.list=config \ No newline at end of file diff --git a/aai-queries/src/test/resources/application-test.properties b/aai-queries/src/test/resources/application-test.properties new file mode 100644 index 0000000..b6aafc7 --- /dev/null +++ b/aai-queries/src/test/resources/application-test.properties @@ -0,0 +1,34 @@ +server.local.startpath=src/main/resources +# Schema related attributes for the oxm and edges +# Any additional schema related attributes should start with prefix schema +schema.configuration.location=N/A +# Choose if the oxm schema is onap or other system +schema.source.name=ecomp +# Location of where the oxm files are +schema.nodes.location=${server.local.startpath}/schema/${schema.source.name}/oxm/ +# Location of where the dbedgerules files are +schema.edges.location=${server.local.startpath}/schema/${schema.source.name}/dbedgerules/ +# Location of where the stored queries are +schema.queries.location=${server.local.startpath}/schema/${schema.source.name}/query/ + +schema.ingest.file=${server.local.startpath}/application-test.properties + +# Schema Version Related Attributes +schema.uri.base.path=/aai +# Lists all of the versions in the schema +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17,v18,v19 +# Specifies from which version should the depth parameter to default to zero +schema.version.depth.start=v10 +# Specifies from which version should the related link be displayed in response payload +schema.version.related.link.start=v10 +# Specifies from which version should the client see only the uri excluding host info +# Before this version server base will also be included +schema.version.app.root.start=v11 +# Specifies from which version should the namespace be changed +schema.version.namespace.change.start=v12 +# Specifies from which version should the client start seeing the edge label in payload +schema.version.edge.label.start=v12 +# Specifies the version that the application should default to +schema.version.api.default=v19 + +schema.translator.list=config diff --git a/aai-queries/src/test/resources/logback.xml b/aai-queries/src/test/resources/logback.xml new file mode 100644 index 0000000..795533f --- /dev/null +++ b/aai-queries/src/test/resources/logback.xml @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + %clr(%d{yyyy-MM-dd HH:mm:ss.SSS}){faint} %clr(${LOG_LEVEL_PATTERN:-%5p}) %clr(${PID:- }){magenta} %clr(---){faint} %clr([%15.15t]){faint} %clr(%-40.40logger{39}){cyan} %clr(:){faint} %m%n${LOG_EXCEPTION_CONVERSION_WORD:-%wEx} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aai-queries/src/test/resources/schema-ingest.properties b/aai-queries/src/test/resources/schema-ingest.properties new file mode 100644 index 0000000..95846ea --- /dev/null +++ b/aai-queries/src/test/resources/schema-ingest.properties @@ -0,0 +1,10 @@ +schema.configuration.location=N/A +schema.nodes.location=src/main/resources/schema/oxm/ +schema.edges.location=src/main/resources/schema/dbedgerules/ + +schema.version.list=v10,v11,v12,v13,v14,v15,v16,v17 +schema.version.depth.start=v10 +schema.version.related.link.start=v10 +schema.version.app.root.start=v11 +schema.version.edge.label.start=v12 +schema.version.api.default=v17 -- cgit 1.2.3-korg