Merge branch '2.1.x'
Closes gh-17079
This commit is contained in:
@@ -62,8 +62,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Kris De Volder
|
||||
* @author Jonas Keßler
|
||||
*/
|
||||
public class ConfigurationMetadataAnnotationProcessorTests
|
||||
extends AbstractMetadataGenerationTests {
|
||||
public class ConfigurationMetadataAnnotationProcessorTests extends AbstractMetadataGenerationTests {
|
||||
|
||||
@Test
|
||||
public void notAnnotated() {
|
||||
@@ -74,15 +73,12 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
@Test
|
||||
public void simpleProperties() {
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
|
||||
.withDefaultValue(false).fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(SimpleProperties.class).withDescription("A simple flag.").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.counter"));
|
||||
assertThat(metadata).doesNotHave(Metadata.withProperty("simple.size"));
|
||||
@@ -91,85 +87,60 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
@Test
|
||||
public void simplePrefixValueProperties() {
|
||||
ConfigurationMetadata metadata = compile(SimplePrefixValueProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("simple")
|
||||
.fromSource(SimplePrefixValueProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.name", String.class)
|
||||
.fromSource(SimplePrefixValueProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimplePrefixValueProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.name", String.class).fromSource(SimplePrefixValueProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void simpleTypeProperties() {
|
||||
ConfigurationMetadata metadata = compile(SimpleTypeProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("simple.type").fromSource(SimpleTypeProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("simple.type").fromSource(SimpleTypeProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-string", String.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-byte", Byte.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-string", String.class));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-char", Character.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-char", Character.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-boolean", Boolean.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-byte", Byte.class));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class).withDefaultValue(false));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-short", Short.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-byte", Byte.class)
|
||||
.withDefaultValue(0));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-short", Short.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-integer", Integer.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-char", Character.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-char", Character.class));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-integer", Integer.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-long", Long.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-boolean", Boolean.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-boolean", Boolean.class)
|
||||
.withDefaultValue(false));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-short", Short.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-short", Short.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-integer", Integer.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-integer", Integer.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-long", Long.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class)
|
||||
.withDefaultValue(0));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-double", Double.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-double", Double.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.type.my-float", Float.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.type.my-primitive-float", Float.class));
|
||||
.has(Metadata.withProperty("simple.type.my-primitive-long", Long.class).withDefaultValue(0));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-double", Double.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-double", Double.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-float", Float.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.type.my-primitive-float", Float.class));
|
||||
assertThat(metadata.getItems().size()).isEqualTo(18);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void hierarchicalProperties() {
|
||||
ConfigurationMetadata metadata = compile(HierarchicalProperties.class,
|
||||
HierarchicalPropertiesParent.class,
|
||||
ConfigurationMetadata metadata = compile(HierarchicalProperties.class, HierarchicalPropertiesParent.class,
|
||||
HierarchicalPropertiesGrandparent.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("hierarchical")
|
||||
assertThat(metadata).has(Metadata.withGroup("hierarchical").fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.first", String.class).withDefaultValue("one")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.first", String.class)
|
||||
.withDefaultValue("one").fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("hierarchical.second", String.class).withDefaultValue("two")
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.second", String.class).withDefaultValue("two")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.third", String.class).withDefaultValue("three")
|
||||
.fromSource(HierarchicalProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("hierarchical.third", String.class)
|
||||
.withDefaultValue("three").fromSource(HierarchicalProperties.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void descriptionProperties() {
|
||||
ConfigurationMetadata metadata = compile(DescriptionProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("description")
|
||||
.fromSource(DescriptionProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("description").fromSource(DescriptionProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("description.simple", String.class)
|
||||
.fromSource(DescriptionProperties.class)
|
||||
.withDescription("A simple description."));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("description.multi-line", String.class)
|
||||
.fromSource(DescriptionProperties.class).withDescription("A simple description."));
|
||||
assertThat(metadata).has(Metadata.withProperty("description.multi-line", String.class)
|
||||
.fromSource(DescriptionProperties.class).withDescription(
|
||||
"This is a lengthy description that spans across multiple lines to showcase that the line separators are cleaned automatically."));
|
||||
}
|
||||
@@ -180,11 +151,10 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
Class<?> type = org.springframework.boot.configurationsample.simple.DeprecatedProperties.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("deprecated").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated.name", String.class)
|
||||
.fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("deprecated.description", String.class)
|
||||
.fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("deprecated.name", String.class).fromSource(type).withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("deprecated.description", String.class).fromSource(type)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -192,11 +162,8 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
Class<?> type = DeprecatedSingleProperty.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("singledeprecated").fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("singledeprecated.new-name", String.class)
|
||||
.fromSource(type));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("singledeprecated.name", String.class).fromSource(type)
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.new-name", String.class).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class).fromSource(type)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name"));
|
||||
}
|
||||
|
||||
@@ -205,12 +172,10 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
Class<?> type = DeprecatedUnrelatedMethodPojo.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("not.deprecated").fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("not.deprecated.counter", Integer.class)
|
||||
.withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("not.deprecated.flag", Boolean.class)
|
||||
.withDefaultValue(false).withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("not.deprecated.counter", Integer.class).withNoDeprecation().fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("not.deprecated.flag", Boolean.class).withDefaultValue(false)
|
||||
.withNoDeprecation().fromSource(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -218,10 +183,9 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
Class<?> type = BoxingPojo.class;
|
||||
ConfigurationMetadata metadata = compile(type);
|
||||
assertThat(metadata).has(Metadata.withGroup("boxing").fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("boxing.flag", Boolean.class)
|
||||
.withDefaultValue(false).fromSource(type));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("boxing.flag", Boolean.class).withDefaultValue(false).fromSource(type));
|
||||
assertThat(metadata).has(Metadata.withProperty("boxing.counter", Integer.class).fromSource(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,17 +194,13 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
// getter and setter
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.integers-to-names",
|
||||
"java.util.Map<java.lang.Integer,java.lang.String>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.longs",
|
||||
"java.util.Collection<java.lang.Long>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.floats",
|
||||
"java.util.List<java.lang.Float>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.longs", "java.util.Collection<java.lang.Long>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.floats", "java.util.List<java.lang.Float>"));
|
||||
// getter only
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.names-to-integers",
|
||||
"java.util.Map<java.lang.String,java.lang.Integer>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.bytes",
|
||||
"java.util.Collection<java.lang.Byte>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.doubles",
|
||||
"java.util.List<java.lang.Double>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.bytes", "java.util.Collection<java.lang.Byte>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.doubles", "java.util.List<java.lang.Double>"));
|
||||
assertThat(metadata).has(Metadata.withProperty("collection.names-to-holders",
|
||||
"java.util.Map<java.lang.String,org.springframework.boot.configurationsample.simple.SimpleCollectionProperties$Holder<java.lang.String>>"));
|
||||
}
|
||||
@@ -248,38 +208,32 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
@Test
|
||||
public void parseArrayConfig() throws Exception {
|
||||
ConfigurationMetadata metadata = compile(SimpleArrayProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("array").ofType(SimpleArrayProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("array.primitive", "java.lang.Integer[]"));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("array.simple", "java.lang.String[]"));
|
||||
assertThat(metadata).has(Metadata.withGroup("array").ofType(SimpleArrayProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.primitive", "java.lang.Integer[]"));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.simple", "java.lang.String[]"));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.inner",
|
||||
"org.springframework.boot.configurationsample.simple.SimpleArrayProperties$Holder[]"));
|
||||
assertThat(metadata).has(Metadata.withProperty("array.name-to-integer",
|
||||
"java.util.Map<java.lang.String,java.lang.Integer>[]"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("array.name-to-integer", "java.util.Map<java.lang.String,java.lang.Integer>[]"));
|
||||
assertThat(metadata.getItems()).hasSize(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void annotatedGetter() {
|
||||
ConfigurationMetadata metadata = compile(AnnotatedGetter.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("specific").fromSource(AnnotatedGetter.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("specific").fromSource(AnnotatedGetter.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("specific.name", String.class)
|
||||
.fromSource(AnnotatedGetter.class));
|
||||
.has(Metadata.withProperty("specific.name", String.class).fromSource(AnnotatedGetter.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void staticAccessor() {
|
||||
ConfigurationMetadata metadata = compile(StaticAccessor.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("specific").fromSource(StaticAccessor.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("specific").fromSource(StaticAccessor.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("specific.counter", Integer.class)
|
||||
.fromSource(StaticAccessor.class).withDefaultValue(42));
|
||||
assertThat(metadata)
|
||||
.doesNotHave(Metadata.withProperty("specific.name", String.class)
|
||||
.fromSource(StaticAccessor.class));
|
||||
.doesNotHave(Metadata.withProperty("specific.name", String.class).fromSource(StaticAccessor.class));
|
||||
assertThat(metadata.getItems()).hasSize(2);
|
||||
}
|
||||
|
||||
@@ -292,20 +246,17 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
@Test
|
||||
public void innerClassProperties() {
|
||||
ConfigurationMetadata metadata = compile(InnerClassProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config").fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.first").ofType(InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config").fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.first").ofType(InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.first.bar.name"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.the-second", InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.the-second", InnerClassProperties.Foo.class)
|
||||
.fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.the-second.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.the-second.bar.name"));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.third")
|
||||
.ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("config.third").ofType(SimplePojo.class).fromSource(InnerClassProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.third.value"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.fourth"));
|
||||
assertThat(metadata).isNotEqualTo(Metadata.withGroup("config.fourth"));
|
||||
@@ -314,12 +265,11 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
@Test
|
||||
public void innerClassPropertiesHierarchical() {
|
||||
ConfigurationMetadata metadata = compile(InnerClassHierarchicalProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("config.foo")
|
||||
.ofType(InnerClassHierarchicalProperties.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.foo.bar")
|
||||
.ofType(InnerClassHierarchicalProperties.Bar.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.foo.bar.baz")
|
||||
.ofType(InnerClassHierarchicalProperties.Foo.Baz.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("config.foo").ofType(InnerClassHierarchicalProperties.Foo.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.foo.bar").ofType(InnerClassHierarchicalProperties.Bar.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("config.foo.bar.baz").ofType(InnerClassHierarchicalProperties.Foo.Baz.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.baz.blah"));
|
||||
assertThat(metadata).has(Metadata.withProperty("config.foo.bar.bling"));
|
||||
}
|
||||
@@ -335,16 +285,12 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
@Test
|
||||
public void nestedClassChildProperties() {
|
||||
ConfigurationMetadata metadata = compile(ClassWithNestedProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("nestedChildProps")
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("nestedChildProps.child-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
|
||||
.withDefaultValue(20));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("nestedChildProps.parent-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class)
|
||||
.withDefaultValue(10));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("nestedChildProps").fromSource(ClassWithNestedProperties.NestedChildClass.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.child-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(20));
|
||||
assertThat(metadata).has(Metadata.withProperty("nestedChildProps.parent-class-property", Integer.class)
|
||||
.fromSource(ClassWithNestedProperties.NestedChildClass.class).withDefaultValue(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -383,30 +329,25 @@ public class ConfigurationMetadataAnnotationProcessorTests
|
||||
|
||||
@Test
|
||||
public void invalidDoubleRegistration() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> compile(InvalidDoubleRegistrationProperties.class))
|
||||
assertThatIllegalStateException().isThrownBy(() -> compile(InvalidDoubleRegistrationProperties.class))
|
||||
.withMessageContaining("Compilation failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithInvalidDefaultValueOnNumber() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueNumberProperties.class))
|
||||
assertThatIllegalStateException().isThrownBy(() -> compile(InvalidDefaultValueNumberProperties.class))
|
||||
.withMessageContaining("Compilation failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithInvalidDefaultValueOnFloatingPoint() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(
|
||||
() -> compile(InvalidDefaultValueFloatingPointProperties.class))
|
||||
assertThatIllegalStateException().isThrownBy(() -> compile(InvalidDefaultValueFloatingPointProperties.class))
|
||||
.withMessageContaining("Compilation failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithInvalidDefaultValueOnCharacter() {
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> compile(InvalidDefaultValueCharacterProperties.class))
|
||||
assertThatIllegalStateException().isThrownBy(() -> compile(InvalidDefaultValueCharacterProperties.class))
|
||||
.withMessageContaining("Compilation failed");
|
||||
}
|
||||
|
||||
|
||||
@@ -47,10 +47,8 @@ public class ConstructorParameterPropertyDescriptorTests extends PropertyDescrip
|
||||
@Test
|
||||
public void constructorParameterSimpleProperty() throws IOException {
|
||||
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "theName");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertThat(property.getName()).isEqualTo("theName");
|
||||
assertThat(property.getSource()).hasToString("theName");
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getTheName");
|
||||
@@ -62,10 +60,8 @@ public class ConstructorParameterPropertyDescriptorTests extends PropertyDescrip
|
||||
@Test
|
||||
public void constructorParameterNestedPropertySameClass() throws IOException {
|
||||
process(ImmutableInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableInnerClassProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "first");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableInnerClassProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertThat(property.getName()).isEqualTo("first");
|
||||
assertThat(property.getSource()).hasToString("first");
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getFirst");
|
||||
@@ -77,10 +73,8 @@ public class ConstructorParameterPropertyDescriptorTests extends PropertyDescrip
|
||||
@Test
|
||||
public void constructorParameterNestedPropertyWithAnnotation() throws IOException {
|
||||
process(ImmutableInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableInnerClassProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "third");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableInnerClassProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "third");
|
||||
assertThat(property.getName()).isEqualTo("third");
|
||||
assertThat(property.getSource()).hasToString("third");
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getThird");
|
||||
@@ -90,13 +84,10 @@ public class ConstructorParameterPropertyDescriptorTests extends PropertyDescrip
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterSimplePropertyWithNoAccessorShouldBeExposed()
|
||||
throws IOException {
|
||||
public void constructorParameterSimplePropertyWithNoAccessorShouldBeExposed() throws IOException {
|
||||
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "counter");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "counter");
|
||||
assertThat(property.getName()).isEqualTo("counter");
|
||||
assertThat(property.getSource()).hasToString("counter");
|
||||
assertThat(property.getGetter()).isNull();
|
||||
@@ -108,55 +99,43 @@ public class ConstructorParameterPropertyDescriptorTests extends PropertyDescrip
|
||||
@Test
|
||||
public void constructorParameterMetadataSimpleProperty() throws IOException {
|
||||
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "counter");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.counter")
|
||||
.hasType(Long.class).hasSourceType(ImmutableSimpleProperties.class)
|
||||
.hasNoDescription().isNotDeprecated();
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "counter");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.counter").hasType(Long.class)
|
||||
.hasSourceType(ImmutableSimpleProperties.class).hasNoDescription().isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterMetadataNestedGroup() throws IOException {
|
||||
process(ImmutableInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableInnerClassProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "first");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableInnerClassProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
|
||||
.hasType(
|
||||
"org.springframework.boot.configurationsample.immutable.ImmutableInnerClassProperties$Foo")
|
||||
.hasSourceType(ImmutableInnerClassProperties.class)
|
||||
.hasSourceMethod("getFirst()").hasNoDescription().isNotDeprecated();
|
||||
.hasType("org.springframework.boot.configurationsample.immutable.ImmutableInnerClassProperties$Foo")
|
||||
.hasSourceType(ImmutableInnerClassProperties.class).hasSourceMethod("getFirst()").hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterDeprecatedPropertyOnGetter() throws IOException {
|
||||
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableSimpleProperties.class);
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ExecutableElement getter = getMethod(ownerElement, "isFlag");
|
||||
VariableElement field = getField(ownerElement, "flag");
|
||||
VariableElement constructorParameter = getConstructorParameter(ownerElement,
|
||||
"flag");
|
||||
ConstructorParameterPropertyDescriptor property = new ConstructorParameterPropertyDescriptor(
|
||||
ownerElement, null, constructorParameter, "flag", field.asType(),
|
||||
field, getter, null);
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithNoInformation();
|
||||
VariableElement constructorParameter = getConstructorParameter(ownerElement, "flag");
|
||||
ConstructorParameterPropertyDescriptor property = new ConstructorParameterPropertyDescriptor(ownerElement,
|
||||
null, constructorParameter, "flag", field.asType(), field, getter, null);
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithDescription() throws IOException {
|
||||
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "theName");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDescription("The name of this simple properties.");
|
||||
});
|
||||
@@ -165,154 +144,86 @@ public class ConstructorParameterPropertyDescriptorTests extends PropertyDescrip
|
||||
@Test
|
||||
public void constructorParameterPropertyWithDefaultValue() throws IOException {
|
||||
process(ImmutableSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDefaultValue("boot");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableSimpleProperties.class);
|
||||
ConstructorParameterPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasDefaultValue("boot");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithPrimitiveTypes() throws IOException {
|
||||
process(ImmutablePrimitiveProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutablePrimitiveProperties.class);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "flag"))
|
||||
.hasDefaultValue(false);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "octet")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "letter"))
|
||||
.hasDefaultValue(null);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "number")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(0L);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "percentage"))
|
||||
.hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "ratio")).hasDefaultValue(0D);
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutablePrimitiveProperties.class);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flag")).hasDefaultValue(false);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue(null);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(0L);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "ratio")).hasDefaultValue(0D);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithPrimitiveTypesAndDefaultValues()
|
||||
throws IOException {
|
||||
process(ImmutablePrimitiveWithDefaultsProperties.class,
|
||||
(roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(
|
||||
ImmutablePrimitiveWithDefaultsProperties.class);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "flag"))
|
||||
.hasDefaultValue(true);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "octet"))
|
||||
.hasDefaultValue(120);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "letter"))
|
||||
.hasDefaultValue("a");
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "number"))
|
||||
.hasDefaultValue(1000);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "counter"))
|
||||
.hasDefaultValue(42);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "value"))
|
||||
.hasDefaultValue(2000);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "percentage"))
|
||||
.hasDefaultValue(0.5);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "ratio"))
|
||||
.hasDefaultValue(42.42);
|
||||
});
|
||||
public void constructorParameterPropertyWithPrimitiveTypesAndDefaultValues() throws IOException {
|
||||
process(ImmutablePrimitiveWithDefaultsProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutablePrimitiveWithDefaultsProperties.class);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flag")).hasDefaultValue(true);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet")).hasDefaultValue(120);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue("a");
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number")).hasDefaultValue(1000);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(42);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(2000);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0.5);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "ratio")).hasDefaultValue(42.42);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithPrimitiveWrapperTypesAndDefaultValues()
|
||||
throws IOException {
|
||||
process(ImmutablePrimitiveWrapperWithDefaultsProperties.class,
|
||||
(roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(
|
||||
ImmutablePrimitiveWrapperWithDefaultsProperties.class);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "flag"))
|
||||
.hasDefaultValue(true);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "octet"))
|
||||
.hasDefaultValue(120);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "letter"))
|
||||
.hasDefaultValue("a");
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "number"))
|
||||
.hasDefaultValue(1000);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "counter"))
|
||||
.hasDefaultValue(42);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "value"))
|
||||
.hasDefaultValue(2000);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "percentage"))
|
||||
.hasDefaultValue(0.5);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "ratio"))
|
||||
.hasDefaultValue(42.42);
|
||||
});
|
||||
public void constructorParameterPropertyWithPrimitiveWrapperTypesAndDefaultValues() throws IOException {
|
||||
process(ImmutablePrimitiveWrapperWithDefaultsProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutablePrimitiveWrapperWithDefaultsProperties.class);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flag")).hasDefaultValue(true);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "octet")).hasDefaultValue(120);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "letter")).hasDefaultValue("a");
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "number")).hasDefaultValue(1000);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "counter")).hasDefaultValue(42);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "value")).hasDefaultValue(2000);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "percentage")).hasDefaultValue(0.5);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "ratio")).hasDefaultValue(42.42);
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void constructorParameterPropertyWithCollectionTypesAndDefaultValues()
|
||||
throws IOException {
|
||||
public void constructorParameterPropertyWithCollectionTypesAndDefaultValues() throws IOException {
|
||||
process(ImmutableCollectionProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(ImmutableCollectionProperties.class);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "names"))
|
||||
.hasDefaultValue(null);
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "flags"))
|
||||
.hasDefaultValue(Arrays.asList(true, false));
|
||||
assertItemMetadata(metadataEnv,
|
||||
createPropertyDescriptor(ownerElement, "durations"))
|
||||
.hasDefaultValue(Arrays.asList("10s", "1m", "1h"));
|
||||
TypeElement ownerElement = roundEnv.getRootElement(ImmutableCollectionProperties.class);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "names")).hasDefaultValue(null);
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "flags"))
|
||||
.hasDefaultValue(Arrays.asList(true, false));
|
||||
assertItemMetadata(metadataEnv, createPropertyDescriptor(ownerElement, "durations"))
|
||||
.hasDefaultValue(Arrays.asList("10s", "1m", "1h"));
|
||||
});
|
||||
}
|
||||
|
||||
protected ConstructorParameterPropertyDescriptor createPropertyDescriptor(
|
||||
TypeElement ownerElement, String name) {
|
||||
VariableElement constructorParameter = getConstructorParameter(ownerElement,
|
||||
name);
|
||||
protected ConstructorParameterPropertyDescriptor createPropertyDescriptor(TypeElement ownerElement, String name) {
|
||||
VariableElement constructorParameter = getConstructorParameter(ownerElement, name);
|
||||
VariableElement field = getField(ownerElement, name);
|
||||
ExecutableElement getter = getMethod(ownerElement,
|
||||
createAccessorMethodName("get", name));
|
||||
ExecutableElement setter = getMethod(ownerElement,
|
||||
createAccessorMethodName("set", name));
|
||||
return new ConstructorParameterPropertyDescriptor(ownerElement, null,
|
||||
constructorParameter, name, field.asType(), field, getter, setter);
|
||||
ExecutableElement getter = getMethod(ownerElement, createAccessorMethodName("get", name));
|
||||
ExecutableElement setter = getMethod(ownerElement, createAccessorMethodName("set", name));
|
||||
return new ConstructorParameterPropertyDescriptor(ownerElement, null, constructorParameter, name,
|
||||
field.asType(), field, getter, setter);
|
||||
}
|
||||
|
||||
private VariableElement getConstructorParameter(TypeElement ownerElement,
|
||||
String name) {
|
||||
List<ExecutableElement> constructors = ElementFilter
|
||||
.constructorsIn(ownerElement.getEnclosedElements()).stream()
|
||||
.filter((constructor) -> !constructor.getParameters().isEmpty())
|
||||
.collect(Collectors.toList());
|
||||
private VariableElement getConstructorParameter(TypeElement ownerElement, String name) {
|
||||
List<ExecutableElement> constructors = ElementFilter.constructorsIn(ownerElement.getEnclosedElements()).stream()
|
||||
.filter((constructor) -> !constructor.getParameters().isEmpty()).collect(Collectors.toList());
|
||||
if (constructors.size() != 1) {
|
||||
throw new IllegalStateException(
|
||||
"No candidate constructor for " + ownerElement);
|
||||
throw new IllegalStateException("No candidate constructor for " + ownerElement);
|
||||
}
|
||||
return constructors.get(0).getParameters().stream()
|
||||
.filter((parameter) -> parameter.getSimpleName().toString().equals(name))
|
||||
.findFirst().orElse(null);
|
||||
.filter((parameter) -> parameter.getSimpleName().toString().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,8 +42,7 @@ public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
@Test
|
||||
public void simpleEndpoint() {
|
||||
ConfigurationMetadata metadata = compile(SimpleEndpoint.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.simple")
|
||||
.fromSource(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);
|
||||
@@ -52,8 +51,7 @@ public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
@Test
|
||||
public void disableEndpoint() {
|
||||
ConfigurationMetadata metadata = compile(DisabledEndpoint.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.disabled")
|
||||
.fromSource(DisabledEndpoint.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.disabled").fromSource(DisabledEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("disabled", false));
|
||||
assertThat(metadata.getItems()).hasSize(2);
|
||||
}
|
||||
@@ -61,8 +59,7 @@ public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
@Test
|
||||
public void enabledEndpoint() {
|
||||
ConfigurationMetadata metadata = compile(EnabledEndpoint.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.enabled")
|
||||
.fromSource(EnabledEndpoint.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.enabled").fromSource(EnabledEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("enabled", true));
|
||||
assertThat(metadata.getItems()).hasSize(2);
|
||||
}
|
||||
@@ -70,11 +67,10 @@ public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
@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"));
|
||||
.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);
|
||||
@@ -83,8 +79,7 @@ public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
@Test
|
||||
public void specificEndpoint() {
|
||||
ConfigurationMetadata metadata = compile(SpecificEndpoint.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.specific")
|
||||
.fromSource(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);
|
||||
@@ -93,27 +88,26 @@ public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
@Test
|
||||
public void camelCaseEndpoint() {
|
||||
ConfigurationMetadata metadata = compile(CamelCaseEndpoint.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("management.endpoint.pascal-case")
|
||||
.fromSource(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);
|
||||
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(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(Metadata.withGroup("management.endpoint.incremental").fromSource(IncrementalEndpoint.class));
|
||||
assertThat(metadata).has(enabledFlag("incremental", false));
|
||||
assertThat(metadata).has(cacheTtl("incremental"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
@@ -121,61 +115,50 @@ public class EndpointMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
|
||||
@Test
|
||||
public void incrementalEndpointBuildChangeCacheFlag() throws Exception {
|
||||
TestProject project = new TestProject(this.temporaryFolder,
|
||||
IncrementalEndpoint.class);
|
||||
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(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");
|
||||
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(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);
|
||||
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(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");
|
||||
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(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, 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) {
|
||||
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.");
|
||||
return Metadata.withProperty("management.endpoint." + endpointId + ".cache.time-to-live").ofType(Duration.class)
|
||||
.withDefaultValue("0ms").withDescription("Maximum time that a response can be cached.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,90 +39,74 @@ public class GenericsMetadataGenerationTests extends AbstractMetadataGenerationT
|
||||
|
||||
@Test
|
||||
public void simpleGenericProperties() {
|
||||
ConfigurationMetadata metadata = compile(AbstractGenericProperties.class,
|
||||
SimpleGenericProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("generic").fromSource(SimpleGenericProperties.class));
|
||||
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));
|
||||
.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));
|
||||
.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 complexGenericProperties() {
|
||||
ConfigurationMetadata metadata = compile(ComplexGenericProperties.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("generic").fromSource(ComplexGenericProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withGroup("generic.test").ofType(UpperBoundGenericPojo.class)
|
||||
.fromSource(ComplexGenericProperties.class));
|
||||
assertThat(metadata).has(Metadata
|
||||
.withProperty("generic.test.mappings",
|
||||
"java.util.Map<java.lang.Enum<T>,java.lang.String>")
|
||||
.fromSource(UpperBoundGenericPojo.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic").fromSource(ComplexGenericProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("generic.test").ofType(UpperBoundGenericPojo.class)
|
||||
.fromSource(ComplexGenericProperties.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("generic.test.mappings", "java.util.Map<java.lang.Enum<T>,java.lang.String>")
|
||||
.fromSource(UpperBoundGenericPojo.class));
|
||||
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));
|
||||
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));
|
||||
.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>>")
|
||||
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));
|
||||
.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.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));
|
||||
.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));
|
||||
.ofType("java.util.List<? super java.lang.Integer>").fromSource(WildcardConfig.class));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
|
||||
@@ -29,21 +29,18 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class ImmutablePropertiesMetadataGenerationTests
|
||||
extends AbstractMetadataGenerationTests {
|
||||
public class ImmutablePropertiesMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
|
||||
@Test
|
||||
public void immutableSimpleProperties() {
|
||||
ConfigurationMetadata metadata = compile(ImmutableSimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("immutable")
|
||||
.fromSource(ImmutableSimpleProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.the-name", String.class)
|
||||
.fromSource(ImmutableSimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot"));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.flag", Boolean.class)
|
||||
.withDefaultValue(false).fromSource(ImmutableSimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withGroup("immutable").fromSource(ImmutableSimpleProperties.class));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("immutable.the-name", String.class).fromSource(ImmutableSimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.").withDefaultValue("boot"));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(ImmutableSimpleProperties.class).withDescription("A simple flag.")
|
||||
.withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.comparator"));
|
||||
assertThat(metadata).has(Metadata.withProperty("immutable.counter"));
|
||||
assertThat(metadata.getItems()).hasSize(5);
|
||||
|
||||
@@ -31,79 +31,65 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public class IncrementalBuildMetadataGenerationTests
|
||||
extends AbstractMetadataGenerationTests {
|
||||
public class IncrementalBuildMetadataGenerationTests extends AbstractMetadataGenerationTests {
|
||||
|
||||
@Test
|
||||
public void incrementalBuild() throws Exception {
|
||||
TestProject project = new TestProject(this.temporaryFolder, FooProperties.class,
|
||||
BarProperties.class);
|
||||
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));
|
||||
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"));
|
||||
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));
|
||||
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));
|
||||
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);
|
||||
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");
|
||||
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).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);
|
||||
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));
|
||||
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));
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -42,10 +42,8 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void javaBeanSimpleProperty() throws IOException {
|
||||
process(SimpleTypeProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(SimpleTypeProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"myString");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleTypeProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "myString");
|
||||
assertThat(property.getName()).isEqualTo("myString");
|
||||
assertThat(property.getSource()).isSameAs(property.getGetter());
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getMyString");
|
||||
@@ -58,10 +56,8 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void javaBeanCollectionProperty() throws IOException {
|
||||
process(SimpleCollectionProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(SimpleCollectionProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"doubles");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleCollectionProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "doubles");
|
||||
assertThat(property.getName()).isEqualTo("doubles");
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getDoubles");
|
||||
assertThat(property.getSetter()).isNull();
|
||||
@@ -73,10 +69,8 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void javaBeanNestedPropertySameClass() throws IOException {
|
||||
process(InnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(InnerClassProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"first");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(InnerClassProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertThat(property.getName()).isEqualTo("first");
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getFirst");
|
||||
assertThat(property.getSetter()).isNull();
|
||||
@@ -88,10 +82,8 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void javaBeanNestedPropertyWithAnnotation() throws IOException {
|
||||
process(InnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(InnerClassProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"third");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(InnerClassProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "third");
|
||||
assertThat(property.getName()).isEqualTo("third");
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getThird");
|
||||
assertThat(property.getSetter()).isNull();
|
||||
@@ -101,14 +93,13 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaBeanSimplePropertyWithOnlyGetterShouldNotBeExposed()
|
||||
throws IOException {
|
||||
public void javaBeanSimplePropertyWithOnlyGetterShouldNotBeExposed() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
ExecutableElement getter = getMethod(ownerElement, "getSize");
|
||||
VariableElement field = getField(ownerElement, "size");
|
||||
JavaBeanPropertyDescriptor property = new JavaBeanPropertyDescriptor(
|
||||
ownerElement, getter, getter, "size", field.asType(), field, null);
|
||||
JavaBeanPropertyDescriptor property = new JavaBeanPropertyDescriptor(ownerElement, getter, getter, "size",
|
||||
field.asType(), field, null);
|
||||
assertThat(property.getName()).isEqualTo("size");
|
||||
assertThat(property.getSource()).isSameAs(property.getGetter());
|
||||
assertThat(property.getGetter().getSimpleName()).hasToString("getSize");
|
||||
@@ -119,14 +110,12 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaBeanSimplePropertyWithOnlySetterShouldNotBeExposed()
|
||||
throws IOException {
|
||||
public void javaBeanSimplePropertyWithOnlySetterShouldNotBeExposed() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
VariableElement field = getField(ownerElement, "counter");
|
||||
JavaBeanPropertyDescriptor property = new JavaBeanPropertyDescriptor(
|
||||
ownerElement, null, null, "counter", field.asType(), field,
|
||||
getMethod(ownerElement, "setCounter"));
|
||||
JavaBeanPropertyDescriptor property = new JavaBeanPropertyDescriptor(ownerElement, null, null, "counter",
|
||||
field.asType(), field, getMethod(ownerElement, "setCounter"));
|
||||
assertThat(property.getName()).isEqualTo("counter");
|
||||
assertThat(property.getSource()).isSameAs(property.getGetter());
|
||||
assertThat(property.getGetter()).isNull();
|
||||
@@ -139,55 +128,43 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void javaBeanMetadataSimpleProperty() throws IOException {
|
||||
process(SimpleTypeProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(SimpleTypeProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"myString");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasName("test.my-string").hasType(String.class)
|
||||
.hasSourceType(SimpleTypeProperties.class).hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleTypeProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "myString");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.my-string").hasType(String.class)
|
||||
.hasSourceType(SimpleTypeProperties.class).hasNoDescription().isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaBeanMetadataCollectionProperty() throws IOException {
|
||||
process(SimpleCollectionProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(SimpleCollectionProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"doubles");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleCollectionProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "doubles");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.doubles")
|
||||
.hasType("java.util.List<java.lang.Double>")
|
||||
.hasSourceType(SimpleCollectionProperties.class).hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
.hasType("java.util.List<java.lang.Double>").hasSourceType(SimpleCollectionProperties.class)
|
||||
.hasNoDescription().isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaBeanMetadataNestedGroup() throws IOException {
|
||||
process(InnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(InnerClassProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"first");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(InnerClassProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
|
||||
.hasType(
|
||||
"org.springframework.boot.configurationsample.specific.InnerClassProperties$Foo")
|
||||
.hasSourceType(InnerClassProperties.class)
|
||||
.hasSourceMethod("getFirst()").hasNoDescription().isNotDeprecated();
|
||||
.hasType("org.springframework.boot.configurationsample.specific.InnerClassProperties$Foo")
|
||||
.hasSourceType(InnerClassProperties.class).hasSourceMethod("getFirst()").hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaBeanMetadataNotACandidatePropertyShouldReturnNull()
|
||||
throws IOException {
|
||||
public void javaBeanMetadataNotACandidatePropertyShouldReturnNull() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
VariableElement field = getField(ownerElement, "counter");
|
||||
JavaBeanPropertyDescriptor property = new JavaBeanPropertyDescriptor(
|
||||
ownerElement, null, null, "counter", field.asType(), field,
|
||||
getMethod(ownerElement, "setCounter"));
|
||||
JavaBeanPropertyDescriptor property = new JavaBeanPropertyDescriptor(ownerElement, null, null, "counter",
|
||||
field.asType(), field, getMethod(ownerElement, "setCounter"));
|
||||
assertThat(property.resolveItemMetadata("test", metadataEnv)).isNull();
|
||||
});
|
||||
}
|
||||
@@ -199,22 +176,17 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
(roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(
|
||||
org.springframework.boot.configurationsample.simple.DeprecatedProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithNoInformation();
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void javaBeanMetadataDeprecatedPropertyWithAnnotation() throws IOException {
|
||||
process(DeprecatedSingleProperty.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(DeprecatedSingleProperty.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithReason("renamed")
|
||||
TypeElement ownerElement = roundEnv.getRootElement(DeprecatedSingleProperty.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithReason("renamed")
|
||||
.isDeprecatedWithReplacement("singledeprecated.new-name");
|
||||
});
|
||||
}
|
||||
@@ -223,10 +195,8 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
public void javaBeanDeprecatedPropertyOnGetter() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"flag", "isFlag", "setFlag");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithNoInformation();
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "flag", "isFlag", "setFlag");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -234,10 +204,8 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
public void javaBeanDeprecatedPropertyOnSetter() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithNoInformation();
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -245,8 +213,7 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
public void javaBeanPropertyWithDescription() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"theName");
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDescription("The name of this simple properties.");
|
||||
});
|
||||
@@ -256,27 +223,22 @@ public class JavaBeanPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
public void javaBeanPropertyWithDefaultValue() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDefaultValue("boot");
|
||||
JavaBeanPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasDefaultValue("boot");
|
||||
});
|
||||
}
|
||||
|
||||
protected JavaBeanPropertyDescriptor createPropertyDescriptor(
|
||||
TypeElement ownerElement, String name) {
|
||||
return createPropertyDescriptor(ownerElement, name,
|
||||
createAccessorMethodName("get", name),
|
||||
protected JavaBeanPropertyDescriptor createPropertyDescriptor(TypeElement ownerElement, String name) {
|
||||
return createPropertyDescriptor(ownerElement, name, createAccessorMethodName("get", name),
|
||||
createAccessorMethodName("set", name));
|
||||
}
|
||||
|
||||
protected JavaBeanPropertyDescriptor createPropertyDescriptor(
|
||||
TypeElement ownerElement, String name, String getterName, String setterName) {
|
||||
protected JavaBeanPropertyDescriptor createPropertyDescriptor(TypeElement ownerElement, String name,
|
||||
String getterName, String setterName) {
|
||||
ExecutableElement getter = getMethod(ownerElement, getterName);
|
||||
ExecutableElement setter = getMethod(ownerElement, setterName);
|
||||
VariableElement field = getField(ownerElement, name);
|
||||
return new JavaBeanPropertyDescriptor(ownerElement, null, getter, name,
|
||||
getter.getReturnType(), field, setter);
|
||||
return new JavaBeanPropertyDescriptor(ownerElement, null, getter, name, getter.getReturnType(), field, setter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -55,63 +55,51 @@ public class LombokMetadataGenerationTests extends AbstractMetadataGenerationTes
|
||||
@Test
|
||||
public void lombokExplicitProperties() {
|
||||
ConfigurationMetadata metadata = compile(LombokExplicitProperties.class);
|
||||
assertSimpleLombokProperties(metadata, LombokExplicitProperties.class,
|
||||
"explicit");
|
||||
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);
|
||||
assertAccessLevelLombokProperties(metadata, LombokAccessLevelProperties.class, "accesslevel", 2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokAccessLevelOverwriteDataProperties() {
|
||||
ConfigurationMetadata metadata = compile(
|
||||
LombokAccessLevelOverwriteDataProperties.class);
|
||||
assertAccessLevelOverwriteLombokProperties(metadata,
|
||||
LombokAccessLevelOverwriteDataProperties.class,
|
||||
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,
|
||||
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,
|
||||
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)
|
||||
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.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));
|
||||
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
|
||||
@@ -124,43 +112,38 @@ public class LombokMetadataGenerationTests extends AbstractMetadataGenerationTes
|
||||
|
||||
@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));
|
||||
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) {
|
||||
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 + ".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 + ".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) {
|
||||
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) {
|
||||
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).has(Metadata.withProperty(prefix + ".name" + i, String.class));
|
||||
}
|
||||
assertThat(metadata.getItems()).hasSize(1 + countNameFields);
|
||||
}
|
||||
|
||||
@@ -45,10 +45,8 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void lombokSimpleProperty() throws IOException {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"name");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertThat(property.getName()).isEqualTo("name");
|
||||
assertThat(property.getSource()).isSameAs(property.getField());
|
||||
assertThat(property.getField().getSimpleName()).hasToString("name");
|
||||
@@ -60,10 +58,8 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void lombokCollectionProperty() throws IOException {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"items");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "items");
|
||||
assertThat(property.getName()).isEqualTo("items");
|
||||
assertThat(property.getSource()).isSameAs(property.getField());
|
||||
assertThat(property.getField().getSimpleName()).hasToString("items");
|
||||
@@ -75,10 +71,8 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void lombokNestedPropertySameClass() throws IOException {
|
||||
process(LombokInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokInnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"first");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokInnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertThat(property.getName()).isEqualTo("first");
|
||||
assertThat(property.getSource()).isSameAs(property.getField());
|
||||
assertThat(property.getField().getSimpleName()).hasToString("first");
|
||||
@@ -90,10 +84,8 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void lombokNestedPropertyWithAnnotation() throws IOException {
|
||||
process(LombokInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokInnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"third");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokInnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "third");
|
||||
assertThat(property.getName()).isEqualTo("third");
|
||||
assertThat(property.getSource()).isSameAs(property.getField());
|
||||
assertThat(property.getField().getSimpleName()).hasToString("third");
|
||||
@@ -103,52 +95,40 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokSimplePropertyWithOnlyGetterOnClassShouldNotBeExposed()
|
||||
throws IOException {
|
||||
public void lombokSimplePropertyWithOnlyGetterOnClassShouldNotBeExposed() throws IOException {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"ignored");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "ignored");
|
||||
assertThat(property.isProperty(metadataEnv)).isFalse();
|
||||
assertThat(property.isNested(metadataEnv)).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokSimplePropertyWithOnlyGetterOnDataClassShouldNotBeExposed()
|
||||
throws IOException {
|
||||
public void lombokSimplePropertyWithOnlyGetterOnDataClassShouldNotBeExposed() throws IOException {
|
||||
process(LombokSimpleDataProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleDataProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"ignored");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleDataProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "ignored");
|
||||
assertThat(property.isProperty(metadataEnv)).isFalse();
|
||||
assertThat(property.isNested(metadataEnv)).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokSimplePropertyWithOnlyGetterOnFieldShouldNotBeExposed()
|
||||
throws IOException {
|
||||
public void lombokSimplePropertyWithOnlyGetterOnFieldShouldNotBeExposed() throws IOException {
|
||||
process(LombokExplicitProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokExplicitProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"ignoredOnlyGetter");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokExplicitProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "ignoredOnlyGetter");
|
||||
assertThat(property.isProperty(metadataEnv)).isFalse();
|
||||
assertThat(property.isNested(metadataEnv)).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokSimplePropertyWithOnlySetterOnFieldShouldNotBeExposed()
|
||||
throws IOException {
|
||||
public void lombokSimplePropertyWithOnlySetterOnFieldShouldNotBeExposed() throws IOException {
|
||||
process(LombokExplicitProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokExplicitProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"ignoredOnlySetter");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokExplicitProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "ignoredOnlySetter");
|
||||
assertThat(property.isProperty(metadataEnv)).isFalse();
|
||||
assertThat(property.isNested(metadataEnv)).isFalse();
|
||||
});
|
||||
@@ -157,70 +137,56 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void lombokMetadataSimpleProperty() throws IOException {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"description");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasName("test.description").hasType(String.class)
|
||||
.hasSourceType(LombokSimpleProperties.class).hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "description");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.description").hasType(String.class)
|
||||
.hasSourceType(LombokSimpleProperties.class).hasNoDescription().isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokMetadataCollectionProperty() throws IOException {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"items");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "items");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasName("test.items")
|
||||
.hasType("java.util.List<java.lang.String>")
|
||||
.hasSourceType(LombokSimpleProperties.class).hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
.hasType("java.util.List<java.lang.String>").hasSourceType(LombokSimpleProperties.class)
|
||||
.hasNoDescription().isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokMetadataNestedGroup() throws IOException {
|
||||
process(LombokInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokInnerClassProperties.class);
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokInnerClassProperties.class);
|
||||
VariableElement field = getField(ownerElement, "third");
|
||||
ExecutableElement getter = getMethod(ownerElement, "getThird");
|
||||
LombokPropertyDescriptor property = new LombokPropertyDescriptor(ownerElement,
|
||||
null, field, "third", field.asType(), getter, null);
|
||||
LombokPropertyDescriptor property = new LombokPropertyDescriptor(ownerElement, null, field, "third",
|
||||
field.asType(), getter, null);
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.third")
|
||||
.hasType(
|
||||
"org.springframework.boot.configurationsample.lombok.SimpleLombokPojo")
|
||||
.hasSourceType(LombokInnerClassProperties.class)
|
||||
.hasSourceMethod("getThird()").hasNoDescription().isNotDeprecated();
|
||||
.hasType("org.springframework.boot.configurationsample.lombok.SimpleLombokPojo")
|
||||
.hasSourceType(LombokInnerClassProperties.class).hasSourceMethod("getThird()").hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokMetadataNestedGroupNoGetter() throws IOException {
|
||||
process(LombokInnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokInnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"first");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokInnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertItemMetadata(metadataEnv, property).isGroup().hasName("test.first")
|
||||
.hasType(
|
||||
"org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties$Foo")
|
||||
.hasSourceType(LombokInnerClassProperties.class).hasSourceMethod(null)
|
||||
.hasNoDescription().isNotDeprecated();
|
||||
.hasType("org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties$Foo")
|
||||
.hasSourceType(LombokInnerClassProperties.class).hasSourceMethod(null).hasNoDescription()
|
||||
.isNotDeprecated();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokMetadataNotACandidatePropertyShouldReturnNull() throws IOException {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"ignored");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "ignored");
|
||||
assertThat(property.resolveItemMetadata("test", metadataEnv)).isNull();
|
||||
});
|
||||
}
|
||||
@@ -232,46 +198,35 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
(roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(
|
||||
org.springframework.boot.configurationsample.lombok.LombokDeprecatedProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(
|
||||
ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithNoInformation();
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokDeprecatedPropertyOnField() throws IOException {
|
||||
process(LombokDeprecatedSingleProperty.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokDeprecatedSingleProperty.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.isDeprecatedWithNoInformation();
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokDeprecatedSingleProperty.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().isDeprecatedWithNoInformation();
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokPropertyWithDescription() throws IOException {
|
||||
process(LombokSimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDescription("Name description.");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokSimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "name");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasDescription("Name description.");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lombokPropertyWithDefaultValue() throws IOException {
|
||||
process(LombokDefaultValueProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(LombokDefaultValueProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"description");
|
||||
assertItemMetadata(metadataEnv, property).isProperty()
|
||||
.hasDefaultValue("my description");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(LombokDefaultValueProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "description");
|
||||
assertItemMetadata(metadataEnv, property).isProperty().hasDefaultValue("my description");
|
||||
});
|
||||
}
|
||||
|
||||
@@ -279,8 +234,7 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
public void lombokPropertyNotCandidate() throws IOException {
|
||||
process(SimpleProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv.getRootElement(SimpleProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"theName");
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "theName");
|
||||
assertThat(property.isProperty(metadataEnv)).isFalse();
|
||||
assertThat(property.isNested(metadataEnv)).isFalse();
|
||||
});
|
||||
@@ -289,24 +243,18 @@ public class LombokPropertyDescriptorTests extends PropertyDescriptorTests {
|
||||
@Test
|
||||
public void lombokNestedPropertyNotCandidate() throws IOException {
|
||||
process(InnerClassProperties.class, (roundEnv, metadataEnv) -> {
|
||||
TypeElement ownerElement = roundEnv
|
||||
.getRootElement(InnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement,
|
||||
"first");
|
||||
TypeElement ownerElement = roundEnv.getRootElement(InnerClassProperties.class);
|
||||
LombokPropertyDescriptor property = createPropertyDescriptor(ownerElement, "first");
|
||||
assertThat(property.isProperty(metadataEnv)).isFalse();
|
||||
assertThat(property.isNested(metadataEnv)).isFalse();
|
||||
});
|
||||
}
|
||||
|
||||
protected LombokPropertyDescriptor createPropertyDescriptor(TypeElement ownerElement,
|
||||
String name) {
|
||||
protected LombokPropertyDescriptor createPropertyDescriptor(TypeElement ownerElement, String name) {
|
||||
VariableElement field = getField(ownerElement, name);
|
||||
ExecutableElement getter = getMethod(ownerElement,
|
||||
createAccessorMethodName("get", name));
|
||||
ExecutableElement setter = getMethod(ownerElement,
|
||||
createAccessorMethodName("set", name));
|
||||
return new LombokPropertyDescriptor(ownerElement, null, field, name,
|
||||
field.asType(), getter, setter);
|
||||
ExecutableElement getter = getMethod(ownerElement, createAccessorMethodName("get", name));
|
||||
ExecutableElement setter = getMethod(ownerElement, createAccessorMethodName("set", name));
|
||||
return new LombokPropertyDescriptor(ownerElement, null, field, name, field.asType(), getter, setter);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -56,114 +56,96 @@ public class MergeMetadataGenerationTests extends AbstractMetadataGenerationTest
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo", String.class)
|
||||
.fromSource(AdditionalMetadata.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo", String.class).fromSource(AdditionalMetadata.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfAdditionalPropertyMatchingGroup() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty(null, "simple",
|
||||
"java.lang.String", null, null, null, null, null);
|
||||
ItemMetadata property = ItemMetadata.newProperty(null, "simple", "java.lang.String", null, null, null, null,
|
||||
null);
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
|
||||
assertThat(metadata).has(Metadata.withGroup("simple").fromSource(SimpleProperties.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple", String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDefaultValue() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null,
|
||||
null, null, true, null);
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", null, null, null, null, true, null);
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class)
|
||||
.fromSource(SimpleProperties.class).withDescription("A simple flag.")
|
||||
.withDeprecation(null, null).withDefaultValue(true));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.flag", Boolean.class).fromSource(SimpleProperties.class)
|
||||
.withDescription("A simple flag.").withDeprecation(null, null).withDefaultValue(true));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyWithSeveralCandidates() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "flag",
|
||||
Boolean.class.getName(), null, null, null, true, null);
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "flag", Boolean.class.getName(), null, null, null,
|
||||
true, null);
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class,
|
||||
SimpleConflictingProperties.class);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class, SimpleConflictingProperties.class);
|
||||
assertThat(metadata.getItems()).hasSize(6);
|
||||
List<ItemMetadata> items = metadata.getItems().stream()
|
||||
.filter((item) -> item.getName().equals("simple.flag"))
|
||||
List<ItemMetadata> items = metadata.getItems().stream().filter((item) -> item.getName().equals("simple.flag"))
|
||||
.collect(Collectors.toList());
|
||||
assertThat(items).hasSize(2);
|
||||
ItemMetadata matchingProperty = items.stream()
|
||||
.filter((item) -> item.getType().equals(Boolean.class.getName()))
|
||||
ItemMetadata matchingProperty = items.stream().filter((item) -> item.getType().equals(Boolean.class.getName()))
|
||||
.findFirst().orElse(null);
|
||||
assertThat(matchingProperty).isNotNull();
|
||||
assertThat(matchingProperty.getDefaultValue()).isEqualTo(true);
|
||||
assertThat(matchingProperty.getSourceType())
|
||||
.isEqualTo(SimpleProperties.class.getName());
|
||||
assertThat(matchingProperty.getSourceType()).isEqualTo(SimpleProperties.class.getName());
|
||||
assertThat(matchingProperty.getDescription()).isEqualTo("A simple flag.");
|
||||
ItemMetadata nonMatchingProperty = items.stream()
|
||||
.filter((item) -> item.getType().equals(String.class.getName()))
|
||||
.findFirst().orElse(null);
|
||||
.filter((item) -> item.getType().equals(String.class.getName())).findFirst().orElse(null);
|
||||
assertThat(nonMatchingProperty).isNotNull();
|
||||
assertThat(nonMatchingProperty.getDefaultValue()).isEqualTo("hello");
|
||||
assertThat(nonMatchingProperty.getSourceType())
|
||||
.isEqualTo(SimpleConflictingProperties.class.getName());
|
||||
assertThat(nonMatchingProperty.getSourceType()).isEqualTo(SimpleConflictingProperties.class.getName());
|
||||
assertThat(nonMatchingProperty.getDescription()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDescription() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null,
|
||||
null, null, "A nice comparator.", null, null);
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, "A nice comparator.",
|
||||
null, null);
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("A nice comparator."));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class).withDescription("A nice comparator."));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDeprecation() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null,
|
||||
null, null, null, null, new ItemDeprecation("Don't use this.",
|
||||
"simple.complex-comparator", "error"));
|
||||
ItemMetadata property = ItemMetadata.newProperty("simple", "comparator", null, null, null, null, null,
|
||||
new ItemDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("simple.comparator", "java.util.Comparator<?>")
|
||||
.fromSource(SimpleProperties.class).withDeprecation(
|
||||
"Don't use this.", "simple.complex-comparator", "error"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("simple.comparator", "java.util.Comparator<?>").fromSource(SimpleProperties.class)
|
||||
.withDeprecation("Don't use this.", "simple.complex-comparator", "error"));
|
||||
assertThat(metadata.getItems()).hasSize(4);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDeprecationOverride() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null,
|
||||
null, null, null, null,
|
||||
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null,
|
||||
new ItemDeprecation("Don't use this.", "single.name"));
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("Don't use this.", "single.name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class).withDeprecation("Don't use this.", "single.name"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergeExistingPropertyDeprecationOverrideLevel() throws Exception {
|
||||
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null,
|
||||
null, null, null, null, new ItemDeprecation(null, null, "error"));
|
||||
ItemMetadata property = ItemMetadata.newProperty("singledeprecated", "name", null, null, null, null, null,
|
||||
new ItemDeprecation(null, null, "error"));
|
||||
writeAdditionalMetadata(property);
|
||||
ConfigurationMetadata metadata = compile(DeprecatedSingleProperty.class);
|
||||
assertThat(metadata).has(
|
||||
Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class).withDeprecation(
|
||||
"renamed", "singledeprecated.new-name", "error"));
|
||||
assertThat(metadata).has(Metadata.withProperty("singledeprecated.name", String.class.getName())
|
||||
.fromSource(DeprecatedSingleProperty.class)
|
||||
.withDeprecation("renamed", "singledeprecated.new-name", "error"));
|
||||
assertThat(metadata.getItems()).hasSize(3);
|
||||
}
|
||||
|
||||
@@ -171,70 +153,59 @@ public class MergeMetadataGenerationTests extends AbstractMetadataGenerationTest
|
||||
public void mergeOfInvalidAdditionalMetadata() throws IOException {
|
||||
File additionalMetadataFile = createAdditionalMetadataFile();
|
||||
FileCopyUtils.copy("Hello World", new FileWriter(additionalMetadataFile));
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> compile(SimpleProperties.class))
|
||||
assertThatIllegalStateException().isThrownBy(() -> compile(SimpleProperties.class))
|
||||
.withMessage("Compilation failed");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfSimpleHint() throws Exception {
|
||||
writeAdditionalHints(ItemHint.newHint("simple.the-name",
|
||||
new ItemHint.ValueHint("boot", "Bla bla"),
|
||||
writeAdditionalHints(ItemHint.newHint("simple.the-name", new ItemHint.ValueHint("boot", "Bla bla"),
|
||||
new ItemHint.ValueHint("spring", null)));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withHint("simple.the-name")
|
||||
.withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla").withValue(1, "spring", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfHintWithNonCanonicalName() throws Exception {
|
||||
writeAdditionalHints(ItemHint.newHint("simple.theName",
|
||||
new ItemHint.ValueHint("boot", "Bla bla")));
|
||||
writeAdditionalHints(ItemHint.newHint("simple.theName", new ItemHint.ValueHint("boot", "Bla bla")));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla"));
|
||||
assertThat(metadata).has(Metadata.withHint("simple.the-name").withValue(0, "boot", "Bla bla"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfHintWithProvider() throws Exception {
|
||||
writeAdditionalHints(new ItemHint("simple.theName", Collections.emptyList(),
|
||||
Arrays.asList(
|
||||
new ItemHint.ValueProvider("first",
|
||||
Collections.singletonMap("target", "org.foo")),
|
||||
Arrays.asList(new ItemHint.ValueProvider("first", Collections.singletonMap("target", "org.foo")),
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.the-name", String.class)
|
||||
.fromSource(SimpleProperties.class)
|
||||
.withDescription("The name of this simple properties.")
|
||||
.fromSource(SimpleProperties.class).withDescription("The name of this simple properties.")
|
||||
.withDefaultValue("boot").withDeprecation(null, null));
|
||||
assertThat(metadata).has(Metadata.withHint("simple.the-name")
|
||||
.withProvider("first", "target", "org.foo").withProvider("second"));
|
||||
assertThat(metadata).has(
|
||||
Metadata.withHint("simple.the-name").withProvider("first", "target", "org.foo").withProvider("second"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfAdditionalDeprecation() throws Exception {
|
||||
writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName",
|
||||
"java.lang.String", null, null, null, null,
|
||||
new ItemDeprecation("Lame name.", "simple.the-name")));
|
||||
writePropertyDeprecation(ItemMetadata.newProperty("simple", "wrongName", "java.lang.String", null, null, null,
|
||||
null, new ItemDeprecation("Lame name.", "simple.the-name")));
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class)
|
||||
.withDeprecation("Lame name.", "simple.the-name"));
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.wrong-name", String.class).withDeprecation("Lame name.",
|
||||
"simple.the-name"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mergingOfAdditionalMetadata() throws Exception {
|
||||
File metaInfFolder = new File(getCompiler().getOutputLocation(), "META-INF");
|
||||
metaInfFolder.mkdirs();
|
||||
File additionalMetadataFile = new File(metaInfFolder,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadataFile = new File(metaInfFolder, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadataFile.createNewFile();
|
||||
JSONObject property = new JSONObject();
|
||||
property.put("name", "foo");
|
||||
@@ -250,8 +221,7 @@ public class MergeMetadataGenerationTests extends AbstractMetadataGenerationTest
|
||||
writer.close();
|
||||
ConfigurationMetadata metadata = compile(SimpleProperties.class);
|
||||
assertThat(metadata).has(Metadata.withProperty("simple.comparator"));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo", String.class)
|
||||
.fromSource(AdditionalMetadata.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo", String.class).fromSource(AdditionalMetadata.class));
|
||||
}
|
||||
|
||||
private void writeAdditionalMetadata(ItemMetadata... metadata) throws Exception {
|
||||
@@ -305,8 +275,7 @@ public class MergeMetadataGenerationTests extends AbstractMetadataGenerationTest
|
||||
private File createAdditionalMetadataFile() throws IOException {
|
||||
File metaInfFolder = new File(getCompiler().getOutputLocation(), "META-INF");
|
||||
metaInfFolder.mkdirs();
|
||||
File additionalMetadataFile = new File(metaInfFolder,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadataFile = new File(metaInfFolder, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadataFile.createNewFile();
|
||||
return additionalMetadataFile;
|
||||
}
|
||||
|
||||
@@ -27,8 +27,7 @@ import org.springframework.boot.configurationprocessor.test.TestConfigurationMet
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class MetadataGenerationEnvironmentFactory
|
||||
implements Function<ProcessingEnvironment, MetadataGenerationEnvironment> {
|
||||
class MetadataGenerationEnvironmentFactory implements Function<ProcessingEnvironment, MetadataGenerationEnvironment> {
|
||||
|
||||
@Override
|
||||
public MetadataGenerationEnvironment apply(ProcessingEnvironment environment) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* 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.
|
||||
@@ -50,13 +50,11 @@ public class MetadataStoreTests {
|
||||
File classesLocation = new File(app, "target/classes");
|
||||
File metaInf = new File(classesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -66,13 +64,11 @@ public class MetadataStoreTests {
|
||||
File resourcesLocation = new File(app, "build/resources/main");
|
||||
File metaInf = new File(resourcesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,13 +78,11 @@ public class MetadataStoreTests {
|
||||
File resourcesLocation = new File(app, "build/resources/main");
|
||||
File metaInf = new File(resourcesLocation, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
assertThat(
|
||||
this.metadataStore.locateAdditionalMetadataFile(new File(classesLocation,
|
||||
"META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(
|
||||
new File(classesLocation, "META-INF/additional-spring-configuration-metadata.json")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,14 +91,12 @@ public class MetadataStoreTests {
|
||||
File location = new File(app, "src/main/resources");
|
||||
File metaInf = new File(location, "META-INF");
|
||||
metaInf.mkdirs();
|
||||
File additionalMetadata = new File(metaInf,
|
||||
"additional-spring-configuration-metadata.json");
|
||||
File additionalMetadata = new File(metaInf, "additional-spring-configuration-metadata.json");
|
||||
additionalMetadata.createNewFile();
|
||||
given(this.environment.getOptions()).willReturn(Collections.singletonMap(
|
||||
ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION,
|
||||
location.getAbsolutePath()));
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(new File(app, "foo")))
|
||||
.isEqualTo(additionalMetadata);
|
||||
given(this.environment.getOptions()).willReturn(
|
||||
Collections.singletonMap(ConfigurationMetadataAnnotationProcessor.ADDITIONAL_METADATA_LOCATIONS_OPTION,
|
||||
location.getAbsolutePath()));
|
||||
assertThat(this.metadataStore.locateAdditionalMetadataFile(new File(app, "foo"))).isEqualTo(additionalMetadata);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -38,31 +38,30 @@ public class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerati
|
||||
@Test
|
||||
public void simpleMethodConfig() {
|
||||
ConfigurationMetadata metadata = compile(SimpleMethodConfig.class);
|
||||
assertThat(metadata).has(Metadata.withGroup("foo").fromSource(SimpleMethodConfig.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withGroup("foo").fromSource(SimpleMethodConfig.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.name", String.class)
|
||||
.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));
|
||||
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)
|
||||
.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)
|
||||
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.flag", Boolean.class)
|
||||
.withDefaultValue(false).fromSource(MethodAndClassConfig.Foo.class));
|
||||
assertThat(metadata).has(Metadata.withProperty("conflict.value", String.class)
|
||||
.fromSource(MethodAndClassConfig.class));
|
||||
assertThat(metadata)
|
||||
.has(Metadata.withProperty("conflict.value", String.class).fromSource(MethodAndClassConfig.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,11 +76,9 @@ public class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerati
|
||||
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));
|
||||
.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
|
||||
@@ -91,13 +88,10 @@ public class MethodBasedMetadataGenerationTests extends AbstractMetadataGenerati
|
||||
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)
|
||||
.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)
|
||||
assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).withDefaultValue(false)
|
||||
.fromSource(org.springframework.boot.configurationsample.method.DeprecatedClassMethodConfig.Foo.class)
|
||||
.withDeprecation(null, null));
|
||||
}
|
||||
|
||||
|
||||
@@ -59,90 +59,76 @@ public class PropertyDescriptorResolverTests {
|
||||
|
||||
@Test
|
||||
public void propertiesWithJavaBeanProperties() throws IOException {
|
||||
process(SimpleProperties.class, propertyNames((stream) -> assertThat(stream)
|
||||
.containsExactly("theName", "flag", "comparator")));
|
||||
process(SimpleProperties.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("theName", "flag", "comparator")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWithJavaBeanHierarchicalProperties() throws IOException {
|
||||
process(HierarchicalProperties.class,
|
||||
Arrays.asList(HierarchicalPropertiesParent.class,
|
||||
HierarchicalPropertiesGrandparent.class),
|
||||
Arrays.asList(HierarchicalPropertiesParent.class, HierarchicalPropertiesGrandparent.class),
|
||||
(type, metadataEnv) -> {
|
||||
PropertyDescriptorResolver resolver = new PropertyDescriptorResolver(
|
||||
metadataEnv);
|
||||
assertThat(
|
||||
resolver.resolve(type, null).map(PropertyDescriptor::getName))
|
||||
.containsExactly("third", "second", "first");
|
||||
PropertyDescriptorResolver resolver = new PropertyDescriptorResolver(metadataEnv);
|
||||
assertThat(resolver.resolve(type, null).map(PropertyDescriptor::getName)).containsExactly("third",
|
||||
"second", "first");
|
||||
assertThat(resolver.resolve(type, null)
|
||||
.map((descriptor) -> descriptor.resolveItemMetadata("test",
|
||||
metadataEnv))
|
||||
.map(ItemMetadata::getDefaultValue)).containsExactly("three",
|
||||
"two", "one");
|
||||
.map((descriptor) -> descriptor.resolveItemMetadata("test", metadataEnv))
|
||||
.map(ItemMetadata::getDefaultValue)).containsExactly("three", "two", "one");
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWithLombokGetterSetterAtClassLevel() throws IOException {
|
||||
process(LombokSimpleProperties.class, propertyNames((stream) -> assertThat(stream)
|
||||
.containsExactly("name", "description", "counter", "number", "items")));
|
||||
process(LombokSimpleProperties.class, propertyNames(
|
||||
(stream) -> assertThat(stream).containsExactly("name", "description", "counter", "number", "items")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWithLombokGetterSetterAtFieldLevel() throws IOException {
|
||||
process(LombokExplicitProperties.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("name",
|
||||
"description", "counter", "number", "items")));
|
||||
process(LombokExplicitProperties.class, propertyNames(
|
||||
(stream) -> assertThat(stream).containsExactly("name", "description", "counter", "number", "items")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWithLombokDataClass() throws IOException {
|
||||
process(LombokSimpleDataProperties.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("name",
|
||||
"description", "counter", "number", "items")));
|
||||
process(LombokSimpleDataProperties.class, propertyNames(
|
||||
(stream) -> assertThat(stream).containsExactly("name", "description", "counter", "number", "items")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWithConstructorParameters() throws IOException {
|
||||
process(ImmutableSimpleProperties.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("theName",
|
||||
"flag", "comparator", "counter")));
|
||||
process(ImmutableSimpleProperties.class, propertyNames(
|
||||
(stream) -> assertThat(stream).containsExactly("theName", "flag", "comparator", "counter")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertiesWithSeveralConstructors() throws IOException {
|
||||
process(TwoConstructorsExample.class, propertyNames((stream) -> assertThat(stream).containsExactly("name")));
|
||||
process(TwoConstructorsExample.class,
|
||||
propertyNames((stream) -> assertThat(stream).containsExactly("name")));
|
||||
process(TwoConstructorsExample.class, properties((stream) -> assertThat(stream)
|
||||
.element(0).isInstanceOf(JavaBeanPropertyDescriptor.class)));
|
||||
properties((stream) -> assertThat(stream).element(0).isInstanceOf(JavaBeanPropertyDescriptor.class)));
|
||||
}
|
||||
|
||||
private BiConsumer<TypeElement, MetadataGenerationEnvironment> properties(
|
||||
Consumer<Stream<PropertyDescriptor<?>>> stream) {
|
||||
return (element, metadataEnv) -> {
|
||||
PropertyDescriptorResolver resolver = new PropertyDescriptorResolver(
|
||||
metadataEnv);
|
||||
PropertyDescriptorResolver resolver = new PropertyDescriptorResolver(metadataEnv);
|
||||
stream.accept(resolver.resolve(element, null));
|
||||
};
|
||||
}
|
||||
|
||||
private BiConsumer<TypeElement, MetadataGenerationEnvironment> propertyNames(
|
||||
Consumer<Stream<String>> stream) {
|
||||
return properties(
|
||||
(result) -> stream.accept(result.map(PropertyDescriptor::getName)));
|
||||
private BiConsumer<TypeElement, MetadataGenerationEnvironment> propertyNames(Consumer<Stream<String>> stream) {
|
||||
return properties((result) -> stream.accept(result.map(PropertyDescriptor::getName)));
|
||||
}
|
||||
|
||||
private void process(Class<?> target,
|
||||
BiConsumer<TypeElement, MetadataGenerationEnvironment> consumer)
|
||||
private void process(Class<?> target, BiConsumer<TypeElement, MetadataGenerationEnvironment> consumer)
|
||||
throws IOException {
|
||||
process(target, Collections.emptyList(), consumer);
|
||||
}
|
||||
|
||||
private void process(Class<?> target, Collection<Class<?>> additionalClasses,
|
||||
BiConsumer<TypeElement, MetadataGenerationEnvironment> consumer)
|
||||
throws IOException {
|
||||
BiConsumer<RoundEnvironmentTester, MetadataGenerationEnvironment> internalConsumer = (
|
||||
roundEnv, metadataEnv) -> {
|
||||
BiConsumer<TypeElement, MetadataGenerationEnvironment> consumer) throws IOException {
|
||||
BiConsumer<RoundEnvironmentTester, MetadataGenerationEnvironment> internalConsumer = (roundEnv,
|
||||
metadataEnv) -> {
|
||||
TypeElement element = roundEnv.getRootElement(target);
|
||||
consumer.accept(element, metadataEnv);
|
||||
};
|
||||
|
||||
@@ -50,24 +50,23 @@ public abstract class PropertyDescriptorTests {
|
||||
}
|
||||
|
||||
protected ExecutableElement getMethod(TypeElement element, String name) {
|
||||
return ElementFilter.methodsIn(element.getEnclosedElements()).stream().filter(
|
||||
(method) -> ((Element) method).getSimpleName().toString().equals(name))
|
||||
.findFirst().orElse(null);
|
||||
return ElementFilter.methodsIn(element.getEnclosedElements()).stream()
|
||||
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name)).findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
protected VariableElement getField(TypeElement element, String name) {
|
||||
return ElementFilter.fieldsIn(element.getEnclosedElements()).stream().filter(
|
||||
(method) -> ((Element) method).getSimpleName().toString().equals(name))
|
||||
.findFirst().orElse(null);
|
||||
return ElementFilter.fieldsIn(element.getEnclosedElements()).stream()
|
||||
.filter((method) -> ((Element) method).getSimpleName().toString().equals(name)).findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
protected ItemMetadataAssert assertItemMetadata(
|
||||
MetadataGenerationEnvironment metadataEnv, PropertyDescriptor<?> property) {
|
||||
protected ItemMetadataAssert assertItemMetadata(MetadataGenerationEnvironment metadataEnv,
|
||||
PropertyDescriptor<?> property) {
|
||||
return new ItemMetadataAssert(property.resolveItemMetadata("test", metadataEnv));
|
||||
}
|
||||
|
||||
protected void process(Class<?> target,
|
||||
BiConsumer<RoundEnvironmentTester, MetadataGenerationEnvironment> consumer)
|
||||
protected void process(Class<?> target, BiConsumer<RoundEnvironmentTester, MetadataGenerationEnvironment> consumer)
|
||||
throws IOException {
|
||||
TestableAnnotationProcessor<MetadataGenerationEnvironment> processor = new TestableAnnotationProcessor<>(
|
||||
consumer, new MetadataGenerationEnvironmentFactory());
|
||||
|
||||
@@ -64,8 +64,7 @@ public class TestProject {
|
||||
|
||||
private Set<File> sourceFiles = new LinkedHashSet<>();
|
||||
|
||||
public TestProject(TemporaryFolder tempFolder, Class<?>... classes)
|
||||
throws IOException {
|
||||
public TestProject(TemporaryFolder tempFolder, Class<?>... classes) throws IOException {
|
||||
this.sourceFolder = tempFolder.newFolder();
|
||||
this.compiler = new TestCompiler(tempFolder) {
|
||||
@Override
|
||||
@@ -134,15 +133,12 @@ public class TestProject {
|
||||
* @param snippetStream the snippet stream
|
||||
* @throws Exception if the source cannot be added
|
||||
*/
|
||||
public void addSourceCode(Class<?> target, InputStream snippetStream)
|
||||
throws Exception {
|
||||
public void addSourceCode(Class<?> target, InputStream snippetStream) throws Exception {
|
||||
File targetFile = getSourceFile(target);
|
||||
String contents = getContents(targetFile);
|
||||
int insertAt = contents.lastIndexOf('}');
|
||||
String additionalSource = FileCopyUtils
|
||||
.copyToString(new InputStreamReader(snippetStream));
|
||||
contents = contents.substring(0, insertAt) + additionalSource
|
||||
+ contents.substring(insertAt);
|
||||
String additionalSource = FileCopyUtils.copyToString(new InputStreamReader(snippetStream));
|
||||
contents = contents.substring(0, insertAt) + additionalSource + contents.substring(insertAt);
|
||||
putContents(targetFile, contents);
|
||||
}
|
||||
|
||||
|
||||
@@ -47,17 +47,13 @@ public class TypeUtilsTests {
|
||||
@Test
|
||||
public void resolveTypeDescriptorOnConcreteClass() throws IOException {
|
||||
process(SimpleGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
TypeDescriptor typeDescriptor = typeUtils.resolveTypeDescriptor(
|
||||
roundEnv.getRootElement(SimpleGenericProperties.class));
|
||||
assertThat(
|
||||
typeDescriptor.getGenerics().keySet().stream().map(Object::toString))
|
||||
.containsOnly("A", "B", "C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A"))
|
||||
.hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B"))
|
||||
.hasToString(Integer.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("C"))
|
||||
.hasToString(Duration.class.getName());
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(SimpleGenericProperties.class));
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B")).hasToString(Integer.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("C")).hasToString(Duration.class.getName());
|
||||
|
||||
});
|
||||
}
|
||||
@@ -65,15 +61,12 @@ public class TypeUtilsTests {
|
||||
@Test
|
||||
public void resolveTypeDescriptorOnIntermediateClass() throws IOException {
|
||||
process(AbstractIntermediateGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
TypeDescriptor typeDescriptor = typeUtils.resolveTypeDescriptor(
|
||||
roundEnv.getRootElement(AbstractIntermediateGenericProperties.class));
|
||||
assertThat(
|
||||
typeDescriptor.getGenerics().keySet().stream().map(Object::toString))
|
||||
.containsOnly("A", "B", "C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A"))
|
||||
.hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B"))
|
||||
.hasToString(Integer.class.getName());
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractIntermediateGenericProperties.class));
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
assertThat(typeDescriptor.resolveGeneric("A")).hasToString(String.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("B")).hasToString(Integer.class.getName());
|
||||
assertThat(typeDescriptor.resolveGeneric("C")).hasToString("C");
|
||||
});
|
||||
}
|
||||
@@ -81,19 +74,16 @@ public class TypeUtilsTests {
|
||||
@Test
|
||||
public void resolveTypeDescriptorWithOnlyGenerics() throws IOException {
|
||||
process(AbstractGenericProperties.class, (roundEnv, typeUtils) -> {
|
||||
TypeDescriptor typeDescriptor = typeUtils.resolveTypeDescriptor(
|
||||
roundEnv.getRootElement(AbstractGenericProperties.class));
|
||||
assertThat(
|
||||
typeDescriptor.getGenerics().keySet().stream().map(Object::toString))
|
||||
.containsOnly("A", "B", "C");
|
||||
TypeDescriptor typeDescriptor = typeUtils
|
||||
.resolveTypeDescriptor(roundEnv.getRootElement(AbstractGenericProperties.class));
|
||||
assertThat(typeDescriptor.getGenerics().keySet().stream().map(Object::toString)).containsOnly("A", "B",
|
||||
"C");
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private void process(Class<?> target,
|
||||
BiConsumer<RoundEnvironmentTester, TypeUtils> consumer) throws IOException {
|
||||
TestableAnnotationProcessor<TypeUtils> processor = new TestableAnnotationProcessor<>(
|
||||
consumer, TypeUtils::new);
|
||||
private void process(Class<?> target, BiConsumer<RoundEnvironmentTester, TypeUtils> consumer) throws IOException {
|
||||
TestableAnnotationProcessor<TypeUtils> processor = new TestableAnnotationProcessor<>(consumer, TypeUtils::new);
|
||||
TestCompiler compiler = new TestCompiler(this.temporaryFolder);
|
||||
compiler.getTask(target).call(processor);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -84,8 +84,7 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
assertThat(values.get("stringArrayNone")).isNull();
|
||||
assertThat(values.get("stringEmptyArray")).isEqualTo(new Object[0]);
|
||||
assertThat(values.get("stringArrayConst")).isEqualTo(new Object[] { "OK", "KO" });
|
||||
assertThat(values.get("stringArrayConstElements"))
|
||||
.isEqualTo(new Object[] { "c" });
|
||||
assertThat(values.get("stringArrayConstElements")).isEqualTo(new Object[] { "c" });
|
||||
assertThat(values.get("integerArray")).isEqualTo(new Object[] { 42, 24 });
|
||||
assertThat(values.get("unknownArray")).isNull();
|
||||
assertThat(values.get("durationNone")).isNull();
|
||||
@@ -103,8 +102,7 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
assertThat(values.get("dataSizeTerabytes")).isEqualTo("40TB");
|
||||
}
|
||||
|
||||
@SupportedAnnotationTypes({
|
||||
"org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedAnnotationTypes({ "org.springframework.boot.configurationsample.ConfigurationProperties" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
private class TestProcessor extends AbstractProcessor {
|
||||
|
||||
@@ -118,14 +116,12 @@ public abstract class AbstractFieldValuesProcessorTests {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv) {
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
for (TypeElement annotation : annotations) {
|
||||
for (Element element : roundEnv.getElementsAnnotatedWith(annotation)) {
|
||||
if (element instanceof TypeElement) {
|
||||
try {
|
||||
this.values.putAll(
|
||||
this.processor.getFieldValues((TypeElement) element));
|
||||
this.values.putAll(this.processor.getFieldValues((TypeElement) element));
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* 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.
|
||||
@@ -28,8 +28,7 @@ import static org.junit.Assume.assumeNoException;
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
public class JavaCompilerFieldValuesProcessorTests
|
||||
extends AbstractFieldValuesProcessorTests {
|
||||
public class JavaCompilerFieldValuesProcessorTests extends AbstractFieldValuesProcessorTests {
|
||||
|
||||
@Override
|
||||
protected FieldValuesParser createProcessor(ProcessingEnvironment env) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* 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.
|
||||
@@ -44,14 +44,12 @@ public class ConfigurationMetadataTests {
|
||||
|
||||
@Test
|
||||
public void toDashedCaseWordsUnderscore() {
|
||||
assertThat(toDashedCase("Word_With_underscore"))
|
||||
.isEqualTo("word-with-underscore");
|
||||
assertThat(toDashedCase("Word_With_underscore")).isEqualTo("word-with-underscore");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toDashedCaseWordsSeveralUnderscores() {
|
||||
assertThat(toDashedCase("Word___With__underscore"))
|
||||
.isEqualTo("word---with--underscore");
|
||||
assertThat(toDashedCase("Word___With__underscore")).isEqualTo("word---with--underscore");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* 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.
|
||||
@@ -34,14 +34,12 @@ public class ItemMetadataTests {
|
||||
|
||||
@Test
|
||||
public void newItemMetadataPrefixWithCamelCaseSuffix() {
|
||||
assertThat(newItemMetadataPrefix("prefix.", "myValue"))
|
||||
.isEqualTo("prefix.my-value");
|
||||
assertThat(newItemMetadataPrefix("prefix.", "myValue")).isEqualTo("prefix.my-value");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void newItemMetadataPrefixWithUpperCamelCaseSuffix() {
|
||||
assertThat(newItemMetadataPrefix("prefix.", "MyValue"))
|
||||
.isEqualTo("prefix.my-value");
|
||||
assertThat(newItemMetadataPrefix("prefix.", "MyValue")).isEqualTo("prefix.my-value");
|
||||
}
|
||||
|
||||
private String newItemMetadataPrefix(String prefix, String suffix) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -38,49 +38,34 @@ public class JsonMarshallerTests {
|
||||
@Test
|
||||
public void marshallAndUnmarshal() throws Exception {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemMetadata.newProperty("a", "b", StringBuffer.class.getName(),
|
||||
InputStream.class.getName(), "sourceMethod", "desc", "x",
|
||||
new ItemDeprecation("Deprecation comment", "b.c.d")));
|
||||
metadata.add(ItemMetadata.newProperty("b.c.d", null, null, null, null, null, null,
|
||||
null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("c", null, null, null, null, null, 123, null));
|
||||
metadata.add(
|
||||
ItemMetadata.newProperty("d", null, null, null, null, null, true, null));
|
||||
metadata.add(ItemMetadata.newProperty("e", null, null, null, null, null,
|
||||
new String[] { "y", "n" }, null));
|
||||
metadata.add(ItemMetadata.newProperty("f", null, null, null, null, null,
|
||||
new Boolean[] { true, false }, null));
|
||||
metadata.add(ItemMetadata.newProperty("a", "b", StringBuffer.class.getName(), InputStream.class.getName(),
|
||||
"sourceMethod", "desc", "x", new ItemDeprecation("Deprecation comment", "b.c.d")));
|
||||
metadata.add(ItemMetadata.newProperty("b.c.d", null, null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("c", null, null, null, null, null, 123, null));
|
||||
metadata.add(ItemMetadata.newProperty("d", null, null, null, null, null, true, null));
|
||||
metadata.add(ItemMetadata.newProperty("e", null, null, null, null, null, new String[] { "y", "n" }, null));
|
||||
metadata.add(ItemMetadata.newProperty("f", null, null, null, null, null, new Boolean[] { true, false }, null));
|
||||
metadata.add(ItemMetadata.newGroup("d", null, null, null));
|
||||
metadata.add(ItemHint.newHint("a.b"));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"),
|
||||
new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(ItemHint.newHint("c", new ItemHint.ValueHint(123, "hey"), new ItemHint.ValueHint(456, null)));
|
||||
metadata.add(new ItemHint("d", null,
|
||||
Arrays.asList(
|
||||
new ItemHint.ValueProvider("first",
|
||||
Collections.singletonMap("target", "foo")),
|
||||
Arrays.asList(new ItemHint.ValueProvider("first", Collections.singletonMap("target", "foo")),
|
||||
new ItemHint.ValueProvider("second", null))));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
ConfigurationMetadata read = marshaller
|
||||
.read(new ByteArrayInputStream(outputStream.toByteArray()));
|
||||
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class)
|
||||
.fromSource(InputStream.class).withDescription("desc")
|
||||
.withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
|
||||
ConfigurationMetadata read = marshaller.read(new ByteArrayInputStream(outputStream.toByteArray()));
|
||||
assertThat(read).has(Metadata.withProperty("a.b", StringBuffer.class).fromSource(InputStream.class)
|
||||
.withDescription("desc").withDefaultValue("x").withDeprecation("Deprecation comment", "b.c.d"));
|
||||
assertThat(read).has(Metadata.withProperty("b.c.d"));
|
||||
assertThat(read).has(Metadata.withProperty("c").withDefaultValue(123));
|
||||
assertThat(read).has(Metadata.withProperty("d").withDefaultValue(true));
|
||||
assertThat(read).has(
|
||||
Metadata.withProperty("e").withDefaultValue(new String[] { "y", "n" }));
|
||||
assertThat(read).has(Metadata.withProperty("f")
|
||||
.withDefaultValue(new Object[] { true, false }));
|
||||
assertThat(read).has(Metadata.withProperty("e").withDefaultValue(new String[] { "y", "n" }));
|
||||
assertThat(read).has(Metadata.withProperty("f").withDefaultValue(new Object[] { true, false }));
|
||||
assertThat(read).has(Metadata.withGroup("d"));
|
||||
assertThat(read).has(Metadata.withHint("a.b"));
|
||||
assertThat(read).has(
|
||||
Metadata.withHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
|
||||
assertThat(read).has(Metadata.withHint("d").withProvider("first", "target", "foo")
|
||||
.withProvider("second"));
|
||||
assertThat(read).has(Metadata.withHint("c").withValue(0, 123, "hey").withValue(1, 456, null));
|
||||
assertThat(read).has(Metadata.withHint("d").withProvider("first", "target", "foo").withProvider("second"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,45 +73,35 @@ public class JsonMarshallerTests {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemHint.newHint("fff"));
|
||||
metadata.add(ItemHint.newHint("eee"));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.bravo",
|
||||
"com.example.AnotherTestProperties", null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.alpha", "com.example.TestProperties",
|
||||
null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.bravo", "com.example.AnotherTestProperties", null, null));
|
||||
metadata.add(ItemMetadata.newGroup("com.acme.alpha", "com.example.TestProperties", null, null));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
String json = new String(outputStream.toByteArray());
|
||||
assertThat(json).containsSubsequence("\"groups\"", "\"com.acme.alpha\"",
|
||||
"\"com.acme.bravo\"", "\"properties\"", "\"com.example.alpha.ccc\"",
|
||||
"\"com.example.alpha.ddd\"", "\"com.example.bravo.aaa\"",
|
||||
assertThat(json).containsSubsequence("\"groups\"", "\"com.acme.alpha\"", "\"com.acme.bravo\"", "\"properties\"",
|
||||
"\"com.example.alpha.ccc\"", "\"com.example.alpha.ddd\"", "\"com.example.bravo.aaa\"",
|
||||
"\"com.example.bravo.bbb\"", "\"hints\"", "\"eee\"", "\"fff\"");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void marshallPutDeprecatedItemsAtTheEnd() throws IOException {
|
||||
ConfigurationMetadata metadata = new ConfigurationMetadata();
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null,
|
||||
null, null, null, new ItemDeprecation(null, null, "warning")));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null,
|
||||
null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null,
|
||||
null, null, null, new ItemDeprecation(null, null, "warning")));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "bbb", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.bravo", "aaa", null, null, null, null, null,
|
||||
new ItemDeprecation(null, null, "warning")));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ddd", null, null, null, null, null, null));
|
||||
metadata.add(ItemMetadata.newProperty("com.example.alpha", "ccc", null, null, null, null, null,
|
||||
new ItemDeprecation(null, null, "warning")));
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
JsonMarshaller marshaller = new JsonMarshaller();
|
||||
marshaller.write(metadata, outputStream);
|
||||
String json = new String(outputStream.toByteArray());
|
||||
assertThat(json).containsSubsequence("\"properties\"",
|
||||
"\"com.example.alpha.ddd\"", "\"com.example.bravo.bbb\"",
|
||||
assertThat(json).containsSubsequence("\"properties\"", "\"com.example.alpha.ddd\"", "\"com.example.bravo.bbb\"",
|
||||
"\"com.example.alpha.ccc\"", "\"com.example.bravo.aaa\"");
|
||||
}
|
||||
|
||||
|
||||
@@ -92,9 +92,8 @@ public final class Metadata {
|
||||
this(itemType, name, null, null, null, null, null, null);
|
||||
}
|
||||
|
||||
public MetadataItemCondition(ItemType itemType, String name, String type,
|
||||
Class<?> sourceType, String sourceMethod, String description,
|
||||
Object defaultValue, ItemDeprecation deprecation) {
|
||||
public MetadataItemCondition(ItemType itemType, String name, String type, Class<?> sourceType,
|
||||
String sourceMethod, String description, Object defaultValue, ItemDeprecation deprecation) {
|
||||
this.itemType = itemType;
|
||||
this.name = name;
|
||||
this.type = type;
|
||||
@@ -139,90 +138,76 @@ public final class Metadata {
|
||||
if (this.type != null && !this.type.equals(itemMetadata.getType())) {
|
||||
return false;
|
||||
}
|
||||
if (this.sourceType != null
|
||||
&& !this.sourceType.getName().equals(itemMetadata.getSourceType())) {
|
||||
if (this.sourceType != null && !this.sourceType.getName().equals(itemMetadata.getSourceType())) {
|
||||
return false;
|
||||
}
|
||||
if (this.sourceMethod != null
|
||||
&& !this.sourceMethod.equals(itemMetadata.getSourceMethod())) {
|
||||
if (this.sourceMethod != null && !this.sourceMethod.equals(itemMetadata.getSourceMethod())) {
|
||||
return false;
|
||||
}
|
||||
if (this.defaultValue != null && !ObjectUtils
|
||||
.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
|
||||
if (this.defaultValue != null
|
||||
&& !ObjectUtils.nullSafeEquals(this.defaultValue, itemMetadata.getDefaultValue())) {
|
||||
return false;
|
||||
}
|
||||
if (this.defaultValue == null && itemMetadata.getDefaultValue() != null) {
|
||||
return false;
|
||||
}
|
||||
if (this.description != null
|
||||
&& !this.description.equals(itemMetadata.getDescription())) {
|
||||
if (this.description != null && !this.description.equals(itemMetadata.getDescription())) {
|
||||
return false;
|
||||
}
|
||||
if (this.deprecation == null && itemMetadata.getDeprecation() != null) {
|
||||
return false;
|
||||
}
|
||||
if (this.deprecation != null
|
||||
&& !this.deprecation.equals(itemMetadata.getDeprecation())) {
|
||||
if (this.deprecation != null && !this.deprecation.equals(itemMetadata.getDeprecation())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public MetadataItemCondition ofType(Class<?> dataType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType.getName(),
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType.getName(), this.sourceType,
|
||||
this.sourceMethod, this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition ofType(String dataType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, dataType, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition fromSource(Class<?> sourceType) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
sourceType, this.sourceMethod, this.description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition fromSourceMethod(String sourceMethod) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, sourceMethod, this.description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, sourceMethod,
|
||||
this.description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDescription(String description) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, description, this.defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
description, this.defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDefaultValue(Object defaultValue) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description, defaultValue,
|
||||
this.deprecation);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, defaultValue, this.deprecation);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement) {
|
||||
return withDeprecation(reason, replacement, null);
|
||||
}
|
||||
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement,
|
||||
String level) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, new ItemDeprecation(reason, replacement, level));
|
||||
public MetadataItemCondition withDeprecation(String reason, String replacement, String level) {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, new ItemDeprecation(reason, replacement, level));
|
||||
}
|
||||
|
||||
public MetadataItemCondition withNoDeprecation() {
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type,
|
||||
this.sourceType, this.sourceMethod, this.description,
|
||||
this.defaultValue, null);
|
||||
return new MetadataItemCondition(this.itemType, this.name, this.type, this.sourceType, this.sourceMethod,
|
||||
this.description, this.defaultValue, null);
|
||||
}
|
||||
|
||||
private ItemMetadata getFirstItemWithName(ConfigurationMetadata metadata,
|
||||
String name) {
|
||||
private ItemMetadata getFirstItemWithName(ConfigurationMetadata metadata, String name) {
|
||||
for (ItemMetadata item : metadata.getItems()) {
|
||||
if (item.isOfItemType(this.itemType) && name.equals(item.getName())) {
|
||||
return item;
|
||||
@@ -247,8 +232,7 @@ public final class Metadata {
|
||||
this.providerConditions = Collections.emptyList();
|
||||
}
|
||||
|
||||
public MetadataHintCondition(String name,
|
||||
List<ItemHintValueCondition> valueConditions,
|
||||
public MetadataHintCondition(String name, List<ItemHintValueCondition> valueConditions,
|
||||
List<ItemHintProviderCondition> providerConditions) {
|
||||
this.name = name;
|
||||
this.valueConditions = valueConditions;
|
||||
@@ -274,12 +258,10 @@ public final class Metadata {
|
||||
if (itemHint == null) {
|
||||
return false;
|
||||
}
|
||||
return matches(itemHint, this.valueConditions)
|
||||
&& matches(itemHint, this.providerConditions);
|
||||
return matches(itemHint, this.valueConditions) && matches(itemHint, this.providerConditions);
|
||||
}
|
||||
|
||||
private boolean matches(ItemHint itemHint,
|
||||
List<? extends Condition<ItemHint>> conditions) {
|
||||
private boolean matches(ItemHint itemHint, List<? extends Condition<ItemHint>> conditions) {
|
||||
for (Condition<ItemHint> condition : conditions) {
|
||||
if (!condition.matches(itemHint)) {
|
||||
return false;
|
||||
@@ -288,8 +270,7 @@ public final class Metadata {
|
||||
return true;
|
||||
}
|
||||
|
||||
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata,
|
||||
String name) {
|
||||
private ItemHint getFirstHintWithName(ConfigurationMetadata metadata, String name) {
|
||||
for (ItemHint hint : metadata.getHints()) {
|
||||
if (name.equals(hint.getName())) {
|
||||
return hint;
|
||||
@@ -298,11 +279,9 @@ public final class Metadata {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MetadataHintCondition withValue(int index, Object value,
|
||||
String description) {
|
||||
public MetadataHintCondition withValue(int index, Object value, String description) {
|
||||
return new MetadataHintCondition(this.name,
|
||||
add(this.valueConditions,
|
||||
new ItemHintValueCondition(index, value, description)),
|
||||
add(this.valueConditions, new ItemHintValueCondition(index, value, description)),
|
||||
this.providerConditions);
|
||||
}
|
||||
|
||||
@@ -310,17 +289,13 @@ public final class Metadata {
|
||||
return withProvider(this.providerConditions.size(), provider, null);
|
||||
}
|
||||
|
||||
public MetadataHintCondition withProvider(String provider, String key,
|
||||
Object value) {
|
||||
return withProvider(this.providerConditions.size(), provider,
|
||||
Collections.singletonMap(key, value));
|
||||
public MetadataHintCondition withProvider(String provider, String key, Object value) {
|
||||
return withProvider(this.providerConditions.size(), provider, Collections.singletonMap(key, value));
|
||||
}
|
||||
|
||||
public MetadataHintCondition withProvider(int index, String provider,
|
||||
Map<String, Object> parameters) {
|
||||
public MetadataHintCondition withProvider(int index, String provider, Map<String, Object> parameters) {
|
||||
return new MetadataHintCondition(this.name, this.valueConditions,
|
||||
add(this.providerConditions,
|
||||
new ItemHintProviderCondition(index, provider, parameters)));
|
||||
add(this.providerConditions, new ItemHintProviderCondition(index, provider, parameters)));
|
||||
}
|
||||
|
||||
private <T> List<T> add(List<T> items, T item) {
|
||||
@@ -367,8 +342,7 @@ public final class Metadata {
|
||||
if (this.value != null && !this.value.equals(valueHint.getValue())) {
|
||||
return false;
|
||||
}
|
||||
if (this.description != null
|
||||
&& !this.description.equals(valueHint.getDescription())) {
|
||||
if (this.description != null && !this.description.equals(valueHint.getDescription())) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -384,8 +358,7 @@ public final class Metadata {
|
||||
|
||||
private final Map<String, Object> parameters;
|
||||
|
||||
ItemHintProviderCondition(int index, String name,
|
||||
Map<String, Object> parameters) {
|
||||
ItemHintProviderCondition(int index, String name, Map<String, Object> parameters) {
|
||||
this.index = index;
|
||||
this.name = name;
|
||||
this.parameters = parameters;
|
||||
|
||||
@@ -39,10 +39,8 @@ public class RoundEnvironmentTester {
|
||||
*/
|
||||
public TypeElement getRootElement(Class<?> type) {
|
||||
return (TypeElement) this.roundEnvironment.getRootElements().stream()
|
||||
.filter((element) -> element.toString().equals(type.getName()))
|
||||
.findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("No element found for "
|
||||
+ type
|
||||
.filter((element) -> element.toString().equals(type.getName())).findFirst()
|
||||
.orElseThrow(() -> new IllegalStateException("No element found for " + type
|
||||
+ " make sure it is included in the list of classes to compile"));
|
||||
}
|
||||
|
||||
|
||||
@@ -38,8 +38,7 @@ import org.springframework.boot.configurationprocessor.metadata.JsonMarshaller;
|
||||
*/
|
||||
@SupportedAnnotationTypes({ "*" })
|
||||
@SupportedSourceVersion(SourceVersion.RELEASE_6)
|
||||
public class TestConfigurationMetadataAnnotationProcessor
|
||||
extends ConfigurationMetadataAnnotationProcessor {
|
||||
public class TestConfigurationMetadataAnnotationProcessor extends ConfigurationMetadataAnnotationProcessor {
|
||||
|
||||
public static final String CONFIGURATION_PROPERTIES_ANNOTATION = "org.springframework.boot.configurationsample.ConfigurationProperties";
|
||||
|
||||
@@ -95,11 +94,9 @@ public class TestConfigurationMetadataAnnotationProcessor
|
||||
protected ConfigurationMetadata writeMetaData() throws Exception {
|
||||
super.writeMetaData();
|
||||
try {
|
||||
File metadataFile = new File(this.outputLocation,
|
||||
"META-INF/spring-configuration-metadata.json");
|
||||
File metadataFile = new File(this.outputLocation, "META-INF/spring-configuration-metadata.json");
|
||||
if (metadataFile.isFile()) {
|
||||
this.metadata = new JsonMarshaller()
|
||||
.read(new FileInputStream(metadataFile));
|
||||
this.metadata = new JsonMarshaller().read(new FileInputStream(metadataFile));
|
||||
}
|
||||
else {
|
||||
this.metadata = new ConfigurationMetadata();
|
||||
|
||||
@@ -57,8 +57,7 @@ public class TestableAnnotationProcessor<T> extends AbstractProcessor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(Set<? extends TypeElement> annotations,
|
||||
RoundEnvironment roundEnv) {
|
||||
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
|
||||
RoundEnvironmentTester tester = new RoundEnvironmentTester(roundEnv);
|
||||
if (!roundEnv.getRootElements().isEmpty()) {
|
||||
this.consumer.accept(tester, this.target);
|
||||
|
||||
@@ -22,7 +22,6 @@ package org.springframework.boot.configurationsample.generic;
|
||||
* @param <C> mapping value type
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class AbstractIntermediateGenericProperties<C>
|
||||
extends AbstractGenericProperties<String, Integer, C> {
|
||||
public abstract class AbstractIntermediateGenericProperties<C> extends AbstractGenericProperties<String, Integer, C> {
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ConfigurationProperties("generic")
|
||||
public class SimpleGenericProperties
|
||||
extends AbstractIntermediateGenericProperties<Duration> {
|
||||
public class SimpleGenericProperties extends AbstractIntermediateGenericProperties<Duration> {
|
||||
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.springframework.boot.configurationsample.ConfigurationProperties;
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
@ConfigurationProperties("generic")
|
||||
public class UnresolvedGenericProperties<B extends Number, C>
|
||||
extends AbstractGenericProperties<String, B, C> {
|
||||
public class UnresolvedGenericProperties<B extends Number, C> extends AbstractGenericProperties<String, B, C> {
|
||||
|
||||
}
|
||||
|
||||
@@ -35,8 +35,7 @@ public class ImmutableCollectionProperties {
|
||||
|
||||
private final List<Duration> durations;
|
||||
|
||||
public ImmutableCollectionProperties(List<String> names,
|
||||
@DefaultValue({ "true", "false" }) List<Boolean> flags,
|
||||
public ImmutableCollectionProperties(List<String> names, @DefaultValue({ "true", "false" }) List<Boolean> flags,
|
||||
@DefaultValue({ "10s", "1m", "1h" }) List<Duration> durations) {
|
||||
this.names = names;
|
||||
this.flags = flags;
|
||||
|
||||
@@ -35,8 +35,7 @@ public class ImmutableInnerClassProperties {
|
||||
|
||||
private final Fourth fourth;
|
||||
|
||||
public ImmutableInnerClassProperties(Foo first, Foo second, SimplePojo third,
|
||||
Fourth fourth) {
|
||||
public ImmutableInnerClassProperties(Foo first, Foo second, SimplePojo third, Fourth fourth) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
|
||||
@@ -40,8 +40,8 @@ public class ImmutablePrimitiveProperties {
|
||||
|
||||
private final double ratio;
|
||||
|
||||
public ImmutablePrimitiveProperties(boolean flag, byte octet, char letter,
|
||||
short number, int counter, long value, float percentage, double ratio) {
|
||||
public ImmutablePrimitiveProperties(boolean flag, byte octet, char letter, short number, int counter, long value,
|
||||
float percentage, double ratio) {
|
||||
this.flag = flag;
|
||||
this.octet = octet;
|
||||
this.letter = letter;
|
||||
|
||||
@@ -42,9 +42,8 @@ public class ImmutablePrimitiveWithDefaultsProperties {
|
||||
|
||||
private final double ratio;
|
||||
|
||||
public ImmutablePrimitiveWithDefaultsProperties(@DefaultValue("true") boolean flag,
|
||||
@DefaultValue("120") byte octet, @DefaultValue("a") char letter,
|
||||
@DefaultValue("1000") short number, @DefaultValue("42") int counter,
|
||||
public ImmutablePrimitiveWithDefaultsProperties(@DefaultValue("true") boolean flag, @DefaultValue("120") byte octet,
|
||||
@DefaultValue("a") char letter, @DefaultValue("1000") short number, @DefaultValue("42") int counter,
|
||||
@DefaultValue("2000") long value, @DefaultValue("0.5") float percentage,
|
||||
@DefaultValue("42.42") double ratio) {
|
||||
this.flag = flag;
|
||||
|
||||
@@ -42,9 +42,8 @@ public class ImmutablePrimitiveWrapperWithDefaultsProperties {
|
||||
|
||||
private final Double ratio;
|
||||
|
||||
public ImmutablePrimitiveWrapperWithDefaultsProperties(
|
||||
@DefaultValue("true") Boolean flag, @DefaultValue("120") Byte octet,
|
||||
@DefaultValue("a") Character letter, @DefaultValue("1000") Short number,
|
||||
public ImmutablePrimitiveWrapperWithDefaultsProperties(@DefaultValue("true") Boolean flag,
|
||||
@DefaultValue("120") Byte octet, @DefaultValue("a") Character letter, @DefaultValue("1000") Short number,
|
||||
@DefaultValue("42") Integer counter, @DefaultValue("2000") Long value,
|
||||
@DefaultValue("0.5") Float percentage, @DefaultValue("42.42") Double ratio) {
|
||||
this.flag = flag;
|
||||
|
||||
@@ -47,8 +47,8 @@ public class ImmutableSimpleProperties {
|
||||
@SuppressWarnings("unused")
|
||||
private final Long counter;
|
||||
|
||||
public ImmutableSimpleProperties(@DefaultValue("boot") String theName, boolean flag,
|
||||
Comparator<?> comparator, Long counter) {
|
||||
public ImmutableSimpleProperties(@DefaultValue("boot") String theName, boolean flag, Comparator<?> comparator,
|
||||
Long counter) {
|
||||
this.theName = theName;
|
||||
this.flag = flag;
|
||||
this.comparator = comparator;
|
||||
|
||||
@@ -30,8 +30,7 @@ public class DeprecatedSingleProperty {
|
||||
private String newName;
|
||||
|
||||
@Deprecated
|
||||
@DeprecatedConfigurationProperty(reason = "renamed",
|
||||
replacement = "singledeprecated.new-name")
|
||||
@DeprecatedConfigurationProperty(reason = "renamed", replacement = "singledeprecated.new-name")
|
||||
public String getName() {
|
||||
return getNewName();
|
||||
}
|
||||
|
||||
@@ -21,8 +21,7 @@ package org.springframework.boot.configurationsample.simple;
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
public abstract class HierarchicalPropertiesParent
|
||||
extends HierarchicalPropertiesGrandparent {
|
||||
public abstract class HierarchicalPropertiesParent extends HierarchicalPropertiesGrandparent {
|
||||
|
||||
private String second = "two";
|
||||
|
||||
|
||||
@@ -30,8 +30,7 @@ public class InvalidDefaultValueFloatingPointProperties {
|
||||
|
||||
private final Double ratio;
|
||||
|
||||
public InvalidDefaultValueFloatingPointProperties(
|
||||
@DefaultValue("55.55.33") Double ratio) {
|
||||
public InvalidDefaultValueFloatingPointProperties(@DefaultValue("55.55.33") Double ratio) {
|
||||
this.ratio = ratio;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user