diff options
Diffstat (limited to 'aai-resources/src')
22 files changed, 264 insertions, 164 deletions
diff --git a/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java b/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java index 007b0d1..51f5609 100644 --- a/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java +++ b/aai-resources/src/main/java/org/onap/aai/ResourcesApp.java @@ -37,24 +37,17 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; +import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; import org.springframework.core.env.Environment; import org.springframework.core.env.Profiles; @SpringBootApplication( exclude = {DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, - HibernateJpaAutoConfiguration.class}) -// Component Scan provides a way to look for spring beans -// It only searches beans in the following packages -// Any method annotated with @Bean annotation or any class -// with @Component, @Configuration, @Service will be picked up -@ComponentScan( - basePackages = {"org.onap.aai.config", "org.onap.aai.web", "org.onap.aai.setup", "org.onap.aai.tasks", - "org.onap.aai.service", "org.onap.aai.rest", "org.onap.aai.aaf", "org.onap.aai.TenantIsolation", - "org.onap.aai.aailog", "org.onap.aai.prevalidation"}) + HibernateJpaAutoConfiguration.class, CassandraDataAutoConfiguration.class, CassandraAutoConfiguration.class}) public class ResourcesApp { private static final Logger logger = LoggerFactory.getLogger(ResourcesApp.class.getName()); diff --git a/aai-resources/src/main/java/org/onap/aai/rest/ExceptionHandler.java b/aai-resources/src/main/java/org/onap/aai/rest/ExceptionHandler.java index 81c49b9..7af598b 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/ExceptionHandler.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/ExceptionHandler.java @@ -25,7 +25,6 @@ import com.fasterxml.jackson.databind.JsonMappingException; import com.sun.istack.SAXParseException2; import java.util.ArrayList; -import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.WebApplicationException; diff --git a/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java b/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java index c518258..689e0b4 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/LegacyMoxyConsumer.java @@ -47,7 +47,6 @@ import org.onap.aai.introspection.sideeffect.OwnerCheck; import org.onap.aai.query.builder.Pageable; import org.onap.aai.parsers.query.QueryParser; import org.onap.aai.query.builder.QueryOptions; -import org.onap.aai.query.builder.Sort; import org.onap.aai.rest.db.DBRequest; import org.onap.aai.rest.db.HttpEntry; import org.onap.aai.rest.exceptions.AAIInvalidXMLNamespace; diff --git a/aai-resources/src/main/java/org/onap/aai/rest/bulk/pojos/Operation.java b/aai-resources/src/main/java/org/onap/aai/rest/bulk/pojos/Operation.java index 814cea0..1920b37 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/bulk/pojos/Operation.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/bulk/pojos/Operation.java @@ -20,7 +20,7 @@ package org.onap.aai.rest.bulk.pojos; -import com.google.gson.*; +import com.google.gson.JsonObject; import com.google.gson.annotations.SerializedName; public class Operation { diff --git a/aai-resources/src/main/java/org/onap/aai/rest/util/EchoResponse.java b/aai-resources/src/main/java/org/onap/aai/rest/util/EchoResponse.java index d4d8d32..0e44a63 100644 --- a/aai-resources/src/main/java/org/onap/aai/rest/util/EchoResponse.java +++ b/aai-resources/src/main/java/org/onap/aai/rest/util/EchoResponse.java @@ -21,7 +21,6 @@ package org.onap.aai.rest.util; import java.util.ArrayList; -import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.GET; diff --git a/aai-resources/src/main/java/org/onap/aai/web/JerseyConfiguration.java b/aai-resources/src/main/java/org/onap/aai/web/JerseyConfiguration.java index 24004d1..41ec8e1 100644 --- a/aai-resources/src/main/java/org/onap/aai/web/JerseyConfiguration.java +++ b/aai-resources/src/main/java/org/onap/aai/web/JerseyConfiguration.java @@ -47,7 +47,6 @@ import org.onap.aai.rest.bulk.BulkSingleTransactionConsumer; import org.onap.aai.rest.util.EchoResponse; import org.onap.logging.filter.base.AuditLogContainerFilter; import org.reflections.Reflections; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; diff --git a/aai-resources/src/main/resources/application.properties b/aai-resources/src/main/resources/application.properties index 960db1b..2f33d8a 100644 --- a/aai-resources/src/main/resources/application.properties +++ b/aai-resources/src/main/resources/application.properties @@ -26,7 +26,7 @@ spring.autoconfigure.exclude=\ spring.jersey.application-path=${schema.uri.base.path} -spring.profiles.active=production,one-way-ssl,kafka +spring.profiles.active=production,one-way-ssl #The max number of active threads in this pool server.jetty.threads.max=200 #The minimum number of threads always kept alive @@ -43,6 +43,7 @@ server.certs.location=${server.local.startpath}/etc/auth/ server.keystore.name=aai_keystore server.truststore.name=aai_keystore server.port=8447 + server.ssl.enabled=false server.ssl.enabled-protocols=TLSv1.1,TLSv1.2 server.ssl.key-store=${server.certs.location}${server.keystore.name} diff --git a/aai-resources/src/test/java/org/onap/aai/AAISetup.java b/aai-resources/src/test/java/org/onap/aai/AAISetup.java index b510c00..81ed8c3 100644 --- a/aai-resources/src/test/java/org/onap/aai/AAISetup.java +++ b/aai-resources/src/test/java/org/onap/aai/AAISetup.java @@ -32,7 +32,6 @@ import org.junit.ClassRule; import org.junit.Rule; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.runner.RunWith; import org.onap.aai.config.ConfigConfiguration; import org.onap.aai.config.IntrospectionConfig; import org.onap.aai.config.RestBeanConfig; @@ -43,6 +42,7 @@ 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.rest.notification.NotificationService; import org.onap.aai.serialization.db.EdgeSerializer; import org.onap.aai.setup.AAIConfigTranslator; import org.onap.aai.setup.SchemaVersion; @@ -58,7 +58,7 @@ import org.springframework.test.context.junit4.rules.SpringMethodRule; @ContextConfiguration( classes = {ConfigConfiguration.class, AAIConfigTranslator.class, NodeIngestor.class, EdgeIngestor.class, EdgeSerializer.class, SpringContextAware.class, IntrospectionConfig.class, - XmlFormatTransformerConfiguration.class, RestBeanConfig.class}) + XmlFormatTransformerConfiguration.class, RestBeanConfig.class, LoaderFactory.class, NotificationService.class}) @TestPropertySource( properties = {"schema.uri.base.path = /aai", "schema.ingest.file = src/test/resources/application-test.properties"}) diff --git a/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java b/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java new file mode 100644 index 0000000..cce0ae7 --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/config/WebClientConfiguration.java @@ -0,0 +1,34 @@ +package org.onap.aai.config; + +import java.time.Duration; +import java.util.Collections; + +import org.onap.aai.setup.SchemaVersions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Lazy; +import org.springframework.http.MediaType; +import org.springframework.test.web.reactive.server.WebTestClient; + +@TestConfiguration +public class WebClientConfiguration { + + @Autowired SchemaVersions schemaVersions; + + @Lazy + @Bean + WebTestClient webTestClient(@LocalServerPort int port) { + return WebTestClient.bindToServer() + .baseUrl("http://localhost:" + port + "/aai/" + schemaVersions.getDefaultVersion()) + .responseTimeout(Duration.ofSeconds(300)) + .defaultHeaders(headers -> { + headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON)); + headers.set("X-FromAppId", "test"); + headers.set("X-TransactionId", "someTransaction"); + headers.setBasicAuth("AAI", "AAI"); + }) + .build(); + } +} diff --git a/aai-resources/src/test/java/org/onap/aai/entities/PServer.java b/aai-resources/src/test/java/org/onap/aai/entities/PServer.java new file mode 100644 index 0000000..988328e --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/entities/PServer.java @@ -0,0 +1,60 @@ +/** + * ============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.entities; + +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.PropertyNamingStrategy; +import com.fasterxml.jackson.databind.annotation.JsonNaming; + +import lombok.Data; + +@Data +@JsonNaming(PropertyNamingStrategy.KebabCaseStrategy.class) +public class PServer { + String resourceVersion; + String hostname; + String ptniiEquipName; + long numberOfCpus; + long diskInGigabytes; + long ramInMegabytes; + String equipType; + String equipVendor; + String equipModel; + String fqdn; + String pserverSelflink; + String ipv4OamAddress; + String serialNumber; + @JsonProperty("ipaddress-v4-loopback-0") + String ipaddressV4Loopback0; + @JsonProperty("ipaddress-v6-loopback-0") + String ipaddressV6Loopback0; + String ipaddressV4Aim; + String ipaddressV6Aim; + String ipaddressV6Oam; + String invStatus; + String pserverId; + String internetTopology; + boolean inMaint; + String pserverName2; + String purpose; + String provStatus; + String managementOption; + String hostProfile; +} diff --git a/aai-resources/src/test/java/org/onap/aai/entities/PServerListResponse.java b/aai-resources/src/test/java/org/onap/aai/entities/PServerListResponse.java new file mode 100644 index 0000000..a08b9ea --- /dev/null +++ b/aai-resources/src/test/java/org/onap/aai/entities/PServerListResponse.java @@ -0,0 +1,30 @@ +/** + * ============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.entities; + +import java.util.List; + +import lombok.Data; + +@Data +public class PServerListResponse { + List<PServer> pserver; +} diff --git a/aai-resources/src/test/java/org/onap/aai/it/performance/K6PerformanceTest.java b/aai-resources/src/test/java/org/onap/aai/it/performance/K6PerformanceTest.java index 8428cb5..00179fe 100644 --- a/aai-resources/src/test/java/org/onap/aai/it/performance/K6PerformanceTest.java +++ b/aai-resources/src/test/java/org/onap/aai/it/performance/K6PerformanceTest.java @@ -36,6 +36,9 @@ import org.onap.aai.db.props.AAIProperties; import org.onap.aai.dbmap.AAIGraph; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; +import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.web.server.LocalServerPort; @@ -48,6 +51,7 @@ import lombok.SneakyThrows; @Testcontainers @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@EnableAutoConfiguration(exclude={CassandraDataAutoConfiguration.class, CassandraAutoConfiguration.class}) // there is no running cassandra instance for the test public class K6PerformanceTest { private static final Logger logger = LoggerFactory.getLogger(ResourcesApp.class.getName()); @@ -56,13 +60,9 @@ public class K6PerformanceTest { @LocalServerPort private int port; - - private boolean initialized = false; - @BeforeEach public void setup() { - if (!initialized) { - initialized = true; + if (!AAIGraph.isInit()) { AAIGraph.getInstance(); long startTime = System.currentTimeMillis(); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java b/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java index 9e901ad..82d726e 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/AbstractSpringRestTest.java @@ -41,6 +41,9 @@ import org.onap.aai.nodes.NodeIngestor; import org.onap.aai.restclient.PropertyPasswordConfiguration; import org.onap.aai.util.AAIConfig; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; +import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Import; @@ -53,10 +56,11 @@ import org.springframework.test.context.junit4.rules.SpringClassRule; import org.springframework.test.context.junit4.rules.SpringMethodRule; import org.springframework.web.client.RestTemplate; -@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ResourcesApp.class) +@Import(ResourcesTestConfiguration.class) @TestPropertySource(locations = "classpath:application-test.properties") @ContextConfiguration(initializers = PropertyPasswordConfiguration.class) -@Import(ResourcesTestConfiguration.class) +@EnableAutoConfiguration(exclude={CassandraDataAutoConfiguration.class, CassandraAutoConfiguration.class}) // there is no running cassandra instance for the test +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = ResourcesApp.class) public abstract class AbstractSpringRestTest { @ClassRule diff --git a/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessorTestAbstraction.java b/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessorTestAbstraction.java index 68974a3..706da69 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessorTestAbstraction.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/BulkProcessorTestAbstraction.java @@ -73,19 +73,11 @@ public abstract class BulkProcessorTestAbstraction extends AAISetup { protected String uri; - private boolean initialized = false; private static final Logger logger = LoggerFactory.getLogger(BulkProcessorTestAbstraction.class.getName()); - @BeforeAll - public static void setupRest() { - // AAIGraph.getInstance(); - - } - @BeforeEach public void setup() { - if (!initialized) { - initialized = true; + if (!AAIGraph.isInit()) { AAIGraph.getInstance(); } logger.info("Starting the setup for the integration tests of Rest Endpoints"); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java index 5e1142d..21f2fb4 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ConfigurationTest.java @@ -38,6 +38,9 @@ import org.onap.aai.config.SpringContextAware; import org.onap.aai.restclient.PropertyPasswordConfiguration; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration; +import org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.web.server.LocalServerPort; import org.springframework.context.annotation.Import; @@ -57,6 +60,7 @@ import org.springframework.web.client.RestTemplate; @TestPropertySource(locations = "classpath:application-test.properties") @ContextConfiguration(initializers = PropertyPasswordConfiguration.class, classes = {SpringContextAware.class}) +@EnableAutoConfiguration(exclude={CassandraDataAutoConfiguration.class, CassandraAutoConfiguration.class}) // there is no running cassandra instance for the test @Import(ResourcesTestConfiguration.class) @SpringBootTest( webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java index 96e7716..73eed51 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ExampleConsumerTest.java @@ -74,14 +74,11 @@ public class ExampleConsumerTest extends AAISetup { private static final Logger logger = LoggerFactory.getLogger(LegacyMoxyConsumerTest.class.getName()); - @BeforeAll - public static void setupRest() { - AAIGraph.getInstance(); - - } - @BeforeEach public void setup() { + if(!AAIGraph.isInit()) { + AAIGraph.getInstance(); + } logger.info("Starting the setup for the integration tests of Rest Endpoints"); exampleConsumer = new ExampleConsumer(); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java index 0780649..21baedc 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ExceptionHandlerTest.java @@ -27,8 +27,6 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import com.fasterxml.jackson.core.JsonFactory; -import com.fasterxml.jackson.core.JsonLocation; import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.JsonMappingException; diff --git a/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java index e54c8e5..d88faa5 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/LegacyMoxyConsumerTest.java @@ -4,6 +4,8 @@ * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ + * Modifications Copyright © 2024 Deutsche Telekom. + * ================================================================================ * 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 @@ -20,6 +22,10 @@ package org.onap.aai.rest; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.samePropertyValuesAs; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; @@ -28,6 +34,7 @@ import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import java.io.IOException; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -42,31 +49,46 @@ import javax.ws.rs.core.MultivaluedMap; import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import org.apache.commons.io.IOUtils; +import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource; +import org.hamcrest.Matcher; +import org.janusgraph.core.JanusGraph; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.json.simple.parser.ParseException; -import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import org.onap.aai.AAISetup; +import org.onap.aai.config.WebClientConfiguration; +import org.onap.aai.db.props.AAIProperties; import org.onap.aai.dbmap.AAIGraph; +import org.onap.aai.entities.PServer; +import org.onap.aai.entities.PServerListResponse; import org.onap.aai.exceptions.AAIException; +import org.onap.aai.setup.SchemaVersions; import org.onap.aai.util.AAIConfig; import org.onap.aai.util.AAIConstants; import org.skyscreamer.jsonassert.JSONAssert; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.context.annotation.Import; import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.test.web.reactive.server.WebTestClient; -// TODO: Change the following test to use spring boot -public class LegacyMoxyConsumerTest extends AAISetup { +import com.fasterxml.jackson.databind.ObjectMapper; + +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Import(WebClientConfiguration.class) +public class LegacyMoxyConsumerTest { - protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); - private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); private static final Logger logger = LoggerFactory.getLogger(LegacyMoxyConsumerTest.class.getName()); + private static final Set<Integer> VALID_HTTP_STATUS_CODES = new HashSet<>(); + protected static final MediaType APPLICATION_JSON = MediaType.valueOf("application/json"); static { VALID_HTTP_STATUS_CODES.add(200); @@ -74,31 +96,23 @@ public class LegacyMoxyConsumerTest extends AAISetup { VALID_HTTP_STATUS_CODES.add(204); } - private LegacyMoxyConsumer legacyMoxyConsumer; + @Autowired WebTestClient webClient; + @Autowired SchemaVersions schemaVersions; - private HttpHeaders httpHeaders; + ObjectMapper mapper = new ObjectMapper(); + private LegacyMoxyConsumer legacyMoxyConsumer; + private HttpHeaders httpHeaders; private UriInfo uriInfo; - private MultivaluedMap<String, String> headersMultiMap; private MultivaluedMap<String, String> queryParameters; - private List<String> aaiRequestContextList; - private List<MediaType> outputMediaTypes; - private boolean initialized = false; private String defaultSchemaVersion; - - @BeforeAll - public static void setupRest() { - // AAIGraph.getInstance(); - } - @BeforeEach public void setup() { - if (!initialized) { - initialized = true; + if(!AAIGraph.isInit()) { AAIGraph.getInstance(); } logger.info("Starting the setup for the integration tests of Rest Endpoints"); @@ -135,96 +149,90 @@ public class LegacyMoxyConsumerTest extends AAISetup { Mockito.doReturn(null).when(queryParameters).remove(any()); when(httpHeaders.getMediaType()).thenReturn(APPLICATION_JSON); - } @Test public void testResponsePutGetDeleteOnResource() throws JSONException, IOException, AAIException { - - String uri = getUri(); String payload = getResourcePayload(getObjectName()); - - assertNotNull(payload, "Introspector returned invalid string when marshalling the object"); - assertNotNull(uri, "Introspector failed to return a valid uri"); - - if (uri.length() != 0 && uri.charAt(0) == '/') { - uri = uri.substring(1); - } - - when(uriInfo.getPath()).thenReturn(uri); - when(uriInfo.getPath(false)).thenReturn(uri); - - MockHttpServletRequest mockReqGet = new MockHttpServletRequest("GET", uri); - Response response = legacyMoxyConsumer.getLegacy(defaultSchemaVersion, uri, -1, -1, - false, "all", "false", httpHeaders, uriInfo, mockReqGet); - - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); - - MockHttpServletRequest mockReq = new MockHttpServletRequest("PUT", uri); - response = legacyMoxyConsumer.update(payload, defaultSchemaVersion, uri, httpHeaders, - uriInfo, mockReq); - - int code = response.getStatus(); - if (!VALID_HTTP_STATUS_CODES.contains(code)) { - logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); - } - - assertEquals(Response.Status.CREATED.getStatusCode(), response.getStatus()); - - queryParameters.add("depth", "10000"); - - response = legacyMoxyConsumer.getLegacy(defaultSchemaVersion, uri, -1, -1, false, - "10000", "false", httpHeaders, uriInfo, mockReqGet); - - code = response.getStatus(); - if (!VALID_HTTP_STATUS_CODES.contains(code)) { - logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); - } - - String pserverEntity = response.getEntity().toString(); - JSONObject pserverJsonbject = new JSONObject(pserverEntity); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); - - JSONAssert.assertEquals(payload, pserverEntity, false); - - String resourceVersion = pserverJsonbject.getString("resource-version"); - - queryParameters.add("resource-version", resourceVersion); - - mockReq = new MockHttpServletRequest("DELETE", uri); - response = legacyMoxyConsumer.delete(defaultSchemaVersion, uri, httpHeaders, uriInfo, - "", mockReq); - - code = response.getStatus(); - if (!VALID_HTTP_STATUS_CODES.contains(code)) { - logger.info("Response Code: " + code + "\tEntity: " + response.getEntity()); - } - - assertEquals(Response.Status.NO_CONTENT.getStatusCode(), response.getStatus()); - - response = legacyMoxyConsumer.getLegacy(defaultSchemaVersion, uri, -1, -1, false, - "all", "false", httpHeaders, uriInfo, mockReqGet); - - assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus()); + PServer expected = mapper.readValue(payload, PServer.class); + + webClient.get() + .uri("/cloud-infrastructure/pservers/pserver/pserver-hostname-test?cleanup=false") + .exchange() + .expectStatus() + .isNotFound(); + + webClient.put() + .uri("/cloud-infrastructure/pservers/pserver/pserver-hostname-test") + .bodyValue(payload) + .exchange() + .expectStatus() + .isCreated(); + + PServer pserver = webClient.get() + .uri("/cloud-infrastructure/pservers/pserver/pserver-hostname-test?cleanup=false&depth=10000") + .exchange() + .expectStatus() + .isOk() + .returnResult(PServer.class) + .getResponseBody() + .blockFirst(); + + assertThat(pserver, samePropertyValuesAs(expected, "resourceVersion")); + + String resourceVersion = pserver.getResourceVersion(); + + webClient.delete() + .uri(uriBuilder -> uriBuilder + .path("/cloud-infrastructure/pservers/pserver/pserver-hostname-test") + .queryParam("resource-version", resourceVersion) + .build()) + .exchange() + .expectStatus() + .isNoContent(); + + webClient.get() + .uri("/cloud-infrastructure/pservers/pserver/pserver-hostname-test?cleanup=false&depth=10000") + .exchange() + .expectStatus() + .isNotFound(); } @Test public void testResponseGetOnResourcePaginated() throws JSONException, IOException, AAIException { - - String uri = getGetAllPserversURI(); - - if (uri.length() != 0 && uri.charAt(0) == '/') { - uri = uri.substring(1); - } - - when(uriInfo.getPath()).thenReturn(uri); - when(uriInfo.getPath(false)).thenReturn(uri); - - MockHttpServletRequest mockReqGet = new MockHttpServletRequest("GET", uri); - Response response = legacyMoxyConsumer.getLegacy(defaultSchemaVersion, uri, 1, 10, true, - "all", "false", httpHeaders, uriInfo, mockReqGet); - assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); + JanusGraph graph = AAIGraph.getInstance().getGraph(); + GraphTraversalSource g = graph.traversal(); + g.addV() + .property("aai-node-type", "pserver") + .property("hostname", "hostname1") + .property("resource-version", UUID.randomUUID().toString()) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/hostname1") + .addV() + .property("aai-node-type", "pserver") + .property("hostname", "hostname2") + .property("resource-version", UUID.randomUUID().toString()) + .property(AAIProperties.AAI_URI, "/cloud-infrastructure/pservers/pserver/hostname2") + .next(); + g.tx().commit(); + + PServerListResponse pservers = webClient.get() + .uri(uriBuilder -> + uriBuilder + .path("/cloud-infrastructure/pservers") + .queryParam("resultIndex", "1") + .queryParam("resultSize", "10") + .build()) + .exchange() + .expectStatus() + .isOk() + // TODO: Assert values here once test data is isolated to individual test + .expectHeader().exists("total-results") + .expectHeader().exists("total-pages") + .returnResult(PServerListResponse.class) + .getResponseBody() + .blockFirst(); + + assertTrue(pservers.getPserver().size() > 0); } @Test @@ -508,12 +516,12 @@ public class LegacyMoxyConsumerTest extends AAISetup { } public String getResourcePayload(String resourceName) throws IOException { - String rawPayload = getPayload("payloads/resource/" + resourceName + ".json"); + String rawPayload = IOUtils.toString(this.getClass().getResourceAsStream("/payloads/resource/" + resourceName + ".json"), StandardCharsets.UTF_8); return String.format(rawPayload, defaultSchemaVersion); } public String getRelationshipPayload(String relationshipName) throws IOException { - String rawPayload = getPayload("payloads/relationship/" + relationshipName + ".json"); + String rawPayload = IOUtils.toString(this.getClass().getResourceAsStream("/payloads/relationship/" + relationshipName + ".json"), StandardCharsets.UTF_8); return String.format(rawPayload, defaultSchemaVersion); } diff --git a/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java b/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java index 374519e..6679c0b 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/ModelDistributionTest.java @@ -26,9 +26,7 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.util.Collections; -import org.json.JSONObject; import org.junit.jupiter.api.Test; -import org.onap.aai.rest.AbstractSpringRestTest; import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; diff --git a/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java index 2e6d49e..e515098 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/URLFromVertexIdConsumerTest.java @@ -79,17 +79,10 @@ public class URLFromVertexIdConsumerTest extends AAISetup { private List<MediaType> outputMediaTypes; private static final Logger logger = LoggerFactory.getLogger(LegacyMoxyConsumerTest.class.getName()); - private boolean initialized = false; - - @BeforeAll - public static void setupRest() { - // AAIGraph.getInstance(); - } @BeforeEach public void setup() { - if (!initialized) { - initialized = true; + if(!AAIGraph.isInit()) { AAIGraph.getInstance(); } logger.info("Starting the setup for the integration tests of Rest Endpoints"); diff --git a/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java b/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java index ce9a423..8c62950 100644 --- a/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java +++ b/aai-resources/src/test/java/org/onap/aai/rest/VertexIdConsumerTest.java @@ -79,17 +79,10 @@ public class VertexIdConsumerTest extends AAISetup { private List<MediaType> outputMediaTypes; private static final Logger logger = LoggerFactory.getLogger(LegacyMoxyConsumerTest.class.getName()); - private boolean initialized = false; - - @BeforeAll - public static void setupRest() { - // AAIGraph.getInstance(); - } @BeforeEach public void setup() { - if (!initialized) { - initialized = true; + if(!AAIGraph.isInit()) { AAIGraph.getInstance(); } logger.info("Starting the setup for the integration tests of Rest Endpoints"); diff --git a/aai-resources/src/test/resources/application-test.properties b/aai-resources/src/test/resources/application-test.properties index a4b613c..253a191 100644 --- a/aai-resources/src/test/resources/application-test.properties +++ b/aai-resources/src/test/resources/application-test.properties @@ -20,7 +20,6 @@ spring.autoconfigure.exclude=\ org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration,\ org.springframework.boot.actuate.autoconfigure.security.servlet.ManagementWebSecurityAutoConfiguration -spring.profiles.active=production #The max number of active threads in this pool server.tomcat.threads.max=200 #The minimum number of threads always kept alive |