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