Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
8773a2fe
Commit
8773a2fe
authored
Feb 21, 2019
by
Stephane Nicoll
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Polish
parent
f2e3e274
Changes
10
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
1060 additions
and
821 deletions
+1060
-821
AbstractMetadataGenerationTests.java
...nfigurationprocessor/AbstractMetadataGenerationTests.java
+56
-0
ConfigurationMetadataAnnotationProcessorTests.java
...cessor/ConfigurationMetadataAnnotationProcessorTests.java
+2
-817
EndpointMetadataGenerationTests.java
...nfigurationprocessor/EndpointMetadataGenerationTests.java
+181
-0
GenericsMetadataGenerationTests.java
...nfigurationprocessor/GenericsMetadataGenerationTests.java
+112
-0
IncrementalBuildMetadataGenerationTests.java
...ionprocessor/IncrementalBuildMetadataGenerationTests.java
+109
-0
LombokMetadataGenerationTests.java
...configurationprocessor/LombokMetadataGenerationTests.java
+168
-0
MergeMetadataGenerationTests.java
.../configurationprocessor/MergeMetadataGenerationTests.java
+324
-0
MethodBasedMetadataGenerationTests.java
...gurationprocessor/MethodBasedMetadataGenerationTests.java
+104
-0
GenericConfig.java
...ework/boot/configurationsample/generic/GenericConfig.java
+2
-2
WildcardConfig.java
...work/boot/configurationsample/generic/WildcardConfig.java
+2
-2
No files found.
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/AbstractMetadataGenerationTests.java
0 → 100644
View file @
8773a2fe
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
configurationprocessor
;
import
java.io.IOException
;
import
org.junit.Before
;
import
org.junit.Rule
;
import
org.junit.rules.TemporaryFolder
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.testsupport.compiler.TestCompiler
;
/**
* Base test infrastructure for metadata generation tests.
*
* @author Stephane Nicoll
*/
public
abstract
class
AbstractMetadataGenerationTests
{
@Rule
public
TemporaryFolder
temporaryFolder
=
new
TemporaryFolder
();
private
TestCompiler
compiler
;
@Before
public
void
createCompiler
()
throws
IOException
{
this
.
compiler
=
new
TestCompiler
(
this
.
temporaryFolder
);
}
protected
TestCompiler
getCompiler
()
{
return
this
.
compiler
;
}
protected
ConfigurationMetadata
compile
(
Class
<?>...
types
)
{
TestConfigurationMetadataAnnotationProcessor
processor
=
new
TestConfigurationMetadataAnnotationProcessor
(
this
.
compiler
.
getOutputLocation
());
this
.
compiler
.
getTask
(
types
).
call
(
processor
);
return
processor
.
getMetadata
();
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/ConfigurationMetadataAnnotationProcessorTests.java
View file @
8773a2fe
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/EndpointMetadataGenerationTests.java
0 → 100644
View file @
8773a2fe
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
configurationprocessor
;
import
java.time.Duration
;
import
org.junit.Test
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationsample.endpoint.CamelCaseEndpoint
;
import
org.springframework.boot.configurationsample.endpoint.CustomPropertiesEndpoint
;
import
org.springframework.boot.configurationsample.endpoint.DisabledEndpoint
;
import
org.springframework.boot.configurationsample.endpoint.EnabledEndpoint
;
import
org.springframework.boot.configurationsample.endpoint.SimpleEndpoint
;
import
org.springframework.boot.configurationsample.endpoint.SpecificEndpoint
;
import
org.springframework.boot.configurationsample.endpoint.incremental.IncrementalEndpoint
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Metadata generation tests for Actuator endpoints.
*
* @author Stephane Nicoll
*/
public
class
EndpointMetadataGenerationTests
extends
AbstractMetadataGenerationTests
{
@Test
public
void
simpleEndpoint
()
{
ConfigurationMetadata
metadata
=
compile
(
SimpleEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.simple"
)
.
fromSource
(
SimpleEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"simple"
,
true
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"simple"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
@Test
public
void
disableEndpoint
()
{
ConfigurationMetadata
metadata
=
compile
(
DisabledEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.disabled"
)
.
fromSource
(
DisabledEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"disabled"
,
false
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
2
);
}
@Test
public
void
enabledEndpoint
()
{
ConfigurationMetadata
metadata
=
compile
(
EnabledEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.enabled"
)
.
fromSource
(
EnabledEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"enabled"
,
true
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
2
);
}
@Test
public
void
customPropertiesEndpoint
()
{
ConfigurationMetadata
metadata
=
compile
(
CustomPropertiesEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.customprops"
)
.
fromSource
(
CustomPropertiesEndpoint
.
class
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"management.endpoint.customprops.name"
)
.
ofType
(
String
.
class
).
withDefaultValue
(
"test"
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"customprops"
,
true
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"customprops"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
4
);
}
@Test
public
void
specificEndpoint
()
{
ConfigurationMetadata
metadata
=
compile
(
SpecificEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.specific"
)
.
fromSource
(
SpecificEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"specific"
,
true
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"specific"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
@Test
public
void
camelCaseEndpoint
()
{
ConfigurationMetadata
metadata
=
compile
(
CamelCaseEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.pascal-case"
)
.
fromSource
(
CamelCaseEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"PascalCase"
,
"pascal-case"
,
true
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
2
);
}
@Test
public
void
incrementalEndpointBuildChangeGeneralEnabledFlag
()
throws
Exception
{
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
IncrementalEndpoint
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.incremental"
)
.
fromSource
(
IncrementalEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"incremental"
,
true
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"incremental"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
project
.
replaceText
(
IncrementalEndpoint
.
class
,
"id = \"incremental\""
,
"id = \"incremental\", enableByDefault = false"
);
metadata
=
project
.
incrementalBuild
(
IncrementalEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.incremental"
)
.
fromSource
(
IncrementalEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"incremental"
,
false
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"incremental"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
@Test
public
void
incrementalEndpointBuildChangeCacheFlag
()
throws
Exception
{
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
IncrementalEndpoint
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.incremental"
)
.
fromSource
(
IncrementalEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"incremental"
,
true
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"incremental"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
project
.
replaceText
(
IncrementalEndpoint
.
class
,
"@Nullable String param"
,
"String param"
);
metadata
=
project
.
incrementalBuild
(
IncrementalEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.incremental"
)
.
fromSource
(
IncrementalEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"incremental"
,
true
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
2
);
}
@Test
public
void
incrementalEndpointBuildEnableSpecificEndpoint
()
throws
Exception
{
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
SpecificEndpoint
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.specific"
)
.
fromSource
(
SpecificEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"specific"
,
true
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"specific"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
project
.
replaceText
(
SpecificEndpoint
.
class
,
"enableByDefault = true"
,
"enableByDefault = false"
);
metadata
=
project
.
incrementalBuild
(
SpecificEndpoint
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"management.endpoint.specific"
)
.
fromSource
(
SpecificEndpoint
.
class
));
assertThat
(
metadata
).
has
(
enabledFlag
(
"specific"
,
false
));
assertThat
(
metadata
).
has
(
cacheTtl
(
"specific"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
private
Metadata
.
MetadataItemCondition
enabledFlag
(
String
endpointId
,
String
endpointSuffix
,
Boolean
defaultValue
)
{
return
Metadata
.
withEnabledFlag
(
"management.endpoint."
+
endpointSuffix
+
".enabled"
)
.
withDefaultValue
(
defaultValue
).
withDescription
(
String
.
format
(
"Whether to enable the %s endpoint."
,
endpointId
));
}
private
Metadata
.
MetadataItemCondition
enabledFlag
(
String
endpointId
,
Boolean
defaultValue
)
{
return
enabledFlag
(
endpointId
,
endpointId
,
defaultValue
);
}
private
Metadata
.
MetadataItemCondition
cacheTtl
(
String
endpointId
)
{
return
Metadata
.
withProperty
(
"management.endpoint."
+
endpointId
+
".cache.time-to-live"
)
.
ofType
(
Duration
.
class
).
withDefaultValue
(
"0ms"
)
.
withDescription
(
"Maximum time that a response can be cached."
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/GenericsMetadataGenerationTests.java
0 → 100644
View file @
8773a2fe
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
configurationprocessor
;
import
org.junit.Test
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationsample.generic.AbstractGenericProperties
;
import
org.springframework.boot.configurationsample.generic.GenericConfig
;
import
org.springframework.boot.configurationsample.generic.SimpleGenericProperties
;
import
org.springframework.boot.configurationsample.generic.UnresolvedGenericProperties
;
import
org.springframework.boot.configurationsample.generic.WildcardConfig
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Metadata generation tests for generics handling.
*
* @author Stephane Nicoll
*/
public
class
GenericsMetadataGenerationTests
extends
AbstractMetadataGenerationTests
{
@Test
public
void
simpleGenericProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
AbstractGenericProperties
.
class
,
SimpleGenericProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic"
).
fromSource
(
SimpleGenericProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.name"
,
String
.
class
)
.
fromSource
(
SimpleGenericProperties
.
class
)
.
withDescription
(
"Generic name."
).
withDefaultValue
(
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.mappings"
,
"java.util.Map<java.lang.Integer,java.time.Duration>"
)
.
fromSource
(
SimpleGenericProperties
.
class
)
.
withDescription
(
"Generic mappings."
).
withDefaultValue
(
null
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
@Test
public
void
unresolvedGenericProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
AbstractGenericProperties
.
class
,
UnresolvedGenericProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic"
)
.
fromSource
(
UnresolvedGenericProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.name"
,
String
.
class
)
.
fromSource
(
UnresolvedGenericProperties
.
class
)
.
withDescription
(
"Generic name."
).
withDefaultValue
(
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.mappings"
,
"java.util.Map<java.lang.Number,java.lang.Object>"
)
.
fromSource
(
UnresolvedGenericProperties
.
class
)
.
withDescription
(
"Generic mappings."
).
withDefaultValue
(
null
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
@Test
public
void
genericTypes
()
{
ConfigurationMetadata
metadata
=
compile
(
GenericConfig
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic"
).
ofType
(
"org.springframework.boot.configurationsample.generic.GenericConfig"
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic.foo"
).
ofType
(
"org.springframework.boot.configurationsample.generic.GenericConfig$Foo"
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic.foo.bar"
).
ofType
(
"org.springframework.boot.configurationsample.generic.GenericConfig$Bar"
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"generic.foo.bar.biz"
).
ofType
(
"org.springframework.boot.configurationsample.generic.GenericConfig$Bar$Biz"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.foo.name"
)
.
ofType
(
String
.
class
).
fromSource
(
GenericConfig
.
Foo
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.foo.string-to-bar"
)
.
ofType
(
"java.util.Map<java.lang.String,org.springframework.boot.configurationsample.generic.GenericConfig$Bar<java.lang.Integer>>"
)
.
fromSource
(
GenericConfig
.
Foo
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.foo.string-to-integer"
)
.
ofType
(
"java.util.Map<java.lang.String,java.lang.Integer>"
)
.
fromSource
(
GenericConfig
.
Foo
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.foo.bar.name"
)
.
ofType
(
"java.lang.String"
).
fromSource
(
GenericConfig
.
Bar
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"generic.foo.bar.biz.name"
)
.
ofType
(
"java.lang.String"
).
fromSource
(
GenericConfig
.
Bar
.
Biz
.
class
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
9
);
}
@Test
public
void
wildcardTypes
()
{
ConfigurationMetadata
metadata
=
compile
(
WildcardConfig
.
class
);
assertThat
(
metadata
)
.
has
(
Metadata
.
withGroup
(
"wildcard"
).
ofType
(
WildcardConfig
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"wildcard.string-to-number"
)
.
ofType
(
"java.util.Map<java.lang.String,? extends java.lang.Number>"
)
.
fromSource
(
WildcardConfig
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"wildcard.integers"
)
.
ofType
(
"java.util.List<? super java.lang.Integer>"
)
.
fromSource
(
WildcardConfig
.
class
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/IncrementalBuildMetadataGenerationTests.java
0 → 100644
View file @
8773a2fe
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
configurationprocessor
;
import
org.junit.Test
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationsample.incremental.BarProperties
;
import
org.springframework.boot.configurationsample.incremental.FooProperties
;
import
org.springframework.boot.configurationsample.incremental.RenamedBarProperties
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Metadata generation tests for incremental builds.
*
* @author Stephane Nicoll
*/
public
class
IncrementalBuildMetadataGenerationTests
extends
AbstractMetadataGenerationTests
{
@Test
public
void
incrementalBuild
()
throws
Exception
{
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
assertThat
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()).
isFalse
();
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
project
.
getOutputFile
(
MetadataStore
.
METADATA_PATH
).
exists
()).
isTrue
();
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
project
.
addSourceCode
(
BarProperties
.
class
,
BarProperties
.
class
.
getResourceAsStream
(
"BarProperties.snippet"
));
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.extra"
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
));
project
.
revert
(
BarProperties
.
class
);
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"bar.extra"
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
));
}
@Test
public
void
incrementalBuildAnnotationRemoved
()
throws
Exception
{
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
));
project
.
replaceText
(
BarProperties
.
class
,
"@ConfigurationProperties"
,
"//@ConfigurationProperties"
);
metadata
=
project
.
incrementalBuild
(
BarProperties
.
class
);
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
"foo.counter"
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"bar.counter"
));
}
@Test
public
void
incrementalBuildTypeRenamed
()
throws
Exception
{
TestProject
project
=
new
TestProject
(
this
.
temporaryFolder
,
FooProperties
.
class
,
BarProperties
.
class
);
ConfigurationMetadata
metadata
=
project
.
fullBuild
();
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
RenamedBarProperties
.
class
));
project
.
delete
(
BarProperties
.
class
);
project
.
add
(
RenamedBarProperties
.
class
);
metadata
=
project
.
incrementalBuild
(
RenamedBarProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.counter"
)
.
fromSource
(
FooProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
"bar.counter"
)
.
fromSource
(
BarProperties
.
class
).
withDefaultValue
(
0
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"bar.counter"
).
withDefaultValue
(
0
)
.
fromSource
(
RenamedBarProperties
.
class
));
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/LombokMetadataGenerationTests.java
0 → 100644
View file @
8773a2fe
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
configurationprocessor
;
import
org.junit.Test
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationsample.lombok.LombokAccessLevelOverwriteDataProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokAccessLevelOverwriteDefaultProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokAccessLevelOverwriteExplicitProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokAccessLevelProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokExplicitProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokInnerClassWithGetterProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokSimpleDataProperties
;
import
org.springframework.boot.configurationsample.lombok.LombokSimpleProperties
;
import
org.springframework.boot.configurationsample.lombok.SimpleLombokPojo
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Metadata generation tests for Lombok classes.
*
* @author Stephane Nicoll
*/
public
class
LombokMetadataGenerationTests
extends
AbstractMetadataGenerationTests
{
@Test
public
void
lombokDataProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokSimpleDataProperties
.
class
);
assertSimpleLombokProperties
(
metadata
,
LombokSimpleDataProperties
.
class
,
"data"
);
}
@Test
public
void
lombokSimpleProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokSimpleProperties
.
class
);
assertSimpleLombokProperties
(
metadata
,
LombokSimpleProperties
.
class
,
"simple"
);
}
@Test
public
void
lombokExplicitProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokExplicitProperties
.
class
);
assertSimpleLombokProperties
(
metadata
,
LombokExplicitProperties
.
class
,
"explicit"
);
assertThat
(
metadata
.
getItems
()).
hasSize
(
6
);
}
@Test
public
void
lombokAccessLevelProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokAccessLevelProperties
.
class
);
assertAccessLevelLombokProperties
(
metadata
,
LombokAccessLevelProperties
.
class
,
"accesslevel"
,
2
);
}
@Test
public
void
lombokAccessLevelOverwriteDataProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokAccessLevelOverwriteDataProperties
.
class
);
assertAccessLevelOverwriteLombokProperties
(
metadata
,
LombokAccessLevelOverwriteDataProperties
.
class
,
"accesslevel.overwrite.data"
);
}
@Test
public
void
lombokAccessLevelOverwriteExplicitProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokAccessLevelOverwriteExplicitProperties
.
class
);
assertAccessLevelOverwriteLombokProperties
(
metadata
,
LombokAccessLevelOverwriteExplicitProperties
.
class
,
"accesslevel.overwrite.explicit"
);
}
@Test
public
void
lombokAccessLevelOverwriteDefaultProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokAccessLevelOverwriteDefaultProperties
.
class
);
assertAccessLevelOverwriteLombokProperties
(
metadata
,
LombokAccessLevelOverwriteDefaultProperties
.
class
,
"accesslevel.overwrite.default"
);
}
@Test
public
void
lombokInnerClassProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokInnerClassProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config"
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config.first"
)
.
ofType
(
LombokInnerClassProperties
.
Foo
.
class
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.first.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.first.bar.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config.second"
,
LombokInnerClassProperties
.
Foo
.
class
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.second.name"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.second.bar.name"
));
assertThat
(
metadata
)
.
has
(
Metadata
.
withGroup
(
"config.third"
).
ofType
(
SimpleLombokPojo
.
class
)
.
fromSource
(
LombokInnerClassProperties
.
class
));
// For some reason the annotation processor resolves a type for SimpleLombokPojo
// that is resolved (compiled) and the source annotations are gone. Because we
// don't see the @Data annotation anymore, no field is harvested. What is crazy is
// that a sample project works fine so this seem to be related to the unit test
// environment for some reason. assertThat(metadata,
// containsProperty("config.third.value"));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.fourth"
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withGroup
(
"config.fourth"
));
}
@Test
public
void
lombokInnerClassWithGetterProperties
()
{
ConfigurationMetadata
metadata
=
compile
(
LombokInnerClassWithGetterProperties
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config"
)
.
fromSource
(
LombokInnerClassWithGetterProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"config.first"
)
.
ofType
(
LombokInnerClassWithGetterProperties
.
Foo
.
class
)
.
fromSourceMethod
(
"getFirst()"
)
.
fromSource
(
LombokInnerClassWithGetterProperties
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"config.first.name"
));
assertThat
(
metadata
.
getItems
()).
hasSize
(
3
);
}
private
void
assertSimpleLombokProperties
(
ConfigurationMetadata
metadata
,
Class
<?>
source
,
String
prefix
)
{
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
prefix
).
fromSource
(
source
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
prefix
+
".id"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
prefix
+
".name"
,
String
.
class
)
.
fromSource
(
source
).
withDescription
(
"Name description."
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
prefix
+
".description"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
prefix
+
".counter"
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
prefix
+
".number"
)
.
fromSource
(
source
).
withDefaultValue
(
0
).
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
prefix
+
".items"
));
assertThat
(
metadata
).
doesNotHave
(
Metadata
.
withProperty
(
prefix
+
".ignored"
));
}
private
void
assertAccessLevelOverwriteLombokProperties
(
ConfigurationMetadata
metadata
,
Class
<?>
source
,
String
prefix
)
{
assertAccessLevelLombokProperties
(
metadata
,
source
,
prefix
,
7
);
}
private
void
assertAccessLevelLombokProperties
(
ConfigurationMetadata
metadata
,
Class
<?>
source
,
String
prefix
,
int
countNameFields
)
{
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
prefix
).
fromSource
(
source
));
for
(
int
i
=
0
;
i
<
countNameFields
;
i
++)
{
assertThat
(
metadata
)
.
has
(
Metadata
.
withProperty
(
prefix
+
".name"
+
i
,
String
.
class
));
}
assertThat
(
metadata
.
getItems
()).
hasSize
(
1
+
countNameFields
);
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/MergeMetadataGenerationTests.java
0 → 100644
View file @
8773a2fe
This diff is collapsed.
Click to expand it.
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationprocessor/MethodBasedMetadataGenerationTests.java
0 → 100644
View file @
8773a2fe
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org
.
springframework
.
boot
.
configurationprocessor
;
import
org.junit.Test
;
import
org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata
;
import
org.springframework.boot.configurationprocessor.metadata.Metadata
;
import
org.springframework.boot.configurationsample.method.DeprecatedMethodConfig
;
import
org.springframework.boot.configurationsample.method.EmptyTypeMethodConfig
;
import
org.springframework.boot.configurationsample.method.InvalidMethodConfig
;
import
org.springframework.boot.configurationsample.method.MethodAndClassConfig
;
import
org.springframework.boot.configurationsample.method.SimpleMethodConfig
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
/**
* Metadata generation tests for types defined by {@code @Bean} methods.
*
* @author Stephane Nicoll
*/
public
class
MethodBasedMetadataGenerationTests
extends
AbstractMetadataGenerationTests
{
@Test
public
void
simpleMethodConfig
()
{
ConfigurationMetadata
metadata
=
compile
(
SimpleMethodConfig
.
class
);
assertThat
(
metadata
)
.
has
(
Metadata
.
withGroup
(
"foo"
).
fromSource
(
SimpleMethodConfig
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.name"
,
String
.
class
)
.
fromSource
(
SimpleMethodConfig
.
Foo
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
).
fromSource
(
SimpleMethodConfig
.
Foo
.
class
));
}
@Test
public
void
invalidMethodConfig
()
{
ConfigurationMetadata
metadata
=
compile
(
InvalidMethodConfig
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"something.name"
,
String
.
class
)
.
fromSource
(
InvalidMethodConfig
.
class
));
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"invalid.name"
));
}
@Test
public
void
methodAndClassConfig
()
{
ConfigurationMetadata
metadata
=
compile
(
MethodAndClassConfig
.
class
);
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"conflict.name"
,
String
.
class
)
.
fromSource
(
MethodAndClassConfig
.
Foo
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"conflict.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
).
fromSource
(
MethodAndClassConfig
.
Foo
.
class
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"conflict.value"
,
String
.
class
)
.
fromSource
(
MethodAndClassConfig
.
class
));
}
@Test
public
void
emptyTypeMethodConfig
()
{
ConfigurationMetadata
metadata
=
compile
(
EmptyTypeMethodConfig
.
class
);
assertThat
(
metadata
).
isNotEqualTo
(
Metadata
.
withProperty
(
"something.foo"
));
}
@Test
public
void
deprecatedMethodConfig
()
{
Class
<
DeprecatedMethodConfig
>
type
=
DeprecatedMethodConfig
.
class
;
ConfigurationMetadata
metadata
=
compile
(
type
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"foo"
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.name"
,
String
.
class
)
.
fromSource
(
DeprecatedMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
).
fromSource
(
DeprecatedMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
}
@Test
@SuppressWarnings
(
"deprecation"
)
public
void
deprecatedMethodConfigOnClass
()
{
Class
<?>
type
=
org
.
springframework
.
boot
.
configurationsample
.
method
.
DeprecatedClassMethodConfig
.
class
;
ConfigurationMetadata
metadata
=
compile
(
type
);
assertThat
(
metadata
).
has
(
Metadata
.
withGroup
(
"foo"
).
fromSource
(
type
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.name"
,
String
.
class
)
.
fromSource
(
org
.
springframework
.
boot
.
configurationsample
.
method
.
DeprecatedClassMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
assertThat
(
metadata
).
has
(
Metadata
.
withProperty
(
"foo.flag"
,
Boolean
.
class
)
.
withDefaultValue
(
false
)
.
fromSource
(
org
.
springframework
.
boot
.
configurationsample
.
method
.
DeprecatedClassMethodConfig
.
Foo
.
class
)
.
withDeprecation
(
null
,
null
));
}
}
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/
specif
ic/GenericConfig.java
→
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/
gener
ic/GenericConfig.java
View file @
8773a2fe
/*
/*
* Copyright 2012-201
7
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
configurationsample
.
specif
ic
;
package
org
.
springframework
.
boot
.
configurationsample
.
gener
ic
;
import
java.util.HashMap
;
import
java.util.HashMap
;
import
java.util.Map
;
import
java.util.Map
;
...
...
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/
specif
ic/WildcardConfig.java
→
spring-boot-project/spring-boot-tools/spring-boot-configuration-processor/src/test/java/org/springframework/boot/configurationsample/
gener
ic/WildcardConfig.java
View file @
8773a2fe
/*
/*
* Copyright 2012-201
8
the original author or authors.
* Copyright 2012-201
9
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.
...
@@ -14,7 +14,7 @@
...
@@ -14,7 +14,7 @@
* limitations under the License.
* limitations under the License.
*/
*/
package
org
.
springframework
.
boot
.
configurationsample
.
specif
ic
;
package
org
.
springframework
.
boot
.
configurationsample
.
gener
ic
;
import
java.util.List
;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Map
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment