Search in sources :

Example 16 with ConfigurationMetadata

use of org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergingOfAdditionalMetadata.

@Test
public void mergingOfAdditionalMetadata() throws Exception {
    File metaInfFolder = new File(this.compiler.getOutputLocation(), "META-INF");
    metaInfFolder.mkdirs();
    File additionalMetadataFile = new File(metaInfFolder, "additional-spring-configuration-metadata.json");
    additionalMetadataFile.createNewFile();
    JSONObject property = new JSONObject();
    property.put("name", "foo");
    property.put("type", "java.lang.String");
    property.put("sourceType", AdditionalMetadata.class.getName());
    JSONArray properties = new JSONArray();
    properties.put(property);
    JSONObject additionalMetadata = new JSONObject();
    additionalMetadata.put("properties", properties);
    FileWriter writer = new FileWriter(additionalMetadataFile);
    writer.append(additionalMetadata.toString(2));
    writer.flush();
    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));
}
Also used : JSONObject(org.json.JSONObject) FileWriter(java.io.FileWriter) JSONArray(org.json.JSONArray) File(java.io.File) ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 17 with ConfigurationMetadata

use of org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method notAnnotated.

@Test
public void notAnnotated() throws Exception {
    ConfigurationMetadata metadata = compile(NotAnnotated.class);
    assertThat(metadata.getItems()).isEmpty();
}
Also used : ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 18 with ConfigurationMetadata

use of org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDeprecation.

@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"));
    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"));
    assertThat(metadata.getItems()).hasSize(4);
}
Also used : ItemDeprecation(org.springframework.boot.configurationprocessor.metadata.ItemDeprecation) ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata) Test(org.junit.Test)

Example 19 with ConfigurationMetadata

use of org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method simpleMethodConfig.

@Test
public void simpleMethodConfig() throws Exception {
    ConfigurationMetadata metadata = compile(SimpleMethodConfig.class);
    assertThat(metadata).has(Metadata.withGroup("foo").fromSource(SimpleMethodConfig.class));
    assertThat(metadata).has(Metadata.withProperty("foo.name", String.class).fromSource(SimpleMethodConfig.Foo.class));
    assertThat(metadata).has(Metadata.withProperty("foo.flag", Boolean.class).fromSource(SimpleMethodConfig.Foo.class));
}
Also used : SimpleMethodConfig(org.springframework.boot.configurationsample.method.SimpleMethodConfig) ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) Test(org.junit.Test)

Example 20 with ConfigurationMetadata

use of org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata in project spring-boot by spring-projects.

the class ConfigurationMetadataAnnotationProcessorTests method mergeExistingPropertyDefaultValue.

@Test
public void mergeExistingPropertyDefaultValue() throws Exception {
    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.getItems()).hasSize(4);
}
Also used : ConfigurationMetadata(org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata) ItemMetadata(org.springframework.boot.configurationprocessor.metadata.ItemMetadata) Test(org.junit.Test)

Aggregations

ConfigurationMetadata (org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata)44 Test (org.junit.Test)42 ItemMetadata (org.springframework.boot.configurationprocessor.metadata.ItemMetadata)5 ItemDeprecation (org.springframework.boot.configurationprocessor.metadata.ItemDeprecation)3 BarProperties (org.springframework.boot.configurationsample.incremental.BarProperties)3 RenamedBarProperties (org.springframework.boot.configurationsample.incremental.RenamedBarProperties)3 JSONObject (org.json.JSONObject)2 FooProperties (org.springframework.boot.configurationsample.incremental.FooProperties)2 LombokInnerClassProperties (org.springframework.boot.configurationsample.lombok.LombokInnerClassProperties)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 JSONArray (org.json.JSONArray)1 InvalidConfigurationMetadataException (org.springframework.boot.configurationprocessor.metadata.InvalidConfigurationMetadataException)1 ItemHint (org.springframework.boot.configurationprocessor.metadata.ItemHint)1 LombokSimpleProperties (org.springframework.boot.configurationsample.lombok.LombokSimpleProperties)1 DeprecatedMethodConfig (org.springframework.boot.configurationsample.method.DeprecatedMethodConfig)1 InvalidMethodConfig (org.springframework.boot.configurationsample.method.InvalidMethodConfig)1 MethodAndClassConfig (org.springframework.boot.configurationsample.method.MethodAndClassConfig)1 SimpleMethodConfig (org.springframework.boot.configurationsample.method.SimpleMethodConfig)1