use of org.revapi.AnalysisContext in project revapi by revapi.
the class SupplementaryJarsTest method testExcludedClassesDontDragUsedTypesIntoAPI.
@Test
public void testExcludedClassesDontDragUsedTypesIntoAPI() throws Exception {
List<Report> allReports;
Revapi revapi = createRevapi(CollectingReporter.class);
AnalysisContext ctx = AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).supportedBy(new ShrinkwrapArchive(supV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).supportedBy(new ShrinkwrapArchive(supV2)).build()).withConfigurationFromJSON("{\"revapi\": {\"java\": {" + "\"filter\": {\"classes\": {\"exclude\": [\"C\"]}}}}}").build();
try (AnalysisResult res = revapi.analyze(ctx)) {
allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
}
Assert.assertEquals(6, allReports.size());
Assert.assertTrue(containsDifference(allReports, null, "class B.T$1.Private", Code.CLASS_NON_PUBLIC_PART_OF_API.code()));
Assert.assertTrue(containsDifference(allReports, null, "field B.T$2.f2", Code.FIELD_ADDED.code()));
Assert.assertTrue(containsDifference(allReports, null, "field A.f3", Code.FIELD_ADDED.code()));
Assert.assertTrue(containsDifference(allReports, "class B.T$2", "class B.T$2", Code.CLASS_NOW_FINAL.code()));
Assert.assertTrue(containsDifference(allReports, null, "class B.T$3", Code.CLASS_ADDED.code()));
Assert.assertTrue(containsDifference(allReports, null, "class B.PrivateUsedClass", Code.CLASS_NON_PUBLIC_PART_OF_API.code()));
Assert.assertFalse(containsDifference(allReports, "class B.UsedByIgnoredClass", "class B.UsedByIgnoredClass", Code.CLASS_KIND_CHANGED.code()));
Assert.assertFalse(containsDifference(allReports, "method void B.UsedByIgnoredClass::<init>()", null, Code.METHOD_REMOVED.code()));
}
use of org.revapi.AnalysisContext in project revapi by revapi.
the class BuildTimeReporterTest method testJSONEscapedInIgnoreHint.
@Test
public void testJSONEscapedInIgnoreHint() {
BuildTimeReporter reporter = new BuildTimeReporter();
API oldApi = API.builder().build();
API newApi = API.builder().build();
AnalysisContext ctx = AnalysisContext.builder().withOldAPI(oldApi).withNewAPI(newApi).withData(BuildTimeReporter.BREAKING_SEVERITY_KEY, DifferenceSeverity.EQUIVALENT).build();
reporter.initialize(ctx);
Element oldEl = new SimpleElement() {
@Nonnull
@Override
public API getApi() {
return oldApi;
}
@Nullable
@Override
public Archive getArchive() {
return null;
}
@Override
public int compareTo(Element o) {
return 0;
}
@Override
public String toString() {
return "old element";
}
};
Element newEl = new SimpleElement() {
@Nonnull
@Override
public API getApi() {
return newApi;
}
@Nullable
@Override
public Archive getArchive() {
return null;
}
@Override
public int compareTo(Element o) {
return 0;
}
@Override
public String toString() {
return "new element";
}
};
Report report = Report.builder().withNew(newEl).withOld(oldEl).addProblem().withCode("diffs\\myDiff").withDescription("the problem").addClassification(CompatibilityType.BINARY, DifferenceSeverity.BREAKING).addAttachment("shouldBeEscaped", "{\"a\", \"b\"}").done().build();
reporter.report(report);
String resultMessage = reporter.getAllProblemsMessage();
Assert.assertNotNull(resultMessage);
int start = resultMessage.indexOf('{');
int end = resultMessage.lastIndexOf('}');
String json = resultMessage.substring(start, end + 1);
json = json.replace("<<<<< ADD YOUR EXPLANATION FOR THE NECESSITY OF THIS CHANGE >>>>>", "\"\"");
ModelNode parsed = ModelNode.fromJSONString(json);
Assert.assertEquals("diffs\\myDiff", parsed.get("code").asString());
Assert.assertEquals("{\"a\", \"b\"}", parsed.get("shouldBeEscaped").asString());
}
use of org.revapi.AnalysisContext in project revapi by revapi.
the class ConfigurationValidatorTest method test.
private ValidationResult test(String object, final String extensionId, final String schema) {
ConfigurationValidator validator = new ConfigurationValidator();
ModelNode fullConfig = ModelNode.fromJSONString(object);
Configurable fakeConfigurable = new Configurable() {
@Nullable
@Override
public String getExtensionId() {
return extensionId;
}
@Nullable
@Override
public Reader getJSONSchema() {
return new StringReader(schema);
}
@Override
public void initialize(@Nonnull AnalysisContext analysisContext) {
}
};
return validator.validate(fullConfig, fakeConfigurable);
}
use of org.revapi.AnalysisContext in project revapi by revapi.
the class ConfigurationValidatorTest method testRevapiValidation.
@Test
public void testRevapiValidation() throws Exception {
String config = "[" + "{\"extension\": \"my-config\", \"configuration\": {\"id\": 3, \"kachna\": \"duck\"}}," + "{\"extension\": \"my-config\", \"configuration\": {\"id\": 4, \"kachna\": \"no duck\"}}," + "{\"extension\": \"other-config\", \"configuration\": 1}" + "]";
Revapi revapi = Revapi.builder().withFilters(TestFilter.class).withReporters(TestReporter.class).withAnalyzers(DummyApiAnalyzer.class).build();
AnalysisContext ctx = AnalysisContext.builder(revapi).withConfigurationFromJSON(config).build();
ValidationResult res = revapi.validateConfiguration(ctx);
Assert.assertFalse(res.isSuccessful());
Assert.assertNotNull(res.getErrors());
Assert.assertEquals(1, res.getErrors().length);
Assert.assertEquals("/[2]/configuration", res.getErrors()[0].dataPath);
}
use of org.revapi.AnalysisContext in project revapi by revapi.
the class ConfigurationValidatorTest method testRevapiValidation_mergeWithoutIds.
@Test
public void testRevapiValidation_mergeWithoutIds() throws Exception {
// partial config of the extension
String config1 = "[" + "{\"extension\": \"my-config\", \"configuration\": {\"id\": 3,}}" + "]";
// complete the config of the extension and add another config for another extension
String config2 = "[" + "{\"extension\": \"my-config\", \"configuration\": {\"kachna\": \"no duck\"}}," + "{\"extension\": \"other-config\", \"configuration\": 1}" + "]";
Revapi revapi = Revapi.builder().withFilters(TestFilter.class).withReporters(TestReporter.class).withAnalyzers(DummyApiAnalyzer.class).build();
AnalysisContext ctx = AnalysisContext.builder(revapi).withConfigurationFromJSON(config1).mergeConfigurationFromJSON(config2).build();
ValidationResult res = revapi.validateConfiguration(ctx);
Assert.assertFalse(res.isSuccessful());
Assert.assertNotNull(res.getErrors());
// we merged "my-config" from the second config into the first, so that should be ok. Only other-config should error out.
Assert.assertEquals(1, res.getErrors().length);
Assert.assertEquals("/[1]/configuration", res.getErrors()[0].dataPath);
}
Aggregations