Migrate generated tests for java resttemplate generator updateFeature/resttemplate junit5 (#18222)

* update(resttemplate): migrate java resttemplate templates to junit 5

* update(java defaults): migrate java defaults as well because resttemplate uses model_tests from default

* update(samples, java): update samples as described in the contribution guidelines

* fix tests: try double quotes

* fix tests: remaining double quotes

* update(samples): regenerate resttemplate

* update(samples): regenerate resttemplate-jakarta

* update(samples): regenerate resttemplate-swagger1

* update(samples): regenerate resttemplate-swagger2

* update(samples): regenerate resttemplate-withXml

* update(samples again): ./bin/generate-samples.sh ./bin/configs/*.yaml
This commit is contained in:
timo-a
2024-03-30 14:06:05 +01:00
committed by GitHub
parent 34ebc1c644
commit f73db59b0e
211 changed files with 1984 additions and 7146 deletions

View File

@@ -5,9 +5,9 @@ package {{package}};
import {{invokerPackage}}.ApiException;
{{#imports}}import {{import}};
{{/imports}}
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Assert;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.time.OffsetDateTime;
@@ -19,7 +19,7 @@ import java.util.Map;
/**
* API tests for {{classname}}
*/
public class {{classname}}Test {
class {{classname}}Test {
private final {{classname}} api = new {{classname}}();
@@ -38,7 +38,7 @@ public class {{classname}}Test {
* if the Api call fails
*/
@Test
public void {{operationId}}Test() throws ApiException {
void {{operationId}}Test() throws ApiException {
//{{#allParams}}
//{{{dataType}}} {{paramName}} = null;
//{{/allParams}}

View File

@@ -125,7 +125,7 @@ ext {
{{/useBeanValidation}}
jersey_version = "1.19.4"
jodatime_version = "2.9.9"
junit_version = "4.13.2"
junit_version = "5.10.2"
}
dependencies {
@@ -149,4 +149,20 @@ dependencies {
implementation "jakarta.validation:jakarta.validation-api:$bean_validation_version"
{{/useBeanValidation}}
testImplementation "junit:junit:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
}
test {
// Enable JUnit 5 (Gradle 4.6+).
useJUnitPlatform()
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'
// Show test results.
testLogging {
events "passed", "skipped", "failed"
}
}

View File

@@ -4,8 +4,9 @@ package {{package}};
{{#imports}}import {{import}};
{{/imports}}
import org.junit.Test;
import org.junit.Ignore;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.web.client.RestClientException;
import java.time.LocalDate;
import java.time.OffsetDateTime;
@@ -17,8 +18,8 @@ import java.util.Map;
/**
* API tests for {{classname}}
*/
@Ignore
public class {{classname}}Test {
@Disabled
class {{classname}}Test {
private final {{classname}} api = new {{classname}}();
@@ -28,11 +29,11 @@ public class {{classname}}Test {
*
* {{notes}}
*
* @throws ApiException
* @throws RestClientException
* if the Api call fails
*/
@Test
public void {{operationId}}Test() {
void {{operationId}}Test() {
{{#allParams}}
{{#isFile}}{{#useAbstractionForFiles}}{{#collectionFormat}}java.util.Collection<org.springframework.core.io.Resource>{{/collectionFormat}}{{^collectionFormat}}org.springframework.core.io.Resource{{/collectionFormat}}{{/useAbstractionForFiles}}{{^useAbstractionForFiles}}{{{dataType}}}{{/useAbstractionForFiles}}{{/isFile}}{{^isFile}}{{{dataType}}}{{/isFile}} {{paramName}} = null;
{{/allParams}}

View File

@@ -129,7 +129,7 @@ ext {
jakarta_annotation_version = "1.3.5"
{{/useJakartaEe}}
jodatime_version = "2.9.9"
junit_version = "4.13.2"
junit_version = "5.10.2"
}
dependencies {
@@ -158,5 +158,20 @@ dependencies {
implementation "com.fasterxml.jackson.dataformat:jackson-dataformat-xml:$jackson_version"
{{/withXml}}
implementation "jakarta.annotation:jakarta.annotation-api:$jakarta_annotation_version"
testImplementation "junit:junit:$junit_version"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_version"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_version"
}
test {
// Enable JUnit 5 (Gradle 4.6+).
useJUnitPlatform()
// Always run tests, even when nothing changed.
dependsOn 'cleanTest'
// Show test results.
testLogging {
events "passed", "skipped", "failed"
}
}

View File

@@ -76,6 +76,14 @@
<forkMode>pertest</forkMode>
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
<dependencies>
<!--Custom provider and engine for Junit 5 to surefire-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
@@ -339,11 +347,17 @@
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform-runner.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -379,6 +393,7 @@
{{#performBeanValidation}}
<hibernate-validator-version>5.4.3.Final</hibernate-validator-version>
{{/performBeanValidation}}
<junit-version>4.13.2</junit-version>
<junit-version>5.10.2</junit-version>
<junit-platform-runner.version>1.10.0</junit-platform-runner.version>
</properties>
</project>

View File

@@ -4,14 +4,14 @@ package {{package}};
{{#imports}}import {{import}};
{{/imports}}
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Model tests for {{classname}}
*/
public class {{classname}}Test {
class {{classname}}Test {
{{#models}}
{{#model}}
{{^vendorExtensions.x-is-one-of-interface}}
@@ -23,7 +23,7 @@ public class {{classname}}Test {
* Model tests for {{classname}}
*/
@Test
public void test{{classname}}() {
void test{{classname}}() {
// TODO: test {{classname}}
}
@@ -32,7 +32,7 @@ public class {{classname}}Test {
* Test the property '{{name}}'
*/
@Test
public void {{name}}Test() {
void {{name}}Test() {
// TODO: test {{name}}
}

View File

@@ -92,6 +92,14 @@
<parallel>methods</parallel>
<forkMode>pertest</forkMode>
</configuration>
<dependencies>
<!--Custom provider and engine for Junit 5 to surefire-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
@@ -335,11 +343,17 @@
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform-runner.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -362,6 +376,7 @@
<beanvalidation-version>3.0.2</beanvalidation-version>
{{/useBeanValidation}}
<maven-plugin-version>1.0.0</maven-plugin-version>
<junit-version>4.13.2</junit-version>
<junit-version>5.10.2</junit-version>
<junit-platform-runner.version>1.10.0</junit-platform-runner.version>
</properties>
</project>