Java 17 Upgrade
[policy/models.git] / models-errors / src / test / java / org / onap / policy / models / errors / concepts / ErrorResponseTest.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP Policy Decision Models
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * Modifications Copyright (C) 2023 Nordix Foundation.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.errors.concepts;
23
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.junit.Assert.assertEquals;
26
27 import jakarta.ws.rs.core.Response;
28 import java.util.List;
29 import org.junit.Test;
30 import org.onap.policy.common.utils.coder.StandardCoder;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33
34 public class ErrorResponseTest {
35
36     public static final Logger logger = LoggerFactory.getLogger(ErrorResponseTest.class);
37
38     @Test
39     public void test() {
40         assertThatCode(() -> {
41             ErrorResponse error = new ErrorResponse();
42
43             error.setResponseCode(Response.Status.NOT_ACCEPTABLE);
44             error.setErrorMessage("Missing metadata section");
45
46             error.setErrorDetails(List.of("You must have a metadata section with policy-id value"));
47
48             error.setWarningDetails(List.of("Please make sure topology template field is included."));
49
50             StandardCoder coder = new StandardCoder();
51             String jsonOutput = coder.encode(error);
52
53             logger.debug("Resulting json output {}", jsonOutput);
54
55             ErrorResponse deserializedResponse = coder.decode(jsonOutput, ErrorResponse.class);
56
57             assertEquals(deserializedResponse, error);
58         }).doesNotThrowAnyException();
59     }
60
61 }