| /* |
| ******************************************************************************* |
| * Copyright (c) 2019 Contributors to the Eclipse Foundation |
| * |
| * See the NOTICE file(s) distributed with this work for additional |
| * information regarding copyright ownership. |
| * |
| * This program and the accompanying materials are made available under the |
| * terms of the Eclipse Public License v. 2.0 which is available at |
| * http://www.eclipse.org/legal/epl-2.0. |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| ******************************************************************************* |
| */ |
| package org.eclipse.openk.contactbasedata.controller; |
| |
| import org.eclipse.openk.contactbasedata.ContactBaseDataApplication; |
| import org.eclipse.openk.contactbasedata.service.VersionService; |
| import org.eclipse.openk.contactbasedata.support.MockDataHelper; |
| import org.eclipse.openk.contactbasedata.viewmodel.VersionDto; |
| import org.junit.jupiter.api.Test; |
| import org.springframework.beans.factory.annotation.Autowired; |
| import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; |
| import org.springframework.boot.test.context.SpringBootTest; |
| import org.springframework.boot.test.mock.mockito.MockBean; |
| import org.springframework.http.MediaType; |
| import org.springframework.test.web.servlet.MockMvc; |
| |
| import static org.hamcrest.Matchers.is; |
| import static org.mockito.Mockito.when; |
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; |
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; |
| |
| @SpringBootTest(classes = ContactBaseDataApplication.class) |
| @AutoConfigureMockMvc |
| public class VersionControllerTest { |
| |
| @MockBean |
| private VersionService versionService; |
| |
| @Autowired |
| private MockMvc mockMvc; |
| |
| |
| @Test |
| public void shouldReturnVersion() throws Exception { |
| VersionDto versionDto = MockDataHelper.mockVersionDto(); |
| when(versionService.getVersion()).thenReturn(versionDto); |
| |
| mockMvc.perform(get("/version")) |
| .andExpect(status().is2xxSuccessful()) |
| .andExpect(content().contentType(MediaType.APPLICATION_JSON)) |
| .andExpect(jsonPath("backendVersion", is( "660"))) |
| .andExpect(jsonPath("dbVersion", is("550"))); |
| } |
| } |