Fail the build if the meta-data are invalid

Make sure to fail the build with a proper compilation error message if
the user-defined meta-data are invalid. For now, this takes care of the
JSON format but other checks may be added in the future.

Closes gh-3329
This commit is contained in:
Stephane Nicoll
2015-07-06 11:35:57 +02:00
parent 4ad23166ea
commit 162cbdd5cb
4 changed files with 75 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ import org.json.JSONObject;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.springframework.boot.configurationprocessor.metadata.ConfigurationMetadata;
import org.springframework.boot.configurationprocessor.metadata.ItemHint;
@@ -52,6 +53,7 @@ import org.springframework.boot.configurationsample.specific.InnerClassAnnotated
import org.springframework.boot.configurationsample.specific.InnerClassProperties;
import org.springframework.boot.configurationsample.specific.InnerClassRootConfig;
import org.springframework.boot.configurationsample.specific.SimplePojo;
import org.springframework.util.FileCopyUtils;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.empty;
@@ -78,6 +80,9 @@ public class ConfigurationMetadataAnnotationProcessorTests {
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Rule
public ExpectedException thrown = ExpectedException.none();
private TestCompiler compiler;
@Before
@@ -346,6 +351,16 @@ public class ConfigurationMetadataAnnotationProcessorTests {
.fromSource(AdditionalMetadata.class));
}
@Test
public void mergeOfInvalidAdditionalMetadata() throws IOException {
File additionalMetadataFile = createAdditionalMetadataFile();
FileCopyUtils.copy("Hello World", new FileWriter(additionalMetadataFile));
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Compilation failed");
compile(SimpleProperties.class);
}
@Test
public void mergingOfSimpleHint() throws Exception {
writeAdditionalHints(ItemHint.newHint("simple.the-name", new ItemHint.ValueHint(