Bael 697 - @ConfigurationProperties in Spring Boot (#1712)

* Initial commit for @ConfigurationProperties

(BAEL-697)

* Additional validations added

(BAEL-697)

* Formatting changes

* Updated main properties file

* Minor changes to pass TravisCI

(BAEL-697)

* Optimisation of imports

(BAEL-697)

* Renamed ConfigPropertiesTest to Integration test

(BAEL-697)
This commit is contained in:
Chandravadan S
2017-04-24 12:08:53 +05:30
committed by Grzegorz Piwowarek
parent 8b028a2946
commit 4d17d26405
5 changed files with 223 additions and 0 deletions
@@ -0,0 +1,52 @@
package org.baeldung.properties;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = ConfigPropertiesDemoApplication.class)
@TestPropertySource("classpath:configprops-test.properties")
public class ConfigPropertiesIntegrationTest {
@Autowired
private ConfigProperties properties;
@Test
public void whenSimplePropertyQueriedthenReturnsProperty() throws Exception {
Assert.assertTrue("From address is read as null!", properties.getFrom() != null);
}
@Test
public void whenListPropertyQueriedthenReturnsProperty() throws Exception {
Assert.assertTrue("Couldn't bind list property!", properties.getDefaultRecipients()
.size() == 2);
Assert.assertTrue("Incorrectly bound list property. Expected 2 entries!", properties.getDefaultRecipients()
.size() == 2);
}
@Test
public void whenMapPropertyQueriedthenReturnsProperty() throws Exception {
Assert.assertTrue("Couldn't bind map property!", properties.getAdditionalHeaders() != null);
Assert.assertTrue("Incorrectly bound map property. Expected 3 Entries!", properties.getAdditionalHeaders()
.size() == 3);
}
@Test
public void whenObjectPropertyQueriedthenReturnsProperty() throws Exception {
Assert.assertTrue("Couldn't bind map property!", properties.getCredentials() != null);
Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials()
.getAuthMethod()
.equals("SHA1"));
Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials()
.getUsername()
.equals("john"));
Assert.assertTrue("Incorrectly bound object property!", properties.getCredentials()
.getPassword()
.equals("password"));
}
}