Add yaml support to pap rest server
[policy/pap.git] / main / src / test / java / org / onap / policy / pap / main / rest / PapRestControllerV1Test.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
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.pap.main.rest;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26
27 import java.util.UUID;
28 import javax.ws.rs.Produces;
29 import javax.ws.rs.core.MediaType;
30 import javax.ws.rs.core.Response;
31 import javax.ws.rs.core.Response.ResponseBuilder;
32 import org.junit.Before;
33 import org.junit.Test;
34
35 public class PapRestControllerV1Test {
36
37     private PapRestControllerV1 ctlr;
38     private ResponseBuilder bldr;
39
40     @Before
41     public void setUp() {
42         ctlr = new PapRestControllerV1();
43         bldr = Response.status(Response.Status.OK);
44     }
45
46     @Test
47     public void testProduces() {
48         Produces annotation = PapRestControllerV1.class.getAnnotation(Produces.class);
49         assertNotNull(annotation);
50         assertThat(annotation.value()).contains(MediaType.APPLICATION_JSON)
51                         .contains(PapRestControllerV1.APPLICATION_YAML);
52     }
53
54     @Test
55     public void testAddVersionControlHeaders() {
56         Response resp = ctlr.addVersionControlHeaders(bldr).build();
57         assertEquals("0", resp.getHeaderString(PapRestControllerV1.VERSION_MINOR_NAME));
58         assertEquals("0", resp.getHeaderString(PapRestControllerV1.VERSION_PATCH_NAME));
59         assertEquals("1.0.0", resp.getHeaderString(PapRestControllerV1.VERSION_LATEST_NAME));
60     }
61
62     @Test
63     public void testAddLoggingHeaders_Null() {
64         Response resp = ctlr.addLoggingHeaders(bldr, null).build();
65         assertNotNull(resp.getHeaderString(PapRestControllerV1.REQUEST_ID_NAME));
66     }
67
68     @Test
69     public void testAddLoggingHeaders_NonNull() {
70         UUID uuid = UUID.randomUUID();
71         Response resp = ctlr.addLoggingHeaders(bldr, uuid).build();
72         assertEquals(uuid.toString(), resp.getHeaderString(PapRestControllerV1.REQUEST_ID_NAME));
73     }
74 }