BAEL-5027: Use BuildProperties bean for getting build information (#13794)
Co-authored-by: Tapan Avasthi <tavasthi@Tapans-MacBook-Air.local>
This commit is contained in:
parent
42dff48c7d
commit
e8d8611e6e
|
@ -74,6 +74,25 @@
|
||||||
</resource>
|
</resource>
|
||||||
</resources>
|
</resources>
|
||||||
<plugins>
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>build-info</id>
|
||||||
|
<goals>
|
||||||
|
<goal>build-info</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<additionalProperties>
|
||||||
|
<java.version>${java.version}</java.version>
|
||||||
|
<description>${project.description}</description>
|
||||||
|
<custom.value>123</custom.value>
|
||||||
|
</additionalProperties>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-resources-plugin</artifactId>
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package com.baeldung.buildproperties;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.extension.ExtendWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.info.BuildProperties;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@ExtendWith(SpringExtension.class)
|
||||||
|
public class BuildPropertiesUnitTest {
|
||||||
|
@Autowired
|
||||||
|
private BuildProperties buildProperties;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenBuildPropertiesBean_WhenFetchDefaultBuildProperties_ThenGetValidValues() {
|
||||||
|
Assertions.assertEquals("spring-boot-properties", buildProperties.getArtifact());
|
||||||
|
Assertions.assertEquals("com.baeldung.spring-boot-modules", buildProperties.getGroup());
|
||||||
|
Assertions.assertEquals("0.0.1-SNAPSHOT", buildProperties.getVersion());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void givenBuildPropertiesBean_WhenFetchCustomBuildProprties_ThenGetValidValues() {
|
||||||
|
Assertions.assertEquals("123", buildProperties.get("custom.value"));
|
||||||
|
Assertions.assertNotNull(buildProperties.get("java.version"));
|
||||||
|
Assertions.assertEquals("Spring Boot Properties Module", buildProperties.get("description"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue