58015ae3d1b60747c2823edee50cf34539cf7ef8
[policy/clamp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.controlloop.common.rest;
22
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25
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;
35
36 class CoderHttpMessageConverterTest {
37
38
39     @Test
40     void coderHttpMesageConverterTest() throws ControlLoopRuntimeException, IOException {
41         var y = new CoderHttpMesageConverter<>("yaml");
42         var j = new CoderHttpMesageConverter<>("json");
43
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);
51         });
52
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);
58         });
59     }
60 }