2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.policy.pap.main.rest;
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
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;
35 public class PapRestControllerV1Test {
37 private PapRestControllerV1 ctlr;
38 private ResponseBuilder bldr;
42 ctlr = new PapRestControllerV1();
43 bldr = Response.status(Response.Status.OK);
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);
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));
63 public void testAddLoggingHeaders_Null() {
64 Response resp = ctlr.addLoggingHeaders(bldr, null).build();
65 assertNotNull(resp.getHeaderString(PapRestControllerV1.REQUEST_ID_NAME));
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));