diff options
Diffstat (limited to 'aai-core/src/test')
5 files changed, 226 insertions, 2 deletions
diff --git a/aai-core/src/test/java/org/onap/aai/AAISetup.java b/aai-core/src/test/java/org/onap/aai/AAISetup.java index 5273c6e7..e280d889 100644 --- a/aai-core/src/test/java/org/onap/aai/AAISetup.java +++ b/aai-core/src/test/java/org/onap/aai/AAISetup.java @@ -53,7 +53,7 @@ import org.springframework.test.context.web.WebAppConfiguration; classes = {ConfigConfiguration.class, AAIConfigTranslator.class, EdgeIngestor.class, EdgeSerializer.class, NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class, RestBeanConfig.class, XmlFormatTransformerConfiguration.class, ValidationService.class, ValidationConfiguration.class, - KafkaConfig.class, LoaderFactory.class, NotificationService.class, KafkaConfig.class}) + KafkaConfig.class, LoaderFactory.class, NotificationService.class}) @TestPropertySource( properties = {"schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000", "schema.translator.list=config", "schema.nodes.location=src/test/resources/onap/oxm", diff --git a/aai-core/src/test/java/org/onap/aai/IntegrationTest.java b/aai-core/src/test/java/org/onap/aai/IntegrationTest.java new file mode 100644 index 00000000..9ee5fce5 --- /dev/null +++ b/aai-core/src/test/java/org/onap/aai/IntegrationTest.java @@ -0,0 +1,61 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2024 Deutsche Telekom. 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; + +import org.junit.jupiter.api.extension.ExtendWith; +import org.onap.aai.config.ConfigConfiguration; +import org.onap.aai.config.GraphConfig; +import org.onap.aai.config.IntrospectionConfig; +import org.onap.aai.config.KafkaConfig; +import org.onap.aai.config.RestBeanConfig; +import org.onap.aai.config.SpringContextAware; +import org.onap.aai.config.XmlFormatTransformerConfiguration; +import org.onap.aai.edges.EdgeIngestor; +import org.onap.aai.introspection.LoaderFactory; +import org.onap.aai.nodes.NodeIngestor; +import org.onap.aai.prevalidation.ValidationConfiguration; +import org.onap.aai.prevalidation.ValidationService; +import org.onap.aai.rest.notification.NotificationService; +import org.onap.aai.serialization.db.EdgeSerializer; +import org.onap.aai.setup.AAIConfigTranslator; +import org.onap.aai.util.GraphChecker; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration( + classes = {ConfigConfiguration.class, AAIConfigTranslator.class, EdgeIngestor.class, EdgeSerializer.class, + NodeIngestor.class, SpringContextAware.class, IntrospectionConfig.class, RestBeanConfig.class, + XmlFormatTransformerConfiguration.class, ValidationService.class, ValidationConfiguration.class, + KafkaConfig.class, LoaderFactory.class, NotificationService.class}) +@TestPropertySource( + value = "classpath:/application.properties", + properties = { + "schema.uri.base.path = /aai", "schema.xsd.maxoccurs = 5000", + "schema.translator.list=config", + "schema.nodes.location=src/test/resources/onap/oxm", + "schema.edges.location=src/test/resources/onap/dbedgerules", + "aai.notifications.enabled=false","classpath:/application.properties", + }) +public class IntegrationTest { + +} diff --git a/aai-core/src/test/java/org/onap/aai/JanusgraphCassandraConfiguration.java b/aai-core/src/test/java/org/onap/aai/JanusgraphCassandraConfiguration.java new file mode 100644 index 00000000..08c99170 --- /dev/null +++ b/aai-core/src/test/java/org/onap/aai/JanusgraphCassandraConfiguration.java @@ -0,0 +1,34 @@ +package org.onap.aai; + +import java.io.FileNotFoundException; + +import org.apache.commons.configuration2.Configuration; +import org.apache.commons.configuration2.PropertiesConfiguration; +import org.apache.commons.configuration2.ex.ConfigurationException; +import org.janusgraph.core.JanusGraphProperty; +import org.janusgraph.core.schema.JanusGraphConfiguration; +import org.onap.aai.dbmap.AAIGraphConfig; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Bean; + +@TestConfiguration +public class JanusgraphCassandraConfiguration { + + @Value("${testcontainers.cassandra.host}") + String cassandraHost; + + @Value("${testcontainers.cassandra.port}") + int cassandraPort; + + @Bean + public org.apache.commons.configuration2.Configuration getGraphProperties() + throws FileNotFoundException, ConfigurationException { + + Configuration janusgraphConfiguration = new PropertiesConfiguration(); + janusgraphConfiguration.addProperty("storage.backend", "cql"); + janusgraphConfiguration.addProperty("storage.hostname", cassandraHost); + janusgraphConfiguration.addProperty("storage.port", cassandraPort); + return janusgraphConfiguration; + } +} diff --git a/aai-core/src/test/java/org/onap/aai/util/GraphCheckerResiliencyTest.java b/aai-core/src/test/java/org/onap/aai/util/GraphCheckerResiliencyTest.java new file mode 100644 index 00000000..03662a93 --- /dev/null +++ b/aai-core/src/test/java/org/onap/aai/util/GraphCheckerResiliencyTest.java @@ -0,0 +1,120 @@ +/** + * ============LICENSE_START======================================================= + * org.onap.aai + * ================================================================================ + * Copyright © 2024 Deutsche Telekom. 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.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.onap.aai.IntegrationTest; +import org.onap.aai.JanusgraphCassandraConfiguration; +import org.onap.aai.config.GraphConfig; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.cassandra.CassandraContainer; +import org.testcontainers.containers.Network; +import org.testcontainers.containers.ToxiproxyContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; + +import eu.rekawek.toxiproxy.Proxy; +import eu.rekawek.toxiproxy.ToxiproxyClient; +import eu.rekawek.toxiproxy.model.ToxicDirection; + +@Testcontainers +@Import(JanusgraphCassandraConfiguration.class) +@ContextConfiguration(classes = { + GraphConfig.class, GraphChecker.class +}) +public class GraphCheckerResiliencyTest extends IntegrationTest { + + private static final Network network = Network.newNetwork(); + + @Container + private static final CassandraContainer cassandraContainer = new CassandraContainer("cassandra:4.0.5") + .withExposedPorts(9042) + .withNetwork(network) + .withNetworkAliases("cassandra"); + + + @Container + private static final ToxiproxyContainer toxiproxy = new ToxiproxyContainer("ghcr.io/shopify/toxiproxy:2.5.0") + .withNetwork(network); + + private static Proxy cassandraProxy; + + @Autowired + GraphChecker graphChecker; + + @Autowired + GraphTraversalSource g; + + @DynamicPropertySource + static void setProperties(DynamicPropertyRegistry registry) throws IOException { + registry.add("testcontainers.cassandra.host", () -> toxiproxy.getHost()); + registry.add("testcontainers.cassandra.port", () -> toxiproxy.getMappedPort(8666)); + + var toxiproxyClient = new ToxiproxyClient(toxiproxy.getHost(), toxiproxy.getControlPort()); + + cassandraProxy = toxiproxyClient.createProxy("cassandra", "0.0.0.0:8666", "cassandra:9042"); + + } + + @BeforeEach + void resetProxy() throws IOException { + for(var toxic: cassandraProxy.toxics().getAll()) { + toxic.remove(); + } + } + + @Test + public void test() { + boolean available = graphChecker.isAaiGraphDbAvailable(); + assertTrue(available); + } + + @Test + public void testConnectionFailure() throws IOException { + assertTrue(graphChecker.isAaiGraphDbAvailable()); + + cassandraProxy.toxics().bandwidth("no-connection-up", ToxicDirection.UPSTREAM, 0); + cassandraProxy.toxics().bandwidth("no-connection-down", ToxicDirection.DOWNSTREAM, 0); + assertFalse(graphChecker.isAaiGraphDbAvailable()); + + // boolean available = graphChecker.isAaiGraphDbAvailable(); + // // g.addV().property("foo","bar").next(); + // // boolean exists = g.V().has("foo","bar").hasNext(); + // assertFalse(available); + } + + @AfterAll + public static void tearDown() { + cassandraContainer.stop(); + } +} diff --git a/aai-core/src/test/java/org/onap/aai/util/GraphCheckerTest.java b/aai-core/src/test/java/org/onap/aai/util/GraphCheckerTest.java index 03634c8c..524a2704 100644 --- a/aai-core/src/test/java/org/onap/aai/util/GraphCheckerTest.java +++ b/aai-core/src/test/java/org/onap/aai/util/GraphCheckerTest.java @@ -8,6 +8,7 @@ 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.Vertex; import org.janusgraph.core.JanusGraph; +import org.janusgraph.core.JanusGraphException; import org.janusgraph.core.JanusGraphTransaction; import org.janusgraph.core.TransactionBuilder; import org.junit.Before; @@ -47,10 +48,18 @@ public class GraphCheckerTest extends AAISetup { boolean available = graphChecker.isAaiGraphDbAvailable(); assertTrue(available); } + @Test - public void thatAvailabilityCanBeFalse() { + public void thatEmptyDBQueryIsInterpretedAsAvailable() { when(traversal.hasNext()).thenReturn(false); boolean available = graphChecker.isAaiGraphDbAvailable(); + assertTrue(available); + } + + @Test + public void thatExceptionWillReturnAvailabilityFalse() { + when(traversal.hasNext()).thenThrow(JanusGraphException.class); + boolean available = graphChecker.isAaiGraphDbAvailable(); assertFalse(available); } |