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