BAEL-4682: Add boolean example to the YAML (#10227)

This commit is contained in:
kwoyke 2020-11-03 09:33:24 +01:00 committed by GitHub
parent 1578788805
commit 8c26df1709
5 changed files with 19 additions and 5 deletions

View File

@ -5,15 +5,13 @@
*/
package com.baeldung.yaml;
import java.util.Collections;
import com.baeldung.yaml.YAMLConfig.Idm;
import com.baeldung.yaml.YAMLConfig.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.baeldung.yaml.YAMLConfig.Idm;
import com.baeldung.yaml.YAMLConfig.Service;
@SpringBootApplication
public class MyApplication implements CommandLineRunner {
@ -28,6 +26,7 @@ public class MyApplication implements CommandLineRunner {
public void run(String... args) throws Exception {
System.out.println("using environment:" + myConfig.getEnvironment());
System.out.println("name:" + myConfig.getName());
System.out.println("enabled:" + myConfig.isEnabled());
System.out.println("servers:" + myConfig.getServers());
if ("testing".equalsIgnoreCase(myConfig.getEnvironment())) {

View File

@ -15,6 +15,7 @@ import org.springframework.context.annotation.Configuration;
public class YAMLConfig {
private String name;
private String environment;
private boolean enabled;
private List<String> servers = new ArrayList<String>();
private List<String> external = new ArrayList<String>();
private Map<String, String> map = new HashMap<String, String>();
@ -43,7 +44,15 @@ public class YAMLConfig {
public void setEnvironment(String environment) {
this.environment = environment;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
public Component getComponent() {
return component;
}

View File

@ -9,6 +9,7 @@ spring:
profiles: test
name: test-YAML
environment: testing
enabled: false
servers:
- www.abc.test.com
- www.xyz.test.com
@ -39,6 +40,7 @@ spring:
profiles: prod
name: prod-YAML
environment: production
enabled: true
servers:
- www.abc.com
- www.xyz.com
@ -49,6 +51,7 @@ spring:
profiles: dev
name: ${DEV_NAME:dev-YAML}
environment: development
enabled: true
servers:
- www.abc.dev.com
- www.xyz.dev.com

View File

@ -21,5 +21,6 @@ class YAMLDevIntegrationTest {
void whenProfileTest_thenNameTesting() {
assertTrue("development".equalsIgnoreCase(config.getEnvironment()));
assertTrue("dev-YAML".equalsIgnoreCase(config.getName()));
assertTrue(config.isEnabled());
}
}

View File

@ -1,5 +1,6 @@
package com.baeldung.yaml;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.junit.jupiter.api.Test;
@ -22,5 +23,6 @@ class YAMLIntegrationTest {
assertTrue("testing".equalsIgnoreCase(config.getEnvironment()));
assertTrue("test-YAML".equalsIgnoreCase(config.getName()));
assertTrue("myurl".equalsIgnoreCase(config.getComponent().getIdm().getUrl()));
assertFalse(config.isEnabled());
}
}