ff2baa9a397ffa25d8ffbda1aeee0a407a7eba59
[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
28 import javax.ws.rs.core.Response;
29
30 import org.junit.Test;
31 import org.onap.policy.common.utils.coder.StandardCoder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
34
35 public class ErrorResponseTest {
36
37     public static final Logger logger = LoggerFactory.getLogger(ErrorResponseTest.class);
38
39     @Test
40     public void test() {
41         assertThatCode(() -> {
42             ErrorResponse error = new ErrorResponse();
43
44             error.setResponseCode(Response.Status.NOT_ACCEPTABLE);
45             error.setErrorMessage("Missing metadata section");
46
47             error.setErrorDetails(Arrays.asList("You must have a metadata section with policy-id value"));
48
49             error.setWarningDetails(Arrays.asList("Please make sure topology template field is included."));
50
51             StandardCoder coder = new StandardCoder();
52             String jsonOutput = coder.encode(error);
53
54             logger.debug("Resulting json output {}", jsonOutput);
55
56             ErrorResponse deserializedResponse = coder.decode(jsonOutput, ErrorResponse.class);
57
58             assertEquals(deserializedResponse, error);
59         }).doesNotThrowAnyException();
60     }
61
62 }