diff options
author | PatrikBuhr <patrik.buhr@est.tech> | 2023-02-23 12:39:31 +0100 |
---|---|---|
committer | KAPIL SINGAL <ks220y@att.com> | 2023-02-27 14:38:18 +0000 |
commit | 1c317ebe1323f5f749adad062ec3486612ef7a25 (patch) | |
tree | 35d33696fdde90b1c71d05dbdcca99bc41464ad8 /a1-policy-management/src/test | |
parent | 4f8895586f154a6ad56774314d9caf714d944ed9 (diff) |
Removal of usage of DMaaP
Issue-ID: CCSDK-3852
Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Change-Id: I88a370ea81f56763f54fde472c30d894c0df04e3
Diffstat (limited to 'a1-policy-management/src/test')
21 files changed, 43 insertions, 653 deletions
diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspectTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspectTest.java index f8882440..cada8bc5 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspectTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/aspect/LogAspectTest.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java index a715191b..ef4ad1c8 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientFactoryTest.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java index 56dc7ed6..b42edb8f 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/A1ClientHelper.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientTest.java index 96769427..12ac46de 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/AsyncRestClientTest.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java index b2fc84a6..9bd10f3a 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/CcsdkA1AdapterClientTest.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java index 731c83a4..c376d90f 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/OscA1ClientTest.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java index 0af8a17c..40154b4f 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/clients/StdA1ClientV2Test.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java index 61543c0b..e43f4015 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigParserTest.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. @@ -28,7 +28,6 @@ import static org.mockito.Mockito.when; import com.google.common.base.Charsets; import com.google.common.io.Resources; -import com.google.gson.Gson; import com.google.gson.JsonIOException; import com.google.gson.JsonObject; import com.google.gson.JsonParser; @@ -61,14 +60,6 @@ class ApplicationConfigParserTest { ApplicationConfigParser.ConfigParserResult result = parserUnderTest.parse(jsonRootObject); - String topicUrl = result.getDmaapProducerTopicUrl(); - assertEquals("http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE", topicUrl, "controller contents"); - - topicUrl = result.getDmaapConsumerTopicUrl(); - assertEquals( - "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=15000&limit=100", - topicUrl, "controller contents"); - Map<String, ControllerConfig> controllers = result.getControllerConfigs(); assertEquals(1, controllers.size(), "size"); ControllerConfig expectedControllerConfig = ControllerConfig.builder() // @@ -90,71 +81,12 @@ class ApplicationConfigParserTest { } private static InputStream getCorrectJson() throws IOException { - URL url = ApplicationConfigParser.class.getClassLoader() - .getResource("test_application_configuration_with_dmaap_config.json"); + URL url = ApplicationConfigParser.class.getClassLoader().getResource("test_application_configuration.json"); String string = Resources.toString(url, Charsets.UTF_8); return new ByteArrayInputStream((string.getBytes(StandardCharsets.UTF_8))); } @Test - @DisplayName("test when Dmaap Config Has Several Streams Publishing") - void whenDmaapConfigHasSeveralStreamsPublishing() throws Exception { - JsonObject jsonRootObject = getJsonRootObject(); - JsonObject json = jsonRootObject.getAsJsonObject("config").getAsJsonObject("streams_publishes"); - JsonObject fake_info_object = new JsonObject(); - fake_info_object.addProperty("fake_info", "fake"); - json.add("fake_info_object", new Gson().toJsonTree(fake_info_object)); - DataPublishing data = new Gson().fromJson(json.toString(), DataPublishing.class); - final String expectedMessage = - "Invalid configuration. Number of streams must be one, config: " + data.toString(); - - Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject)); - - assertEquals(expectedMessage, actualException.getMessage(), - "Wrong error message when the DMaaP config has several streams publishing"); - } - - class DataPublishing { - private JsonObject dmaap_publisher; - private JsonObject fake_info_object; - - @Override - public String toString() { - return String.format("[dmaap_publisher=%s, fake_info_object=%s]", dmaap_publisher.toString(), - fake_info_object.toString()); - } - } - - @Test - @DisplayName("test when Dmaap Config Has Several Streams Subscribing") - void whenDmaapConfigHasSeveralStreamsSubscribing() throws Exception { - JsonObject jsonRootObject = getJsonRootObject(); - JsonObject json = jsonRootObject.getAsJsonObject("config").getAsJsonObject("streams_subscribes"); - JsonObject fake_info_object = new JsonObject(); - fake_info_object.addProperty("fake_info", "fake"); - json.add("fake_info_object", new Gson().toJsonTree(fake_info_object)); - DataSubscribing data = new Gson().fromJson(json.toString(), DataSubscribing.class); - final String expectedMessage = - "Invalid configuration. Number of streams must be one, config: " + data.toString(); - - Exception actualException = assertThrows(ServiceException.class, () -> parserUnderTest.parse(jsonRootObject)); - - assertEquals(expectedMessage, actualException.getMessage(), - "Wrong error message when the DMaaP config has several streams subscribing"); - } - - private class DataSubscribing { - private JsonObject dmaap_subscriber; - private JsonObject fake_info_object; - - @Override - public String toString() { - return String.format("[dmaap_subscriber=%s, fake_info_object=%s]", dmaap_subscriber.toString(), - fake_info_object.toString()); - } - } - - @Test @DisplayName("test when Wrong Member Name In Object") void whenWrongMemberNameInObject() throws Exception { JsonObject jsonRootObject = getJsonRootObject(); @@ -180,10 +112,4 @@ class ApplicationConfigParserTest { assertThat(actualException.getMessage()).contains("Json schema validation failure"); } - - JsonObject getDmaapInfo(JsonObject jsonRootObject, String streamsPublishesOrSubscribes, - String dmaapPublisherOrSubscriber) throws Exception { - return jsonRootObject.getAsJsonObject("config").getAsJsonObject(streamsPublishesOrSubscribes) - .getAsJsonObject(dmaapPublisherOrSubscriber).getAsJsonObject("dmaap_info"); - } } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java index 39a8aa89..15e4739a 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ApplicationConfigTest.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. @@ -55,8 +55,6 @@ class ApplicationConfigTest { ConfigParserResult configParserResult(RicConfig... rics) { return ConfigParserResult.builder() // .ricConfigs(Arrays.asList(rics)) // - .dmaapConsumerTopicUrl("dmaapConsumerTopicUrl") // - .dmaapProducerTopicUrl("dmaapProducerTopicUrl") // .controllerConfigs(new HashMap<>()) // .build(); } diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFileTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFileTest.java index 7875cfb5..b79a4ca8 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFileTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/configuration/ConfigurationFileTest.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. 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 4e535ab2..0bf212a7 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 @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java index 3c5b1d9e..c0a6b4e4 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/controllers/v2/ConfigurationControllerTest.java @@ -1,6 +1,6 @@ /*- * ========================LICENSE_START================================= - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. @@ -134,8 +134,8 @@ class ConfigurationControllerTest { } private String configAsString() throws Exception { - File configFile = new File(getClass().getClassLoader() - .getResource("test_application_configuration_with_dmaap_config.json").getFile()); + File configFile = + new File(getClass().getClassLoader().getResource("test_application_configuration.json").getFile()); return FileUtils.readFileToString(configFile, "UTF-8"); } 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 371bd959..337c4798 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 @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * O-RAN-SC * %% - * Copyright (C) 2020 Nordix Foundation + * Copyright (C) 2020-2023 Nordix Foundation * %% * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumerTest.java deleted file mode 100644 index 7abc5db8..00000000 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageConsumerTest.java +++ /dev/null @@ -1,215 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. 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.ccsdk.oran.a1policymanagementservice.dmaap; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; - -import java.util.ArrayList; - -import org.junit.Assert; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; -import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient; -import org.onap.ccsdk.oran.a1policymanagementservice.clients.SecurityContext; -import org.onap.ccsdk.oran.a1policymanagementservice.configuration.ApplicationConfig; -import org.onap.ccsdk.oran.a1policymanagementservice.dmaap.DmaapRequestMessage.Operation; -import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.ServiceException; -import org.onap.ccsdk.oran.a1policymanagementservice.utils.LoggingUtils; - -import reactor.core.publisher.Flux; -import reactor.core.publisher.Mono; - -@ExtendWith(MockitoExtension.class) -class DmaapMessageConsumerTest { - @Mock - private ApplicationConfig applicationConfigMock; - @Mock - private AsyncRestClient messageRouterConsumerMock; - @Mock - private DmaapMessageHandler messageHandlerMock; - - private DmaapMessageConsumer messageConsumerUnderTest; - - private Gson gson = new GsonBuilder().create(); - - @AfterEach - void resetLogging() { - LoggingUtils.getLogListAppender(DmaapMessageConsumer.class); - } - - private void setTaskNumberOfLoops(int number) { - ArrayList<Integer> l = new ArrayList<>(); - for (int i = 0; i < number; ++i) { - l.add(i); - } - Flux<Integer> f = Flux.fromIterable(l); - doReturn(f).when(messageConsumerUnderTest).infiniteFlux(); - } - - private void disableTaskDelay() { - doReturn(Mono.empty()).when(messageConsumerUnderTest).delay(); - } - - @Test - @DisplayName("successful Case dmaap Not Configured then Sleep And Retry Until Config") - void successfulCase_dmaapNotConfigured_thenSleepAndRetryUntilConfig() throws Exception { - messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock, new SecurityContext(""))); - - setTaskNumberOfLoops(3); - disableTaskDelay(); - - when(this.applicationConfigMock.getDmaapConsumerTopicUrl()).thenReturn("getDmaapConsumerTopicUrl"); - doReturn(false, false, true).when(messageConsumerUnderTest).isDmaapConfigured(); - doReturn(Mono.just(dmaapRequestMessageString())).when(messageConsumerUnderTest) - .getFromMessageRouter(anyString()); - - doReturn(Mono.just("responseFromHandler")).when(messageConsumerUnderTest).handleDmaapMsg(any()); - - String s = messageConsumerUnderTest.createTask().blockLast(); - assertEquals("responseFromHandler", s); - verify(messageConsumerUnderTest, times(2)).delay(); - verify(messageConsumerUnderTest, times(1)).handleDmaapMsg(any()); - } - - @Test - @DisplayName("return Error From Dmapp then Sleep And Retry") - void returnErrorFromDmapp_thenSleepAndRetry() throws Exception { - messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock, new SecurityContext(""))); - - setTaskNumberOfLoops(2); - disableTaskDelay(); - setUpMrConfig(); - - { - Mono<String> dmaapError = Mono.error(new ServiceException("dmaapError")); - Mono<String> dmaapResponse = Mono.just(dmaapRequestMessageString()); - doReturn(dmaapError, dmaapResponse).when(messageConsumerUnderTest).getFromMessageRouter(anyString()); - } - - doReturn(Mono.just("response1")).when(messageConsumerUnderTest).handleDmaapMsg(any()); - - String s = messageConsumerUnderTest.createTask().blockLast(); - - verify(messageConsumerUnderTest, times(2)).getFromMessageRouter(anyString()); - verify(messageConsumerUnderTest, times(0)).sendErrorResponse(anyString()); - verify(messageConsumerUnderTest, times(1)).delay(); - verify(messageConsumerUnderTest, times(1)).handleDmaapMsg(any()); - assertEquals("response1", s); - } - - @Test - @DisplayName("unParsable Message then Send Response And Continue") - void unParsableMessage_thenSendResponseAndContinue() throws Exception { - messageConsumerUnderTest = spy(new DmaapMessageConsumer(applicationConfigMock, new SecurityContext(""))); - setTaskNumberOfLoops(2); - setUpMrConfig(); - - { - Mono<String> dmaapError = Mono.just("Non valid JSON \""); - Mono<String> dmaapResponse = Mono.just(dmaapRequestMessageString()); - doReturn(dmaapError, dmaapResponse).when(messageConsumerUnderTest).getFromMessageRouter(anyString()); - } - - doReturn(Mono.just("response1")).when(messageConsumerUnderTest).handleDmaapMsg(any()); - - String s = messageConsumerUnderTest.createTask().blockLast(); - assertEquals("response1", s); - - verify(messageConsumerUnderTest, times(2)).getFromMessageRouter(anyString()); - verify(messageConsumerUnderTest, times(1)).sendErrorResponse(anyString()); - verify(messageConsumerUnderTest, times(0)).delay(); - verify(messageConsumerUnderTest, times(1)).handleDmaapMsg(dmaapRequestMessage()); - } - - private String dmaapRequestMessageString() { - String json = gson.toJson(dmaapRequestMessage()); - return jsonArray(json); - } - - @Test - @DisplayName("test Message Parsing") - void testMessageParsing() throws ServiceException { - messageConsumerUnderTest = new DmaapMessageConsumer(applicationConfigMock, new SecurityContext("")); - String json = gson.toJson(dmaapRequestMessage()); - { - String jsonArrayOfObject = jsonArray(json); - DmaapRequestMessage parsedMessage = - messageConsumerUnderTest.parseReceivedMessage(jsonArrayOfObject).blockLast(); - assertNotNull(parsedMessage); - assertNotNull(parsedMessage.getPayload()); - - Assert.assertEquals(dmaapRequestMessage(), parsedMessage); - } - { - String jsonArrayOfString = jsonArray(quote(json)); - DmaapRequestMessage parsedMessage = - messageConsumerUnderTest.parseReceivedMessage(jsonArrayOfString).blockLast(); - assertNotNull(parsedMessage); - assertNotNull(parsedMessage.getPayload()); - Assert.assertEquals(dmaapRequestMessage(), parsedMessage); - } - - } - - private void setUpMrConfig() { - when(applicationConfigMock.getDmaapConsumerTopicUrl()).thenReturn("url"); - when(applicationConfigMock.getDmaapProducerTopicUrl()).thenReturn("url"); - } - - private String jsonArray(String s) { - return "[" + s + "]"; - } - - private String quote(String s) { - return "\"" + s.replace("\"", "\\\"") + "\""; - } - - private DmaapRequestMessage dmaapRequestMessage() { - return DmaapRequestMessage.builder() // - .apiVersion("apiVersion") // - .correlationId("correlationId") // - .operation(Operation.PUT) // - .originatorId("originatorId") // - .payload(new JsonObject()) // - .requestId("requestId") // - .target("target") // - .timestamp("timestamp") // - .url("URL") // - .build(); - } - -} diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java deleted file mode 100644 index 2ec3664c..00000000 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/dmaap/DmaapMessageHandlerTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/*- - * ========================LICENSE_START================================= - * ONAP : ccsdk oran - * ====================================================================== - * Copyright (C) 2019-2020 Nordix Foundation. 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.ccsdk.oran.a1policymanagementservice.dmaap; - -import static ch.qos.logback.classic.Level.WARN; -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; - -import ch.qos.logback.classic.spi.ILoggingEvent; -import ch.qos.logback.core.read.ListAppender; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.JsonObject; - -import java.io.IOException; -import java.nio.charset.Charset; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.mockito.ArgumentCaptor; -import org.onap.ccsdk.oran.a1policymanagementservice.clients.AsyncRestClient; -import org.onap.ccsdk.oran.a1policymanagementservice.dmaap.DmaapRequestMessage.Operation; -import org.onap.ccsdk.oran.a1policymanagementservice.utils.LoggingUtils; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; -import org.springframework.http.ResponseEntity; -import org.springframework.web.reactive.function.client.WebClientResponseException; - -import reactor.core.publisher.Mono; -import reactor.test.StepVerifier; - -class DmaapMessageHandlerTest { - private static final String URL = "url"; - - private final AsyncRestClient dmaapClient = mock(AsyncRestClient.class); - private final AsyncRestClient pmsClient = mock(AsyncRestClient.class); - private DmaapMessageHandler testedObject; - private Gson gson = new GsonBuilder().create(); // - - @BeforeEach - private void setUp() throws Exception { - testedObject = spy(new DmaapMessageHandler(dmaapClient, pmsClient)); - } - - JsonObject payloadAsJson() { - return gson.fromJson(payloadAsString(), JsonObject.class); - } - - String payloadAsString() { - return "{\"param\":\"value\"}"; - } - - DmaapRequestMessage dmaapRequestMessage(Operation operation) { - JsonObject payload = ((operation == Operation.PUT || operation == Operation.POST) ? payloadAsJson() : null); - return DmaapRequestMessage.builder() // - .apiVersion("apiVersion") // - .correlationId("correlationId") // - .operation(operation) // - .originatorId("originatorId") // - .payload(payload) // - .requestId("requestId") // - .target("target") // - .timestamp("timestamp") // - .url(URL) // - .build(); - } - - private Mono<ResponseEntity<String>> okResponse() { - ResponseEntity<String> entity = new ResponseEntity<>("OK", HttpStatus.OK); - return Mono.just(entity); - } - - private Mono<ResponseEntity<String>> notOkResponse() { - ResponseEntity<String> entity = new ResponseEntity<>("NOK", HttpStatus.BAD_GATEWAY); - return Mono.just(entity); - } - - @Test - @DisplayName("test successful Delete") - void successfulDelete() throws IOException { - doReturn(okResponse()).when(pmsClient).deleteForEntity(anyString()); - doReturn(Mono.just("OK")).when(dmaapClient).post(anyString(), anyString()); - - DmaapRequestMessage message = dmaapRequestMessage(Operation.DELETE); - - StepVerifier // - .create(testedObject.handleDmaapMsg(message)) // - .expectSubscription() // - .expectNext("OK") // - .verifyComplete(); // - - verify(pmsClient).deleteForEntity(URL); - verifyNoMoreInteractions(pmsClient); - - verify(dmaapClient).post(anyString(), anyString()); - - verifyNoMoreInteractions(dmaapClient); - } - - @Test - @DisplayName("test successful Get") - void successfulGet() throws IOException { - doReturn(okResponse()).when(pmsClient).getForEntity(anyString()); - doReturn(Mono.just("OK")).when(dmaapClient).post(anyString(), anyString()); - - DmaapRequestMessage message = dmaapRequestMessage(Operation.GET); - StepVerifier // - .create(testedObject.handleDmaapMsg(message)) // - .expectSubscription() // - .expectNext("OK") // - .verifyComplete(); // - - verify(pmsClient).getForEntity(URL); - verifyNoMoreInteractions(pmsClient); - - verify(dmaapClient).post(anyString(), anyString()); - verifyNoMoreInteractions(dmaapClient); - } - - @Test - @DisplayName("test exception From Pms When Get then Post Error") - void exceptionFromPmsWhenGet_thenPostError() throws IOException { - String errorBody = "Unavailable"; - WebClientResponseException webClientResponseException = new WebClientResponseException( - HttpStatus.SERVICE_UNAVAILABLE.value(), "", (HttpHeaders) null, errorBody.getBytes(), (Charset) null); - doReturn(Mono.error(webClientResponseException)).when(pmsClient).getForEntity(anyString()); - doReturn(Mono.just("OK")).when(dmaapClient).post(anyString(), anyString()); - - DmaapRequestMessage message = dmaapRequestMessage(Operation.GET); - StepVerifier // - .create(testedObject.handleDmaapMsg(message)) // - .expectSubscription() // - .verifyComplete(); // - - ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); - verify(dmaapClient).post(anyString(), captor.capture()); - String actualMessage = captor.getValue(); - assertThat(actualMessage).contains(HttpStatus.SERVICE_UNAVAILABLE.toString()) // - .contains(errorBody); - } - - @Test - @DisplayName("test successful Put") - void successfulPut() throws IOException { - doReturn(okResponse()).when(pmsClient).putForEntity(anyString(), anyString()); - doReturn(Mono.just("OK")).when(dmaapClient).post(anyString(), anyString()); - - DmaapRequestMessage message = dmaapRequestMessage(Operation.PUT); - StepVerifier // - .create(testedObject.handleDmaapMsg(message)) // - .expectSubscription() // - .expectNext("OK") // - .verifyComplete(); // - - verify(pmsClient).putForEntity(URL, payloadAsString()); - verifyNoMoreInteractions(pmsClient); - - verify(dmaapClient).post(anyString(), anyString()); - verifyNoMoreInteractions(dmaapClient); - } - - @Test - @DisplayName("test successful Post") - void successfulPost() throws IOException { - doReturn(okResponse()).when(pmsClient).postForEntity(anyString(), anyString()); - doReturn(Mono.just("OK")).when(dmaapClient).post(anyString(), anyString()); - - DmaapRequestMessage message = dmaapRequestMessage(Operation.POST); - StepVerifier // - .create(testedObject.handleDmaapMsg(message)) // - .expectSubscription() // - .expectNext("OK") // - .verifyComplete(); // - - verify(pmsClient).postForEntity(URL, payloadAsString()); - verifyNoMoreInteractions(pmsClient); - - verify(dmaapClient).post(anyString(), anyString()); - verifyNoMoreInteractions(dmaapClient); - } - - @Test - @DisplayName("test exception When Calling Pms then Error Response") - void exceptionWhenCallingPms_thenErrorResponse() throws IOException { - - doReturn(notOkResponse()).when(pmsClient).putForEntity(anyString(), anyString()); - doReturn(Mono.just("OK")).when(dmaapClient).post(anyString(), anyString()); - - DmaapRequestMessage message = dmaapRequestMessage(Operation.PUT); - testedObject.handleDmaapMsg(message).block(); - - verify(pmsClient).putForEntity(anyString(), anyString()); - verifyNoMoreInteractions(pmsClient); - - ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class); - verify(dmaapClient).post(anyString(), captor.capture()); - String actualMessage = captor.getValue(); - assertThat(actualMessage).as("Message \"%s\" sent to DMaaP contains %s", actualMessage, HttpStatus.BAD_GATEWAY) - .contains(HttpStatus.BAD_GATEWAY.toString()); - - verifyNoMoreInteractions(dmaapClient); - } - - @Test - @DisplayName("test put Without Payload then Not Found Response With Warning") - void putWithoutPayload_thenNotFoundResponseWithWarning() throws Exception { - DmaapRequestMessage message = DmaapRequestMessage.builder() // - .apiVersion("apiVersion") // - .correlationId("correlationId") // - .operation(DmaapRequestMessage.Operation.PUT) // - .originatorId("originatorId") // - .payload(null) // - .requestId("requestId") // - .target("target") // - .timestamp("timestamp") // - .url(URL) // - .build(); - - final ListAppender<ILoggingEvent> logAppender = - LoggingUtils.getLogListAppender(DmaapMessageHandler.class, WARN); - - doReturn(notOkResponse()).when(pmsClient).putForEntity(anyString(), anyString()); - testedObject.handleDmaapMsg(message).block(); - - assertThat(logAppender.list.get(0).getFormattedMessage()) - .startsWith("Expected payload in message from DMAAP: "); - } - -} 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 a2d20ac2..d84359ad 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 @@ -40,7 +40,6 @@ import java.time.Duration; import java.util.Arrays; import java.util.Optional; import java.util.Properties; -import java.util.Vector; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -74,13 +73,6 @@ class RefreshConfigTaskTest { @Mock ConfigurationFile configurationFileMock; - private static final String RIC_1_NAME = "ric1"; - private static final RicConfig CORRECT_RIC_CONIFG = RicConfig.builder() // - .ricId(RIC_1_NAME) // - .baseUrl("http://localhost:8080/") // - .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) // - .build(); - private RefreshConfigTask createTestObject(boolean configFileExists) { return createTestObject(configFileExists, spy(new Rics()), new Policies(appConfig), true); } @@ -120,10 +112,9 @@ class RefreshConfigTaskTest { verify(refreshTaskUnderTest.rics, times(2)).put(any(Ric.class)); - Iterable<RicConfig> ricConfigs = appConfig.getRicConfigs(); - RicConfig ricConfig = ricConfigs.iterator().next(); + java.util.Collection<RicConfig> ricConfigs = appConfig.getRicConfigs(); assertThat(ricConfigs).isNotNull(); - assertThat(ricConfig).isEqualTo(CORRECT_RIC_CONIFG); + assertThat(ricConfigs).hasSize(2); } @Test 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 7b5e9768..1b41ce08 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 @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. 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 1f933cde..c2f419fb 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 @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java index 80bfff72..91b762c5 100644 --- a/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java +++ b/a1-policy-management/src/test/java/org/onap/ccsdk/oran/a1policymanagementservice/utils/MockA1Client.java @@ -2,7 +2,7 @@ * ========================LICENSE_START================================= * ONAP : ccsdk oran * ====================================================================== - * Copyright (C) 2020 Nordix Foundation. All rights reserved. + * Copyright (C) 2020-2023 Nordix Foundation. 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. diff --git a/a1-policy-management/src/test/resources/test_application_configuration.json b/a1-policy-management/src/test/resources/test_application_configuration.json index fef2382a..c9f67a46 100644 --- a/a1-policy-management/src/test/resources/test_application_configuration.json +++ b/a1-policy-management/src/test/resources/test_application_configuration.json @@ -1,10 +1,20 @@ { "config": { - "description": "Application configuration", + "description": "Test", + "controller": [ + { + "name": "controller1", + "baseUrl": "http://localhost:8083/", + "userName": "user", + "password": "password" + } + ], "ric": [ { "name": "ric1", - "baseUrl": "http://localhost:8080/", + "controller": "controller1", + "baseUrl": "http://localhost:8083/", + "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory", "managedElementIds": [ "kista_1", "kista_2" @@ -12,29 +22,20 @@ }, { "name": "ric2", - "baseUrl": "http://localhost:8081/", - "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory", + "baseUrl": "http://localhost:8085/", + "managedElementIds": [ + "kista_3", + "kista_4" + ] + }, + { + "name": "ric3_noBaseURL", + "baseUrl": "", "managedElementIds": [ "kista_3", "kista_4" ] } - ], - "streams_publishes": { - "dmaap_publisher": { - "type": "message_router", - "dmaap_info": { - "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE" - } - } - }, - "streams_subscribes": { - "dmaap_subscriber": { - "type": "message_router", - "dmaap_info": { - "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=15000&limit=100" - } - } - } + ] } } diff --git a/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json b/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json deleted file mode 100644 index 6e1de75e..00000000 --- a/a1-policy-management/src/test/resources/test_application_configuration_with_dmaap_config.json +++ /dev/null @@ -1,57 +0,0 @@ -{ - "config": { - "description": "Test", - "controller": [ - { - "name": "controller1", - "baseUrl": "http://localhost:8083/", - "userName": "user", - "password": "password" - } - ], - "ric": [ - { - "name": "ric1", - "controller": "controller1", - "baseUrl": "http://localhost:8083/", - "customAdapterClass": "org.onap.ccsdk.oran.a1policymanagementservice.clients.StdA1ClientVersion2$Factory", - "managedElementIds": [ - "kista_1", - "kista_2" - ] - }, - { - "name": "ric2", - "baseUrl": "http://localhost:8085/", - "managedElementIds": [ - "kista_3", - "kista_4" - ] - }, - { - "name": "ric3_noBaseURL", - "baseUrl": "", - "managedElementIds": [ - "kista_3", - "kista_4" - ] - } - ], - "streams_publishes": { - "dmaap_publisher": { - "type": "message_router", - "dmaap_info": { - "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-WRITE" - } - } - }, - "streams_subscribes": { - "dmaap_subscriber": { - "type": "message_router", - "dmaap_info": { - "topic_url": "http://admin:admin@localhost:6845/events/A1-POLICY-AGENT-READ/users/policy-agent?timeout=15000&limit=100" - } - } - } - } -}
\ No newline at end of file |