targetFramework to testFramework
This commit is contained in:
@@ -245,7 +245,7 @@ from the Groovy DSL should be placed. By default its value is
|
||||
`$buildDir/generated-test-sources/contractVerifier`.
|
||||
* *stubsOutputDir*: Specifies the directory where the generated WireMock stubs from
|
||||
the Groovy DSL should be placed.
|
||||
* *targetFramework*: Specifies the target test framework to be used. Currently, Spock, JUnit 4 (`TestFramework.JUNIT` and
|
||||
* *testFramework*: Specifies the target test framework to be used. Currently, Spock, JUnit 4 (`TestFramework.JUNIT` and
|
||||
JUnit 5 are supported with JUnit 4 being the default framework.
|
||||
* *contractsProperties*: a map containing properties to be passed to Spring Cloud Contract
|
||||
components. Those properties might be used by e.g. inbuilt or custom Stub Downloaders.
|
||||
|
||||
@@ -135,7 +135,7 @@ class TestGenerator {
|
||||
}
|
||||
|
||||
private String resolveNameSuffix() {
|
||||
return configProperties.nameSuffixForTests ?: configProperties.targetFramework.classNameSuffix
|
||||
return configProperties.nameSuffixForTests ?: configProperties.testFramework.classNameSuffix
|
||||
}
|
||||
|
||||
protected static String buildPackage(final String packageNameForClass, final String includedDirectoryRelativePath) {
|
||||
|
||||
@@ -67,13 +67,13 @@ class ClassBuilder {
|
||||
static ClassBuilder createClass(String className, String classPackage, ContractVerifierConfigProperties properties,
|
||||
String includedDirectoryRelativePath) {
|
||||
String baseClassForTests
|
||||
if (properties.targetFramework == TestFramework.SPOCK && !properties.baseClassForTests
|
||||
if (properties.testFramework == TestFramework.SPOCK && !properties.baseClassForTests
|
||||
&& !properties.packageWithBaseClasses && !properties.baseClassMappings) {
|
||||
baseClassForTests = 'spock.lang.Specification'
|
||||
} else {
|
||||
baseClassForTests = retrieveBaseClass(properties, includedDirectoryRelativePath)
|
||||
}
|
||||
return new ClassBuilder(className, classPackage, baseClassForTests, properties.targetFramework)
|
||||
return new ClassBuilder(className, classPackage, baseClassForTests, properties.testFramework)
|
||||
}
|
||||
|
||||
protected static String retrieveBaseClass(ContractVerifierConfigProperties properties, String includedDirectoryRelativePath) {
|
||||
|
||||
@@ -64,8 +64,8 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
}
|
||||
}
|
||||
if (isScenarioClass(listOfFiles)) {
|
||||
clazz.addImports(configProperties.targetFramework.getOrderAnnotationImports())
|
||||
clazz.addClassLevelAnnotation(configProperties.targetFramework.getOrderAnnotation())
|
||||
clazz.addImports(configProperties.testFramework.getOrderAnnotationImports())
|
||||
clazz.addClassLevelAnnotation(configProperties.testFramework.getOrderAnnotation())
|
||||
}
|
||||
addJsonPathRelatedImports(clazz)
|
||||
processContractFiles(listOfFiles, configProperties, clazz)
|
||||
@@ -79,8 +79,8 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
boolean toIgnore = listOfFiles.ignored.find {it}
|
||||
contracts.each {ParsedDsl key, TestType value ->
|
||||
if (!conditionalImportsAdded) {
|
||||
clazz.addImports(getImports(configProperties.targetFramework))
|
||||
clazz.addStaticImports(getStaticImports(configProperties.targetFramework))
|
||||
clazz.addImports(getImports(configProperties.testFramework))
|
||||
clazz.addStaticImports(getStaticImports(configProperties.testFramework))
|
||||
if (contracts.values().contains(TestType.HTTP)) {
|
||||
addHttpRelatedEntries(clazz, configProperties)
|
||||
}
|
||||
@@ -97,14 +97,14 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
}
|
||||
|
||||
if (toIgnore) {
|
||||
clazz.addImport(configProperties.targetFramework.getIgnoreClass())
|
||||
clazz.addImport(configProperties.testFramework.getIgnoreClass())
|
||||
}
|
||||
}
|
||||
|
||||
private void addRule(ContractVerifierConfigProperties configProperties, ClassBuilder clazz) {
|
||||
clazz.addImport(getRuleImport())
|
||||
if (configProperties.targetFramework.annotationLevelRules()) {
|
||||
clazz.addClassLevelAnnotation(configProperties.targetFramework
|
||||
if (configProperties.testFramework.annotationLevelRules()) {
|
||||
clazz.addClassLevelAnnotation(configProperties.testFramework
|
||||
.getRuleAnnotation(configProperties.ruleClassForTests))
|
||||
} else {
|
||||
clazz.addRule(configProperties.ruleClassForTests)
|
||||
@@ -113,8 +113,8 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
|
||||
private void addHttpRelatedEntries(ClassBuilder clazz, ContractVerifierConfigProperties configProperties) {
|
||||
HttpImportProvider httpImportProvider = new HttpImportProvider(getRestAssuredPackage())
|
||||
clazz.addImports(httpImportProvider.getImports(configProperties.targetFramework, configProperties.testMode))
|
||||
clazz.addStaticImports(httpImportProvider.getStaticImports(configProperties.targetFramework, configProperties.testMode))
|
||||
clazz.addImports(httpImportProvider.getImports(configProperties.testFramework, configProperties.testMode))
|
||||
clazz.addStaticImports(httpImportProvider.getStaticImports(configProperties.testFramework, configProperties.testMode))
|
||||
}
|
||||
|
||||
// TODO for 2.2: leave only RestAssured 3
|
||||
@@ -129,7 +129,7 @@ class JavaTestGenerator implements SingleTestGenerator {
|
||||
|
||||
@Override
|
||||
String fileExtension(ContractVerifierConfigProperties properties) {
|
||||
return properties.targetFramework.classExtension
|
||||
return properties.testFramework.classExtension
|
||||
}
|
||||
|
||||
private Map<ParsedDsl, TestType> mapContractsToTheirTestTypes(Collection<ContractMetadata> listOfFiles) {
|
||||
|
||||
@@ -98,9 +98,9 @@ class MethodBuilder {
|
||||
blockBuilder.addLine('@Test')
|
||||
}
|
||||
if (ignored) {
|
||||
blockBuilder.addLine(configProperties.targetFramework.ignoreAnnotation)
|
||||
blockBuilder.addLine(configProperties.testFramework.ignoreAnnotation)
|
||||
}
|
||||
blockBuilder.addLine(configProperties.targetFramework.methodModifier + "validate_$methodName() throws Exception {")
|
||||
blockBuilder.addLine(configProperties.testFramework.methodModifier + "validate_$methodName() throws Exception {")
|
||||
getMethodBodyBuilder().appendTo(blockBuilder)
|
||||
blockBuilder.addLine('}')
|
||||
}
|
||||
@@ -128,13 +128,13 @@ class MethodBuilder {
|
||||
}
|
||||
// in Groovy we're using def so we don't have to update the imports
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
} else if (configProperties.targetFramework == SPOCK) {
|
||||
} else if (configProperties.testFramework == SPOCK) {
|
||||
return new HttpSpockMethodRequestProcessingBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
return new MockMvcJUnitMethodBodyBuilder(stubContent, configProperties)
|
||||
}
|
||||
|
||||
private boolean isJUnitType() {
|
||||
return JUNIT == configProperties.targetFramework || JUNIT5 == configProperties.targetFramework
|
||||
return JUNIT == configProperties.testFramework || JUNIT5 == configProperties.testFramework
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class ContractVerifierConfigProperties {
|
||||
|
||||
@Deprecated
|
||||
void setTargetFramework(TestFramework targetFramework) {
|
||||
log.warn("Please use the [testFramework] field. This one is deprecated")
|
||||
log.warn("Please use the [testFramework] field. [targetFramework] is deprecated")
|
||||
setTestFramework(targetFramework)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ class GeneratorScannerSpec extends Specification {
|
||||
|
||||
def "should create class with full package"() {
|
||||
given:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(targetFramework: SPOCK)
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(testFramework: SPOCK)
|
||||
properties.contractsDslDir = new File(this.getClass().getResource("/directory/with/stubs/package").toURI())
|
||||
TestGenerator testGenerator = new TestGenerator(properties, classGenerator, Stub(FileSaver))
|
||||
when:
|
||||
|
||||
@@ -25,7 +25,7 @@ class MainTest {
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
contractsDslDir: new File('/some/path/dsl'),
|
||||
generatedTestSourcesDir: new File('/tmp/contracts'),
|
||||
targetFramework: TestFramework.SPOCK, testMode: TestMode.MOCKMVC, basePackageForTests: 'io.test',
|
||||
testFramework: TestFramework.SPOCK, testMode: TestMode.MOCKMVC, basePackageForTests: 'io.test',
|
||||
staticImports: ['com.package.Test.*'], imports: ['org.package.Test'], excludedFiles: ["**/other"])
|
||||
println new TestGenerator(properties).generate()
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
File temp = tmpFolder.newFolder()
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
targetFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
basePackageForTests: 'a.b',
|
||||
generatedTestSourcesDir: temp
|
||||
)
|
||||
@@ -625,7 +625,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
File temp = tmpFolder.newFolder()
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
targetFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
basePackageForTests: 'a.b', generatedTestSourcesDir: temp
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
@@ -649,7 +649,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
File temp = tmpFolder.newFolder()
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
targetFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
baseClassForTests: 'a.b.SomeClass', generatedTestSourcesDir: temp
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
@@ -673,7 +673,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
File temp = tmpFolder.newFolder()
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
targetFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
packageWithBaseClasses: 'a.b', generatedTestSourcesDir: temp
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
@@ -697,7 +697,7 @@ class SingleTestGeneratorSpec extends Specification {
|
||||
File temp = tmpFolder.newFolder()
|
||||
and:
|
||||
ContractVerifierConfigProperties properties = new ContractVerifierConfigProperties(
|
||||
targetFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
testFramework: testFramework, contractsDslDir: contractLocation.parentFile,
|
||||
generatedTestSourcesDir: temp
|
||||
)
|
||||
TestGenerator testGenerator = new TestGenerator(properties)
|
||||
|
||||
Reference in New Issue
Block a user