summaryrefslogtreecommitdiffstats
path: root/a1-policy-management/src/test
diff options
context:
space:
mode:
authorPatrikBuhr <patrik.buhr@est.tech>2022-10-14 11:38:22 +0200
committerPatrikBuhr <patrik.buhr@est.tech>2022-11-11 15:08:52 +0100
commite3693cfdaf24a9ecaa341c938eb8b1d61a61cbf6 (patch)
treea2e2a791c5ef0e710056a3ebf0a3e2ad2ab12a95 /a1-policy-management/src/test
parent7e311a7dd9490ba90decde4b98460bb965567c08 (diff)
Support for using Amazon S3 - Cloud Object Storage
Introduce using Amazon S3 - Cloud Object Storage - AWS for storing of data. Change-Id: I68365c24c63544b5ad8e958a98f48d95f83e3084 Issue-ID: CCSDK-3810 Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src/test')
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java (renamed from a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java)84
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ApplicationTest.java39
-rw-r--r--a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java1
3 files changed, 74 insertions, 50 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java
index bd315c26..5ab3d5a3 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshCounterTaskTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/MetersTest.java
@@ -18,23 +18,21 @@
* ========================LICENSE_END===================================
*/
-package org.onap.ccsdk.oran.a1policymanagementservice.tasks;
+package org.onap.ccsdk.oran.a1policymanagementservice.configuration;
import static org.assertj.core.api.Assertions.assertThat;
-import static org.mockito.Mockito.spy;
-import io.micrometer.core.instrument.MeterRegistry;
import io.micrometer.prometheus.PrometheusConfig;
import io.micrometer.prometheus.PrometheusMeterRegistry;
+
import java.time.Instant;
import java.util.Arrays;
import java.util.Vector;
+
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig;
-import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policies;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
@@ -43,7 +41,7 @@ import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
@ExtendWith(MockitoExtension.class)
-class RefreshCounterTaskTest {
+public class MetersTest {
private static final String POLICY_TYPE_1_NAME = "type1";
private static final PolicyType POLICY_TYPE_1 = PolicyType.builder().id(POLICY_TYPE_1_NAME).schema("").build();
@@ -57,21 +55,28 @@ class RefreshCounterTaskTest {
.ric(RIC_1).type(POLICY_TYPE_1).lastModified(Instant.now()).isTransient(false)
.statusNotificationUri("statusNotificationUri").build();
- private final PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
+ private PrometheusMeterRegistry prometheusMeterRegistry = new PrometheusMeterRegistry(PrometheusConfig.DEFAULT);
private final ApplicationConfig appConfig = new ApplicationConfig();
- private PolicyTypes policyTypes;
+ private PolicyTypes types;
private Policies policies;
private Rics rics = new Rics();
+ Meters testObject;
+
@BeforeEach
void init() {
- policyTypes = new PolicyTypes(appConfig);
+ types = new PolicyTypes(appConfig);
policies = new Policies(appConfig);
rics.clear();
+ policies.clear();
+ types.clear();
+
RIC_1.setState(Ric.RicState.AVAILABLE);
RIC_1.clearSupportedPolicyTypes();
+
+ this.testObject = createMeters();
}
@Test
@@ -80,16 +85,15 @@ class RefreshCounterTaskTest {
RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
rics.put(RIC_1);
- policyTypes.put(POLICY_TYPE_1);
+ types.put(POLICY_TYPE_1);
policies.put(POLICY_1);
- RefreshCounterTask spy = spy(createRefreshCounterTask()); // instantiate RefreshCounterTask
- MeterRegistry meterRegistry = spy.getMeterRegistry();
+ createMeters();
- assertThat(meterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
- assertThat(meterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
- assertThat(meterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
+ assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
+ assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
+ assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
}
@Test
@@ -98,30 +102,27 @@ class RefreshCounterTaskTest {
RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
rics.put(RIC_1);
- policyTypes.put(POLICY_TYPE_1);
+ types.put(POLICY_TYPE_1);
policies.put(POLICY_1);
String POLICY_2_ID = "policyId2";
- Policy POLICY_2 = Policy.builder()
- .id(POLICY_2_ID)
- .json("")
- .ownerServiceId("service")
- .ric(RIC_1)
- .type(POLICY_TYPE_1)
- .lastModified(Instant.now())
+ Policy POLICY_2 = Policy.builder() //
+ .id(POLICY_2_ID) //
+ .json("") //
+ .ownerServiceId("service") //
+ .ric(RIC_1) //
+ .type(POLICY_TYPE_1) //
+ .lastModified(Instant.now()) //
.isTransient(false) //
- .statusNotificationUri("statusNotificationUri")
+ .statusNotificationUri("statusNotificationUri") //
.build();
policies.put(POLICY_2);
- RefreshCounterTask spy = spy(createRefreshCounterTask()); // instantiate RefreshCounterTask
- MeterRegistry meterRegistry = spy.getMeterRegistry();
-
- assertThat(meterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
- assertThat(meterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
- assertThat(meterRegistry.get("total_policy_count").gauge().value()).isEqualTo(2);
+ assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
+ assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(1);
+ assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(2);
}
@Test
@@ -129,29 +130,26 @@ class RefreshCounterTaskTest {
RIC_1.setState(Ric.RicState.AVAILABLE);
String POLICY_TYPE_2_NAME = "type2";
- PolicyType POLICY_TYPE_2 = PolicyType.builder()
- .id(POLICY_TYPE_2_NAME)
- .schema("")
+ PolicyType POLICY_TYPE_2 = PolicyType.builder() //
+ .id(POLICY_TYPE_2_NAME) //
+ .schema("") //
.build();
RIC_1.addSupportedPolicyType(POLICY_TYPE_1);
RIC_1.addSupportedPolicyType(POLICY_TYPE_2);
rics.put(RIC_1);
- policyTypes.put(POLICY_TYPE_1);
- policyTypes.put(POLICY_TYPE_2);
+ types.put(POLICY_TYPE_1);
+ types.put(POLICY_TYPE_2);
policies.put(POLICY_1);
- RefreshCounterTask spy = spy(createRefreshCounterTask()); // instantiate RefreshCounterTask
- MeterRegistry meterRegistry = spy.getMeterRegistry();
-
- assertThat(meterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
- assertThat(meterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(2);
- assertThat(meterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
+ assertThat(prometheusMeterRegistry.get("total_ric_count").gauge().value()).isEqualTo(1);
+ assertThat(prometheusMeterRegistry.get("total_policy_type_count").gauge().value()).isEqualTo(2);
+ assertThat(prometheusMeterRegistry.get("total_policy_count").gauge().value()).isEqualTo(1);
}
- private RefreshCounterTask createRefreshCounterTask() {
- return new RefreshCounterTask(rics, policyTypes, policies, prometheusMeterRegistry);
+ private Meters createMeters() {
+ return new Meters(rics, types, policies, prometheusMeterRegistry);
}
}
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 ab58027a..76838bb8 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
@@ -44,6 +44,7 @@ import java.util.Collections;
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.Test;
import org.onap.ccsdk.oran.a1policymanagementservice.clients.A1ClientFactory;
@@ -87,6 +88,7 @@ import org.springframework.http.HttpStatus;
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.WebClientResponseException;
import reactor.core.publisher.Mono;
@@ -98,8 +100,9 @@ import reactor.util.annotation.Nullable;
"server.ssl.key-store=./config/keystore.jks", //
"app.webclient.trust-store=./config/truststore.jks", //
"app.webclient.trust-store-used=true", //
- "app.vardata-directory=./target/testdata", //
- "app.filepath=" //
+ "app.vardata-directory=/tmp/pmstest", //
+ "app.filepath=", //
+ "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);
@@ -178,6 +181,15 @@ class ApplicationTest {
this.securityContext.setAuthTokenFilePath(null);
}
+ @AfterAll
+ static void clearTestDir() {
+ try {
+ FileSystemUtils.deleteRecursively(Path.of("/tmp/pmstest"));
+ } catch (Exception e) {
+ logger.warn("Could test directory : {}", e.getMessage());
+ }
+ }
+
@AfterEach
void verifyNoRicLocks() {
for (Ric ric : this.rics.getRics()) {
@@ -205,7 +217,7 @@ class ApplicationTest {
}
@Test
- void testPersistencyPolicies() throws ServiceException {
+ void testPersistencyPolicies() throws Exception {
Ric ric = this.addRic("ric1");
PolicyType type = this.addPolicyType("type1", ric.id());
@@ -213,37 +225,50 @@ class ApplicationTest {
for (int i = 0; i < noOfPolicies; ++i) {
addPolicy("id" + i, type.getId(), "service", ric.id());
}
+ waitforS3();
{
Policies policies = new Policies(this.applicationConfig);
- policies.restoreFromDatabase(ric, this.policyTypes);
+ policies.restoreFromDatabase(ric, this.policyTypes).blockLast();
assertThat(policies.size()).isEqualTo(noOfPolicies);
}
{
restClient().delete("/policies/id2").block();
Policies policies = new Policies(this.applicationConfig);
- policies.restoreFromDatabase(ric, this.policyTypes);
+ policies.restoreFromDatabase(ric, this.policyTypes).blockLast();
assertThat(policies.size()).isEqualTo(noOfPolicies - 1);
}
}
@Test
- void testPersistencyPolicyTypes() throws ServiceException {
+ void testPersistencyPolicyTypes() throws Exception {
Ric ric = this.addRic("ric1");
this.addPolicyType("type1", ric.id());
+ waitforS3();
+
PolicyTypes types = new PolicyTypes(this.applicationConfig);
+ types.restoreFromDatabase().blockLast();
assertThat(types.size()).isEqualTo(1);
}
+ @SuppressWarnings("squid:S2925") // "Thread.sleep" should not be used in tests.
+ private void waitforS3() throws Exception {
+ if (applicationConfig.isS3Enabled()) {
+ Thread.sleep(1000);
+ }
+ }
+
@Test
- void testPersistencyService() throws ServiceException {
+ void testPersistencyService() throws Exception {
final String SERVICE = "serviceName";
putService(SERVICE, 1234, HttpStatus.CREATED);
assertThat(this.services.size()).isEqualTo(1);
Service service = this.services.getService(SERVICE);
+ waitforS3();
Services servicesRestored = new Services(this.applicationConfig);
+ servicesRestored.restoreFromDatabase().blockLast();
Service serviceRestored = servicesRestored.getService(SERVICE);
assertThat(servicesRestored.size()).isEqualTo(1);
assertThat(serviceRestored.getCallbackUrl()).isEqualTo(service.getCallbackUrl());
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
index d9b36d9c..b2bf58e4 100644
--- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
+++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSupervisionTest.java
@@ -34,6 +34,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Vector;
+
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;