|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2019 the original author or authors. |
|
|
|
* Copyright 2002-2023 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -21,14 +21,20 @@ import java.beans.PropertyEditor; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.env.StandardEnvironment; |
|
|
|
import org.springframework.core.env.StandardEnvironment; |
|
|
|
|
|
|
|
import org.springframework.core.io.ClassPathResource; |
|
|
|
|
|
|
|
import org.springframework.core.io.FileUrlResource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
import org.springframework.core.io.Resource; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* Tests for {@link ResourceArrayPropertyEditor}. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Dave Syer |
|
|
|
* @author Dave Syer |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
|
|
|
|
* @author Yanming Zhou |
|
|
|
|
|
|
|
* @author Stephane Nicoll |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class ResourceArrayPropertyEditorTests { |
|
|
|
class ResourceArrayPropertyEditorTests { |
|
|
|
|
|
|
|
|
|
|
|
@ -83,4 +89,31 @@ class ResourceArrayPropertyEditorTests { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void commaDelimitedResourcesWithSingleResource() { |
|
|
|
|
|
|
|
PropertyEditor editor = new ResourceArrayPropertyEditor(); |
|
|
|
|
|
|
|
editor.setAsText("classpath:org/springframework/core/io/support/ResourceArrayPropertyEditor.class,file:/test.txt"); |
|
|
|
|
|
|
|
Resource[] resources = (Resource[]) editor.getValue(); |
|
|
|
|
|
|
|
assertThat(resources).isNotNull(); |
|
|
|
|
|
|
|
assertThat(resources[0]).isInstanceOfSatisfying(ClassPathResource.class, |
|
|
|
|
|
|
|
resource -> assertThat(resource.exists()).isTrue()); |
|
|
|
|
|
|
|
assertThat(resources[1]).isInstanceOfSatisfying(FileUrlResource.class, |
|
|
|
|
|
|
|
resource -> assertThat(resource.getFilename()).isEqualTo("test.txt")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
void commaDelimitedResourcesWithMultipleResources() { |
|
|
|
|
|
|
|
PropertyEditor editor = new ResourceArrayPropertyEditor(); |
|
|
|
|
|
|
|
editor.setAsText("file:/test.txt, classpath:org/springframework/core/io/support/test-resources/*.txt"); |
|
|
|
|
|
|
|
Resource[] resources = (Resource[]) editor.getValue(); |
|
|
|
|
|
|
|
assertThat(resources).isNotNull(); |
|
|
|
|
|
|
|
assertThat(resources[0]).isInstanceOfSatisfying(FileUrlResource.class, |
|
|
|
|
|
|
|
resource -> assertThat(resource.getFilename()).isEqualTo("test.txt")); |
|
|
|
|
|
|
|
assertThat(resources).anySatisfy(candidate -> |
|
|
|
|
|
|
|
assertThat(candidate.getFilename()).isEqualTo("resource1.txt")); |
|
|
|
|
|
|
|
assertThat(resources).anySatisfy(candidate -> |
|
|
|
|
|
|
|
assertThat(candidate.getFilename()).isEqualTo("resource2.txt")); |
|
|
|
|
|
|
|
assertThat(resources).hasSize(3); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|