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
12 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
22 package org.onap.policy.models.errors.concepts;
24 import static org.assertj.core.api.Assertions.assertThatCode;
25 import static org.junit.Assert.assertEquals;
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;
34 public class ErrorResponseTest {
36 public static final Logger logger = LoggerFactory.getLogger(ErrorResponseTest.class);
40 assertThatCode(() -> {
41 ErrorResponse error = new ErrorResponse();
43 error.setResponseCode(Response.Status.NOT_ACCEPTABLE);
44 error.setErrorMessage("Missing metadata section");
46 error.setErrorDetails(List.of("You must have a metadata section with policy-id value"));
48 error.setWarningDetails(List.of("Please make sure topology template field is included."));
50 StandardCoder coder = new StandardCoder();
51 String jsonOutput = coder.encode(error);
53 logger.debug("Resulting json output {}", jsonOutput);
55 ErrorResponse deserializedResponse = coder.decode(jsonOutput, ErrorResponse.class);
57 assertEquals(deserializedResponse, error);
58 }).doesNotThrowAnyException();