diff options
author | PatrikBuhr <patrik.buhr@est.tech> | 2021-04-28 08:42:13 +0200 |
---|---|---|
committer | PatrikBuhr <patrik.buhr@est.tech> | 2021-04-30 11:03:06 +0200 |
commit | 25d78500922291a2ade59799654c8b05a5ee7640 (patch) | |
tree | af76baca65c18e2fcb15e587b046f9f18a48ca9b /a1-policy-management/src/test | |
parent | b28e811178bf9d828615f62c67f30a78c0414eb1 (diff) |
PMS Persistent storage of service definitions - A1 Istanbul
Storing or registerred services to survice a restart.
Change-Id: If1b41d0a3c995b51bb93000caca5ecff9da6fbc1
Issue-ID: CCSDK-3256
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Diffstat (limited to 'a1-policy-management/src/test')
5 files changed, 76 insertions, 27 deletions
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 5ffe5153..84bc47ad 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 @@ -171,6 +171,7 @@ class ApplicationTest { services.clear(); a1ClientFactory.reset(); this.rAppSimulator.getTestResults().clear(); + this.a1ClientFactory.setPolicyTypes(policyTypes); // Default same types in RIC and in this app } @AfterEach @@ -200,11 +201,9 @@ class ApplicationTest { } @Test - void testPersistency() throws ServiceException { + void testPersistencyPolicies() throws ServiceException { Ric ric = this.addRic("ric1"); PolicyType type = this.addPolicyType("type1", ric.id()); - PolicyTypes types = new PolicyTypes(this.applicationConfig); - assertThat(types.size()).isEqualTo(1); final int noOfPolicies = 100; for (int i = 0; i < noOfPolicies; ++i) { @@ -213,27 +212,74 @@ class ApplicationTest { { Policies policies = new Policies(this.applicationConfig); - policies.restoreFromDatabase(ric, types); + policies.restoreFromDatabase(ric, this.policyTypes); assertThat(policies.size()).isEqualTo(noOfPolicies); } { restClient().delete("/policies/id2").block(); Policies policies = new Policies(this.applicationConfig); - policies.restoreFromDatabase(ric, types); + policies.restoreFromDatabase(ric, this.policyTypes); assertThat(policies.size()).isEqualTo(noOfPolicies - 1); } + } - { - // Test adding the RIC from configuration - RicConfig config = ric.getConfig(); - this.rics.remove("ric1"); - ApplicationConfig.RicConfigUpdate update = - new ApplicationConfig.RicConfigUpdate(config, ApplicationConfig.RicConfigUpdate.Type.ADDED); - refreshConfigTask.handleUpdatedRicConfig(update).block(); - ric = this.rics.getRic("ric1"); - assertThat(ric.getSupportedPolicyTypes().size()).isEqualTo(1); - } + @Test + void testPersistencyPolicyTypes() throws ServiceException { + Ric ric = this.addRic("ric1"); + this.addPolicyType("type1", ric.id()); + PolicyTypes types = new PolicyTypes(this.applicationConfig); + assertThat(types.size()).isEqualTo(1); + } + + @Test + void testPersistencyService() throws ServiceException { + final String SERVICE = "serviceName"; + putService(SERVICE, 1234, HttpStatus.CREATED); + assertThat(this.services.size()).isEqualTo(1); + Service service = this.services.getService(SERVICE); + + Services servicesRestored = new Services(this.applicationConfig); + Service serviceRestored = servicesRestored.getService(SERVICE); + assertThat(servicesRestored.size()).isEqualTo(1); + assertThat(serviceRestored.getCallbackUrl()).isEqualTo(service.getCallbackUrl()); + assertThat(serviceRestored.getKeepAliveInterval()).isEqualTo(service.getKeepAliveInterval()); + + // check that the service can be deleted + this.services.remove(SERVICE); + servicesRestored = new Services(this.applicationConfig); + assertThat(servicesRestored.size()).isEqualTo(0); + } + + @Test + void testAddingRicFromConfiguration() throws Exception { + // Test adding the RIC from configuration + + final String RIC = "ric1"; + final String TYPE = "type123"; + PolicyTypes nearRtRicPolicyTypes = new PolicyTypes(this.applicationConfig); + nearRtRicPolicyTypes.put(createPolicyType(TYPE)); + this.a1ClientFactory.setPolicyTypes(nearRtRicPolicyTypes); + + putService("service"); + + RicConfig config = ricConfig(RIC, "me1"); + ApplicationConfig.RicConfigUpdate update = + new ApplicationConfig.RicConfigUpdate(config, ApplicationConfig.RicConfigUpdate.Type.ADDED); + refreshConfigTask.handleUpdatedRicConfig(update).block(); + waitForRicState(RIC, RicState.AVAILABLE); + + // Test that the type has been synched + Ric addedRic = this.rics.getRic(RIC); + assertThat(addedRic.getSupportedPolicyTypes().size()).isEqualTo(1); + assertThat(addedRic.getSupportedPolicyTypes().iterator().next().getId()).isEqualTo(TYPE); + + // Check that a service callback for the AVAILABLE RIC is invoked + RappSimulatorController.TestResults receivedCallbacks = rAppSimulator.getTestResults(); + assertThat(receivedCallbacks.getReceivedInfo().size()).isEqualTo(1); + ServiceCallbackInfo callbackInfo = receivedCallbacks.getReceivedInfo().get(0); + assertThat(callbackInfo.ricId).isEqualTo(RIC); + assertThat(callbackInfo.eventType).isEqualTo(ServiceCallbackInfo.EventType.AVAILABLE); } @Test @@ -887,20 +933,25 @@ class ApplicationTest { return addRic(ricId, null); } - private Ric addRic(String ricId, String managedElement) { - if (rics.get(ricId) != null) { - return rics.get(ricId); - } + private RicConfig ricConfig(String ricId, String managedElement) { List<String> mes = new ArrayList<>(); if (managedElement != null) { mes.add(managedElement); } - RicConfig conf = ImmutableRicConfig.builder() // + return ImmutableRicConfig.builder() // .ricId(ricId) // .baseUrl(ricId) // .managedElementIds(mes) // .controllerName("") // .build(); + } + + private Ric addRic(String ricId, String managedElement) { + if (rics.get(ricId) != null) { + return rics.get(ricId); + } + + RicConfig conf = ricConfig(ricId, managedElement); Ric ric = new Ric(conf); ric.setState(Ric.RicState.AVAILABLE); this.rics.put(ric); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java index 83a2d784..e5998346 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/RappSimulatorController.java @@ -75,7 +75,7 @@ public class RappSimulatorController { content = @Content(schema = @Schema(implementation = VoidResponse.class)))} // ) - public ResponseEntity<Object> jobStatusCallback( // + public ResponseEntity<Object> serviceCallback( // @RequestBody ServiceCallbackInfo body) { logger.info("R-App callback body: {}", gson.toJson(body)); this.testResults.receivedInfo.add(body); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java index c999214d..762d800f 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RefreshConfigTaskTest.java @@ -121,7 +121,7 @@ class RefreshConfigTaskTest { boolean stubConfigFileExists) { RefreshConfigTask obj = spy(new RefreshConfigTask(configurationFileMock, appConfig, rics, policies, - new Services(), new PolicyTypes(appConfig), new A1ClientFactory(appConfig))); + new Services(appConfig), new PolicyTypes(appConfig), new A1ClientFactory(appConfig))); if (stubConfigFileExists) { when(configurationFileMock.readFile()).thenReturn(Optional.empty()); } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java index a2e7c75b..9bd5c502 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/RicSynchronizationTaskTest.java @@ -110,7 +110,7 @@ class RicSynchronizationTaskTest { void init() { policyTypes = new PolicyTypes(appConfig); policies = new Policies(appConfig); - services = new Services(); + services = new Services(appConfig); rics = new Rics(); RIC_1.setState(RicState.UNAVAILABLE); RIC_1.clearSupportedPolicyTypes(); @@ -165,7 +165,6 @@ class RicSynchronizationTaskTest { verifyNoMoreInteractions(a1ClientMock); verify(synchronizerUnderTest).run(RIC_1); - verify(synchronizerUnderTest).notifyServices(any()); assertThat(policyTypes.size()).isEqualTo(1); assertThat(policies.size()).isZero(); diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java index 4c0e96f5..294b220c 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/tasks/ServiceSupervisionTest.java @@ -177,11 +177,10 @@ class ServiceSupervisionTest { } private void setUpRepositoryWithKeepAliveInterval(Duration keepAliveInterval) { - services = new Services(); + ApplicationConfig appConfig = new ApplicationConfig(); + services = new Services(appConfig); service = new Service(SERVICE_NAME, keepAliveInterval, "callbackUrl"); services.put(service); - - ApplicationConfig appConfig = new ApplicationConfig(); policies = new Policies(appConfig); policies.put(policy); } |