From a44ab7dc563658140230ba3d231b43e5d63d52ae Mon Sep 17 00:00:00 2001 From: "m.raheem" <m.abdelbaset.dev@gmail.com> Date: Sun, 16 Feb 2020 15:20:48 +0200 Subject: [PATCH] deleting spring-boot-testing project --- .../configurationproperties/Credentials.java | 28 -------- .../CustomCredentialsConverter.java | 16 ----- .../configurationproperties/MailServer.java | 59 ---------------- .../PropertyConversion.java | 67 ------------------- .../configurationproperties/ServerConfig.java | 43 ------------ .../ServerConfigFactory.java | 15 ----- .../resources/property-validation.properties | 4 -- ...indingPropertiesToBeanMethodsUnitTest.java | 34 ---------- ...ngPropertiesToUserDefinedPOJOUnitTest.java | 32 --------- .../BindingYMLPropertiesUnitTest.java | 33 --------- .../PropertyValidationUnitTest.java | 37 ---------- .../SpringPropertiesConversionUnitTest.java | 45 ------------- .../src/test/resources/application.yml | 15 ----- .../property-validation-test.properties | 4 -- .../resources/server-config-test.properties | 6 -- .../spring-conversion-test.properties | 10 --- 16 files changed, 448 deletions(-) delete mode 100644 spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/Credentials.java delete mode 100644 spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/CustomCredentialsConverter.java delete mode 100644 spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java delete mode 100644 spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/PropertyConversion.java delete mode 100644 spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfig.java delete mode 100644 spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfigFactory.java delete mode 100644 spring-boot-testing/src/main/resources/property-validation.properties delete mode 100644 spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToBeanMethodsUnitTest.java delete mode 100644 spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToUserDefinedPOJOUnitTest.java delete mode 100644 spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java delete mode 100644 spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java delete mode 100644 spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/SpringPropertiesConversionUnitTest.java delete mode 100644 spring-boot-testing/src/test/resources/application.yml delete mode 100644 spring-boot-testing/src/test/resources/property-validation-test.properties delete mode 100644 spring-boot-testing/src/test/resources/server-config-test.properties delete mode 100644 spring-boot-testing/src/test/resources/spring-conversion-test.properties diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/Credentials.java b/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/Credentials.java deleted file mode 100644 index 673adad41b..0000000000 --- a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/Credentials.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -public class Credentials { - - private String username; - private String password; - - public Credentials(String username, String password) { - this.username = username; - this.password = password; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } -} diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/CustomCredentialsConverter.java b/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/CustomCredentialsConverter.java deleted file mode 100644 index deb71dcdad..0000000000 --- a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/CustomCredentialsConverter.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; -import org.springframework.core.convert.converter.Converter; -import org.springframework.stereotype.Component; - -@Component -@ConfigurationPropertiesBinding -public class CustomCredentialsConverter implements Converter<String, Credentials> { - - @Override - public Credentials convert(String source) { - String data[] = source.split(","); - return new Credentials(data[0], data[1]); - } -} diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java b/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java deleted file mode 100644 index 8ba42d76f8..0000000000 --- a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/MailServer.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import java.util.Map; - -import javax.validation.Valid; -import javax.validation.constraints.Email; -import javax.validation.constraints.NotBlank; -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.PropertySource; -import org.springframework.validation.annotation.Validated; - -@Configuration -@ConfigurationProperties(prefix = "validate") -@PropertySource("classpath:property-validation.properties") -@Validated -public class MailServer { - - @NotNull - @NotEmpty - private Map<String, @NotBlank String> propertiesMap; - - @Valid - private MailConfig mailConfig = new MailConfig(); - - public static class MailConfig { - - @NotBlank - @Email - private String address; - - public String getAddress() { - return address; - } - - public void setAddress(String address) { - this.address = address; - } - } - - public Map<String, String> getPropertiesMap() { - return propertiesMap; - } - - public void setPropertiesMap(Map<String, String> propertiesMap) { - this.propertiesMap = propertiesMap; - } - - public MailConfig getMailConfig() { - return mailConfig; - } - - public void setMailConfig(MailConfig mailConfig) { - this.mailConfig = mailConfig; - } -} \ No newline at end of file diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/PropertyConversion.java b/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/PropertyConversion.java deleted file mode 100644 index 9747858ed7..0000000000 --- a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/PropertyConversion.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import java.time.Duration; -import java.time.temporal.ChronoUnit; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.boot.convert.DataSizeUnit; -import org.springframework.boot.convert.DurationUnit; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.unit.DataSize; -import org.springframework.util.unit.DataUnit; - -@Configuration -@ConfigurationProperties(prefix = "server") -public class PropertyConversion { - - private DataSize uploadSpeed; - - @DataSizeUnit(DataUnit.GIGABYTES) - private DataSize downloadSpeed; - - private Duration backupDay; - - @DurationUnit(ChronoUnit.HOURS) - private Duration backupHour; - - private Credentials credentials; - - public Duration getBackupDay() { - return backupDay; - } - - public void setBackupDay(Duration backupDay) { - this.backupDay = backupDay; - } - - public Duration getBackupHour() { - return backupHour; - } - - public void setBackupHour(Duration backupHour) { - this.backupHour = backupHour; - } - - public DataSize getUploadSpeed() { - return uploadSpeed; - } - - public void setUploadSpeed(DataSize uploadSpeed) { - this.uploadSpeed = uploadSpeed; - } - - public DataSize getDownloadSpeed() { - return downloadSpeed; - } - - public void setDownloadSpeed(DataSize downloadSpeed) { - this.downloadSpeed = downloadSpeed; - } - - public Credentials getCredentials() { - return credentials; - } - - public void setCredentials(Credentials credentials) { - this.credentials = credentials; - } -} diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfig.java b/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfig.java deleted file mode 100644 index bfacc6e679..0000000000 --- a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfig.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import java.util.Map; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConfigurationProperties(prefix = "server") -public class ServerConfig { - - private Address address; - private Map<String, String> resourcesPath; - - public static class Address { - - private String ip; - - public String getIp() { - return ip; - } - - public void setIp(String ip) { - this.ip = ip; - } - } - - public Address getAddress() { - return address; - } - - public void setAddress(Address address) { - this.address = address; - } - - public Map<String, String> getResourcesPath() { - return resourcesPath; - } - - public void setResourcesPath(Map<String, String> resourcesPath) { - this.resourcesPath = resourcesPath; - } -} diff --git a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfigFactory.java b/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfigFactory.java deleted file mode 100644 index 8d74de1732..0000000000 --- a/spring-boot-testing/src/main/java/com/baeldung/boot/configurationproperties/ServerConfigFactory.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -public class ServerConfigFactory { - - @Bean - @ConfigurationProperties(prefix = "server.default") - public ServerConfig getDefaultConfigs() { - return new ServerConfig(); - } -} \ No newline at end of file diff --git a/spring-boot-testing/src/main/resources/property-validation.properties b/spring-boot-testing/src/main/resources/property-validation.properties deleted file mode 100644 index 6b4c881dc0..0000000000 --- a/spring-boot-testing/src/main/resources/property-validation.properties +++ /dev/null @@ -1,4 +0,0 @@ -validate.propertiesMap.first=prop1 -validate.propertiesMap.second=prop2 - -validate.mail_config.address=user1@test \ No newline at end of file diff --git a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToBeanMethodsUnitTest.java b/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToBeanMethodsUnitTest.java deleted file mode 100644 index a5bc09e290..0000000000 --- a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToBeanMethodsUnitTest.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@EnableConfigurationProperties(value = ServerConfig.class) -@ContextConfiguration(classes = ServerConfigFactory.class) -@TestPropertySource("classpath:server-config-test.properties") -public class BindingPropertiesToBeanMethodsUnitTest { - - @Autowired - private ServerConfigFactory configFactory; - - @Test - void givenBeanAnnotatedMethod_whenBindingProperties_thenAllFieldsAreSet() { - - assertEquals("192.168.0.2", configFactory.getDefaultConfigs().getAddress().getIp()); - - Map<String, String> expectedResourcesPath = new HashMap<>(); - expectedResourcesPath.put("imgs", "/root/def/imgs"); - assertEquals(expectedResourcesPath, configFactory.getDefaultConfigs().getResourcesPath()); - } -} \ No newline at end of file diff --git a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToUserDefinedPOJOUnitTest.java b/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToUserDefinedPOJOUnitTest.java deleted file mode 100644 index 96bbc6639a..0000000000 --- a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingPropertiesToUserDefinedPOJOUnitTest.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@EnableConfigurationProperties(value = ServerConfig.class) -@TestPropertySource("classpath:server-config-test.properties") -public class BindingPropertiesToUserDefinedPOJOUnitTest { - - @Autowired - private ServerConfig serverConfig; - - @Test - void givenUserDefinedPOJO_whenBindingPropertiesFile_thenAllFieldsAreSet() { - - assertEquals("192.168.0.1", serverConfig.getAddress().getIp()); - - Map<String, String> expectedResourcesPath = new HashMap<>(); - expectedResourcesPath.put("imgs", "/root/imgs"); - assertEquals(expectedResourcesPath, serverConfig.getResourcesPath()); - } -} \ No newline at end of file diff --git a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java b/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java deleted file mode 100644 index eda8eb7f6b..0000000000 --- a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/BindingYMLPropertiesUnitTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import java.util.HashMap; -import java.util.Map; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.ConfigFileApplicationContextInitializer; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@ContextConfiguration(initializers = ConfigFileApplicationContextInitializer.class) -@EnableConfigurationProperties(value = ServerConfig.class) -@ActiveProfiles("test") -public class BindingYMLPropertiesUnitTest { - - @Autowired - private ServerConfig serverConfig; - - @Test - void whenBindingYMLConfigFile_thenAllFieldsAreSet() { - - assertEquals("192.168.0.4", serverConfig.getAddress().getIp()); - - Map<String, String> expectedResourcesPath = new HashMap<>(); - expectedResourcesPath.put("imgs", "/etc/test/imgs"); - assertEquals(expectedResourcesPath, serverConfig.getResourcesPath()); - } -} \ No newline at end of file diff --git a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java b/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java deleted file mode 100644 index 8833011425..0000000000 --- a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/PropertyValidationUnitTest.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import javax.validation.Validation; -import javax.validation.Validator; - -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@EnableConfigurationProperties(value = MailServer.class) -@TestPropertySource("classpath:property-validation-test.properties") -public class PropertyValidationUnitTest { - - @Autowired - private MailServer mailServer; - - private static Validator propertyValidator; - - @BeforeAll - public static void setup() { - propertyValidator = Validation.buildDefaultValidatorFactory().getValidator(); - } - - @Test - void whenBindingPropertiesToValidatedBeans_thenConstrainsAreChecked() { - - assertEquals(0, propertyValidator.validate(mailServer.getPropertiesMap()).size()); - assertEquals(0, propertyValidator.validate(mailServer.getMailConfig()).size()); - } -} \ No newline at end of file diff --git a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/SpringPropertiesConversionUnitTest.java b/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/SpringPropertiesConversionUnitTest.java deleted file mode 100644 index d24d563de4..0000000000 --- a/spring-boot-testing/src/test/java/com/baeldung/boot/configurationproperties/SpringPropertiesConversionUnitTest.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.baeldung.boot.configurationproperties; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import java.time.Duration; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.util.unit.DataSize; - -@ExtendWith(SpringExtension.class) -@EnableConfigurationProperties(value = PropertyConversion.class) -@ContextConfiguration(classes = CustomCredentialsConverter.class) -@TestPropertySource("classpath:spring-conversion-test.properties") -public class SpringPropertiesConversionUnitTest { - - @Autowired - private PropertyConversion propertyConversion; - - @Test - void whenUsingSpringDefaultSizeConversion_thenDataSizeObjectIsSet() { - - assertEquals(DataSize.ofMegabytes(500), propertyConversion.getUploadSpeed()); - assertEquals(DataSize.ofGigabytes(10), propertyConversion.getDownloadSpeed()); - } - - @Test - void whenUsingSpringDefaultDurationConversion_thenDurationObjectIsSet() { - - assertEquals(Duration.ofDays(1), propertyConversion.getBackupDay()); - assertEquals(Duration.ofHours(8), propertyConversion.getBackupHour()); - } - - @Test - void whenRegisteringCustomCredentialsConverter_thenCredentialsAreParsed() { - - assertEquals("user", propertyConversion.getCredentials().getUsername()); - assertEquals("123", propertyConversion.getCredentials().getPassword()); - } -} \ No newline at end of file diff --git a/spring-boot-testing/src/test/resources/application.yml b/spring-boot-testing/src/test/resources/application.yml deleted file mode 100644 index 7dfd4d98a8..0000000000 --- a/spring-boot-testing/src/test/resources/application.yml +++ /dev/null @@ -1,15 +0,0 @@ -spring: - profiles: test -server: - address: - ip: 192.168.0.4 - resources_path: - imgs: /etc/test/imgs ---- -spring: - profiles: dev -server: - address: - ip: 192.168.0.5 - resources_path: - imgs: /etc/dev/imgs \ No newline at end of file diff --git a/spring-boot-testing/src/test/resources/property-validation-test.properties b/spring-boot-testing/src/test/resources/property-validation-test.properties deleted file mode 100644 index 6b4c881dc0..0000000000 --- a/spring-boot-testing/src/test/resources/property-validation-test.properties +++ /dev/null @@ -1,4 +0,0 @@ -validate.propertiesMap.first=prop1 -validate.propertiesMap.second=prop2 - -validate.mail_config.address=user1@test \ No newline at end of file diff --git a/spring-boot-testing/src/test/resources/server-config-test.properties b/spring-boot-testing/src/test/resources/server-config-test.properties deleted file mode 100644 index 62b23ed1d6..0000000000 --- a/spring-boot-testing/src/test/resources/server-config-test.properties +++ /dev/null @@ -1,6 +0,0 @@ -server.address.ip=192.168.0.1 -server.resources_path.imgs=/root/imgs - -# default config -server.default.address.ip=192.168.0.2 -server.default.resources_path.imgs=/root/def/imgs \ No newline at end of file diff --git a/spring-boot-testing/src/test/resources/spring-conversion-test.properties b/spring-boot-testing/src/test/resources/spring-conversion-test.properties deleted file mode 100644 index 87444cee10..0000000000 --- a/spring-boot-testing/src/test/resources/spring-conversion-test.properties +++ /dev/null @@ -1,10 +0,0 @@ -# bandwidth -server.upload_speed=500MB -server.download_speed=10 - -# backup date -server.backup_day=1d -server.backup_hour=8 - -# custom converter -server.credentials=user,123 \ No newline at end of file