Modularize spring-boot-test-autoconfigure
This commit modularizes spring-boot-test-autoconfigure. It now contains only the code that's central to test auto-configuration. Feature-specific functionality has moved out into -test modules, some existing and some newly created. For example, `@DataJpaTest` can now be found in spring-boot-data-jpa-test. Closes gh-47322
This commit is contained in:
parent
7979a51f65
commit
5348880b69
|
@ -133,10 +133,6 @@ gradlePlugin {
|
|||
id = "org.springframework.boot.integration-test"
|
||||
implementationClass = "org.springframework.boot.build.test.IntegrationTestPlugin"
|
||||
}
|
||||
systemTestPlugin {
|
||||
id = "org.springframework.boot.system-test"
|
||||
implementationClass = "org.springframework.boot.build.test.SystemTestPlugin"
|
||||
}
|
||||
mavenPluginPlugin {
|
||||
id = "org.springframework.boot.maven-plugin"
|
||||
implementationClass = "org.springframework.boot.build.mavenplugin.MavenPluginPlugin"
|
||||
|
@ -153,10 +149,22 @@ gradlePlugin {
|
|||
id = "org.springframework.boot.starter"
|
||||
implementationClass = "org.springframework.boot.build.starters.StarterPlugin"
|
||||
}
|
||||
systemTestPlugin {
|
||||
id = "org.springframework.boot.system-test"
|
||||
implementationClass = "org.springframework.boot.build.test.SystemTestPlugin"
|
||||
}
|
||||
testAutoConfigurationPlugin {
|
||||
id = "org.springframework.boot.test-auto-configuration"
|
||||
implementationClass = "org.springframework.boot.build.test.autoconfigure.TestAutoConfigurationPlugin"
|
||||
}
|
||||
testFailuresPlugin {
|
||||
id = "org.springframework.boot.test-failures"
|
||||
implementationClass = "org.springframework.boot.build.testing.TestFailuresPlugin"
|
||||
}
|
||||
testSlicePlugin {
|
||||
id = "org.springframework.boot.test-slice"
|
||||
implementationClass = "org.springframework.boot.build.test.autoconfigure.TestSlicePlugin"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ package org.springframework.boot.build.autoconfigure;
|
|||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -54,8 +55,8 @@ public record AutoConfigurationClass(String name, List<String> before, List<Stri
|
|||
attributes.getOrDefault("afterName", Collections.emptyList()));
|
||||
}
|
||||
|
||||
static AutoConfigurationClass of(File classFile) {
|
||||
try (FileInputStream input = new FileInputStream(classFile)) {
|
||||
public static AutoConfigurationClass of(InputStream input) {
|
||||
try {
|
||||
ClassReader classReader = new ClassReader(input);
|
||||
AutoConfigurationClassVisitor visitor = new AutoConfigurationClassVisitor();
|
||||
classReader.accept(visitor, ClassReader.SKIP_DEBUG | ClassReader.SKIP_CODE | ClassReader.SKIP_FRAMES);
|
||||
|
@ -66,6 +67,15 @@ public record AutoConfigurationClass(String name, List<String> before, List<Stri
|
|||
}
|
||||
}
|
||||
|
||||
static AutoConfigurationClass of(File classFile) {
|
||||
try (InputStream input = new FileInputStream(classFile)) {
|
||||
return of(input);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private static final class AutoConfigurationClassVisitor extends ClassVisitor {
|
||||
|
||||
private AutoConfigurationClass autoConfigurationClass;
|
||||
|
|
|
@ -38,7 +38,10 @@ import org.gradle.api.tasks.SkipWhenEmpty;
|
|||
*/
|
||||
public abstract class AutoConfigurationImportsTask extends DefaultTask {
|
||||
|
||||
static final String IMPORTS_FILE = "META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports";
|
||||
/**
|
||||
* The path of the {@code AutoConfiguration.imports} file.
|
||||
*/
|
||||
public static final String IMPORTS_FILE = "META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports";
|
||||
|
||||
private FileCollection sourceFiles = getProject().getObjects().fileCollection();
|
||||
|
||||
|
|
|
@ -65,7 +65,7 @@ public class ConfigurationPropertiesPlugin implements Plugin<Project> {
|
|||
public static final String CHECK_ADDITIONAL_SPRING_CONFIGURATION_METADATA_TASK_NAME = "checkAdditionalSpringConfigurationMetadata";
|
||||
|
||||
/**
|
||||
* Name of the {@link CheckAdditionalSpringConfigurationMetadata} task.
|
||||
* Name of the {@link CheckSpringConfigurationMetadata} task.
|
||||
*/
|
||||
public static final String CHECK_SPRING_CONFIGURATION_METADATA_TASK_NAME = "checkSpringConfigurationMetadata";
|
||||
|
||||
|
|
|
@ -0,0 +1,233 @@
|
|||
/*
|
||||
* Copyright 2025-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.test.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.jar.JarFile;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.file.DirectoryProperty;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.file.FileTree;
|
||||
import org.gradle.api.tasks.Classpath;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.OutputDirectory;
|
||||
import org.gradle.api.tasks.PathSensitive;
|
||||
import org.gradle.api.tasks.PathSensitivity;
|
||||
import org.gradle.api.tasks.SkipWhenEmpty;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import org.gradle.api.tasks.VerificationException;
|
||||
import org.gradle.language.base.plugins.LifecycleBasePlugin;
|
||||
|
||||
import org.springframework.boot.build.autoconfigure.AutoConfigurationClass;
|
||||
|
||||
/**
|
||||
* Task to check the contents of a project's
|
||||
* {@code META-INF/spring/*.AutoConfigure*.imports} files.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class CheckAutoConfigureImports extends DefaultTask {
|
||||
|
||||
private FileCollection sourceFiles = getProject().getObjects().fileCollection();
|
||||
|
||||
private FileCollection classpath = getProject().getObjects().fileCollection();
|
||||
|
||||
public CheckAutoConfigureImports() {
|
||||
getOutputDirectory().convention(getProject().getLayout().getBuildDirectory().dir(getName()));
|
||||
setGroup(LifecycleBasePlugin.VERIFICATION_GROUP);
|
||||
}
|
||||
|
||||
@InputFiles
|
||||
@SkipWhenEmpty
|
||||
@PathSensitive(PathSensitivity.RELATIVE)
|
||||
public FileTree getSource() {
|
||||
return this.sourceFiles.getAsFileTree()
|
||||
.matching((filter) -> filter.include("META-INF/spring/*.AutoConfigure*.imports"));
|
||||
}
|
||||
|
||||
public void setSource(Object source) {
|
||||
this.sourceFiles = getProject().getObjects().fileCollection().from(source);
|
||||
}
|
||||
|
||||
@Classpath
|
||||
public FileCollection getClasspath() {
|
||||
return this.classpath;
|
||||
}
|
||||
|
||||
public void setClasspath(Object classpath) {
|
||||
this.classpath = getProject().getObjects().fileCollection().from(classpath);
|
||||
}
|
||||
|
||||
@OutputDirectory
|
||||
public abstract DirectoryProperty getOutputDirectory();
|
||||
|
||||
@TaskAction
|
||||
void execute() {
|
||||
Map<String, List<String>> allProblems = new TreeMap<>();
|
||||
for (AutoConfigureImports autoConfigureImports : loadImports()) {
|
||||
List<String> problems = new ArrayList<>();
|
||||
if (!find(autoConfigureImports.annotationName)) {
|
||||
problems.add("Annotation '%s' was not found".formatted(autoConfigureImports.annotationName));
|
||||
}
|
||||
for (String imported : autoConfigureImports.imports) {
|
||||
String importedClassName = imported;
|
||||
if (importedClassName.startsWith("optional:")) {
|
||||
importedClassName = importedClassName.substring("optional:".length());
|
||||
}
|
||||
boolean found = find(importedClassName, (input) -> {
|
||||
if (!correctlyAnnotated(input)) {
|
||||
problems.add("Imported auto-configuration '%s' is not annotated with @AutoConfiguration"
|
||||
.formatted(imported));
|
||||
}
|
||||
});
|
||||
if (!found) {
|
||||
problems.add("Imported auto-configuration '%s' was not found".formatted(importedClassName));
|
||||
}
|
||||
|
||||
}
|
||||
List<String> sortedValues = new ArrayList<>(autoConfigureImports.imports);
|
||||
Collections.sort(sortedValues, (i1, i2) -> {
|
||||
boolean imported1 = i1.startsWith("optional:");
|
||||
boolean imported2 = i2.startsWith("optional:");
|
||||
int comparison = Boolean.compare(imported1, imported2);
|
||||
if (comparison != 0) {
|
||||
return comparison;
|
||||
}
|
||||
return i1.compareTo(i2);
|
||||
});
|
||||
if (!sortedValues.equals(autoConfigureImports.imports)) {
|
||||
File sortedOutputFile = getOutputDirectory().file("sorted-" + autoConfigureImports.fileName)
|
||||
.get()
|
||||
.getAsFile();
|
||||
writeString(sortedOutputFile, sortedValues.stream().collect(Collectors.joining(System.lineSeparator()))
|
||||
+ System.lineSeparator());
|
||||
problems.add(
|
||||
"Entries should be required then optional, each sorted alphabetically (expected content written to '%s')"
|
||||
.formatted(sortedOutputFile.getAbsolutePath()));
|
||||
}
|
||||
if (!problems.isEmpty()) {
|
||||
allProblems.computeIfAbsent(autoConfigureImports.fileName, (unused) -> new ArrayList<>())
|
||||
.addAll(problems);
|
||||
}
|
||||
}
|
||||
File outputFile = getOutputDirectory().file("failure-report.txt").get().getAsFile();
|
||||
writeReport(allProblems, outputFile);
|
||||
if (!allProblems.isEmpty()) {
|
||||
throw new VerificationException(
|
||||
"AutoConfigure….imports checks failed. See '%s' for details".formatted(outputFile));
|
||||
}
|
||||
}
|
||||
|
||||
private List<AutoConfigureImports> loadImports() {
|
||||
return getSource().getFiles().stream().map((file) -> {
|
||||
String fileName = file.getName();
|
||||
String annotationName = fileName.substring(0, fileName.length() - ".imports".length());
|
||||
return new AutoConfigureImports(annotationName, loadImports(file), fileName);
|
||||
}).toList();
|
||||
}
|
||||
|
||||
private List<String> loadImports(File importsFile) {
|
||||
try {
|
||||
return Files.readAllLines(importsFile.toPath());
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean find(String className) {
|
||||
return find(className, (input) -> {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean find(String className, Consumer<InputStream> handler) {
|
||||
for (File root : this.classpath.getFiles()) {
|
||||
String classFilePath = className.replace(".", "/") + ".class";
|
||||
if (root.isDirectory()) {
|
||||
File classFile = new File(root, classFilePath);
|
||||
if (classFile.isFile()) {
|
||||
try (InputStream input = new FileInputStream(classFile)) {
|
||||
handler.accept(input);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
try (JarFile jar = new JarFile(root)) {
|
||||
ZipEntry entry = jar.getEntry(classFilePath);
|
||||
if (entry != null) {
|
||||
try (InputStream input = jar.getInputStream(entry)) {
|
||||
handler.accept(input);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean correctlyAnnotated(InputStream classFile) {
|
||||
return AutoConfigurationClass.of(classFile) != null;
|
||||
}
|
||||
|
||||
private void writeReport(Map<String, List<String>> allProblems, File outputFile) {
|
||||
outputFile.getParentFile().mkdirs();
|
||||
StringBuilder report = new StringBuilder();
|
||||
if (!allProblems.isEmpty()) {
|
||||
allProblems.forEach((fileName, problems) -> {
|
||||
report.append("Found problems in '%s':%n".formatted(fileName));
|
||||
problems.forEach((problem) -> report.append(" - %s%n".formatted(problem)));
|
||||
});
|
||||
}
|
||||
writeString(outputFile, report.toString());
|
||||
}
|
||||
|
||||
private void writeString(File file, String content) {
|
||||
try {
|
||||
Files.writeString(file.toPath(), content);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
record AutoConfigureImports(String annotationName, List<String> imports, String fileName) {
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -17,17 +17,14 @@
|
|||
package org.springframework.boot.build.test.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.Task;
|
||||
|
@ -38,9 +35,9 @@ import org.gradle.api.tasks.OutputFile;
|
|||
import org.gradle.api.tasks.PathSensitive;
|
||||
import org.gradle.api.tasks.PathSensitivity;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
import tools.jackson.databind.json.JsonMapper;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.boot.build.test.autoconfigure.TestSliceMetadata.TestSlice;
|
||||
|
||||
/**
|
||||
* {@link Task} used to document test slices.
|
||||
|
@ -49,16 +46,16 @@ import org.springframework.util.StringUtils;
|
|||
*/
|
||||
public abstract class DocumentTestSlices extends DefaultTask {
|
||||
|
||||
private FileCollection testSlices;
|
||||
private FileCollection testSliceMetadata;
|
||||
|
||||
@InputFiles
|
||||
@PathSensitive(PathSensitivity.RELATIVE)
|
||||
public FileCollection getTestSlices() {
|
||||
return this.testSlices;
|
||||
return this.testSliceMetadata;
|
||||
}
|
||||
|
||||
public void setTestSlices(FileCollection testSlices) {
|
||||
this.testSlices = testSlices;
|
||||
this.testSliceMetadata = testSlices;
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
|
@ -66,61 +63,42 @@ public abstract class DocumentTestSlices extends DefaultTask {
|
|||
|
||||
@TaskAction
|
||||
void documentTestSlices() throws IOException {
|
||||
Set<TestSlice> testSlices = readTestSlices();
|
||||
Map<String, List<TestSlice>> testSlices = readTestSlices();
|
||||
writeTable(testSlices);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private Set<TestSlice> readTestSlices() throws IOException {
|
||||
Set<TestSlice> testSlices = new TreeSet<>();
|
||||
for (File metadataFile : this.testSlices) {
|
||||
Properties metadata = new Properties();
|
||||
try (Reader reader = new FileReader(metadataFile)) {
|
||||
metadata.load(reader);
|
||||
}
|
||||
for (String name : Collections.list((Enumeration<String>) metadata.propertyNames())) {
|
||||
testSlices.add(new TestSlice(name,
|
||||
new TreeSet<>(StringUtils.commaDelimitedListToSet(metadata.getProperty(name)))));
|
||||
}
|
||||
private Map<String, List<TestSlice>> readTestSlices() {
|
||||
Map<String, List<TestSlice>> testSlices = new TreeMap<>();
|
||||
for (File metadataFile : this.testSliceMetadata) {
|
||||
JsonMapper mapper = JsonMapper.builder().build();
|
||||
TestSliceMetadata metadata = mapper.readValue(metadataFile, TestSliceMetadata.class);
|
||||
List<TestSlice> slices = new ArrayList<>(metadata.testSlices());
|
||||
Collections.sort(slices, (s1, s2) -> s1.annotation().compareTo(s2.annotation()));
|
||||
testSlices.put(metadata.module(), slices);
|
||||
}
|
||||
return testSlices;
|
||||
}
|
||||
|
||||
private void writeTable(Set<TestSlice> testSlices) throws IOException {
|
||||
private void writeTable(Map<String, List<TestSlice>> testSlicesByModule) throws IOException {
|
||||
File outputFile = getOutputFile().getAsFile().get();
|
||||
outputFile.getParentFile().mkdirs();
|
||||
try (PrintWriter writer = new PrintWriter(new FileWriter(outputFile))) {
|
||||
writer.println("[cols=\"d,a\"]");
|
||||
writer.println("[cols=\"d,d,a\"]");
|
||||
writer.println("|===");
|
||||
writer.println("| Test slice | Imported auto-configuration");
|
||||
for (TestSlice testSlice : testSlices) {
|
||||
writer.println();
|
||||
writer.printf("| `@%s`%n", testSlice.className);
|
||||
writer.println("| ");
|
||||
for (String importedAutoConfiguration : testSlice.importedAutoConfigurations) {
|
||||
writer.printf("`%s`%n", importedAutoConfiguration);
|
||||
}
|
||||
}
|
||||
writer.println("|Module | Test slice | Imported auto-configuration");
|
||||
testSlicesByModule.forEach((module, testSlices) -> {
|
||||
testSlices.forEach((testSlice) -> {
|
||||
writer.println();
|
||||
writer.printf("| `%s`%n", module);
|
||||
writer.printf("| javadoc:%s[format=annotation]%n", testSlice.annotation());
|
||||
writer.println("| ");
|
||||
for (String importedAutoConfiguration : testSlice.importedAutoConfigurations()) {
|
||||
writer.printf("`%s`%n", importedAutoConfiguration);
|
||||
}
|
||||
});
|
||||
});
|
||||
writer.println("|===");
|
||||
}
|
||||
}
|
||||
|
||||
private static final class TestSlice implements Comparable<TestSlice> {
|
||||
|
||||
private final String className;
|
||||
|
||||
private final SortedSet<String> importedAutoConfigurations;
|
||||
|
||||
private TestSlice(String className, SortedSet<String> importedAutoConfigurations) {
|
||||
this.className = ClassUtils.getShortName(className);
|
||||
this.importedAutoConfigurations = importedAutoConfigurations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compareTo(TestSlice other) {
|
||||
return this.className.compareTo(other.className);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,238 @@
|
|||
/*
|
||||
* Copyright 2012-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.test.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.model.ObjectFactory;
|
||||
import org.gradle.api.tasks.Classpath;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.PathSensitive;
|
||||
import org.gradle.api.tasks.PathSensitivity;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import org.springframework.boot.build.test.autoconfigure.TestSliceMetadata.TestSlice;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* A {@link Task} for generating metadata describing a project's test slices.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class GenerateTestSliceMetadata extends DefaultTask {
|
||||
|
||||
private final ObjectFactory objectFactory;
|
||||
|
||||
private FileCollection classpath;
|
||||
|
||||
private FileCollection importsFiles;
|
||||
|
||||
private FileCollection classesDirs;
|
||||
|
||||
@Inject
|
||||
public GenerateTestSliceMetadata(ObjectFactory objectFactory) {
|
||||
this.objectFactory = objectFactory;
|
||||
}
|
||||
|
||||
public void setSourceSet(SourceSet sourceSet) {
|
||||
this.classpath = sourceSet.getRuntimeClasspath();
|
||||
this.importsFiles = this.objectFactory.fileTree()
|
||||
.from(new File(sourceSet.getOutput().getResourcesDir(), "META-INF/spring"));
|
||||
this.importsFiles.filter((file) -> file.getName().endsWith(".imports"));
|
||||
getSpringFactories().set(new File(sourceSet.getOutput().getResourcesDir(), "META-INF/spring.factories"));
|
||||
this.classesDirs = sourceSet.getOutput().getClassesDirs();
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public abstract RegularFileProperty getOutputFile();
|
||||
|
||||
@InputFiles
|
||||
@PathSensitive(PathSensitivity.RELATIVE)
|
||||
abstract RegularFileProperty getSpringFactories();
|
||||
|
||||
@Classpath
|
||||
FileCollection getClasspath() {
|
||||
return this.classpath;
|
||||
}
|
||||
|
||||
@InputFiles
|
||||
@PathSensitive(PathSensitivity.RELATIVE)
|
||||
FileCollection getImportFiles() {
|
||||
return this.importsFiles;
|
||||
}
|
||||
|
||||
@Classpath
|
||||
FileCollection getClassesDirs() {
|
||||
return this.classesDirs;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void generateTestSliceMetadata() throws IOException {
|
||||
TestSliceMetadata metadata = readTestSlices();
|
||||
File outputFile = getOutputFile().getAsFile().get();
|
||||
outputFile.getParentFile().mkdirs();
|
||||
metadata.writeTo(outputFile);
|
||||
}
|
||||
|
||||
private TestSliceMetadata readTestSlices() throws IOException {
|
||||
List<TestSlice> testSlices = new ArrayList<>();
|
||||
try (URLClassLoader classLoader = new URLClassLoader(
|
||||
StreamSupport.stream(this.classpath.spliterator(), false).map(this::toURL).toArray(URL[]::new))) {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(classLoader);
|
||||
Properties springFactories = readSpringFactories(getSpringFactories().getAsFile().getOrNull());
|
||||
readImportsFiles(springFactories, this.importsFiles);
|
||||
for (File classesDir : this.classesDirs) {
|
||||
testSlices.addAll(readTestSlices(classesDir, metadataReaderFactory, springFactories));
|
||||
}
|
||||
}
|
||||
return new TestSliceMetadata(getProject().getName(), testSlices);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given imports files and puts them in springFactories. The key is the file
|
||||
* name, the value is the file contents, split by line, delimited with a comma. This
|
||||
* is done to mimic the spring.factories structure.
|
||||
* @param springFactories spring.factories parsed as properties
|
||||
* @param importsFiles the imports files to read
|
||||
*/
|
||||
private void readImportsFiles(Properties springFactories, FileCollection importsFiles) {
|
||||
for (File file : importsFiles.getFiles()) {
|
||||
try {
|
||||
List<String> lines = removeComments(Files.readAllLines(file.toPath()));
|
||||
String fileNameWithoutExtension = file.getName()
|
||||
.substring(0, file.getName().length() - ".imports".length());
|
||||
springFactories.setProperty(fileNameWithoutExtension,
|
||||
StringUtils.collectionToCommaDelimitedString(lines));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException("Failed to read file " + file, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> removeComments(List<String> lines) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String line : lines) {
|
||||
int commentIndex = line.indexOf('#');
|
||||
if (commentIndex > -1) {
|
||||
line = line.substring(0, commentIndex);
|
||||
}
|
||||
line = line.trim();
|
||||
if (!line.isEmpty()) {
|
||||
result.add(line);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private URL toURL(File file) {
|
||||
try {
|
||||
return file.toURI().toURL();
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Properties readSpringFactories(File file) throws IOException {
|
||||
Properties springFactories = new Properties();
|
||||
if (file.isFile()) {
|
||||
try (Reader in = new FileReader(file)) {
|
||||
springFactories.load(in);
|
||||
}
|
||||
}
|
||||
return springFactories;
|
||||
}
|
||||
|
||||
private List<TestSlice> readTestSlices(File classesDir, MetadataReaderFactory metadataReaderFactory,
|
||||
Properties springFactories) throws IOException {
|
||||
try (Stream<Path> classes = Files.walk(classesDir.toPath())) {
|
||||
return classes.filter((path) -> path.toString().endsWith("Test.class"))
|
||||
.map((path) -> getMetadataReader(path, metadataReaderFactory))
|
||||
.filter((metadataReader) -> metadataReader.getClassMetadata().isAnnotation())
|
||||
.map((metadataReader) -> readTestSlice(metadataReader, springFactories))
|
||||
.toList();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private MetadataReader getMetadataReader(Path path, MetadataReaderFactory metadataReaderFactory) {
|
||||
try {
|
||||
return metadataReaderFactory.getMetadataReader(new FileSystemResource(path));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private TestSlice readTestSlice(MetadataReader metadataReader, Properties springFactories) {
|
||||
String annotationName = metadataReader.getClassMetadata().getClassName();
|
||||
List<String> importedAutoConfiguration = getImportedAutoConfiguration(springFactories,
|
||||
metadataReader.getAnnotationMetadata());
|
||||
return new TestSlice(annotationName, importedAutoConfiguration);
|
||||
}
|
||||
|
||||
private List<String> getImportedAutoConfiguration(Properties springFactories,
|
||||
AnnotationMetadata annotationMetadata) {
|
||||
Stream<String> importers = findMetaImporters(annotationMetadata);
|
||||
if (annotationMetadata.isAnnotated("org.springframework.boot.autoconfigure.ImportAutoConfiguration")) {
|
||||
importers = Stream.concat(importers, Stream.of(annotationMetadata.getClassName()));
|
||||
}
|
||||
return importers
|
||||
.flatMap((importer) -> StringUtils.commaDelimitedListToSet(springFactories.getProperty(importer)).stream())
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Stream<String> findMetaImporters(AnnotationMetadata annotationMetadata) {
|
||||
return annotationMetadata.getAnnotationTypes()
|
||||
.stream()
|
||||
.filter((annotationType) -> isAutoConfigurationImporter(annotationType, annotationMetadata));
|
||||
}
|
||||
|
||||
private boolean isAutoConfigurationImporter(String annotationType, AnnotationMetadata metadata) {
|
||||
return metadata.getMetaAnnotationTypes(annotationType)
|
||||
.contains("org.springframework.boot.autoconfigure.ImportAutoConfiguration");
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Copyright 2012-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.test.autoconfigure;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.file.ConfigurableFileCollection;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
|
||||
/**
|
||||
* {@link Plugin} for projects that define test auto-configuration. When the
|
||||
* {@link JavaPlugin} is applied it:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Add checks to ensure AutoConfigure*.import files and related annotations are
|
||||
* correct</li>
|
||||
* </ul>
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class TestAutoConfigurationPlugin implements Plugin<Project> {
|
||||
|
||||
@Override
|
||||
public void apply(Project target) {
|
||||
target.getPlugins().withType(JavaPlugin.class, (plugin) -> {
|
||||
target.getTasks().register("checkAutoConfigureImports", CheckAutoConfigureImports.class, (task) -> {
|
||||
SourceSet mainSourceSet = target.getExtensions()
|
||||
.getByType(JavaPluginExtension.class)
|
||||
.getSourceSets()
|
||||
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
||||
task.setSource(mainSourceSet.getResources());
|
||||
ConfigurableFileCollection classpath = target.files(mainSourceSet.getRuntimeClasspath(),
|
||||
target.getConfigurations().getByName(mainSourceSet.getRuntimeClasspathConfigurationName()));
|
||||
task.setClasspath(classpath);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -17,229 +17,30 @@
|
|||
package org.springframework.boot.build.test.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.Reader;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
import java.util.stream.StreamSupport;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.gradle.api.DefaultTask;
|
||||
import org.gradle.api.Task;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.file.FileCollection;
|
||||
import org.gradle.api.file.RegularFileProperty;
|
||||
import org.gradle.api.model.ObjectFactory;
|
||||
import org.gradle.api.tasks.Classpath;
|
||||
import org.gradle.api.tasks.InputFile;
|
||||
import org.gradle.api.tasks.InputFiles;
|
||||
import org.gradle.api.tasks.OutputFile;
|
||||
import org.gradle.api.tasks.PathSensitive;
|
||||
import org.gradle.api.tasks.PathSensitivity;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.TaskAction;
|
||||
|
||||
import org.springframework.core.CollectionFactory;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
import tools.jackson.databind.SerializationFeature;
|
||||
import tools.jackson.databind.json.JsonMapper;
|
||||
|
||||
/**
|
||||
* A {@link Task} for generating metadata describing a project's test slices.
|
||||
* Metadata describing a module's test slices.
|
||||
*
|
||||
* @param module the module's name
|
||||
* @param testSlices the module's test slices
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public abstract class TestSliceMetadata extends DefaultTask {
|
||||
record TestSliceMetadata(String module, List<TestSlice> testSlices) {
|
||||
|
||||
private final ObjectFactory objectFactory;
|
||||
|
||||
private FileCollection classpath;
|
||||
|
||||
private FileCollection importsFiles;
|
||||
|
||||
private FileCollection classesDirs;
|
||||
|
||||
@Inject
|
||||
public TestSliceMetadata(ObjectFactory objectFactory) {
|
||||
this.objectFactory = objectFactory;
|
||||
Configuration testSliceMetadata = getProject().getConfigurations().maybeCreate("testSliceMetadata");
|
||||
getProject().afterEvaluate((evaluated) -> evaluated.getArtifacts()
|
||||
.add(testSliceMetadata.getName(), getOutputFile(), (artifact) -> artifact.builtBy(this)));
|
||||
static TestSliceMetadata readFrom(File file) {
|
||||
return JsonMapper.builder().build().readValue(file, TestSliceMetadata.class);
|
||||
}
|
||||
|
||||
public void setSourceSet(SourceSet sourceSet) {
|
||||
this.classpath = sourceSet.getRuntimeClasspath();
|
||||
this.importsFiles = this.objectFactory.fileTree()
|
||||
.from(new File(sourceSet.getOutput().getResourcesDir(), "META-INF/spring"));
|
||||
this.importsFiles.filter((file) -> file.getName().endsWith(".imports"));
|
||||
getSpringFactories().set(new File(sourceSet.getOutput().getResourcesDir(), "META-INF/spring.factories"));
|
||||
this.classesDirs = sourceSet.getOutput().getClassesDirs();
|
||||
void writeTo(File file) {
|
||||
JsonMapper.builder().enable(SerializationFeature.INDENT_OUTPUT).build().writeValue(file, this);
|
||||
}
|
||||
|
||||
@OutputFile
|
||||
public abstract RegularFileProperty getOutputFile();
|
||||
record TestSlice(String annotation, List<String> importedAutoConfigurations) {
|
||||
|
||||
@InputFile
|
||||
@PathSensitive(PathSensitivity.RELATIVE)
|
||||
abstract RegularFileProperty getSpringFactories();
|
||||
|
||||
@Classpath
|
||||
FileCollection getClasspath() {
|
||||
return this.classpath;
|
||||
}
|
||||
|
||||
@InputFiles
|
||||
@PathSensitive(PathSensitivity.RELATIVE)
|
||||
FileCollection getImportFiles() {
|
||||
return this.importsFiles;
|
||||
}
|
||||
|
||||
@Classpath
|
||||
FileCollection getClassesDirs() {
|
||||
return this.classesDirs;
|
||||
}
|
||||
|
||||
@TaskAction
|
||||
void documentTestSlices() throws IOException {
|
||||
Properties testSlices = readTestSlices();
|
||||
File outputFile = getOutputFile().getAsFile().get();
|
||||
outputFile.getParentFile().mkdirs();
|
||||
try (FileWriter writer = new FileWriter(outputFile)) {
|
||||
testSlices.store(writer, null);
|
||||
}
|
||||
}
|
||||
|
||||
private Properties readTestSlices() throws IOException {
|
||||
Properties testSlices = CollectionFactory.createSortedProperties(true);
|
||||
try (URLClassLoader classLoader = new URLClassLoader(
|
||||
StreamSupport.stream(this.classpath.spliterator(), false).map(this::toURL).toArray(URL[]::new))) {
|
||||
MetadataReaderFactory metadataReaderFactory = new SimpleMetadataReaderFactory(classLoader);
|
||||
Properties springFactories = readSpringFactories(getSpringFactories().getAsFile().get());
|
||||
readImportsFiles(springFactories, this.importsFiles);
|
||||
for (File classesDir : this.classesDirs) {
|
||||
addTestSlices(testSlices, classesDir, metadataReaderFactory, springFactories);
|
||||
}
|
||||
}
|
||||
return testSlices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the given imports files and puts them in springFactories. The key is the file
|
||||
* name, the value is the file contents, split by line, delimited with a comma. This
|
||||
* is done to mimic the spring.factories structure.
|
||||
* @param springFactories spring.factories parsed as properties
|
||||
* @param importsFiles the imports files to read
|
||||
*/
|
||||
private void readImportsFiles(Properties springFactories, FileCollection importsFiles) {
|
||||
for (File file : importsFiles.getFiles()) {
|
||||
try {
|
||||
List<String> lines = removeComments(Files.readAllLines(file.toPath()));
|
||||
String fileNameWithoutExtension = file.getName()
|
||||
.substring(0, file.getName().length() - ".imports".length());
|
||||
springFactories.setProperty(fileNameWithoutExtension,
|
||||
StringUtils.collectionToCommaDelimitedString(lines));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new UncheckedIOException("Failed to read file " + file, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> removeComments(List<String> lines) {
|
||||
List<String> result = new ArrayList<>();
|
||||
for (String line : lines) {
|
||||
int commentIndex = line.indexOf('#');
|
||||
if (commentIndex > -1) {
|
||||
line = line.substring(0, commentIndex);
|
||||
}
|
||||
line = line.trim();
|
||||
if (!line.isEmpty()) {
|
||||
result.add(line);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private URL toURL(File file) {
|
||||
try {
|
||||
return file.toURI().toURL();
|
||||
}
|
||||
catch (MalformedURLException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private Properties readSpringFactories(File file) throws IOException {
|
||||
Properties springFactories = new Properties();
|
||||
try (Reader in = new FileReader(file)) {
|
||||
springFactories.load(in);
|
||||
}
|
||||
return springFactories;
|
||||
}
|
||||
|
||||
private void addTestSlices(Properties testSlices, File classesDir, MetadataReaderFactory metadataReaderFactory,
|
||||
Properties springFactories) throws IOException {
|
||||
try (Stream<Path> classes = Files.walk(classesDir.toPath())) {
|
||||
classes.filter((path) -> path.toString().endsWith("Test.class"))
|
||||
.map((path) -> getMetadataReader(path, metadataReaderFactory))
|
||||
.filter((metadataReader) -> metadataReader.getClassMetadata().isAnnotation())
|
||||
.forEach((metadataReader) -> addTestSlice(testSlices, springFactories, metadataReader));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private MetadataReader getMetadataReader(Path path, MetadataReaderFactory metadataReaderFactory) {
|
||||
try {
|
||||
return metadataReaderFactory.getMetadataReader(new FileSystemResource(path));
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void addTestSlice(Properties testSlices, Properties springFactories, MetadataReader metadataReader) {
|
||||
testSlices.setProperty(metadataReader.getClassMetadata().getClassName(),
|
||||
StringUtils.collectionToCommaDelimitedString(
|
||||
getImportedAutoConfiguration(springFactories, metadataReader.getAnnotationMetadata())));
|
||||
}
|
||||
|
||||
private SortedSet<String> getImportedAutoConfiguration(Properties springFactories,
|
||||
AnnotationMetadata annotationMetadata) {
|
||||
Stream<String> importers = findMetaImporters(annotationMetadata);
|
||||
if (annotationMetadata.isAnnotated("org.springframework.boot.autoconfigure.ImportAutoConfiguration")) {
|
||||
importers = Stream.concat(importers, Stream.of(annotationMetadata.getClassName()));
|
||||
}
|
||||
return importers
|
||||
.flatMap((importer) -> StringUtils.commaDelimitedListToSet(springFactories.getProperty(importer)).stream())
|
||||
.collect(Collectors.toCollection(TreeSet::new));
|
||||
}
|
||||
|
||||
private Stream<String> findMetaImporters(AnnotationMetadata annotationMetadata) {
|
||||
return annotationMetadata.getAnnotationTypes()
|
||||
.stream()
|
||||
.filter((annotationType) -> isAutoConfigurationImporter(annotationType, annotationMetadata));
|
||||
}
|
||||
|
||||
private boolean isAutoConfigurationImporter(String annotationType, AnnotationMetadata metadata) {
|
||||
return metadata.getMetaAnnotationTypes(annotationType)
|
||||
.contains("org.springframework.boot.autoconfigure.ImportAutoConfiguration");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,78 @@
|
|||
/*
|
||||
* Copyright 2012-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.test.autoconfigure;
|
||||
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.attributes.Category;
|
||||
import org.gradle.api.attributes.Usage;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginExtension;
|
||||
import org.gradle.api.plugins.PluginContainer;
|
||||
import org.gradle.api.tasks.SourceSet;
|
||||
import org.gradle.api.tasks.TaskProvider;
|
||||
|
||||
/**
|
||||
* {@link Plugin} for projects that define one or more test slices. When applied, it:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Applies the {@link TestAutoConfigurationPlugin}
|
||||
* </ul>
|
||||
* Additionally, when the {@link JavaPlugin} is applied it:
|
||||
*
|
||||
* <ul>
|
||||
* <li>Defines a task that produces metadata describing the test slices. The metadata is
|
||||
* made available as an artifact in the {@code testSliceMetadata} configuration
|
||||
* </ul>
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class TestSlicePlugin implements Plugin<Project> {
|
||||
|
||||
private static final String TEST_SLICE_METADATA_CONFIGURATION_NAME = "testSliceMetadata";
|
||||
|
||||
@Override
|
||||
public void apply(Project target) {
|
||||
PluginContainer plugins = target.getPlugins();
|
||||
plugins.apply(TestAutoConfigurationPlugin.class);
|
||||
plugins.withType(JavaPlugin.class, (plugin) -> {
|
||||
TaskProvider<GenerateTestSliceMetadata> generateTestSliceMetadata = target.getTasks()
|
||||
.register("generateTestSliceMetadata", GenerateTestSliceMetadata.class, (task) -> {
|
||||
SourceSet mainSourceSet = target.getExtensions()
|
||||
.getByType(JavaPluginExtension.class)
|
||||
.getSourceSets()
|
||||
.getByName(SourceSet.MAIN_SOURCE_SET_NAME);
|
||||
task.setSourceSet(mainSourceSet);
|
||||
task.getOutputFile().set(target.getLayout().getBuildDirectory().file("test-slice-metadata.json"));
|
||||
});
|
||||
addMetadataArtifact(target, generateTestSliceMetadata);
|
||||
});
|
||||
}
|
||||
|
||||
private void addMetadataArtifact(Project project, TaskProvider<GenerateTestSliceMetadata> task) {
|
||||
project.getConfigurations().consumable(TEST_SLICE_METADATA_CONFIGURATION_NAME, (configuration) -> {
|
||||
configuration.attributes((attributes) -> {
|
||||
attributes.attribute(Category.CATEGORY_ATTRIBUTE,
|
||||
project.getObjects().named(Category.class, Category.DOCUMENTATION));
|
||||
attributes.attribute(Usage.USAGE_ATTRIBUTE,
|
||||
project.getObjects().named(Usage.class, "test-slice-metadata"));
|
||||
});
|
||||
});
|
||||
project.getArtifacts().add(TEST_SLICE_METADATA_CONFIGURATION_NAME, task);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright 2012-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.build.test.autoconfigure;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import org.springframework.boot.build.test.autoconfigure.TestSliceMetadata.TestSlice;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests for {@link TestSliceMetadata}.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
*/
|
||||
public class TestSliceMetadataTests {
|
||||
|
||||
@TempDir
|
||||
private File temp;
|
||||
|
||||
@Test
|
||||
void roundtripJson() {
|
||||
TestSliceMetadata source = new TestSliceMetadata("example",
|
||||
List.of(new TestSlice("ExampleOneTest", List.of("com.example.OneAutoConfiguration")),
|
||||
new TestSlice("ExampleTwoTest", List.of("com.example.TwoAutoConfiguration"))));
|
||||
File metadataFile = new File(this.temp, "metadata.json");
|
||||
source.writeTo(metadataFile);
|
||||
TestSliceMetadata readBack = TestSliceMetadata.readFrom(metadataFile);
|
||||
assertThat(source).isEqualTo(readBack);
|
||||
}
|
||||
|
||||
}
|
|
@ -6,7 +6,10 @@
|
|||
<module name="SuppressionFilter">
|
||||
<property name="file" value="${config_loc}/checkstyle-suppressions.xml"/>
|
||||
</module>
|
||||
<module name="io.spring.javaformat.checkstyle.SpringChecks" />
|
||||
<module name="io.spring.javaformat.checkstyle.SpringChecks">
|
||||
<property name="avoidStaticImportExcludes"
|
||||
value="org.springframework.boot.autoconfigure.AutoConfigurationImportedCondition.importedAutoConfiguration" />
|
||||
</module>
|
||||
<module name="io.spring.javaformat.checkstyle.check.SpringHeaderCheck">
|
||||
<property name="headerFile" value="${config_loc}/checkstyle-header.txt"/>
|
||||
</module>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure;
|
||||
package org.springframework.boot.autoconfigure;
|
||||
|
||||
import org.assertj.core.api.Condition;
|
||||
import org.assertj.core.description.TextDescription;
|
|
@ -90,9 +90,18 @@ dependencies {
|
|||
implementation(project(path: ":module:spring-boot-amqp"))
|
||||
implementation(project(path: ":module:spring-boot-cache"))
|
||||
implementation(project(path: ":module:spring-boot-data-cassandra"))
|
||||
implementation(project(path: ":module:spring-boot-data-cassandra-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-couchbase-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-elasticsearch"))
|
||||
implementation(project(path: ":module:spring-boot-data-elasticsearch-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-jpa-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-ldap-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-mongodb-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-neo4j"))
|
||||
implementation(project(path: ":module:spring-boot-data-neo4j-test"))
|
||||
implementation(project(path: ":module:spring-boot-data-redis-test"))
|
||||
implementation(project(path: ":module:spring-boot-devtools"))
|
||||
implementation(project(path: ":module:spring-boot-graphql-test"))
|
||||
implementation(project(path: ":module:spring-boot-health"))
|
||||
implementation(project(path: ":module:spring-boot-hibernate"))
|
||||
implementation(project(path: ":module:spring-boot-http-converter"))
|
||||
|
@ -100,23 +109,31 @@ dependencies {
|
|||
implementation(project(path: ":module:spring-boot-integration"))
|
||||
implementation(project(path: ":module:spring-boot-jackson"))
|
||||
implementation(project(path: ":module:spring-boot-jdbc"))
|
||||
implementation(project(path: ":module:spring-boot-jdbc-test"))
|
||||
implementation(project(path: ":module:spring-boot-jooq-test"))
|
||||
implementation(project(path: ":module:spring-boot-jpa"))
|
||||
implementation(project(path: ":module:spring-boot-jms"))
|
||||
implementation(project(path: ":module:spring-boot-jsonb"))
|
||||
implementation(project(path: ":module:spring-boot-json-test"))
|
||||
implementation(project(path: ":module:spring-boot-ldap"))
|
||||
implementation(project(path: ":module:spring-boot-micrometer-metrics"))
|
||||
implementation(project(path: ":module:spring-boot-persistence"))
|
||||
implementation(project(path: ":module:spring-boot-r2dbc"))
|
||||
implementation(project(path: ":module:spring-boot-restdocs"))
|
||||
implementation(project(path: ":module:spring-boot-reactor-netty"))
|
||||
implementation(project(path: ":module:spring-boot-restclient"))
|
||||
implementation(project(path: ":module:spring-boot-restclient-test"))
|
||||
implementation(project(path: ":module:spring-boot-security"))
|
||||
implementation(project(path: ":module:spring-boot-test-autoconfigure"))
|
||||
implementation(project(path: ":module:spring-boot-tomcat"))
|
||||
implementation(project(path: ":module:spring-boot-web-server-test"))
|
||||
implementation(project(path: ":module:spring-boot-webclient"))
|
||||
implementation(project(path: ":module:spring-boot-webflux"))
|
||||
implementation(project(path: ":module:spring-boot-webflux-test"))
|
||||
implementation(project(path: ":module:spring-boot-webmvc"))
|
||||
implementation(project(path: ":module:spring-boot-webmvc-test"))
|
||||
implementation(project(path: ":module:spring-boot-webservices"))
|
||||
implementation(project(path: ":module:spring-boot-webservices-test"))
|
||||
implementation("ch.qos.logback:logback-classic")
|
||||
implementation("com.redis:testcontainers-redis")
|
||||
implementation("com.zaxxer:HikariCP")
|
||||
|
@ -254,8 +271,15 @@ project.rootProject.gradle.projectsEvaluated {
|
|||
}
|
||||
}
|
||||
|
||||
aggregates {
|
||||
testSliceMetadata {
|
||||
category = Category.DOCUMENTATION
|
||||
usage = "test-slice-metadata"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register("documentTestSlices", org.springframework.boot.build.test.autoconfigure.DocumentTestSlices) {
|
||||
testSlices = configurations.testSlices
|
||||
testSlices = aggregates.testSliceMetadata.files
|
||||
outputFile = layout.buildDirectory.file("generated/docs/test-auto-configuration/documented-slices.adoc")
|
||||
}
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ For example, the test in the snippet below will run with an authenticated user t
|
|||
|
||||
include-code::MySecurityTests[]
|
||||
|
||||
Spring Security provides comprehensive integration with Spring MVC Test, and this can also be used when testing controllers using the javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] slice and javadoc:org.springframework.test.web.servlet.MockMvc[].
|
||||
Spring Security provides comprehensive integration with Spring MVC Test, and this can also be used when testing controllers using the javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] slice and javadoc:org.springframework.test.web.servlet.MockMvc[].
|
||||
|
||||
For additional details on Spring Security's testing support, see Spring Security's {url-spring-security-docs}/servlet/test/index.html[reference documentation].
|
||||
|
||||
|
@ -30,7 +30,7 @@ Consider this example:
|
|||
|
||||
include-code::MyConfiguration[]
|
||||
|
||||
For a javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] for an application with the above javadoc:org.springframework.context.annotation.Configuration[format=annotation] class, you might expect to have the javadoc:org.springframework.security.web.SecurityFilterChain[] bean in the application context so that you can test if your controller endpoints are secured properly.
|
||||
For a javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] for an application with the above javadoc:org.springframework.context.annotation.Configuration[format=annotation] class, you might expect to have the javadoc:org.springframework.security.web.SecurityFilterChain[] bean in the application context so that you can test if your controller endpoints are secured properly.
|
||||
However, `MyConfiguration` is not picked up by @WebMvcTest's component scanning filter because it doesn't match any of the types specified by the filter.
|
||||
You can include the configuration explicitly by annotating the test class with `@Import(MyConfiguration.class)`.
|
||||
This will load all the beans in `MyConfiguration` including the javadoc:com.zaxxer.hikari.HikariDataSource[] bean which isn't required when testing the web tier.
|
||||
|
|
|
@ -267,7 +267,7 @@ This is similar to the way the "real" cache providers behave if you use an undec
|
|||
|
||||
When javadoc:org.springframework.cache.annotation.EnableCaching[format=annotation] is present in your configuration, a suitable cache configuration is expected as well.
|
||||
If you have a custom ` org.springframework.cache.CacheManager`, consider defining it in a separate javadoc:org.springframework.context.annotation.Configuration[format=annotation] class so that you can override it if necessary.
|
||||
None uses a no-op implementation that is useful in tests, and slice tests use that by default via javadoc:org.springframework.boot.test.autoconfigure.core.AutoConfigureCache[format=annotation].
|
||||
None uses a no-op implementation that is useful in tests, and slice tests use that by default through javadoc:org.springframework.boot.cache.test.autoconfigure.AutoConfigureCache[format=annotation] when the `spring-boot-cache-test` module is present.
|
||||
|
||||
If you need to use a no-op cache rather than the auto-configured cache manager in a certain environment, set the cache type to `none`, as shown in the following example:
|
||||
|
||||
|
|
|
@ -2,9 +2,10 @@
|
|||
= Testing
|
||||
|
||||
Spring Boot provides a number of utilities and annotations to help when testing your application.
|
||||
Test support is provided by two modules: `spring-boot-test` contains core items, and `spring-boot-test-autoconfigure` supports auto-configuration for tests.
|
||||
|
||||
Most developers use the `spring-boot-starter-test` starter, which imports both Spring Boot test modules as well as JUnit Jupiter, AssertJ, Hamcrest, and a number of other useful libraries.
|
||||
Test support is provided by two general-purpose modules – `spring-boot-test` contains core items and `spring-boot-test-autoconfigure` supports auto-configuration for tests – and several focused `-test` modules that provide testing support for a particular feature.
|
||||
|
||||
Most developers use the `spring-boot-starter-test` starter, which imports both general-purpose Spring Boot test modules as well as JUnit Jupiter, AssertJ, Hamcrest, and a number of other useful libraries, and the focused `-test` modules that are applicable to their particular application.
|
||||
|
||||
[TIP]
|
||||
====
|
||||
|
|
|
@ -18,7 +18,7 @@ You can use the `webEnvironment` attribute of javadoc:org.springframework.boot.t
|
|||
* `MOCK`(Default) : Loads a web javadoc:org.springframework.context.ApplicationContext[] and provides a mock web environment.
|
||||
Embedded servers are not started when using this annotation.
|
||||
If a web environment is not available on your classpath, this mode transparently falls back to creating a regular non-web javadoc:org.springframework.context.ApplicationContext[].
|
||||
It can be used in conjunction with xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-mock-environment[`@AutoConfigureMockMvc` or javadoc:org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient[format=annotation]] for mock-based testing of your web application.
|
||||
It can be used in conjunction with xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-mock-environment[`@AutoConfigureMockMvc` or javadoc:org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebTestClient[format=annotation]] for mock-based testing of your web application.
|
||||
* `RANDOM_PORT`: Loads a javadoc:org.springframework.boot.web.context.WebServerApplicationContext[] and provides a real web environment.
|
||||
Embedded servers are started and listen on a random port.
|
||||
* `DEFINED_PORT`: Loads a javadoc:org.springframework.boot.web.context.WebServerApplicationContext[] and provides a real web environment.
|
||||
|
@ -151,7 +151,7 @@ The following example showcases the available integrations:
|
|||
|
||||
include-code::MyMockMvcTests[]
|
||||
|
||||
TIP: If you want to focus only on the web layer and not start a complete javadoc:org.springframework.context.ApplicationContext[], consider xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spring-mvc-tests[using javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] instead].
|
||||
TIP: If you want to focus only on the web layer and not start a complete javadoc:org.springframework.context.ApplicationContext[], consider xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.spring-mvc-tests[using javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] instead].
|
||||
|
||||
With Spring WebFlux endpoints, you can use {url-spring-framework-docs}/testing/webtestclient.html[`WebTestClient`] as shown in the following example:
|
||||
|
||||
|
@ -180,10 +180,10 @@ For convenience, tests that need to make REST calls to the started server can ad
|
|||
|
||||
include-code::MyRandomPortWebTestClientTests[]
|
||||
|
||||
TIP: javadoc:org.springframework.test.web.reactive.server.WebTestClient[] can also used with a xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-mock-environment[mock environment], removing the need for a running server, by annotating your test class with javadoc:org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient[format=annotation].
|
||||
TIP: javadoc:org.springframework.test.web.reactive.server.WebTestClient[] can also used with a xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-mock-environment[mock environment], removing the need for a running server, by annotating your test class with javadoc:org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebTestClient[format=annotation] from `spring-boot-webflux-test`.
|
||||
|
||||
This setup requires `spring-webflux` on the classpath.
|
||||
If you can not or will not add webflux, Spring Boot also provides a javadoc:org.springframework.boot.test.web.client.TestRestTemplate[] facility:
|
||||
If you can not or will not add webflux, the `spring-boot-web-server-test` modules provides a javadoc:org.springframework.boot.web.server.test.client.TestRestTemplate[] facility:
|
||||
|
||||
include-code::MyRandomPortTestRestTemplateTests[]
|
||||
|
||||
|
@ -210,7 +210,7 @@ include-code::MyJmxTests[]
|
|||
[[testing.spring-boot-applications.observations]]
|
||||
== Using Observations
|
||||
|
||||
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation], it auto-configures an javadoc:io.micrometer.observation.ObservationRegistry[].
|
||||
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.micrometer.tracing.test.autoconfigure.AutoConfigureTracing[format=annotation] from `spring-boot-micrometer-tracing-test` or with javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation] from `spring-boot-micrometer-metrics-test`, it auto-configures an javadoc:io.micrometer.observation.ObservationRegistry[].
|
||||
|
||||
|
||||
|
||||
|
@ -219,10 +219,10 @@ If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-a
|
|||
|
||||
Regardless of your classpath, meter registries, except the in-memory backed, are not auto-configured when using javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation].
|
||||
|
||||
If you need to export metrics to a different backend as part of an integration test, annotate it with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation].
|
||||
If you need to export metrics to a different backend as part of an integration test, annotate it with javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation].
|
||||
|
||||
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation], it auto-configures an in-memory javadoc:io.micrometer.core.instrument.MeterRegistry[].
|
||||
Data exporting in sliced tests is not supported with the javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation] annotation.
|
||||
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation], it auto-configures an in-memory javadoc:io.micrometer.core.instrument.MeterRegistry[].
|
||||
Data exporting in sliced tests is not supported with the javadoc:org.springframework.boot.micrometer.metrics.test.autoconfigure.AutoConfigureMetrics[format=annotation] annotation.
|
||||
|
||||
|
||||
|
||||
|
@ -231,12 +231,12 @@ Data exporting in sliced tests is not supported with the javadoc:org.springframe
|
|||
|
||||
Regardless of your classpath, tracing components which are reporting data are not auto-configured when using javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation].
|
||||
|
||||
If you need those components as part of an integration test, annotate the test with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation].
|
||||
If you need those components as part of an integration test, annotate the test with javadoc:org.springframework.boot.micrometer.tracing.test.autoconfigure.AutoConfigureTracing[format=annotation].
|
||||
|
||||
If you have created your own reporting components (e.g. a custom javadoc:io.opentelemetry.sdk.trace.export.SpanExporter[] or `brave.handler.SpanHandler`) and you don't want them to be active in tests, you can use the javadoc:org.springframework.boot.micrometer.tracing.autoconfigure.ConditionalOnEnabledTracingExport[format=annotation] annotation to disable them.
|
||||
|
||||
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation], it auto-configures a no-op javadoc:io.micrometer.tracing.Tracer[].
|
||||
Data exporting in sliced tests is not supported with the javadoc:org.springframework.boot.test.autoconfigure.actuate.observability.AutoConfigureObservability[format=annotation] annotation.
|
||||
If you annotate xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-tests[a sliced test] with javadoc:org.springframework.boot.micrometer.tracing.test.autoconfigure.AutoConfigureTracing[format=annotation] , it auto-configures a no-op javadoc:io.micrometer.tracing.Tracer[].
|
||||
Data exporting in sliced tests is not supported with the javadoc:org.springframework.boot.micrometer.tracing.test.autoconfigure.AutoConfigureTracing[format=annotation] annotation.
|
||||
|
||||
|
||||
|
||||
|
@ -260,7 +260,7 @@ Spring Boot's auto-configuration system works well for applications but can some
|
|||
It often helps to load only the parts of the configuration that are required to test a "`slice`" of your application.
|
||||
For example, you might want to test that Spring MVC controllers are mapping URLs correctly, and you do not want to involve database calls in those tests, or you might want to test JPA entities, and you are not interested in the web layer when those tests run.
|
||||
|
||||
The `spring-boot-test-autoconfigure` module includes a number of annotations that can be used to automatically configure such "`slices`".
|
||||
When combined with `spring-boot-test-autoconfigure`, Spring Boot's xref:reference:testing/test-modules.adoc[test modules] include a number of annotations that can be used to automatically configure such "`slices`".
|
||||
Each of them works in a similar way, providing a `@...Test` annotation that loads the javadoc:org.springframework.context.ApplicationContext[] and one or more `@AutoConfigure...` annotations that can be used to customize auto-configuration settings.
|
||||
|
||||
NOTE: Each slice restricts component scan to appropriate components and loads a very restricted set of auto-configuration classes.
|
||||
|
@ -278,26 +278,26 @@ You can use this combination if you are not interested in "`slicing`" your appli
|
|||
[[testing.spring-boot-applications.json-tests]]
|
||||
== Auto-configured JSON Tests
|
||||
|
||||
To test that object JSON serialization and deserialization is working as expected, you can use the javadoc:org.springframework.boot.test.autoconfigure.json.JsonTest[format=annotation] annotation.
|
||||
javadoc:org.springframework.boot.test.autoconfigure.json.JsonTest[format=annotation] auto-configures the available supported JSON mapper, which can be one of the following libraries:
|
||||
To test that object JSON serialization and deserialization is working as expected, you can use the javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation] annotation from the `spring-boot-json-test` module.
|
||||
javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation] auto-configures the available supported JSON mapper, which can be one of the following libraries:
|
||||
|
||||
* Jackson javadoc:tools.jackson.databind.JsonMapper[], any javadoc:org.springframework.boot.jackson.JsonComponent[format=annotation] beans and any Jackson javadoc:tools.jackson.databind.JacksonModule[]
|
||||
* `Gson`
|
||||
* `Jsonb`
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.test.autoconfigure.json.JsonTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
If you need to configure elements of the auto-configuration, you can use the javadoc:org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters[format=annotation] annotation.
|
||||
If you need to configure elements of the auto-configuration, you can use the javadoc:org.springframework.boot.json.test.autoconfigure.AutoConfigureJsonTesters[format=annotation] annotation.
|
||||
|
||||
Spring Boot includes AssertJ-based helpers that work with the JSONAssert and JsonPath libraries to check that JSON appears as expected.
|
||||
The javadoc:org.springframework.boot.test.json.JacksonTester[], javadoc:org.springframework.boot.test.json.GsonTester[], javadoc:org.springframework.boot.test.json.JsonbTester[], and javadoc:org.springframework.boot.test.json.BasicJsonTester[] classes can be used for Jackson, Gson, Jsonb, and Strings respectively.
|
||||
Any helper fields on the test class can be javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation] when using javadoc:org.springframework.boot.test.autoconfigure.json.JsonTest[format=annotation].
|
||||
Any helper fields on the test class can be javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation] when using javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation].
|
||||
The following example shows a test class for Jackson:
|
||||
|
||||
include-code::MyJsonTests[]
|
||||
|
||||
NOTE: JSON helper classes can also be used directly in standard unit tests.
|
||||
To do so, call the `initFields` method of the helper in your javadoc:org.junit.jupiter.api.BeforeEach[format=annotation] method if you do not use javadoc:org.springframework.boot.test.autoconfigure.json.JsonTest[format=annotation].
|
||||
To do so, call the `initFields` method of the helper in your javadoc:org.junit.jupiter.api.BeforeEach[format=annotation] method if you do not use javadoc:org.springframework.boot.json.test.autoconfigure.JsonTest[format=annotation].
|
||||
|
||||
If you use Spring Boot's AssertJ-based helpers to assert on a number value at a given JSON path, you might not be able to use `isEqualTo` depending on the type.
|
||||
Instead, you can use AssertJ's `satisfies` to assert that the value matches the given condition.
|
||||
|
@ -310,27 +310,27 @@ include-code::MyJsonAssertJTests[tag=*]
|
|||
[[testing.spring-boot-applications.spring-mvc-tests]]
|
||||
== Auto-configured Spring MVC Tests
|
||||
|
||||
To test whether Spring MVC controllers are working as expected, use the javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] annotation.
|
||||
javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] auto-configures the Spring MVC infrastructure and limits scanned beans to javadoc:org.springframework.stereotype.Controller[format=annotation], javadoc:org.springframework.web.bind.annotation.ControllerAdvice[format=annotation], javadoc:org.springframework.boot.jackson.JsonComponent[format=annotation], javadoc:org.springframework.core.convert.converter.Converter[], javadoc:org.springframework.core.convert.converter.GenericConverter[], javadoc:jakarta.servlet.Filter[], javadoc:org.springframework.web.servlet.HandlerInterceptor[], javadoc:org.springframework.web.servlet.config.annotation.WebMvcConfigurer[], javadoc:org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations[], and javadoc:org.springframework.web.method.support.HandlerMethodArgumentResolver[].
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] annotation is used.
|
||||
To test whether Spring MVC controllers are working as expected, use the javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] annotation from the `spring-boot-webmvc-test` module.
|
||||
javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] auto-configures the Spring MVC infrastructure and limits scanned beans to javadoc:org.springframework.stereotype.Controller[format=annotation], javadoc:org.springframework.web.bind.annotation.ControllerAdvice[format=annotation], javadoc:org.springframework.boot.jackson.JsonComponent[format=annotation], javadoc:org.springframework.core.convert.converter.Converter[], javadoc:org.springframework.core.convert.converter.GenericConverter[], javadoc:jakarta.servlet.Filter[], javadoc:org.springframework.web.servlet.HandlerInterceptor[], javadoc:org.springframework.web.servlet.config.annotation.WebMvcConfigurer[], javadoc:org.springframework.boot.autoconfigure.web.servlet.WebMvcRegistrations[], and javadoc:org.springframework.web.method.support.HandlerMethodArgumentResolver[].
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
TIP: If you need to register extra components, such as a javadoc:tools.jackson.databind.JacksonModule[], you can import additional configuration classes by using javadoc:org.springframework.context.annotation.Import[format=annotation] on your test.
|
||||
|
||||
Often, javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] is limited to a single controller and is used in combination with javadoc:org.springframework.test.context.bean.override.mockito.MockitoBean[format=annotation] to provide mock implementations for required collaborators.
|
||||
Often, javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] is limited to a single controller and is used in combination with javadoc:org.springframework.test.context.bean.override.mockito.MockitoBean[format=annotation] to provide mock implementations for required collaborators.
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] also auto-configures javadoc:org.springframework.test.web.servlet.MockMvc[].
|
||||
javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] also auto-configures javadoc:org.springframework.test.web.servlet.MockMvc[].
|
||||
Mock MVC offers a powerful way to quickly test MVC controllers without needing to start a full HTTP server.
|
||||
If AssertJ is available, the AssertJ support provided by javadoc:org.springframework.test.web.servlet.assertj.MockMvcTester[] is auto-configured as well.
|
||||
|
||||
TIP: You can also auto-configure javadoc:org.springframework.test.web.servlet.MockMvc[] and javadoc:org.springframework.test.web.servlet.assertj.MockMvcTester[] in a non-`@WebMvcTest` (such as javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation]) by annotating it with javadoc:org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc[format=annotation].
|
||||
TIP: You can also auto-configure javadoc:org.springframework.test.web.servlet.MockMvc[] and javadoc:org.springframework.test.web.servlet.assertj.MockMvcTester[] in a non-`@WebMvcTest` (such as javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation]) by annotating it with javadoc:org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc[format=annotation].
|
||||
The following example uses javadoc:org.springframework.test.web.servlet.assertj.MockMvcTester[]:
|
||||
|
||||
include-code::MyControllerTests[]
|
||||
|
||||
TIP: If you need to configure elements of the auto-configuration (for example, when servlet filters should be applied) you can use attributes in the javadoc:org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc[format=annotation] annotation.
|
||||
TIP: If you need to configure elements of the auto-configuration (for example, when servlet filters should be applied) you can use attributes in the javadoc:org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc[format=annotation] annotation.
|
||||
|
||||
If you use HtmlUnit and Selenium, auto-configuration also provides an HtmlUnit javadoc:org.springframework.web.reactive.function.client.WebClient[] bean and/or a Selenium javadoc:org.openqa.selenium.WebDriver[] bean.
|
||||
The following example uses HtmlUnit:
|
||||
|
@ -341,9 +341,9 @@ NOTE: By default, Spring Boot puts javadoc:org.openqa.selenium.WebDriver[] beans
|
|||
If you do not want this behavior, you can add `@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)` to your javadoc:org.openqa.selenium.WebDriver[] javadoc:org.springframework.context.annotation.Bean[format=annotation] definition.
|
||||
|
||||
WARNING: The `webDriver` scope created by Spring Boot will replace any user defined scope of the same name.
|
||||
If you define your own `webDriver` scope you may find it stops working when you use javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation].
|
||||
If you define your own `webDriver` scope you may find it stops working when you use javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation].
|
||||
|
||||
If you have Spring Security on the classpath, javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation] will also scan javadoc:org.springframework.security.config.annotation.web.WebSecurityConfigurer[] beans.
|
||||
If you have Spring Security on the classpath, javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation] will also scan javadoc:org.springframework.security.config.annotation.web.WebSecurityConfigurer[] beans.
|
||||
Instead of disabling security completely for such tests, you can use Spring Security's test support.
|
||||
More details on how to use Spring Security's javadoc:org.springframework.test.web.servlet.MockMvc[] support can be found in this xref:how-to:testing.adoc#howto.testing.with-spring-security[] "`How-to Guides`" section.
|
||||
|
||||
|
@ -354,30 +354,30 @@ TIP: Sometimes writing Spring MVC tests is not enough; Spring Boot can help you
|
|||
[[testing.spring-boot-applications.spring-webflux-tests]]
|
||||
== Auto-configured Spring WebFlux Tests
|
||||
|
||||
To test that {url-spring-framework-docs}/web-reactive.html[Spring WebFlux] controllers are working as expected, you can use the javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] annotation.
|
||||
javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] auto-configures the Spring WebFlux infrastructure and limits scanned beans to javadoc:org.springframework.stereotype.Controller[format=annotation], javadoc:org.springframework.web.bind.annotation.ControllerAdvice[format=annotation], javadoc:org.springframework.boot.jackson.JsonComponent[format=annotation], javadoc:org.springframework.core.convert.converter.Converter[], javadoc:org.springframework.core.convert.converter.GenericConverter[] and javadoc:org.springframework.web.reactive.config.WebFluxConfigurer[].
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] annotation is used.
|
||||
To test that {url-spring-framework-docs}/web-reactive.html[Spring WebFlux] controllers are working as expected, you can use the javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] annotation from the `spring-boot-webflux-test` module.
|
||||
javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] auto-configures the Spring WebFlux infrastructure and limits scanned beans to javadoc:org.springframework.stereotype.Controller[format=annotation], javadoc:org.springframework.web.bind.annotation.ControllerAdvice[format=annotation], javadoc:org.springframework.boot.jackson.JsonComponent[format=annotation], javadoc:org.springframework.core.convert.converter.Converter[], javadoc:org.springframework.core.convert.converter.GenericConverter[] and javadoc:org.springframework.web.reactive.config.WebFluxConfigurer[].
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
TIP: If you need to register extra components, such as a javadoc:tools.jackson.databind.JacksonModule[], you can import additional configuration classes using javadoc:org.springframework.context.annotation.Import[format=annotation] on your test.
|
||||
|
||||
Often, javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] is limited to a single controller and used in combination with the javadoc:org.springframework.test.context.bean.override.mockito.MockitoBean[format=annotation] annotation to provide mock implementations for required collaborators.
|
||||
Often, javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] is limited to a single controller and used in combination with the javadoc:org.springframework.test.context.bean.override.mockito.MockitoBean[format=annotation] annotation to provide mock implementations for required collaborators.
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] also auto-configures {url-spring-framework-docs}/testing/webtestclient.html[`WebTestClient`], which offers a powerful way to quickly test WebFlux controllers without needing to start a full HTTP server.
|
||||
javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] also auto-configures {url-spring-framework-docs}/testing/webtestclient.html[`WebTestClient`], which offers a powerful way to quickly test WebFlux controllers without needing to start a full HTTP server.
|
||||
|
||||
TIP: You can also auto-configure javadoc:org.springframework.test.web.reactive.server.WebTestClient[] in a non-`@WebFluxTest` (such as javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation]) by annotating it with javadoc:org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient[format=annotation].
|
||||
The following example shows a class that uses both javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] and a javadoc:org.springframework.test.web.reactive.server.WebTestClient[]:
|
||||
TIP: You can also auto-configure javadoc:org.springframework.test.web.reactive.server.WebTestClient[] in a non-`@WebFluxTest` (such as javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation]) by annotating it with javadoc:org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebTestClient[format=annotation].
|
||||
The following example shows a class that uses both javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] and a javadoc:org.springframework.test.web.reactive.server.WebTestClient[]:
|
||||
|
||||
include-code::MyControllerTests[]
|
||||
|
||||
TIP: This setup is only supported by WebFlux applications as using javadoc:org.springframework.test.web.reactive.server.WebTestClient[] in a mocked web application only works with WebFlux at the moment.
|
||||
|
||||
NOTE: javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] cannot detect routes registered through the functional web framework.
|
||||
NOTE: javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] cannot detect routes registered through the functional web framework.
|
||||
For testing javadoc:org.springframework.web.reactive.function.server.RouterFunction[] beans in the context, consider importing your javadoc:org.springframework.web.reactive.function.server.RouterFunction[] yourself by using javadoc:org.springframework.context.annotation.Import[format=annotation] or by using javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation].
|
||||
|
||||
NOTE: javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] cannot detect custom security configuration registered as a javadoc:org.springframework.context.annotation.Bean[format=annotation] of type javadoc:org.springframework.security.web.server.SecurityWebFilterChain[].
|
||||
NOTE: javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] cannot detect custom security configuration registered as a javadoc:org.springframework.context.annotation.Bean[format=annotation] of type javadoc:org.springframework.security.web.server.SecurityWebFilterChain[].
|
||||
To include that in your test, you will need to import the configuration that registers the bean by using javadoc:org.springframework.context.annotation.Import[format=annotation] or by using javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation].
|
||||
|
||||
TIP: Sometimes writing Spring WebFlux tests is not enough; Spring Boot can help you run xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.with-running-server[full end-to-end tests with an actual server].
|
||||
|
@ -424,21 +424,21 @@ There are javadoc:org.springframework.graphql.test.tester.GraphQlTester[] varian
|
|||
* the javadoc:org.springframework.graphql.test.tester.ExecutionGraphQlServiceTester[] performs tests on the server side, without a client nor a transport
|
||||
* the javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] performs tests with a client that connects to a server, with or without a live server
|
||||
|
||||
Spring Boot helps you to test your {url-spring-graphql-docs}/controllers.html[Spring GraphQL Controllers] with the javadoc:org.springframework.boot.test.autoconfigure.graphql.GraphQlTest[format=annotation] annotation.
|
||||
javadoc:org.springframework.boot.test.autoconfigure.graphql.GraphQlTest[format=annotation] auto-configures the Spring GraphQL infrastructure, without any transport nor server being involved.
|
||||
Spring Boot helps you to test your {url-spring-graphql-docs}/controllers.html[Spring GraphQL Controllers] with the javadoc:org.springframework.boot.graphql.test.autoconfigure.GraphQlTest[format=annotation] annotation from the `spring-boot-graphql-test` module.
|
||||
javadoc:org.springframework.boot.graphql.test.autoconfigure.GraphQlTest[format=annotation] auto-configures the Spring GraphQL infrastructure, without any transport nor server being involved.
|
||||
This limits scanned beans to javadoc:org.springframework.stereotype.Controller[format=annotation], javadoc:org.springframework.graphql.execution.RuntimeWiringConfigurer[], javadoc:org.springframework.boot.jackson.JsonComponent[], javadoc:org.springframework.core.convert.converter.Converter[], javadoc:org.springframework.core.convert.converter.GenericConverter[], javadoc:org.springframework.graphql.execution.DataFetcherExceptionResolver[], javadoc:graphql.execution.instrumentation.Instrumentation[] and javadoc:org.springframework.boot.graphql.autoconfigure.GraphQlSourceBuilderCustomizer[].
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.graphql.GraphQlTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.graphql.test.autoconfigure.GraphQlTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.test.autoconfigure.graphql.GraphQlTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.graphql.test.autoconfigure.GraphQlTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
Often, javadoc:org.springframework.boot.test.autoconfigure.graphql.GraphQlTest[format=annotation] is limited to a set of controllers and used in combination with the javadoc:org.springframework.test.context.bean.override.mockito.MockitoBean[format=annotation] annotation to provide mock implementations for required collaborators.
|
||||
Often, javadoc:org.springframework.boot.graphql.test.autoconfigure.GraphQlTest[format=annotation] is limited to a set of controllers and used in combination with the javadoc:org.springframework.test.context.bean.override.mockito.MockitoBean[format=annotation] annotation to provide mock implementations for required collaborators.
|
||||
|
||||
include-code::GreetingControllerTests[]
|
||||
|
||||
javadoc:org.springframework.boot.test.context.SpringBootTest[format=annotation] tests are full integration tests and involve the entire application.
|
||||
When using a random or defined port, a live server is configured and an javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean is contributed automatically so you can use it to test your server.
|
||||
When a MOCK environment is configured, you can also request an javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean by annotating your test class with javadoc:org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester[format=annotation]:
|
||||
When a MOCK environment is configured, you can also request an javadoc:org.springframework.graphql.test.tester.HttpGraphQlTester[] bean by annotating your test class with javadoc:org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester[format=annotation] from the `spring-boot-graphql-test` module:
|
||||
|
||||
include-code::GraphQlIntegrationTests[]
|
||||
|
||||
|
@ -447,13 +447,13 @@ include-code::GraphQlIntegrationTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-cassandra]]
|
||||
== Auto-configured Data Cassandra Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest[format=annotation] to test Cassandra applications.
|
||||
You can use javadoc:org.springframework.boot.data.cassandra.test.autoconfigure.DataCassandraTest[format=annotation] from the `spring-boot-data-cassandra-test` module to test Data Cassandra applications.
|
||||
By default, it configures a javadoc:org.springframework.data.cassandra.core.CassandraTemplate[], scans for javadoc:org.springframework.data.cassandra.core.mapping.Table[format=annotation] classes, and configures Spring Data Cassandra repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.cassandra.test.autoconfigure.DataCassandraTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
(For more about using Cassandra with Spring Boot, see xref:data/nosql.adoc#data.nosql.cassandra[].)
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.cassandra.test.autoconfigure.DataCassandraTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows a typical setup for using Cassandra tests in Spring Boot:
|
||||
|
||||
|
@ -464,13 +464,13 @@ include-code::MyDataCassandraTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-couchbase]]
|
||||
== Auto-configured Data Couchbase Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest[format=annotation] to test Couchbase applications.
|
||||
You can use javadoc:org.springframework.boot.data.couchbase.test.autoconfigure.DataCouchbaseTest[format=annotation] from the `spring-boot-data-couchbase-test` module to test Data Couchbase applications.
|
||||
By default, it configures a javadoc:org.springframework.data.couchbase.core.CouchbaseTemplate[] or javadoc:org.springframework.data.couchbase.core.ReactiveCouchbaseTemplate[], scans for javadoc:org.springframework.data.couchbase.core.mapping.Document[format=annotation] classes, and configures Spring Data Couchbase repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.couchbase.test.autoconfigure.DataCouchbaseTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
(For more about using Couchbase with Spring Boot, see xref:data/nosql.adoc#data.nosql.couchbase[], earlier in this chapter.)
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.couchbase.test.autoconfigure.DataCouchbaseTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows a typical setup for using Couchbase tests in Spring Boot:
|
||||
|
||||
|
@ -481,13 +481,13 @@ include-code::MyDataCouchbaseTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-elasticsearch]]
|
||||
== Auto-configured Data Elasticsearch Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest[format=annotation] to test Elasticsearch applications.
|
||||
You can use javadoc:org.springframework.boot.data.elasticsearch.test.autoconfigure.DataElasticsearchTest[format=annotation] from the `spring-boot-data-elasticsearch-test` module to test Data Elasticsearch applications.
|
||||
By default, it configures an javadoc:org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate[], scans for javadoc:org.springframework.data.elasticsearch.annotations.Document[format=annotation] classes, and configures Spring Data Elasticsearch repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.elasticsearch.test.autoconfigure.DataElasticsearchTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
(For more about using Elasticsearch with Spring Boot, see xref:data/nosql.adoc#data.nosql.elasticsearch[], earlier in this chapter.)
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.elasticsearch.test.autoconfigure.DataElasticsearchTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows a typical setup for using Elasticsearch tests in Spring Boot:
|
||||
|
||||
|
@ -498,16 +498,16 @@ include-code::MyDataElasticsearchTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-jpa]]
|
||||
== Auto-configured Data JPA Tests
|
||||
|
||||
You can use the javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation] annotation to test JPA applications.
|
||||
You can use the javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation] annotation from the `spring-boot-data-jpa-test` module to test Data JPA applications.
|
||||
By default, it scans for javadoc:jakarta.persistence.Entity[format=annotation] classes and configures Spring Data JPA repositories.
|
||||
If an embedded database is available on the classpath, it configures one as well.
|
||||
SQL queries are logged by default by setting the `spring.jpa.show-sql` property to `true`.
|
||||
This can be disabled using the `showSql` attribute of the annotation.
|
||||
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
By default, data JPA tests are transactional and roll back at the end of each test.
|
||||
See the {url-spring-framework-docs}/testing/testcontext-framework/tx.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details.
|
||||
|
@ -515,18 +515,18 @@ If that is not what you want, you can disable transaction management for a test
|
|||
|
||||
include-code::MyNonTransactionalTests[]
|
||||
|
||||
Data JPA tests may also inject a javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager[] bean, which provides an alternative to the standard JPA javadoc:jakarta.persistence.EntityManager[] that is specifically designed for tests.
|
||||
Data JPA tests may also inject a javadoc:org.springframework.boot.jpa.test.autoconfigure.TestEntityManager[] bean, which provides an alternative to the standard JPA javadoc:jakarta.persistence.EntityManager[] that is specifically designed for tests.
|
||||
|
||||
TIP: javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager[] can also be auto-configured to any of your Spring-based test class by adding javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.AutoConfigureTestEntityManager[format=annotation].
|
||||
TIP: javadoc:org.springframework.boot.jpa.test.autoconfigure.TestEntityManager[] can also be auto-configured to any of your Spring-based test class by adding javadoc:org.springframework.boot.jpa.test.autoconfigure.AutoConfigureTestEntityManager[format=annotation].
|
||||
When doing so, make sure that your test is running in a transaction, for instance by adding javadoc:org.springframework.transaction.annotation.Transactional[format=annotation] on your test class or method.
|
||||
|
||||
A javadoc:org.springframework.jdbc.core.JdbcTemplate[] is also available if you need that.
|
||||
The following example shows the javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation] annotation in use:
|
||||
The following example shows the javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation] annotation in use:
|
||||
|
||||
include-code::withoutdb/MyRepositoryTests[]
|
||||
|
||||
In-memory embedded databases generally work well for tests, since they are fast and do not require any installation.
|
||||
If, however, you prefer to run tests against a real database you can use the javadoc:org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase[format=annotation] annotation, as shown in the following example:
|
||||
If, however, you prefer to run tests against a real database you can use the javadoc:org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase[format=annotation] annotation, as shown in the following example:
|
||||
|
||||
include-code::withdb/MyRepositoryTests[]
|
||||
|
||||
|
@ -535,12 +535,12 @@ include-code::withdb/MyRepositoryTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-jdbc]]
|
||||
== Auto-configured JDBC Tests
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.jdbc.JdbcTest[format=annotation] is similar to javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation] but is for tests that only require a javadoc:javax.sql.DataSource[] and do not use Spring Data JDBC.
|
||||
javadoc:org.springframework.boot.jdbc.test.autoconfigure.JdbcTest[format=annotation] from the `spring-boot-jdbc-test` module is similar to javadoc:org.springframework.boot.data.jdbc.test.autoconfigure.DataJdbcTest[format=annotation] but is for tests that only require a javadoc:javax.sql.DataSource[] and do not use Spring Data JDBC.
|
||||
By default, it configures an in-memory embedded database and a javadoc:org.springframework.jdbc.core.JdbcTemplate[].
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.jdbc.JdbcTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.jdbc.test.autoconfigure.JdbcTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.test.autoconfigure.jdbc.JdbcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.jdbc.test.autoconfigure.JdbcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
By default, JDBC tests are transactional and roll back at the end of each test.
|
||||
See the {url-spring-framework-docs}/testing/testcontext-framework/tx.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details.
|
||||
|
@ -548,7 +548,7 @@ If that is not what you want, you can disable transaction management for a test
|
|||
|
||||
include-code::MyTransactionalTests[]
|
||||
|
||||
If you prefer your test to run against a real database, you can use the javadoc:org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase[format=annotation] annotation in the same way as for javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation].
|
||||
If you prefer your test to run against a real database, you can use the javadoc:org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase[format=annotation] annotation in the same way as for javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation].
|
||||
(See xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-spring-data-jpa[].)
|
||||
|
||||
|
||||
|
@ -556,18 +556,18 @@ If you prefer your test to run against a real database, you can use the javadoc:
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-jdbc]]
|
||||
== Auto-configured Data JDBC Tests
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest[format=annotation] is similar to javadoc:org.springframework.boot.test.autoconfigure.jdbc.JdbcTest[format=annotation] but is for tests that use Spring Data JDBC repositories.
|
||||
javadoc:org.springframework.boot.data.jdbc.test.autoconfigure.DataJdbcTest[format=annotation] from the `spring-boot-data-jdbc-test` module is similar to javadoc:org.springframework.boot.jdbc.test.autoconfigure.JdbcTest[format=annotation] but is for tests that use Spring Data JDBC repositories.
|
||||
By default, it configures an in-memory embedded database, a javadoc:org.springframework.jdbc.core.JdbcTemplate[], and Spring Data JDBC repositories.
|
||||
Only javadoc:org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration[] subclasses are scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest[format=annotation] annotation is used, regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned.
|
||||
Only javadoc:org.springframework.data.jdbc.repository.config.AbstractJdbcConfiguration[] subclasses are scanned when the javadoc:org.springframework.boot.data.jdbc.test.autoconfigure.DataJdbcTest[format=annotation] annotation is used, regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.data.jdbc.test.autoconfigure.DataJdbcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
By default, Data JDBC tests are transactional and roll back at the end of each test.
|
||||
See the {url-spring-framework-docs}/testing/testcontext-framework/tx.html#testcontext-tx-enabling-transactions[relevant section] in the Spring Framework Reference Documentation for more details.
|
||||
If that is not what you want, you can disable transaction management for a test or for the whole test class as xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-jdbc[shown in the JDBC example].
|
||||
|
||||
If you prefer your test to run against a real database, you can use the javadoc:org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase[format=annotation] annotation in the same way as for javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation].
|
||||
If you prefer your test to run against a real database, you can use the javadoc:org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase[format=annotation] annotation in the same way as for javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation].
|
||||
(See xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-spring-data-jpa[].)
|
||||
|
||||
|
||||
|
@ -575,16 +575,16 @@ If you prefer your test to run against a real database, you can use the javadoc:
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-r2dbc]]
|
||||
== Auto-configured Data R2DBC Tests
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.data.r2dbc.DataR2dbcTest[format=annotation] is similar to javadoc:org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest[format=annotation] but is for tests that use Spring Data R2DBC repositories.
|
||||
javadoc:org.springframework.boot.data.r2dbc.test.autoconfigure.DataR2dbcTest[format=annotation] from the `spring-boot-data-r2dbc-test` module is similar to javadoc:org.springframework.boot.data.jdbc.test.autoconfigure.DataJdbcTest[format=annotation] but is for tests that use Spring Data R2DBC repositories.
|
||||
By default, it configures an in-memory embedded database, an javadoc:org.springframework.data.r2dbc.core.R2dbcEntityTemplate[], and Spring Data R2DBC repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.r2dbc.DataR2dbcTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.r2dbc.test.autoconfigure.DataR2dbcTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.r2dbc.DataR2dbcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.data.r2dbc.test.autoconfigure.DataR2dbcTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
By default, Data R2DBC tests are not transactional.
|
||||
|
||||
If you prefer your test to run against a real database, you can use the javadoc:org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase[format=annotation] annotation in the same way as for javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation].
|
||||
If you prefer your test to run against a real database, you can use the javadoc:org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase[format=annotation] annotation in the same way as for javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation].
|
||||
(See xref:testing/spring-boot-applications.adoc#testing.spring-boot-applications.autoconfigured-spring-data-jpa[].)
|
||||
|
||||
|
||||
|
@ -592,17 +592,17 @@ If you prefer your test to run against a real database, you can use the javadoc:
|
|||
[[testing.spring-boot-applications.autoconfigured-jooq]]
|
||||
== Auto-configured jOOQ Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.jooq.JooqTest[format=annotation] in a similar fashion as javadoc:org.springframework.boot.test.autoconfigure.jdbc.JdbcTest[format=annotation] but for jOOQ-related tests.
|
||||
You can use javadoc:org.springframework.boot.jooq.test.autoconfigure.JooqTest[format=annotation] from `spring-boot-jooq-test` in a similar fashion as javadoc:org.springframework.boot.jdbc.test.autoconfigure.JdbcTest[format=annotation] but for jOOQ-related tests.
|
||||
As jOOQ relies heavily on a Java-based schema that corresponds with the database schema, the existing javadoc:javax.sql.DataSource[] is used.
|
||||
If you want to replace it with an in-memory database, you can use javadoc:org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase[format=annotation] to override those settings.
|
||||
If you want to replace it with an in-memory database, you can use javadoc:org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase[format=annotation] to override those settings.
|
||||
(For more about using jOOQ with Spring Boot, see xref:data/sql.adoc#data.sql.jooq[].)
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.jooq.JooqTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.jooq.test.autoconfigure.JooqTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.test.autoconfigure.jooq.JooqTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configurations that are enabled by javadoc:org.springframework.boot.jooq.test.autoconfigure.JooqTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.jooq.JooqTest[format=annotation] configures a javadoc:org.jooq.DSLContext[].
|
||||
The following example shows the javadoc:org.springframework.boot.test.autoconfigure.jooq.JooqTest[format=annotation] annotation in use:
|
||||
javadoc:org.springframework.boot.jooq.test.autoconfigure.JooqTest[format=annotation] configures a javadoc:org.jooq.DSLContext[].
|
||||
The following example shows the javadoc:org.springframework.boot.jooq.test.autoconfigure.JooqTest[format=annotation] annotation in use:
|
||||
|
||||
include-code::MyJooqTests[]
|
||||
|
||||
|
@ -614,15 +614,15 @@ If that is not what you want, you can disable transaction management for a test
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-mongodb]]
|
||||
== Auto-configured Data MongoDB Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest[format=annotation] to test MongoDB applications.
|
||||
You can use javadoc:org.springframework.boot.data.mongodb.test.autoconfigure.DataMongoTest[format=annotation] from the `spring-boot-data-mongodb-test` module to test MongoDB applications.
|
||||
By default, it configures a javadoc:org.springframework.data.mongodb.core.MongoTemplate[], scans for javadoc:org.springframework.data.mongodb.core.mapping.Document[format=annotation] classes, and configures Spring Data MongoDB repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.mongodb.test.autoconfigure.DataMongoTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
(For more about using MongoDB with Spring Boot, see xref:data/nosql.adoc#data.nosql.mongodb[].)
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.mongodb.test.autoconfigure.DataMongoTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following class shows the javadoc:org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest[format=annotation] annotation in use:
|
||||
The following class shows the javadoc:org.springframework.boot.data.mongodb.test.autoconfigure.DataMongoTest[format=annotation] annotation in use:
|
||||
|
||||
include-code::MyDataMongoDbTests[]
|
||||
|
||||
|
@ -631,13 +631,13 @@ include-code::MyDataMongoDbTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-neo4j]]
|
||||
== Auto-configured Data Neo4j Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest[format=annotation] to test Neo4j applications.
|
||||
You can use javadoc:org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest[format=annotation] from the `spring-boot-data-neo4j-test` module to test Neo4j applications.
|
||||
By default, it scans for javadoc:org.springframework.data.neo4j.core.schema.Node[format=annotation] classes, and configures Spring Data Neo4j repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
(For more about using Neo4J with Spring Boot, see xref:data/nosql.adoc#data.nosql.neo4j[].)
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows a typical setup for using Neo4J tests in Spring Boot:
|
||||
|
||||
|
@ -650,22 +650,22 @@ If that is not what you want, you can disable transaction management for a test
|
|||
include-code::nopropagation/MyDataNeo4jTests[]
|
||||
|
||||
NOTE: Transactional tests are not supported with reactive access.
|
||||
If you are using this style, you must configure javadoc:org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest[format=annotation] tests as described above.
|
||||
If you are using this style, you must configure javadoc:org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest[format=annotation] tests as described above.
|
||||
|
||||
|
||||
|
||||
[[testing.spring-boot-applications.autoconfigured-spring-data-redis]]
|
||||
== Auto-configured Data Redis Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest[format=annotation] to test Redis applications.
|
||||
You can use javadoc:org.springframework.boot.data.redis.test.autoconfigure.DataRedisTest[format=annotation] from the `spring-boot-data-redis-test` module to test Data Redis applications.
|
||||
By default, it scans for javadoc:org.springframework.data.redis.core.RedisHash[format=annotation] classes and configures Spring Data Redis repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.redis.test.autoconfigure.DataRedisTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
(For more about using Redis with Spring Boot, see xref:data/nosql.adoc#data.nosql.redis[].)
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.redis.test.autoconfigure.DataRedisTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows the javadoc:org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest[format=annotation] annotation in use:
|
||||
The following example shows the javadoc:org.springframework.boot.data.redis.test.autoconfigure.DataRedisTest[format=annotation] annotation in use:
|
||||
|
||||
include-code::MyDataRedisTests[]
|
||||
|
||||
|
@ -674,15 +674,15 @@ include-code::MyDataRedisTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-data-ldap]]
|
||||
== Auto-configured Data LDAP Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest[format=annotation] to test LDAP applications.
|
||||
You can use javadoc:org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest[format=annotation] to test Data LDAP applications.
|
||||
By default, it configures an in-memory embedded LDAP (if available), configures an javadoc:org.springframework.ldap.core.LdapTemplate[], scans for javadoc:org.springframework.ldap.odm.annotations.Entry[format=annotation] classes, and configures Spring Data LDAP repositories.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
(For more about using LDAP with Spring Boot, see xref:data/nosql.adoc#data.nosql.ldap[].)
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows the javadoc:org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest[format=annotation] annotation in use:
|
||||
The following example shows the javadoc:org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest[format=annotation] annotation in use:
|
||||
|
||||
include-code::inmemory/MyDataLdapTests[]
|
||||
|
||||
|
@ -696,14 +696,14 @@ include-code::server/MyDataLdapTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-rest-client]]
|
||||
== Auto-configured REST Clients
|
||||
|
||||
You can use the javadoc:org.springframework.boot.test.autoconfigure.web.client.RestClientTest[format=annotation] annotation to test REST clients.
|
||||
You can use the javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation] annotation from the `spring-boot-restclient-test` moule to test REST clients.
|
||||
By default, it auto-configures Jackson, GSON, and Jsonb support, configures a javadoc:org.springframework.boot.web.client.RestTemplateBuilder[] and a javadoc:org.springframework.web.client.RestClient$Builder[], and adds support for javadoc:org.springframework.test.web.client.MockRestServiceServer[].
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.test.autoconfigure.web.client.RestClientTest[format=annotation] annotation is used.
|
||||
Regular javadoc:org.springframework.stereotype.Component[format=annotation] and javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans are not scanned when the javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation] annotation is used.
|
||||
javadoc:org.springframework.boot.context.properties.EnableConfigurationProperties[format=annotation] can be used to include javadoc:org.springframework.boot.context.properties.ConfigurationProperties[format=annotation] beans.
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.web.client.RestClientTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The specific beans that you want to test should be specified by using the `value` or `components` attribute of javadoc:org.springframework.boot.test.autoconfigure.web.client.RestClientTest[format=annotation].
|
||||
The specific beans that you want to test should be specified by using the `value` or `components` attribute of javadoc:org.springframework.boot.restclient.test.autoconfigure.RestClientTest[format=annotation].
|
||||
|
||||
When using a javadoc:org.springframework.boot.web.client.RestTemplateBuilder[] in the beans under test and `RestTemplateBuilder.rootUri(String rootUri)` has been called when building the javadoc:org.springframework.web.client.RestTemplate[], then the root URI should be omitted from the javadoc:org.springframework.test.web.client.MockRestServiceServer[] expectations as shown in the following example:
|
||||
|
||||
|
@ -718,10 +718,10 @@ include-code::MyRestClientServiceTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-restdocs]]
|
||||
== Auto-configured Spring REST Docs Tests
|
||||
|
||||
You can use the javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation] annotation to use {url-spring-restdocs-site}[Spring REST Docs] in your tests with Mock MVC, REST Assured, or WebTestClient.
|
||||
You can use the javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation] annotation from the `spring-boot-restdocs- module to use {url-spring-restdocs-site}[Spring REST Docs] in your tests with Mock MVC, REST Assured, or WebTestClient.
|
||||
It removes the need for the JUnit extension in Spring REST Docs.
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation] can be used to override the default output directory (`target/generated-snippets` if you are using Maven or `build/generated-snippets` if you are using Gradle).
|
||||
javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation] can be used to override the default output directory (`target/generated-snippets` if you are using Maven or `build/generated-snippets` if you are using Gradle).
|
||||
It can also be used to configure the host, scheme, and port that appears in any documented URIs.
|
||||
|
||||
|
||||
|
@ -729,7 +729,7 @@ It can also be used to configure the host, scheme, and port that appears in any
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-restdocs.with-mock-mvc]]
|
||||
=== Auto-configured Spring REST Docs Tests With Mock MVC
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation] customizes the javadoc:org.springframework.test.web.servlet.MockMvc[] bean to use Spring REST Docs when testing servlet-based web applications.
|
||||
javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation] customizes the javadoc:org.springframework.test.web.servlet.MockMvc[] bean to use Spring REST Docs when testing servlet-based web applications.
|
||||
You can inject it by using javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation] and use it in your tests as you normally would when using Mock MVC and Spring REST Docs, as shown in the following example:
|
||||
|
||||
include-code::hamcrest/MyUserDocumentationTests[]
|
||||
|
@ -740,7 +740,7 @@ include-code::assertj/MyUserDocumentationTests[]
|
|||
|
||||
Both reuses the same javadoc:org.springframework.test.web.servlet.MockMvc[] instance behind the scenes so any configuration to it applies to both.
|
||||
|
||||
If you require more control over Spring REST Docs configuration than offered by the attributes of javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation], you can use a javadoc:org.springframework.boot.test.autoconfigure.restdocs.RestDocsMockMvcConfigurationCustomizer[] bean, as shown in the following example:
|
||||
If you require more control over Spring REST Docs configuration than offered by the attributes of javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation], you can use a javadoc:org.springframework.boot.restdocs.test.autoconfigure.RestDocsMockMvcConfigurationCustomizer[] bean, as shown in the following example:
|
||||
|
||||
include-code::MyRestDocsConfiguration[]
|
||||
|
||||
|
@ -755,12 +755,12 @@ include-code::MyResultHandlerConfiguration[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-restdocs.with-web-test-client]]
|
||||
=== Auto-configured Spring REST Docs Tests With WebTestClient
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation] can also be used with javadoc:org.springframework.test.web.reactive.server.WebTestClient[] when testing reactive web applications.
|
||||
You can inject it by using javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation] and use it in your tests as you normally would when using javadoc:org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest[format=annotation] and Spring REST Docs, as shown in the following example:
|
||||
javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation] can also be used with javadoc:org.springframework.test.web.reactive.server.WebTestClient[] when testing reactive web applications.
|
||||
You can inject it by using javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation] and use it in your tests as you normally would when using javadoc:org.springframework.boot.webflux.test.autoconfigure.WebFluxTest[format=annotation] and Spring REST Docs, as shown in the following example:
|
||||
|
||||
include-code::MyUsersDocumentationTests[]
|
||||
|
||||
If you require more control over Spring REST Docs configuration than offered by the attributes of javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation], you can use a javadoc:org.springframework.boot.test.autoconfigure.restdocs.RestDocsWebTestClientConfigurationCustomizer[] bean, as shown in the following example:
|
||||
If you require more control over Spring REST Docs configuration than offered by the attributes of javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation], you can use a javadoc:org.springframework.boot.restdocs.test.autoconfigure.RestDocsWebTestClientConfigurationCustomizer[] bean, as shown in the following example:
|
||||
|
||||
include-code::MyRestDocsConfiguration[]
|
||||
|
||||
|
@ -774,12 +774,12 @@ include-code::MyWebTestClientBuilderCustomizerConfiguration[]
|
|||
[[testing.spring-boot-applications.autoconfigured-spring-restdocs.with-rest-assured]]
|
||||
=== Auto-configured Spring REST Docs Tests With REST Assured
|
||||
|
||||
javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation] makes a javadoc:io.restassured.specification.RequestSpecification[] bean, preconfigured to use Spring REST Docs, available to your tests.
|
||||
javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation] makes a javadoc:io.restassured.specification.RequestSpecification[] bean, preconfigured to use Spring REST Docs, available to your tests.
|
||||
You can inject it by using javadoc:org.springframework.beans.factory.annotation.Autowired[format=annotation] and use it in your tests as you normally would when using REST Assured and Spring REST Docs, as shown in the following example:
|
||||
|
||||
include-code::MyUserDocumentationTests[]
|
||||
|
||||
If you require more control over Spring REST Docs configuration than offered by the attributes of javadoc:org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs[format=annotation], a javadoc:org.springframework.boot.test.autoconfigure.restdocs.RestDocsRestAssuredConfigurationCustomizer[] bean can be used, as shown in the following example:
|
||||
If you require more control over Spring REST Docs configuration than offered by the attributes of javadoc:org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs[format=annotation], a javadoc:org.springframework.boot.restdocs.test.autoconfigure.RestDocsRestAssuredConfigurationCustomizer[] bean can be used, as shown in the following example:
|
||||
|
||||
include-code::MyRestDocsConfiguration[]
|
||||
|
||||
|
@ -793,14 +793,14 @@ include-code::MyRestDocsConfiguration[]
|
|||
[[testing.spring-boot-applications.autoconfigured-webservices.client]]
|
||||
=== Auto-configured Spring Web Services Client Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.webservices.client.WebServiceClientTest[format=annotation] to test applications that call web services using the Spring Web Services project.
|
||||
You can use javadoc:org.springframework.boot.webservices.test.autoconfigure.client.WebServiceClientTest[format=annotation] from the `spring-boot-webservices-test` module to test applications that call web services using the Spring Web Services project.
|
||||
By default, it configures a javadoc:org.springframework.ws.test.client.MockWebServiceServer[] bean and automatically customizes your javadoc:org.springframework.boot.webservices.client.WebServiceTemplateBuilder[].
|
||||
(For more about using Web Services with Spring Boot, see xref:io/webservices.adoc[].)
|
||||
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.webservices.client.WebServiceClientTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.webservices.test.autoconfigure.client.WebServiceClientTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows the javadoc:org.springframework.boot.test.autoconfigure.webservices.client.WebServiceClientTest[format=annotation] annotation in use:
|
||||
The following example shows the javadoc:org.springframework.boot.webservices.test.autoconfigure.client.WebServiceClientTest[format=annotation] annotation in use:
|
||||
|
||||
include-code::MyWebServiceClientTests[]
|
||||
|
||||
|
@ -809,14 +809,14 @@ include-code::MyWebServiceClientTests[]
|
|||
[[testing.spring-boot-applications.autoconfigured-webservices.server]]
|
||||
=== Auto-configured Spring Web Services Server Tests
|
||||
|
||||
You can use javadoc:org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest[format=annotation] to test applications that implement web services using the Spring Web Services project.
|
||||
You can use javadoc:org.springframework.boot.webservices.test.autoconfigure.server.WebServiceServerTest[format=annotation] from the `spring-boot-webservices-test` module to test applications that implement web services using the Spring Web Services project.
|
||||
By default, it configures a javadoc:org.springframework.ws.test.server.MockWebServiceClient[] bean that can be used to call your web service endpoints.
|
||||
(For more about using Web Services with Spring Boot, see xref:io/webservices.adoc[].)
|
||||
|
||||
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
TIP: A list of the auto-configuration settings that are enabled by javadoc:org.springframework.boot.webservices.test.autoconfigure.server.WebServiceServerTest[format=annotation] can be xref:appendix:test-auto-configuration/index.adoc[found in the appendix].
|
||||
|
||||
The following example shows the javadoc:org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest[format=annotation] annotation in use:
|
||||
The following example shows the javadoc:org.springframework.boot.webservices.test.autoconfigure.server.WebServiceServerTest[format=annotation] annotation in use:
|
||||
|
||||
include-code::MyWebServiceServerTests[]
|
||||
|
||||
|
@ -834,13 +834,13 @@ NOTE: Make sure to not use the regular javadoc:org.springframework.context.annot
|
|||
|
||||
Alternatively, additional auto-configurations can be added for any use of a slice annotation by registering them in a file stored in `META-INF/spring` as shown in the following example:
|
||||
|
||||
.META-INF/spring/org.springframework.boot.test.autoconfigure.jdbc.JdbcTest.imports
|
||||
.META-INF/spring/org.springframework.boot.jdbc.test.autoconfigure.JdbcTest.imports
|
||||
[source]
|
||||
----
|
||||
com.example.IntegrationAutoConfiguration
|
||||
----
|
||||
|
||||
In this example, the `+com.example.IntegrationAutoConfiguration+` is enabled on every test annotated with javadoc:org.springframework.boot.test.autoconfigure.jdbc.JdbcTest[format=annotation].
|
||||
In this example, the `+com.example.IntegrationAutoConfiguration+` is enabled on every test annotated with javadoc:org.springframework.boot.jdbc.test.autoconfigure.JdbcTest[format=annotation].
|
||||
|
||||
TIP: You can use comments with `#` in this file.
|
||||
|
||||
|
@ -870,7 +870,7 @@ The latter approach lets you enable it in one of your tests, if necessary, with
|
|||
See xref:how-to:testing.adoc#howto.testing.slice-tests[this how-to section] for more details on when you might want to enable specific javadoc:org.springframework.context.annotation.Configuration[format=annotation] classes for slice tests.
|
||||
|
||||
Test slices exclude javadoc:org.springframework.context.annotation.Configuration[format=annotation] classes from scanning.
|
||||
For example, for a javadoc:org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest[format=annotation], the following configuration will not include the given javadoc:org.springframework.web.servlet.config.annotation.WebMvcConfigurer[] bean in the application context loaded by the test slice:
|
||||
For example, for a javadoc:org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest[format=annotation], the following configuration will not include the given javadoc:org.springframework.web.servlet.config.annotation.WebMvcConfigurer[] bean in the application context loaded by the test slice:
|
||||
|
||||
include-code::MyWebConfiguration[]
|
||||
|
||||
|
@ -885,7 +885,7 @@ Your application may resemble the following code:
|
|||
include-code::scan/MyApplication[]
|
||||
|
||||
Doing so effectively overrides the default component scan directive with the side effect of scanning those two packages regardless of the slice that you chose.
|
||||
For instance, a javadoc:org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest[format=annotation] seems to suddenly scan components and user configurations of your application.
|
||||
For instance, a javadoc:org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest[format=annotation] seems to suddenly scan components and user configurations of your application.
|
||||
Again, moving the custom directive to a separate class is a good way to fix this issue.
|
||||
|
||||
TIP: If this is not an option for you, you can create a javadoc:org.springframework.boot.SpringBootConfiguration[format=annotation] somewhere in the hierarchy of your test so that it is used instead.
|
||||
|
|
|
@ -0,0 +1,82 @@
|
|||
[[testing.test-modules]]
|
||||
= Test Modules
|
||||
|
||||
Spring Boot offers several focused, feature-specific `-test` modules:
|
||||
|
||||
[cols="1,3"]
|
||||
|===
|
||||
|Module | Purpose
|
||||
|
||||
|`spring-boot-cache-test`
|
||||
|Testing applications that use Spring Framework's cache abstration.
|
||||
|
||||
|`spring-boot-data-cassandra-test`
|
||||
|Testing applications that use Spring Data Cassandra. Provides the `@DataCassandraTest` test slice.
|
||||
|
||||
|`spring-boot-data-couchbase-test`
|
||||
|Testing applications that use Spring Data Couchbase. Provides the `@DataCouchbaseTest` test slice.
|
||||
|
||||
|`spring-boot-data-elasticsearch-test`
|
||||
|Testing applications that use Spring Data Elasticsearch. Provides the `@DataElasticsearchTest` test slice.
|
||||
|
||||
|`spring-boot-data-jdbc-test`
|
||||
|Testing applications that use Spring Data JDBC. Provides the `@DataJdbcTest` test slice.
|
||||
|
||||
|`spring-boot-data-jpa-test`
|
||||
|Testing applications that use Spring Data JPA. Provides the `@DataJpaTest` test slice.
|
||||
|
||||
|`spring-boot-data-ldap-test`
|
||||
|Testing applications that use Spring Data LDAP. Provides the `@DataLdapTest` test slice.
|
||||
|
||||
|`spring-boot-mongodb-test`
|
||||
|Testing applications that use Spring Data MongoDB. Provides the `@DataMongoTest` test slice.
|
||||
|
||||
|`spring-boot-data-neo4j-test`
|
||||
|Testing applications that use Spring Data JPA. Provides the `@DataNeo4jTest` test slice.
|
||||
|
||||
|`spring-boot-data-r2dbc-test`
|
||||
|Testing applications that use Spring Data R2DBC. Provides the `@DataR2dbcTest` test slice.
|
||||
|
||||
|`spring-boot-data-redis-test`
|
||||
|Testing applications that use Spring Data Redis. Provides the `@DataRedisTest` test slice.
|
||||
|
||||
|`spring-boot-graphql-test`
|
||||
|Testing applications that use Spring GraphQL. Provides the `@GraphQlTest` test slice.
|
||||
|
||||
|`spring-boot-jdbc-test`
|
||||
|Testing applications that using Spring JDBC. Provides the `@JdbcTest` test slice.
|
||||
|
||||
|`spring-boot-jooq-test`
|
||||
|Testing applications that using jOOQ. Provides the `@JooqTest` test slice.
|
||||
|
||||
|`spring-boot-jpa-test`
|
||||
|Testing applications that use JPA.
|
||||
|
||||
|`spring-boot-json-test`
|
||||
|Testing applications that use JSON. Provides the `@JsonTest` test slice.
|
||||
|
||||
|`spring-boot-micrometer-metrics-test`
|
||||
|Testing applications that use Micrometer Metrics.
|
||||
|
||||
|`spring-boot-micrometer-tracing-test`
|
||||
|Testing applications that use Micrometer Tracing.
|
||||
|
||||
|`spring-boot-restclient-test`
|
||||
|Testing applications that use REST clients. Provides the `@RestClientTest` test slice.
|
||||
|
||||
|`spring-boot-security-test`
|
||||
|Testing applications that use Spring Security.
|
||||
|
||||
|`spring-boot-web-server-test`
|
||||
|Testing applications that use an embedded web server.
|
||||
|
||||
|`spring-boot-webflux-test`
|
||||
|Testing applications that use Spring WebFlux. Provides the `@WebFluxTest` test slice.
|
||||
|
||||
|`spring-boot-webmvc-test`
|
||||
|Testing applications that use Spring Web MVC. Provides the `@WebMvcTest` test slice.
|
||||
|
||||
|`spring-boot-webservices-test`
|
||||
|Testing applications that use Spring Web Services. Provides the `@WebServiceClientTest` and `@WebServiceServerTest` test slices.
|
||||
|
||||
|===
|
|
@ -57,6 +57,7 @@
|
|||
*** xref:reference:messaging/websockets.adoc[]
|
||||
|
||||
** xref:reference:testing/index.adoc[]
|
||||
*** xref:reference:testing/test-modules.adoc[]
|
||||
*** xref:reference:testing/test-scope-dependencies.adoc[]
|
||||
*** xref:reference:testing/spring-applications.adoc[]
|
||||
*** xref:reference:testing/spring-boot-applications.adoc[]
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.howto.testing.withspringsecurity;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.security.test.context.support.WithMockUser;
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester;
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.springframework.boot.docs.testing.springbootapplications.additionala
|
|||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
|
||||
import org.springframework.boot.integration.autoconfigure.IntegrationAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
|
||||
import org.springframework.boot.jdbc.test.autoconfigure.JdbcTest;
|
||||
|
||||
@JdbcTest
|
||||
@ImportAutoConfiguration(IntegrationAutoConfiguration.class)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredjdbc;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest;
|
||||
import org.springframework.boot.jdbc.test.autoconfigure.JdbcTest;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.jooq.DSLContext;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.jooq.JooqTest;
|
||||
import org.springframework.boot.jooq.test.autoconfigure.JooqTest;
|
||||
|
||||
@JooqTest
|
||||
class MyJooqTests {
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest;
|
||||
import org.springframework.boot.restclient.test.autoconfigure.RestClientTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest;
|
||||
import org.springframework.boot.restclient.test.autoconfigure.RestClientTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.client.MockRestServiceServer;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatacassandra;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest;
|
||||
import org.springframework.boot.data.cassandra.test.autoconfigure.DataCassandraTest;
|
||||
|
||||
@DataCassandraTest
|
||||
class MyDataCassandraTests {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatacouchbase;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest;
|
||||
import org.springframework.boot.data.couchbase.test.autoconfigure.DataCouchbaseTest;
|
||||
|
||||
@DataCouchbaseTest
|
||||
class MyDataCouchbaseTests {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataelasticsearch;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
|
||||
import org.springframework.boot.data.elasticsearch.test.autoconfigure.DataElasticsearchTest;
|
||||
|
||||
@DataElasticsearchTest
|
||||
class MyDataElasticsearchTests {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatajpa;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatajpa.withdb;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
|
||||
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase;
|
||||
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase.Replace;
|
||||
|
||||
@DataJpaTest
|
||||
@AutoConfigureTestDatabase(replace = Replace.NONE)
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
|
||||
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest;
|
||||
import org.springframework.boot.jpa.test.autoconfigure.TestEntityManager;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataldap.inmemory;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest;
|
||||
import org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest;
|
||||
import org.springframework.ldap.core.LdapTemplate;
|
||||
|
||||
@DataLdapTest
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataldap.server;
|
||||
|
||||
import org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest;
|
||||
import org.springframework.boot.ldap.autoconfigure.embedded.EmbeddedLdapAutoConfiguration;
|
||||
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest;
|
||||
|
||||
@DataLdapTest(excludeAutoConfiguration = EmbeddedLdapAutoConfiguration.class)
|
||||
class MyDataLdapTests {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatamongodb;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
|
||||
import org.springframework.boot.data.mongodb.test.autoconfigure.DataMongoTest;
|
||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||
|
||||
@DataMongoTest
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataneo4j.nopropagation;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest;
|
||||
import org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest;
|
||||
import org.springframework.transaction.annotation.Propagation;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataneo4j.propagation;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest;
|
||||
import org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest;
|
||||
|
||||
@DataNeo4jTest
|
||||
class MyDataNeo4jTests {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataredis;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest;
|
||||
import org.springframework.boot.data.redis.test.autoconfigure.DataRedisTest;
|
||||
|
||||
@DataRedisTest
|
||||
class MyDataRedisTests {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringrestdocs.withmockmvc;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsMockMvcConfigurationCustomizer;
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsMockMvcConfigurationCustomizer;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester;
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringrestdocs.withrestassured;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsRestAssuredConfigurationCustomizer;
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsRestAssuredConfigurationCustomizer;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.restdocs.restassured.RestAssuredRestDocumentationConfigurer;
|
||||
import org.springframework.restdocs.templates.TemplateFormats;
|
||||
|
|
|
@ -20,7 +20,7 @@ import io.restassured.specification.RequestSpecification;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
import org.springframework.boot.web.server.test.LocalServerPort;
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringrestdocs.withwebtestclient;
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsWebTestClientConfigurationCustomizer;
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsWebTestClientConfigurationCustomizer;
|
||||
import org.springframework.boot.test.context.TestConfiguration;
|
||||
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer;
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs;
|
||||
import org.springframework.boot.webflux.test.autoconfigure.WebFluxTest;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.document;
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.webservices.client.WebServiceClientTest;
|
||||
import org.springframework.boot.webservices.test.autoconfigure.client.WebServiceClientTest;
|
||||
import org.springframework.ws.test.client.MockWebServiceServer;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest;
|
||||
import org.springframework.boot.webservices.test.autoconfigure.server.WebServiceServerTest;
|
||||
import org.springframework.ws.test.server.MockWebServiceClient;
|
||||
import org.springframework.ws.test.server.RequestCreators;
|
||||
import org.springframework.ws.test.server.ResponseMatchers;
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.jsontests;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.json.JsonTest;
|
||||
import org.springframework.boot.json.test.autoconfigure.JsonTest;
|
||||
import org.springframework.boot.test.json.JacksonTester;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.jsontests;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.json.JsonTest;
|
||||
import org.springframework.boot.json.test.autoconfigure.JsonTest;
|
||||
import org.springframework.boot.test.json.JacksonTester;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.springgraph
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester;
|
||||
import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester;
|
||||
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
|
|||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.docs.web.graphql.runtimewiring.GreetingController;
|
||||
import org.springframework.boot.test.autoconfigure.graphql.GraphQlTest;
|
||||
import org.springframework.boot.graphql.test.autoconfigure.GraphQlTest;
|
||||
import org.springframework.graphql.test.tester.GraphQlTester;
|
||||
|
||||
@GraphQlTest(GreetingController.class)
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.springmvcte
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester;
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.htmlunit.html.HtmlPage;
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.springwebfl
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest;
|
||||
import org.springframework.boot.webflux.test.autoconfigure.WebFluxTest;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.withmockenv
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester;
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.withmockenv
|
|||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebTestClient;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
@SpringBootTest
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.testcontainers.junit.jupiter.Container;
|
|||
import org.testcontainers.junit.jupiter.Testcontainers;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest;
|
||||
import org.springframework.boot.data.elasticsearch.test.autoconfigure.DataElasticsearchTest;
|
||||
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
|
||||
import org.springframework.boot.testcontainers.service.connection.Ssl;
|
||||
import org.springframework.data.elasticsearch.client.elc.ElasticsearchTemplate;
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.howto.testing.withspringsecurity
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest
|
||||
import org.springframework.security.test.context.support.WithMockUser
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.springframework.boot.docs.testing.springbootapplications.additionala
|
|||
|
||||
import org.springframework.boot.autoconfigure.ImportAutoConfiguration
|
||||
import org.springframework.boot.integration.autoconfigure.IntegrationAutoConfiguration
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest
|
||||
import org.springframework.boot.jdbc.test.autoconfigure.JdbcTest
|
||||
|
||||
@JdbcTest
|
||||
@ImportAutoConfiguration(IntegrationAutoConfiguration::class)
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredjdbc
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest
|
||||
import org.springframework.boot.jdbc.test.autoconfigure.JdbcTest
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
|
||||
import org.jooq.DSLContext
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.jooq.JooqTest
|
||||
import org.springframework.boot.jooq.test.autoconfigure.JooqTest
|
||||
|
||||
@JooqTest
|
||||
class MyJooqTests(@Autowired val dslContext: DSLContext) {
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest
|
||||
import org.springframework.boot.restclient.test.autoconfigure.RestClientTest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.test.web.client.MockRestServiceServer
|
||||
import org.springframework.test.web.client.match.MockRestRequestMatchers
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.client.RestClientTest
|
||||
import org.springframework.boot.restclient.test.autoconfigure.RestClientTest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.test.web.client.MockRestServiceServer
|
||||
import org.springframework.test.web.client.match.MockRestRequestMatchers
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatacassandra
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.data.cassandra.DataCassandraTest
|
||||
import org.springframework.boot.data.cassandra.test.autoconfigure.DataCassandraTest
|
||||
|
||||
@DataCassandraTest
|
||||
class MyDataCassandraTests(@Autowired val repository: SomeRepository)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatacouchbase
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest
|
||||
import org.springframework.boot.data.couchbase.test.autoconfigure.DataCouchbaseTest
|
||||
|
||||
@DataCouchbaseTest
|
||||
class MyDataCouchbaseTests(@Autowired val repository: SomeRepository) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataelasticsearch
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.data.elasticsearch.DataElasticsearchTest
|
||||
import org.springframework.boot.data.elasticsearch.test.autoconfigure.DataElasticsearchTest
|
||||
|
||||
@DataElasticsearchTest
|
||||
class MyDataElasticsearchTests(@Autowired val repository: SomeRepository) {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatajpa
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
|
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatajpa.withdb
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||
import org.springframework.boot.jdbc.test.autoconfigure.AutoConfigureTestDatabase
|
||||
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest
|
||||
|
||||
@DataJpaTest
|
||||
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
|
||||
import org.springframework.boot.data.jpa.test.autoconfigure.DataJpaTest
|
||||
import org.springframework.boot.jpa.test.autoconfigure.TestEntityManager
|
||||
|
||||
@DataJpaTest
|
||||
class MyRepositoryTests(@Autowired val entityManager: TestEntityManager, @Autowired val repository: UserRepository) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataldap.inmemory
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest
|
||||
import org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest
|
||||
import org.springframework.ldap.core.LdapTemplate
|
||||
|
||||
@DataLdapTest
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataldap.server
|
||||
|
||||
import org.springframework.boot.ldap.autoconfigure.embedded.EmbeddedLdapAutoConfiguration
|
||||
import org.springframework.boot.test.autoconfigure.data.ldap.DataLdapTest
|
||||
import org.springframework.boot.data.ldap.test.autoconfigure.DataLdapTest
|
||||
|
||||
@DataLdapTest(excludeAutoConfiguration = [EmbeddedLdapAutoConfiguration::class])
|
||||
class MyDataLdapTests {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdatamongodb
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest
|
||||
import org.springframework.boot.data.mongodb.test.autoconfigure.DataMongoTest
|
||||
import org.springframework.data.mongodb.core.MongoTemplate
|
||||
|
||||
@DataMongoTest
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataneo4j.nopropagation
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest
|
||||
import org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest
|
||||
import org.springframework.transaction.annotation.Propagation
|
||||
import org.springframework.transaction.annotation.Transactional
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataneo4j.propagation
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.data.neo4j.DataNeo4jTest
|
||||
import org.springframework.boot.data.neo4j.test.autoconfigure.DataNeo4jTest
|
||||
|
||||
@DataNeo4jTest
|
||||
class MyDataNeo4jTests(@Autowired val repository: SomeRepository) {
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringdataredis
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.data.redis.DataRedisTest
|
||||
import org.springframework.boot.data.redis.test.autoconfigure.DataRedisTest
|
||||
|
||||
@DataRedisTest
|
||||
class MyDataRedisTests(@Autowired val repository: SomeRepository) {
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringrestdocs.withmockmvc
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsMockMvcConfigurationCustomizer
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsMockMvcConfigurationCustomizer
|
||||
import org.springframework.boot.test.context.TestConfiguration
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentationConfigurer
|
||||
import org.springframework.restdocs.templates.TemplateFormats
|
||||
|
|
|
@ -19,8 +19,8 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringrestdocs.withrestassured
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsRestAssuredConfigurationCustomizer
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsRestAssuredConfigurationCustomizer
|
||||
import org.springframework.boot.test.context.TestConfiguration
|
||||
import org.springframework.restdocs.restassured.RestAssuredRestDocumentationConfigurer
|
||||
import org.springframework.restdocs.templates.TemplateFormats
|
||||
|
|
|
@ -21,7 +21,7 @@ import io.restassured.specification.RequestSpecification
|
|||
import org.hamcrest.Matchers
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment
|
||||
import org.springframework.boot.web.server.test.LocalServerPort
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
package org.springframework.boot.docs.testing.springbootapplications.autoconfiguredspringrestdocs.withwebtestclient
|
||||
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.RestDocsWebTestClientConfigurationCustomizer
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.RestDocsWebTestClientConfigurationCustomizer
|
||||
import org.springframework.boot.test.context.TestConfiguration
|
||||
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentationConfigurer
|
||||
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
|
||||
import org.springframework.boot.restdocs.test.autoconfigure.AutoConfigureRestDocs
|
||||
import org.springframework.boot.webflux.test.autoconfigure.WebFluxTest
|
||||
import org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.webservices.client.WebServiceClientTest
|
||||
import org.springframework.boot.webservices.test.autoconfigure.client.WebServiceClientTest
|
||||
import org.springframework.ws.test.client.MockWebServiceServer
|
||||
import org.springframework.ws.test.client.RequestMatchers
|
||||
import org.springframework.ws.test.client.ResponseCreators
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.springframework.boot.docs.testing.springbootapplications.autoconfigu
|
|||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.webservices.server.WebServiceServerTest
|
||||
import org.springframework.boot.webservices.test.autoconfigure.server.WebServiceServerTest
|
||||
import org.springframework.ws.test.server.MockWebServiceClient
|
||||
import org.springframework.ws.test.server.RequestCreators
|
||||
import org.springframework.ws.test.server.ResponseMatchers
|
||||
|
|
|
@ -21,7 +21,7 @@ import org.assertj.core.api.Assertions.within
|
|||
import org.assertj.core.api.ThrowingConsumer
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.json.JsonTest
|
||||
import org.springframework.boot.json.test.autoconfigure.JsonTest
|
||||
import org.springframework.boot.test.json.JacksonTester
|
||||
|
||||
@JsonTest
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.jsontests
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.json.JsonTest
|
||||
import org.springframework.boot.json.test.autoconfigure.JsonTest
|
||||
import org.springframework.boot.test.json.JacksonTester
|
||||
|
||||
@JsonTest
|
||||
|
|
|
@ -18,7 +18,7 @@ package org.springframework.boot.docs.testing.springbootapplications.springgraph
|
|||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.graphql.tester.AutoConfigureHttpGraphQlTester
|
||||
import org.springframework.boot.graphql.test.autoconfigure.tester.AutoConfigureHttpGraphQlTester
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.graphql.test.tester.HttpGraphQlTester
|
||||
import org.springframework.http.HttpHeaders
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.springgraph
|
|||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.docs.web.graphql.runtimewiring.GreetingController
|
||||
import org.springframework.boot.test.autoconfigure.graphql.GraphQlTest
|
||||
import org.springframework.boot.graphql.test.autoconfigure.GraphQlTest
|
||||
import org.springframework.graphql.test.tester.GraphQlTester
|
||||
|
||||
@GraphQlTest(GreetingController::class)
|
||||
|
|
|
@ -20,7 +20,7 @@ import org.assertj.core.api.Assertions.assertThat
|
|||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.BDDMockito.given
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||
import org.springframework.test.web.servlet.assertj.MockMvcTester
|
||||
|
|
|
@ -22,7 +22,7 @@ import org.htmlunit.html.HtmlPage
|
|||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.BDDMockito.given
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.WebMvcTest
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||
|
||||
@WebMvcTest(UserVehicleController::class)
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.springwebfl
|
|||
import org.junit.jupiter.api.Test
|
||||
import org.mockito.BDDMockito.given
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.WebFluxTest
|
||||
import org.springframework.boot.webflux.test.autoconfigure.WebFluxTest
|
||||
import org.springframework.http.MediaType
|
||||
import org.springframework.test.context.bean.override.mockito.MockitoBean
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
|
|
|
@ -19,7 +19,7 @@ package org.springframework.boot.docs.testing.springbootapplications.withmockenv
|
|||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
|
||||
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
import org.springframework.test.web.reactive.server.expectBody
|
||||
|
|
|
@ -18,8 +18,8 @@ package org.springframework.boot.docs.testing.springbootapplications.withmockenv
|
|||
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.springframework.beans.factory.annotation.Autowired
|
||||
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
import org.springframework.boot.webflux.test.autoconfigure.AutoConfigureWebTestClient
|
||||
import org.springframework.test.web.reactive.server.WebTestClient
|
||||
import org.springframework.test.web.reactive.server.expectBody
|
||||
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* Copyright 2012-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License);
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
id "org.springframework.boot.deployed"
|
||||
id "org.springframework.boot.optional-dependencies"
|
||||
id "org.springframework.boot.test-auto-configuration"
|
||||
}
|
||||
|
||||
description = "Spring Boot Cache Test"
|
||||
|
||||
dependencies {
|
||||
api(project(":module:spring-boot-cache"))
|
||||
|
||||
implementation(project(":core:spring-boot-test"))
|
||||
|
||||
optional(project(":module:spring-boot-test-autoconfigure"))
|
||||
|
||||
testImplementation(project(":test-support:spring-boot-test-support"))
|
||||
|
||||
testRuntimeOnly("ch.qos.logback:logback-classic")
|
||||
}
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.core;
|
||||
package org.springframework.boot.cache.test.autoconfigure;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
|
@ -35,7 +35,7 @@ import org.springframework.cache.support.NoOpCacheManager;
|
|||
* {@link NoOpCacheManager}.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @since 1.4.0
|
||||
* @since 4.0.0
|
||||
*/
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
|
@ -0,0 +1,23 @@
|
|||
/*
|
||||
* Copyright 2012-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for testing code that uses the cache abstraction.
|
||||
*/
|
||||
@NullMarked
|
||||
package org.springframework.boot.cache.test.autoconfigure;
|
||||
|
||||
import org.jspecify.annotations.NullMarked;
|
|
@ -0,0 +1 @@
|
|||
org.springframework.boot.cache.autoconfigure.CacheAutoConfiguration
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.core;
|
||||
package org.springframework.boot.cache.test.autoconfigure;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.test.autoconfigure.core;
|
||||
package org.springframework.boot.cache.test.autoconfigure;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright 2012-present the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the License);
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id "java-library"
|
||||
id "org.springframework.boot.deployed"
|
||||
id "org.springframework.boot.docker-test"
|
||||
id "org.springframework.boot.optional-dependencies"
|
||||
id "org.springframework.boot.test-slice"
|
||||
}
|
||||
|
||||
description = "Spring Boot Data Cassandra Test"
|
||||
|
||||
dependencies {
|
||||
api(project(":module:spring-boot-data-cassandra"))
|
||||
|
||||
implementation(project(":core:spring-boot-test"))
|
||||
|
||||
optional(project(":core:spring-boot-testcontainers"))
|
||||
optional(project(":module:spring-boot-test-autoconfigure"))
|
||||
optional("org.junit.jupiter:junit-jupiter-api")
|
||||
|
||||
dockerTestImplementation(project(":core:spring-boot-testcontainers"))
|
||||
dockerTestImplementation(project(":test-support:spring-boot-docker-test-support"))
|
||||
dockerTestImplementation(testFixtures(project(":core:spring-boot-autoconfigure")))
|
||||
dockerTestImplementation("org.assertj:assertj-core")
|
||||
dockerTestImplementation("org.junit.jupiter:junit-jupiter")
|
||||
dockerTestImplementation("org.testcontainers:cassandra")
|
||||
dockerTestImplementation("org.testcontainers:junit-jupiter")
|
||||
dockerTestImplementation("org.testcontainers:testcontainers")
|
||||
|
||||
testImplementation(project(":test-support:spring-boot-test-support"))
|
||||
|
||||
testRuntimeOnly("ch.qos.logback:logback-classic")
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue