2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.oransc.participant.dme.restclient;
23 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
24 import static org.junit.jupiter.api.Assertions.assertFalse;
25 import static org.junit.jupiter.api.Assertions.assertThrows;
26 import static org.junit.jupiter.api.Assertions.assertTrue;
27 import static org.mockito.ArgumentMatchers.any;
28 import static org.mockito.Mockito.when;
30 import com.fasterxml.jackson.databind.ObjectMapper;
31 import com.oransc.participant.dme.rest.DataConsumerApiClient;
32 import com.oransc.participant.dme.rest.DataProducerRegistrationApiClient;
35 import java.util.stream.Stream;
36 import org.junit.jupiter.api.BeforeEach;
37 import org.junit.jupiter.api.Test;
38 import org.junit.jupiter.api.extension.ExtendWith;
39 import org.junit.jupiter.params.ParameterizedTest;
40 import org.junit.jupiter.params.provider.Arguments;
41 import org.junit.jupiter.params.provider.MethodSource;
42 import org.oransc.participant.dme.exception.DmeException;
43 import org.springframework.boot.test.mock.mockito.MockBean;
44 import org.springframework.http.ResponseEntity;
45 import org.springframework.test.context.junit.jupiter.SpringExtension;
47 @ExtendWith(SpringExtension.class)
48 class AcA1PmsClientTest {
51 DataProducerRegistrationApiClient dataProducerRegistrationApiClient;
54 DataConsumerApiClient dataConsumerApiClient;
57 AcDmeClient acDmeClient;
59 ObjectMapper objectMapper = new ObjectMapper();
63 acDmeClient = new AcDmeClient(dataProducerRegistrationApiClient, dataConsumerApiClient, objectMapper);
67 void testHealthyDme() {
68 when(dataProducerRegistrationApiClient.getInfoTypdentifiersWithHttpInfo()).thenReturn(
69 ResponseEntity.ok().build());
70 assertTrue(acDmeClient.isDmeHealthy());
74 void testUnhealthyDme() {
75 when(dataProducerRegistrationApiClient.getInfoTypdentifiersWithHttpInfo()).thenReturn(
76 ResponseEntity.internalServerError().build());
77 assertFalse(acDmeClient.isDmeHealthy());
81 @MethodSource("getInfoTypes")
82 void testcreateInfoTypeSuccess(Map<String, String> infoTypeMap) {
83 when(dataProducerRegistrationApiClient.putInfoTypeWithHttpInfo(any(), any())).thenReturn(
84 ResponseEntity.ok().build());
85 assertDoesNotThrow(() -> acDmeClient.createInfoType(infoTypeMap));
89 void testcreateInfoTypeFailure() {
90 when(dataProducerRegistrationApiClient.putInfoTypeWithHttpInfo(any(), any())).thenReturn(
91 ResponseEntity.internalServerError().build());
92 assertThrows(DmeException.class, () -> acDmeClient.createInfoType(Map.of("infotype1", "{}")));
96 @MethodSource("getDataProducers")
97 void testcreateDataProducerSuccess(Map<String, String> dataProducerMap) {
98 when(dataProducerRegistrationApiClient.putInfoProducerWithHttpInfo(any(), any())).thenReturn(
99 ResponseEntity.ok().build());
100 assertDoesNotThrow(() -> acDmeClient.createDataProducer(dataProducerMap));
105 void testcreateDataProducerFailure() {
106 when(dataProducerRegistrationApiClient.putInfoProducerWithHttpInfo(any(), any())).thenReturn(
107 ResponseEntity.internalServerError().build());
108 assertThrows(DmeException.class, () -> acDmeClient.createDataProducer(Map.of("producer1", "{}")));
112 @MethodSource("getDataConsumers")
113 void testcreateDataConsumerSuccess(Map<String, String> dataConsumerMap) {
114 when(dataConsumerApiClient.putIndividualInfoJobWithHttpInfo(any(), any())).thenReturn(
115 ResponseEntity.ok().build());
116 assertDoesNotThrow(() -> acDmeClient.createDataConsumer(dataConsumerMap));
120 void testcreateDataConsumerFailure() {
121 when(dataConsumerApiClient.putIndividualInfoJobWithHttpInfo(any(), any())).thenReturn(
122 ResponseEntity.internalServerError().build());
123 assertThrows(DmeException.class, () -> acDmeClient.createDataConsumer(Map.of("consumer1", "{}")));
127 @MethodSource("getDeleteDataProducers")
128 void testDeleteDataProducerSuccess() {
129 when(dataProducerRegistrationApiClient.deleteInfoProducerWithHttpInfo(any())).thenReturn(
130 ResponseEntity.ok().build());
131 assertDoesNotThrow(() -> acDmeClient.deleteDataProducer(Set.of("producer1")));
135 void testDeleteDataProducerFailure() {
136 when(dataProducerRegistrationApiClient.deleteInfoProducerWithHttpInfo(any())).thenReturn(
137 ResponseEntity.internalServerError().build());
138 assertThrows(DmeException.class, () -> acDmeClient.deleteDataProducer(Set.of("producer1")));
142 @MethodSource("getDeleteDataConsumers")
143 void testDeleteDataConsumerSuccess() {
144 when(dataConsumerApiClient.deleteIndividualInfoJobWithHttpInfo(any())).thenReturn(ResponseEntity.ok().build());
145 assertDoesNotThrow(() -> acDmeClient.deleteDataConsumer(Set.of("consumer1")));
149 void testDeleteDataConsumerFailure() {
150 when(dataConsumerApiClient.deleteIndividualInfoJobWithHttpInfo(any())).thenReturn(
151 ResponseEntity.internalServerError().build());
152 assertThrows(DmeException.class, () -> acDmeClient.deleteDataConsumer(Set.of("consumer1")));
155 private static Stream<Arguments> getDeleteDataProducers() {
156 return Stream.of(Arguments.of(Set.of("producer1")), Arguments.of(Set.of()));
159 private static Stream<Arguments> getDeleteDataConsumers() {
160 return Stream.of(Arguments.of(Set.of("consumer1")), Arguments.of(Set.of()));
162 private static Stream<Arguments> getInfoTypes() {
163 return Stream.of(Arguments.of(Map.of("infotype1", "{}")), Arguments.of(Map.of()));
166 private static Stream<Arguments> getDataProducers() {
167 return Stream.of(Arguments.of(Map.of("dataproducers", "{}")), Arguments.of(Map.of()));
170 private static Stream<Arguments> getDataConsumers() {
171 return Stream.of(Arguments.of(Map.of("dataconsumer", "{}")), Arguments.of(Map.of()));