Rework the samples to avoid depending on Spring Boot

Closes gh-711
This commit is contained in:
Andy Wilkinson
2021-09-28 18:11:14 +01:00
parent 4223f70102
commit be0528bdcb
31 changed files with 505 additions and 268 deletions

View File

@@ -2,11 +2,8 @@ plugins {
id "eclipse"
id "java"
id "org.asciidoctor.jvm.convert" version "3.3.2"
id "org.springframework.boot" version "2.4.7"
}
apply plugin: 'io.spring.dependency-management'
repositories {
mavenLocal()
maven { url 'https://repo.spring.io/milestone' }
@@ -20,26 +17,23 @@ sourceCompatibility = 17
targetCompatibility = 17
ext {
restdocsVersion = '3.0.0-SNAPSHOT'
snippetsDir = file('build/generated-snippets')
}
ext['spring-restdocs.version'] = '3.0.0-SNAPSHOT'
configurations {
asciidoctorExtensions
}
dependencies {
asciidoctorExtensions 'org.springframework.restdocs:spring-restdocs-asciidoctor'
asciidoctorExtensions "org.springframework.restdocs:spring-restdocs-asciidoctor:$restdocsVersion"
implementation 'org.springframework.boot:spring-boot-starter-web'
testImplementation('org.springframework.boot:spring-boot-starter-test') {
exclude group: 'junit', module: 'junit;'
}
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
testImplementation 'org.junit.jupiter:junit-jupiter-api'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
implementation 'org.springframework:spring-webmvc:6.0.0-SNAPSHOT'
testImplementation "org.springframework.restdocs:spring-restdocs-mockmvc:$restdocsVersion"
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.0'
}
test {
@@ -53,12 +47,9 @@ asciidoctor {
dependsOn test
}
bootJar {
jar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
eclipseJdt.onlyIf { false }
cleanEclipseJdt.onlyIf { false }

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2017 the original author or authors.
* Copyright 2014-2021 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.
@@ -16,18 +16,13 @@
package com.example.junit5;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@Configuration
public class SampleJUnit5Application {
public static void main(String[] args) {
new SpringApplication(SampleJUnit5Application.class).run(args);
}
@RestController
private static class SampleController {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2018 the original author or authors.
* Copyright 2014-2021 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.
@@ -25,15 +25,17 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.restdocs.RestDocumentationContextProvider;
import org.springframework.restdocs.RestDocumentationExtension;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@SpringBootTest
@WebAppConfiguration
@ContextConfiguration(classes = SampleJUnit5Application.class)
@ExtendWith({RestDocumentationExtension.class, SpringExtension.class})
public class SampleJUnit5ApplicationTests {