|
|
@ -1,5 +1,5 @@
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
* Copyright 2012-2019 the original author or authors.
|
|
|
|
* Copyright 2012-2020 the original author or authors.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@ -16,14 +16,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.diagnostics.analyzer;
|
|
|
|
package org.springframework.boot.diagnostics.analyzer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
import javax.servlet.http.HttpServlet;
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.diagnostics.FailureAnalysis;
|
|
|
|
import org.springframework.boot.diagnostics.FailureAnalysis;
|
|
|
|
|
|
|
|
import org.springframework.boot.diagnostics.analyzer.NoSuchMethodFailureAnalyzer.ClassDescriptor;
|
|
|
|
import org.springframework.boot.diagnostics.analyzer.NoSuchMethodFailureAnalyzer.NoSuchMethodDescriptor;
|
|
|
|
import org.springframework.boot.diagnostics.analyzer.NoSuchMethodFailureAnalyzer.NoSuchMethodDescriptor;
|
|
|
|
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
|
|
|
|
import org.springframework.boot.testsupport.classpath.ClassPathOverrides;
|
|
|
|
|
|
|
|
import org.springframework.data.r2dbc.mapping.R2dbcMappingContext;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
@ -34,7 +38,8 @@ import static org.mockito.Mockito.mock;
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Andy Wilkinson
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
* @author Stephane Nicoll
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@ClassPathOverrides("javax.servlet:servlet-api:2.5")
|
|
|
|
@ClassPathOverrides({ "javax.servlet:servlet-api:2.5",
|
|
|
|
|
|
|
|
"org.springframework.data:spring-data-relational:1.1.7.RELEASE" })
|
|
|
|
class NoSuchMethodFailureAnalyzerTests {
|
|
|
|
class NoSuchMethodFailureAnalyzerTests {
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -48,7 +53,9 @@ class NoSuchMethodFailureAnalyzerTests {
|
|
|
|
+ "Ljavax/servlet/ServletRegistration$Dynamic;");
|
|
|
|
+ "Ljavax/servlet/ServletRegistration$Dynamic;");
|
|
|
|
assertThat(descriptor.getClassName()).isEqualTo("javax.servlet.ServletContext");
|
|
|
|
assertThat(descriptor.getClassName()).isEqualTo("javax.servlet.ServletContext");
|
|
|
|
assertThat(descriptor.getCandidateLocations().size()).isGreaterThan(1);
|
|
|
|
assertThat(descriptor.getCandidateLocations().size()).isGreaterThan(1);
|
|
|
|
assertThat(descriptor.getActualLocation()).asString().contains("servlet-api-2.5.jar");
|
|
|
|
List<ClassDescriptor> typeHierarchy = descriptor.getTypeHierarchy();
|
|
|
|
|
|
|
|
assertThat(typeHierarchy).hasSize(1);
|
|
|
|
|
|
|
|
assertThat(typeHierarchy.get(0).getLocation()).asString().contains("servlet-api-2.5.jar");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -62,7 +69,9 @@ class NoSuchMethodFailureAnalyzerTests {
|
|
|
|
+ "Ljavax/servlet/ServletRegistration$Dynamic;");
|
|
|
|
+ "Ljavax/servlet/ServletRegistration$Dynamic;");
|
|
|
|
assertThat(descriptor.getClassName()).isEqualTo("javax.servlet.ServletContext");
|
|
|
|
assertThat(descriptor.getClassName()).isEqualTo("javax.servlet.ServletContext");
|
|
|
|
assertThat(descriptor.getCandidateLocations().size()).isGreaterThan(1);
|
|
|
|
assertThat(descriptor.getCandidateLocations().size()).isGreaterThan(1);
|
|
|
|
assertThat(descriptor.getActualLocation()).asString().contains("servlet-api-2.5.jar");
|
|
|
|
List<ClassDescriptor> typeHierarchy = descriptor.getTypeHierarchy();
|
|
|
|
|
|
|
|
assertThat(typeHierarchy).hasSize(1);
|
|
|
|
|
|
|
|
assertThat(typeHierarchy.get(0).getLocation()).asString().contains("servlet-api-2.5.jar");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -76,11 +85,13 @@ class NoSuchMethodFailureAnalyzerTests {
|
|
|
|
+ "java.lang.String, javax.servlet.Servlet)'");
|
|
|
|
+ "java.lang.String, javax.servlet.Servlet)'");
|
|
|
|
assertThat(descriptor.getClassName()).isEqualTo("javax.servlet.ServletContext");
|
|
|
|
assertThat(descriptor.getClassName()).isEqualTo("javax.servlet.ServletContext");
|
|
|
|
assertThat(descriptor.getCandidateLocations().size()).isGreaterThan(1);
|
|
|
|
assertThat(descriptor.getCandidateLocations().size()).isGreaterThan(1);
|
|
|
|
assertThat(descriptor.getActualLocation()).asString().contains("servlet-api-2.5.jar");
|
|
|
|
List<ClassDescriptor> typeHierarchy = descriptor.getTypeHierarchy();
|
|
|
|
|
|
|
|
assertThat(typeHierarchy).hasSize(1);
|
|
|
|
|
|
|
|
assertThat(typeHierarchy.get(0).getLocation()).asString().contains("servlet-api-2.5.jar");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
void noSuchMethodErrorIsAnalyzed() {
|
|
|
|
void whenAMethodOnAnInterfaceIsMissingThenNoSuchMethodErrorIsAnalyzed() {
|
|
|
|
Throwable failure = createFailure();
|
|
|
|
Throwable failure = createFailure();
|
|
|
|
assertThat(failure).isNotNull();
|
|
|
|
assertThat(failure).isNotNull();
|
|
|
|
FailureAnalysis analysis = new NoSuchMethodFailureAnalyzer().analyze(failure);
|
|
|
|
FailureAnalysis analysis = new NoSuchMethodFailureAnalyzer().analyze(failure);
|
|
|
@ -90,6 +101,20 @@ class NoSuchMethodFailureAnalyzerTests {
|
|
|
|
.contains("class, javax.servlet.ServletContext,");
|
|
|
|
.contains("class, javax.servlet.ServletContext,");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
void whenAnInheritedMethodIsMissingThenNoSuchMethodErrorIsAnalyzed() {
|
|
|
|
|
|
|
|
Throwable failure = createFailureForMissingInheritedMethod();
|
|
|
|
|
|
|
|
assertThat(failure).isNotNull();
|
|
|
|
|
|
|
|
FailureAnalysis analysis = new NoSuchMethodFailureAnalyzer().analyze(failure);
|
|
|
|
|
|
|
|
assertThat(analysis).isNotNull();
|
|
|
|
|
|
|
|
assertThat(analysis.getDescription()).contains(R2dbcMappingContext.class.getName() + ".<init>(")
|
|
|
|
|
|
|
|
.contains("setForceQuote(Z)V")
|
|
|
|
|
|
|
|
.contains("class, org.springframework.data.r2dbc.mapping.R2dbcMappingContext,")
|
|
|
|
|
|
|
|
.contains(" org.springframework.data.r2dbc.mapping.R2dbcMappingContext")
|
|
|
|
|
|
|
|
.contains(" org.springframework.data.relational.core.mapping.RelationalMappingContext")
|
|
|
|
|
|
|
|
.contains(" org.springframework.data.mapping.context.AbstractMappingContext");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private Throwable createFailure() {
|
|
|
|
private Throwable createFailure() {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ServletContext servletContext = mock(ServletContext.class);
|
|
|
|
ServletContext servletContext = mock(ServletContext.class);
|
|
|
@ -102,4 +127,14 @@ class NoSuchMethodFailureAnalyzerTests {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Throwable createFailureForMissingInheritedMethod() {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
new R2dbcMappingContext();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch (Throwable ex) {
|
|
|
|
|
|
|
|
return ex;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|