@ -16,12 +16,13 @@
package org.springframework.boot.env ;
package org.springframework.boot.env ;
import java.util. Map ;
import java.util. List ;
import java.util.Properties ;
import java.util.Properties ;
import org.junit.jupiter.api.BeforeEach ;
import org.junit.jupiter.api.BeforeEach ;
import org.junit.jupiter.api.Test ;
import org.junit.jupiter.api.Test ;
import org.springframework.boot.env.OriginTrackedPropertiesLoader.Document ;
import org.springframework.boot.origin.OriginTrackedValue ;
import org.springframework.boot.origin.OriginTrackedValue ;
import org.springframework.boot.origin.TextResourceOrigin ;
import org.springframework.boot.origin.TextResourceOrigin ;
import org.springframework.core.io.ClassPathResource ;
import org.springframework.core.io.ClassPathResource ;
@ -40,47 +41,48 @@ class OriginTrackedPropertiesLoaderTests {
private ClassPathResource resource ;
private ClassPathResource resource ;
private Map< String , OriginTrackedValue > properti es;
private List< Document > document es;
@BeforeEach
@BeforeEach
void setUp ( ) throws Exception {
void setUp ( ) throws Exception {
String path = "test-properties.properties" ;
String path = "test-properties.properties" ;
this . resource = new ClassPathResource ( path , getClass ( ) ) ;
this . resource = new ClassPathResource ( path , getClass ( ) ) ;
this . properti es = new OriginTrackedPropertiesLoader ( this . resource ) . load ( ) ;
this . document es = new OriginTrackedPropertiesLoader ( this . resource ) . load ( ) ;
}
}
@Test
@Test
void compareToJavaProperties ( ) throws Exception {
void compareToJavaProperties ( ) throws Exception {
Properties java = PropertiesLoaderUtils . loadProperties ( this . resource ) ;
Properties java = PropertiesLoaderUtils . loadProperties ( this . resource ) ;
Properties ours = new Properties ( ) ;
Properties ours = new Properties ( ) ;
new OriginTrackedPropertiesLoader ( this . resource ) . load ( false ) . forEach ( ( k , v ) - > ours . put ( k , v . getValue ( ) ) ) ;
new OriginTrackedPropertiesLoader ( this . resource ) . load ( false ) . get ( 0 ) . asMap ( )
. forEach ( ( k , v ) - > ours . put ( k , v . getValue ( ) ) ) ;
assertThat ( ours ) . isEqualTo ( java ) ;
assertThat ( ours ) . isEqualTo ( java ) ;
}
}
@Test
@Test
void getSimpleProperty ( ) {
void getSimpleProperty ( ) {
OriginTrackedValue value = this . properties . ge t( "test" ) ;
OriginTrackedValue value = getFromFirs t( "test" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "properties" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "properties" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "11:6" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "11:6" ) ;
}
}
@Test
@Test
void getSimplePropertyWithColonSeparator ( ) {
void getSimplePropertyWithColonSeparator ( ) {
OriginTrackedValue value = this . properties . ge t( "test-colon-separator" ) ;
OriginTrackedValue value = getFromFirs t( "test-colon-separator" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "my-property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "my-property" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "15:23" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "15:23" ) ;
}
}
@Test
@Test
void getPropertyWithSeparatorSurroundedBySpaces ( ) {
void getPropertyWithSeparatorSurroundedBySpaces ( ) {
OriginTrackedValue value = this . properties . ge t( "blah" ) ;
OriginTrackedValue value = getFromFirs t( "blah" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "hello world" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "hello world" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "2:12" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "2:12" ) ;
}
}
@Test
@Test
void getUnicodeProperty ( ) {
void getUnicodeProperty ( ) {
OriginTrackedValue value = this . properties . ge t( "test-unicode" ) ;
OriginTrackedValue value = getFromFirs t( "test-unicode" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "properties&test" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "properties&test" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "12:14" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "12:14" ) ;
}
}
@ -95,165 +97,169 @@ class OriginTrackedPropertiesLoaderTests {
@Test
@Test
void getEscapedProperty ( ) {
void getEscapedProperty ( ) {
OriginTrackedValue value = this . properties . ge t( "test=property" ) ;
OriginTrackedValue value = getFromFirs t( "test=property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "helloworld" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "helloworld" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "14:15" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "14:15" ) ;
}
}
@Test
@Test
void getPropertyWithTab ( ) {
void getPropertyWithTab ( ) {
OriginTrackedValue value = this . properties . ge t( "test-tab-property" ) ;
OriginTrackedValue value = getFromFirs t( "test-tab-property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\tbar" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\tbar" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "16:19" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "16:19" ) ;
}
}
@Test
@Test
void getPropertyWithBang ( ) {
void getPropertyWithBang ( ) {
OriginTrackedValue value = this . properties . ge t( "test-bang-property" ) ;
OriginTrackedValue value = getFromFirs t( "test-bang-property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo!" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo!" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "34:20" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "34:20" ) ;
}
}
@Test
@Test
void getPropertyWithValueComment ( ) {
void getPropertyWithValueComment ( ) {
OriginTrackedValue value = this . properties . ge t( "test-property-value-comment" ) ;
OriginTrackedValue value = getFromFirs t( "test-property-value-comment" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo !bar #foo" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo !bar #foo" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "36:29" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "36:29" ) ;
}
}
@Test
@Test
void getPropertyWithMultilineImmediateBang ( ) {
void getPropertyWithMultilineImmediateBang ( ) {
OriginTrackedValue value = this . properties . ge t( "test-multiline-immediate-bang" ) ;
OriginTrackedValue value = getFromFirs t( "test-multiline-immediate-bang" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "!foo" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "!foo" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "39:1" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "39:1" ) ;
}
}
@Test
@Test
void getPropertyWithCarriageReturn ( ) {
void getPropertyWithCarriageReturn ( ) {
OriginTrackedValue value = this . properties . ge t( "test-return-property" ) ;
OriginTrackedValue value = getFromFirs t( "test-return-property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\rbar" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\rbar" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "17:22" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "17:22" ) ;
}
}
@Test
@Test
void getPropertyWithNewLine ( ) {
void getPropertyWithNewLine ( ) {
OriginTrackedValue value = this . properties . ge t( "test-newline-property" ) ;
OriginTrackedValue value = getFromFirs t( "test-newline-property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\nbar" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\nbar" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "18:23" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "18:23" ) ;
}
}
@Test
@Test
void getPropertyWithFormFeed ( ) {
void getPropertyWithFormFeed ( ) {
OriginTrackedValue value = this . properties . ge t( "test-form-feed-property" ) ;
OriginTrackedValue value = getFromFirs t( "test-form-feed-property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\fbar" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo\fbar" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "19:25" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "19:25" ) ;
}
}
@Test
@Test
void getPropertyWithWhiteSpace ( ) {
void getPropertyWithWhiteSpace ( ) {
OriginTrackedValue value = this . properties . ge t( "test-whitespace-property" ) ;
OriginTrackedValue value = getFromFirs t( "test-whitespace-property" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo bar" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo bar" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "20:32" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "20:32" ) ;
}
}
@Test
@Test
void getCommentedOutPropertyShouldBeNull ( ) {
void getCommentedOutPropertyShouldBeNull ( ) {
assertThat ( this . properties . ge t( "commented-property" ) ) . isNull ( ) ;
assertThat ( getFromFirs t( "commented-property" ) ) . isNull ( ) ;
assertThat ( this . properties . ge t( "#commented-property" ) ) . isNull ( ) ;
assertThat ( getFromFirs t( "#commented-property" ) ) . isNull ( ) ;
assertThat ( this . properties . ge t( "commented-two" ) ) . isNull ( ) ;
assertThat ( getFromFirs t( "commented-two" ) ) . isNull ( ) ;
assertThat ( this . properties . ge t( "!commented-two" ) ) . isNull ( ) ;
assertThat ( getFromFirs t( "!commented-two" ) ) . isNull ( ) ;
}
}
@Test
@Test
void getMultiline ( ) {
void getMultiline ( ) {
OriginTrackedValue value = this . properties . ge t( "test-multiline" ) ;
OriginTrackedValue value = getFromFirs t( "test-multiline" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "ab\\c" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "ab\\c" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "21:17" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "21:17" ) ;
}
}
@Test
@Test
void getImmediateMultiline ( ) {
void getImmediateMultiline ( ) {
OriginTrackedValue value = this . properties . ge t( "test-multiline-immediate" ) ;
OriginTrackedValue value = getFromFirs t( "test-multiline-immediate" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "32:1" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "32:1" ) ;
}
}
@Test
@Test
void getPropertyWithWhitespaceAfterKey ( ) {
void getPropertyWithWhitespaceAfterKey ( ) {
OriginTrackedValue value = this . properties . ge t( "bar" ) ;
OriginTrackedValue value = getFromFirs t( "bar" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo=baz" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "foo=baz" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "3:7" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "3:7" ) ;
}
}
@Test
@Test
void getPropertyWithSpaceSeparator ( ) {
void getPropertyWithSpaceSeparator ( ) {
OriginTrackedValue value = this . properties . ge t( "hello" ) ;
OriginTrackedValue value = getFromFirs t( "hello" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "world" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "world" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "4:9" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "4:9" ) ;
}
}
@Test
@Test
void getPropertyWithBackslashEscaped ( ) {
void getPropertyWithBackslashEscaped ( ) {
OriginTrackedValue value = this . properties . ge t( "proper\\ty" ) ;
OriginTrackedValue value = getFromFirs t( "proper\\ty" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "test" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "test" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "5:11" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "5:11" ) ;
}
}
@Test
@Test
void getPropertyWithEmptyValue ( ) {
void getPropertyWithEmptyValue ( ) {
OriginTrackedValue value = this . properties . ge t( "foo" ) ;
OriginTrackedValue value = getFromFirs t( "foo" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "7:0" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "7:0" ) ;
}
}
@Test
@Test
void getPropertyWithBackslashEscapedInValue ( ) {
void getPropertyWithBackslashEscapedInValue ( ) {
OriginTrackedValue value = this . properties . ge t( "bat" ) ;
OriginTrackedValue value = getFromFirs t( "bat" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "a\\" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "a\\" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "7:7" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "7:7" ) ;
}
}
@Test
@Test
void getPropertyWithSeparatorInValue ( ) {
void getPropertyWithSeparatorInValue ( ) {
OriginTrackedValue value = this . properties . ge t( "bling" ) ;
OriginTrackedValue value = getFromFirs t( "bling" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "a=b" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "a=b" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "8:9" ) ;
assertThat ( getLocation ( value ) ) . isEqualTo ( "8:9" ) ;
}
}
@Test
@Test
void getListProperty ( ) {
void getListProperty ( ) {
OriginTrackedValue apple = this . properties . ge t( "foods[0]" ) ;
OriginTrackedValue apple = getFromFirs t( "foods[0]" ) ;
assertThat ( getValue ( apple ) ) . isEqualTo ( "Apple" ) ;
assertThat ( getValue ( apple ) ) . isEqualTo ( "Apple" ) ;
assertThat ( getLocation ( apple ) ) . isEqualTo ( "24:9" ) ;
assertThat ( getLocation ( apple ) ) . isEqualTo ( "24:9" ) ;
OriginTrackedValue orange = this . properties . ge t( "foods[1]" ) ;
OriginTrackedValue orange = getFromFirs t( "foods[1]" ) ;
assertThat ( getValue ( orange ) ) . isEqualTo ( "Orange" ) ;
assertThat ( getValue ( orange ) ) . isEqualTo ( "Orange" ) ;
assertThat ( getLocation ( orange ) ) . isEqualTo ( "25:1" ) ;
assertThat ( getLocation ( orange ) ) . isEqualTo ( "25:1" ) ;
OriginTrackedValue strawberry = this . properties . ge t( "foods[2]" ) ;
OriginTrackedValue strawberry = getFromFirs t( "foods[2]" ) ;
assertThat ( getValue ( strawberry ) ) . isEqualTo ( "Strawberry" ) ;
assertThat ( getValue ( strawberry ) ) . isEqualTo ( "Strawberry" ) ;
assertThat ( getLocation ( strawberry ) ) . isEqualTo ( "26:1" ) ;
assertThat ( getLocation ( strawberry ) ) . isEqualTo ( "26:1" ) ;
OriginTrackedValue mango = this . properties . ge t( "foods[3]" ) ;
OriginTrackedValue mango = getFromFirs t( "foods[3]" ) ;
assertThat ( getValue ( mango ) ) . isEqualTo ( "Mango" ) ;
assertThat ( getValue ( mango ) ) . isEqualTo ( "Mango" ) ;
assertThat ( getLocation ( mango ) ) . isEqualTo ( "27:1" ) ;
assertThat ( getLocation ( mango ) ) . isEqualTo ( "27:1" ) ;
}
}
@Test
@Test
void getPropertyWithISO88591Character ( ) {
void getPropertyWithISO88591Character ( ) {
OriginTrackedValue value = this . properties . ge t( "test-iso8859-1-chars" ) ;
OriginTrackedValue value = getFromFirs t( "test-iso8859-1-chars" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "æ×ÈÅÞßáñÀÿ" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "æ×ÈÅÞßáñÀÿ" ) ;
}
}
@Test
@Test
void getPropertyWithTrailingSpace ( ) {
void getPropertyWithTrailingSpace ( ) {
OriginTrackedValue value = this . properties . ge t( "test-with-trailing-space" ) ;
OriginTrackedValue value = getFromFirs t( "test-with-trailing-space" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "trailing " ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "trailing " ) ;
}
}
@Test
@Test
void getPropertyWithEscapedTrailingSpace ( ) {
void getPropertyWithEscapedTrailingSpace ( ) {
OriginTrackedValue value = this . properties . ge t( "test-with-escaped-trailing-space" ) ;
OriginTrackedValue value = getFromFirs t( "test-with-escaped-trailing-space" ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "trailing " ) ;
assertThat ( getValue ( value ) ) . isEqualTo ( "trailing " ) ;
}
}
private OriginTrackedValue getFromFirst ( String key ) {
return this . documentes . get ( 0 ) . asMap ( ) . get ( key ) ;
}
private Object getValue ( OriginTrackedValue value ) {
private Object getValue ( OriginTrackedValue value ) {
return ( value ! = null ) ? value . getValue ( ) : null ;
return ( value ! = null ) ? value . getValue ( ) : null ;
}
}