Remove 'All rights reserved.' on apache 2 license
[externalapi/nbi.git] / src / test / java / org / onap / nbi / apis / StatusResourceTest.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
4  *     Licensed under the Apache License, Version 2.0 (the "License");
5  *     you may not use this file except in compliance with the License.
6  *     You may obtain a copy of the License at
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *     Unless required by applicable law or agreed to in writing, software
11  *     distributed under the License is distributed on an "AS IS" BASIS,
12  *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *     See the License for the specific language governing permissions and
14  *     limitations under the License.
15  */
16 package org.onap.nbi.apis;
17
18
19 import com.fasterxml.jackson.databind.node.ObjectNode;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.junit.runner.RunWith;
23 import org.onap.nbi.apis.status.StatusResource;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.boot.test.context.SpringBootTest;
26 import org.springframework.http.HttpStatus;
27 import org.springframework.http.ResponseEntity;
28 import org.springframework.mock.web.MockHttpServletRequest;
29 import org.springframework.test.context.junit4.SpringRunner;
30 import static org.assertj.core.api.Assertions.assertThat;
31
32
33 @RunWith(SpringRunner.class)
34 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
35 public class StatusResourceTest {
36
37     @Autowired
38     StatusResource statusResource;
39
40     private MockHttpServletRequest request;
41
42     @Before
43     public void setup() {
44         request = new MockHttpServletRequest();
45         request.setRequestURI("/nbi/api/v1/status");
46     }
47
48     @Test
49     public void testHealthCheck() {
50         ResponseEntity<Object> response = statusResource.status(request);
51         assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
52         ObjectNode status = (ObjectNode) response.getBody();
53         assertThat(status.get("name").textValue()).isEqualTo("nbi");
54         assertThat(status.get("status").toString()).isEqualTo("OK");
55         assertThat(status.get("version").textValue()).isEqualTo("v1");
56     }
57 }