Skip to content

Commit

Permalink
✨ : add api service for build infos
Browse files Browse the repository at this point in the history
  • Loading branch information
cdubuisson committed Apr 9, 2020
1 parent 93ffff5 commit 82b8155
Show file tree
Hide file tree
Showing 6 changed files with 120 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/main/client/app/shared/api/build-infos-api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import axios from 'axios';

export const getBuildInfo = async () => {
const resp = await axios.get('/build-info');
return resp.data;
};
1 change: 1 addition & 0 deletions src/main/client/app/shared/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export {
getAuthorities,
doLogout,
} from './authentication-api';
export { getBuildInfo } from './build-infos-api';
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.codeka.gaia.client.controller

import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.info.BuildProperties
import org.springframework.boot.info.GitProperties
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/build-info")
class BuildInfoRestController constructor(
@Autowired(required = false) var buildProperties: BuildProperties? = null,
@Autowired(required = false) var gitProperties: GitProperties? = null) {

@GetMapping
fun infos(): Map<String, String?>? =
if (buildProperties == null && gitProperties == null) {
null
} else {
mapOf(
"version" to buildProperties?.version,
"commitId" to gitProperties?.shortCommitId)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class SecurityConfig constructor(
.antMatchers("/auth/user").authenticated()
.antMatchers("/auth/authorities").authenticated()
.antMatchers("/auth/providers").permitAll()
.antMatchers("/build-info").permitAll()
// @formatter:on
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package io.codeka.gaia.client.controller

import io.codeka.gaia.test.whenever
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.ExtendWith
import org.mockito.InjectMocks
import org.mockito.Mock
import org.mockito.junit.jupiter.MockitoExtension
import org.springframework.boot.info.BuildProperties
import org.springframework.boot.info.GitProperties

@ExtendWith(MockitoExtension::class)
class BuildInfoRestControllerTest {

@Mock
lateinit var buildProperties: BuildProperties

@Mock
lateinit var gitProperties: GitProperties

@InjectMocks
lateinit var controller: BuildInfoRestController

@Test
fun `infos() should return version`() {
// when
whenever(buildProperties.version).thenReturn("x.y.z")
val result = controller.infos();

// then
assertThat(result)
.isNotNull
.containsEntry("version", "x.y.z")
}

@Test
fun `infos() should return null version if not available`() {
// when
controller.buildProperties = null
val result = controller.infos();

// then
assertThat(result)
.isNotNull
.containsEntry("version", null)
}

@Test
fun `infos() should return commitId`() {
// when
whenever(gitProperties.shortCommitId).thenReturn("7d1d8a")
val result = controller.infos();

// then
assertThat(result)
.isNotNull
.containsEntry("commitId", "7d1d8a")
}

@Test
fun `infos() should return null commitId if not available`() {
// when
controller.gitProperties = null
val result = controller.infos();

// then
assertThat(result)
.isNotNull
.containsEntry("commitId", null)
}

@Test
fun `infos() should return nothing if no data`() {
// given
controller = BuildInfoRestController(null, null)

// when
val result = controller.infos();

// then
assertThat(result).isNull()
}

}
2 changes: 1 addition & 1 deletion vue.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module.exports = {
errors: true,
},
proxy: {
'^/(api|auth)': {
'^/(api|auth|build-info)': {
target: 'http://localhost:8080',
ws: true,
changeOrigin: false,
Expand Down

0 comments on commit 82b8155

Please sign in to comment.