BAEL-4682: Add boolean example to the YAML (#10227)
This commit is contained in:
parent
1578788805
commit
8c26df1709
@ -5,15 +5,13 @@
|
|||||||
*/
|
*/
|
||||||
package com.baeldung.yaml;
|
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.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.boot.SpringApplication;
|
import org.springframework.boot.SpringApplication;
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
|
||||||
import com.baeldung.yaml.YAMLConfig.Idm;
|
|
||||||
import com.baeldung.yaml.YAMLConfig.Service;
|
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class MyApplication implements CommandLineRunner {
|
public class MyApplication implements CommandLineRunner {
|
||||||
|
|
||||||
@ -28,6 +26,7 @@ public class MyApplication implements CommandLineRunner {
|
|||||||
public void run(String... args) throws Exception {
|
public void run(String... args) throws Exception {
|
||||||
System.out.println("using environment:" + myConfig.getEnvironment());
|
System.out.println("using environment:" + myConfig.getEnvironment());
|
||||||
System.out.println("name:" + myConfig.getName());
|
System.out.println("name:" + myConfig.getName());
|
||||||
|
System.out.println("enabled:" + myConfig.isEnabled());
|
||||||
System.out.println("servers:" + myConfig.getServers());
|
System.out.println("servers:" + myConfig.getServers());
|
||||||
|
|
||||||
if ("testing".equalsIgnoreCase(myConfig.getEnvironment())) {
|
if ("testing".equalsIgnoreCase(myConfig.getEnvironment())) {
|
||||||
|
@ -15,6 +15,7 @@ import org.springframework.context.annotation.Configuration;
|
|||||||
public class YAMLConfig {
|
public class YAMLConfig {
|
||||||
private String name;
|
private String name;
|
||||||
private String environment;
|
private String environment;
|
||||||
|
private boolean enabled;
|
||||||
private List<String> servers = new ArrayList<String>();
|
private List<String> servers = new ArrayList<String>();
|
||||||
private List<String> external = new ArrayList<String>();
|
private List<String> external = new ArrayList<String>();
|
||||||
private Map<String, String> map = new HashMap<String, String>();
|
private Map<String, String> map = new HashMap<String, String>();
|
||||||
@ -43,7 +44,15 @@ public class YAMLConfig {
|
|||||||
public void setEnvironment(String environment) {
|
public void setEnvironment(String environment) {
|
||||||
this.environment = environment;
|
this.environment = environment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
public Component getComponent() {
|
public Component getComponent() {
|
||||||
return component;
|
return component;
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ spring:
|
|||||||
profiles: test
|
profiles: test
|
||||||
name: test-YAML
|
name: test-YAML
|
||||||
environment: testing
|
environment: testing
|
||||||
|
enabled: false
|
||||||
servers:
|
servers:
|
||||||
- www.abc.test.com
|
- www.abc.test.com
|
||||||
- www.xyz.test.com
|
- www.xyz.test.com
|
||||||
@ -39,6 +40,7 @@ spring:
|
|||||||
profiles: prod
|
profiles: prod
|
||||||
name: prod-YAML
|
name: prod-YAML
|
||||||
environment: production
|
environment: production
|
||||||
|
enabled: true
|
||||||
servers:
|
servers:
|
||||||
- www.abc.com
|
- www.abc.com
|
||||||
- www.xyz.com
|
- www.xyz.com
|
||||||
@ -49,6 +51,7 @@ spring:
|
|||||||
profiles: dev
|
profiles: dev
|
||||||
name: ${DEV_NAME:dev-YAML}
|
name: ${DEV_NAME:dev-YAML}
|
||||||
environment: development
|
environment: development
|
||||||
|
enabled: true
|
||||||
servers:
|
servers:
|
||||||
- www.abc.dev.com
|
- www.abc.dev.com
|
||||||
- www.xyz.dev.com
|
- www.xyz.dev.com
|
||||||
|
@ -21,5 +21,6 @@ class YAMLDevIntegrationTest {
|
|||||||
void whenProfileTest_thenNameTesting() {
|
void whenProfileTest_thenNameTesting() {
|
||||||
assertTrue("development".equalsIgnoreCase(config.getEnvironment()));
|
assertTrue("development".equalsIgnoreCase(config.getEnvironment()));
|
||||||
assertTrue("dev-YAML".equalsIgnoreCase(config.getName()));
|
assertTrue("dev-YAML".equalsIgnoreCase(config.getName()));
|
||||||
|
assertTrue(config.isEnabled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.baeldung.yaml;
|
package com.baeldung.yaml;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
@ -22,5 +23,6 @@ class YAMLIntegrationTest {
|
|||||||
assertTrue("testing".equalsIgnoreCase(config.getEnvironment()));
|
assertTrue("testing".equalsIgnoreCase(config.getEnvironment()));
|
||||||
assertTrue("test-YAML".equalsIgnoreCase(config.getName()));
|
assertTrue("test-YAML".equalsIgnoreCase(config.getName()));
|
||||||
assertTrue("myurl".equalsIgnoreCase(config.getComponent().getIdm().getUrl()));
|
assertTrue("myurl".equalsIgnoreCase(config.getComponent().getIdm().getUrl()));
|
||||||
|
assertFalse(config.isEnabled());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user