2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2021 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.onap.policy.clamp.controlloop.common.rest;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
26 import java.io.ByteArrayInputStream;
27 import java.io.ByteArrayOutputStream;
28 import java.io.IOException;
29 import org.junit.jupiter.api.Test;
30 import org.mockito.Mockito;
31 import org.onap.policy.clamp.controlloop.common.exception.ControlLoopRuntimeException;
32 import org.onap.policy.clamp.controlloop.common.startstop.CommonCommandLineArguments;
33 import org.springframework.http.HttpInputMessage;
34 import org.springframework.http.HttpOutputMessage;
36 class CoderHttpMessageConverterTest {
40 void coderHttpMesageConverterTest() throws ControlLoopRuntimeException, IOException {
41 var y = new CoderHttpMesageConverter<>("yaml");
42 var j = new CoderHttpMesageConverter<>("json");
44 assertTrue(y.supports(CommonCommandLineArguments.class));
45 assertTrue(j.supports(CommonCommandLineArguments.class));
46 var testInputStream = new ByteArrayInputStream("testdata".getBytes());
47 HttpInputMessage input = Mockito.mock(HttpInputMessage.class);
48 Mockito.when(input.getBody()).thenReturn(testInputStream);
49 assertThrows(ControlLoopRuntimeException.class, () -> {
50 y.readInternal(RequestResponseLoggingFilterTest.class, input);
53 var testOutputStream = new ByteArrayOutputStream();
54 HttpOutputMessage output = Mockito.mock(HttpOutputMessage.class);
55 Mockito.when(output.getBody()).thenReturn(testOutputStream);
56 assertThrows(ControlLoopRuntimeException.class, () -> {
57 j.writeInternal(String.class, output);