aboutsummaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2022-11-28 09:40:36 +0100
committerPatrikBuhr <patrik.buhr@est.tech>2023-01-11 11:10:35 +0100
commitc0218ada67784a7d5c3a488303bcbab2b3dce5b5 (patch)
treecc864b9997d3c1da6dbfdedf96ec5c57c0750870 /a1-policy-management/src/test
parent4242d5b611a547a437183ccdcb2e59ac11d27837 (diff)
A1-PMS, graceful shutdown
Support for granceful shutdown via signal "SIGTERM" and via calling REST POST /actuator/shutdown Issue-ID: CCSDK-3830 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech> Change-Id: Ibc71cd8a2c9f44ec844ab49c8f225ae128549776
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java3
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java34
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java3
3 files changed, 37 insertions, 3 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
index 3b7695e8..d60c4322 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/MockPolicyManagementService.java
@@ -27,6 +27,7 @@ import com.google.gson.JsonParser;
import java.io.File;
import java.io.IOException;
+import java.lang.invoke.MethodHandles;
import java.net.URL;
import java.nio.file.Files;
import java.time.Instant;
@@ -61,7 +62,7 @@ import org.springframework.util.StringUtils;
// but a mock
// of the server.
class MockPolicyManagementService {
- private static final Logger logger = LoggerFactory.getLogger(MockPolicyManagementService.class);
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Autowired
Rics rics;
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
index bec55735..1e8278a9 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java
@@ -33,6 +33,7 @@ import com.google.gson.GsonBuilder;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.lang.invoke.MethodHandles;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -46,7 +47,9 @@ import java.util.List;
import org.json.JSONObject;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.MethodOrderer;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.TestMethodOrder;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClientFactory;
@@ -89,12 +92,14 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.TestPropertySource;
import org.springframework.util.FileSystemUtils;
+import org.springframework.web.reactive.function.client.WebClientRequestException;
import org.springframework.web.reactive.function.client.WebClientResponseException;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import reactor.util.annotation.Nullable;
+@TestMethodOrder(MethodOrderer.MethodName.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
@TestPropertySource(properties = { //
"server.ssl.key-store=./config/keystore.jks", //
@@ -105,7 +110,7 @@ import reactor.util.annotation.Nullable;
"app.s3.bucket=" // If this is set, S3 will be used to store data.
})
class ApplicationTest {
- private static final Logger logger = LoggerFactory.getLogger(ApplicationTest.class);
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
@Autowired
ApplicationContext context;
@@ -201,6 +206,33 @@ class ApplicationTest {
}
@Test
+ @SuppressWarnings("squid:S2925") // "Thread.sleep" should not be used in tests.
+ void testZZActuator() throws Exception {
+ // The test must be run last, hence the "ZZ" in the name. All succeeding tests
+ // will fail.
+ AsyncRestClient client = restClient(baseUrl(), false);
+
+ client.post("/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice",
+ "{\"configuredLevel\":\"trace\"}").block();
+
+ String resp = client.get("/actuator/loggers/org.onap.ccsdk.oran.a1policymanagementservice").block();
+ assertThat(resp).contains("TRACE");
+
+ client.post("/actuator/loggers/org.springframework.boot.actuate", "{\"configuredLevel\":\"trace\"}").block();
+
+ // This will stop the web server and all coming tests will fail.
+ client.post("/actuator/shutdown", "").block();
+
+ Thread.sleep(1000);
+
+ StepVerifier.create(restClient().get("/rics")) // Any call
+ .expectSubscription() //
+ .expectErrorMatches(t -> t instanceof WebClientRequestException) //
+ .verify();
+
+ }
+
+ @Test
void generateApiDoc() throws IOException {
String url = "https://localhost:" + this.port + "/v3/api-docs";
ResponseEntity<String> resp = restClient("", false).getForEntity(url).block();
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java
index 3a4aae86..4e535ab2 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConcurrencyTestRunnable.java
@@ -23,6 +23,7 @@ package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
+import java.lang.invoke.MethodHandles;
import java.time.Instant;
import java.util.concurrent.atomic.AtomicInteger;
@@ -44,7 +45,7 @@ import org.springframework.http.ResponseEntity;
* thread. For test of robustness using concurrent clients.
*/
class ConcurrencyTestRunnable implements Runnable {
- private static final Logger logger = LoggerFactory.getLogger(ConcurrencyTestRunnable.class);
+ private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
private final AsyncRestClient webClient;
static AtomicInteger nextCount = new AtomicInteger(0);
private final int count;