2 * Copyright (c) 2018 Orange
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.onap.nbi.apis;
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.beans.factory.annotation.Value;
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;
34 @RunWith(SpringRunner.class)
35 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
36 public class StatusResourceTest {
39 StatusResource statusResource;
41 @Value("${server.contextPath}")
44 @Value("${nbi.version}")
47 private MockHttpServletRequest request;
51 request = new MockHttpServletRequest();
52 request.setRequestURI(contextPath);
56 public void testHealthCheck() {
57 ResponseEntity<Object> response = statusResource.status(request);
58 assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
59 ObjectNode status = (ObjectNode) response.getBody();
60 assertThat(status.get("name").textValue()).isEqualTo("nbi");
61 assertThat(status.get("status").toString()).isEqualTo("OK");
62 assertThat(status.get("version").textValue()).isEqualTo(version);