use of org.revapi.Report 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_CRITICALITY_KEY, Criticality.ALLOWED).withData(BuildTimeReporter.SUGGESTIONS_BUILDER_KEY, new JsonSuggestionsBuilder()).build();
reporter.initialize(ctx);
DummyElement oldEl = new DummyElement(oldApi);
DummyElement newEl = new DummyElement(newApi);
Report report = Report.builder().withNew(newEl).withOld(oldEl).addDifference().withCode("diffs\\myDiff").withDescription("the problem").addClassification(CompatibilityType.BINARY, DifferenceSeverity.BREAKING).addAttachment("shouldBeEscaped", "{\"a\", \"b\"}").withCriticality(Criticality.ERROR).withIdentifyingAttachments(Collections.singletonList("shouldBeEscaped")).done().build();
reporter.report(report);
String resultMessage = reporter.getIgnoreSuggestion();
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.Report in project revapi by revapi.
the class MissingClassReportingTest method testMissingClassFiltering.
@Test
public void testMissingClassFiltering() throws Exception {
AnalysisContext ctx = AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).build()).withConfigurationFromJSON("[{\"extension\": \"revapi.java\", \"configuration\": {\"missing-classes\": {\"behavior\": \"report\"}}}," + "{\"extension\": \"revapi.filter\", \"configuration\": {\"archives\": {\"include\": [\"apiV..jar\"]}}}]").build();
revapi.validateConfiguration(ctx);
List<Report> allReports = revapi.analyze(ctx).getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
Assert.assertEquals(1, allReports.size());
Assert.assertTrue(containsDifference(allReports, null, "field A.f3", Code.FIELD_ADDED.code()));
}
use of org.revapi.Report in project revapi by revapi.
the class MissingClassReportingTest method testReportsMissingClasses.
@Test
public void testReportsMissingClasses() throws Exception {
AnalysisContext ctx = AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).build()).withConfigurationFromJSON("{\"revapi\" : { \"java\" : { \"missing-classes\" : {\"behavior\" : \"report\" }}}}").build();
revapi.validateConfiguration(ctx);
List<Report> allReports = revapi.analyze(ctx).getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
Assert.assertEquals(3, allReports.size());
Assert.assertTrue(containsDifference(allReports, "missing-class B.T$2", "missing-class B.T$2", Code.MISSING_IN_NEW_API.code()));
Assert.assertTrue(containsDifference(allReports, "missing-class B.T$2", "missing-class B.T$2", Code.MISSING_IN_OLD_API.code()));
Assert.assertTrue(containsDifference(allReports, null, "missing-class B.T$3", Code.MISSING_IN_NEW_API.code()));
Assert.assertTrue(containsDifference(allReports, null, "field A.f3", Code.FIELD_ADDED.code()));
boolean containsMissingOld = false;
boolean containsMissingNew = false;
for (Difference d : allReports.get(0).getDifferences()) {
if (d.code.equals(Code.MISSING_IN_NEW_API.code())) {
containsMissingNew = true;
}
if (d.code.equals(Code.MISSING_IN_OLD_API.code())) {
containsMissingOld = true;
}
}
Assert.assertTrue(containsMissingOld);
Assert.assertTrue(containsMissingNew);
}
use of org.revapi.Report in project revapi by revapi.
the class MissingClassReportingTest method testMissingClassHasValidPackage.
@Test
public void testMissingClassHasValidPackage() throws Exception {
AnalysisContext ctx = AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).build()).withConfigurationFromJSON("{\"revapi\" : { \"java\" : { \"missing-classes\" : {\"behavior\" : \"report\" }}}}").build();
revapi.validateConfiguration(ctx);
List<Report> allReports = revapi.analyze(ctx).getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
for (Report r : allReports) {
if (r.getNewElement() != null && r.getNewElement() instanceof TypeElement) {
Assert.assertNotNull(((JavaModelElement) r.getNewElement()).getDeclaringElement().getEnclosingElement());
}
if (r.getOldElement() != null && r.getNewElement() instanceof TypeElement) {
Assert.assertNotNull(((JavaModelElement) r.getOldElement()).getDeclaringElement().getEnclosingElement());
}
}
}
use of org.revapi.Report in project revapi by revapi.
the class MissingClassReportingTest method testIgnoresMissingClasses.
@Test
public void testIgnoresMissingClasses() throws Exception {
AnalysisResult res = revapi.analyze(AnalysisContext.builder(revapi).withOldAPI(API.of(new ShrinkwrapArchive(apiV1)).build()).withNewAPI(API.of(new ShrinkwrapArchive(apiV2)).build()).withConfigurationFromJSON("{\"revapi\" : { \"java\" : { \"missing-classes\" : {\"behavior\" : \"ignore\" }}}}").build());
res.throwIfFailed();
List<Report> allReports = res.getExtensions().getFirstExtension(CollectingReporter.class, null).getReports();
Assert.assertEquals(1, allReports.size());
Assert.assertTrue(containsDifference(allReports, null, "field A.f3", Code.FIELD_ADDED.code()));
}
Aggregations