diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverter.groovy b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverter.groovy index 619bd8b235..616595e8bb 100644 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverter.groovy +++ b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverter.groovy @@ -2,12 +2,16 @@ package io.codearte.accurest.wiremock import groovy.transform.CompileStatic import io.codearte.accurest.dsl.WireMockStubStrategy +import io.codearte.accurest.file.Contract + +import java.nio.charset.StandardCharsets @CompileStatic class DslToWireMockClientConverter extends DslToWireMockConverter { @Override - String convertContent(String dslBody) { - return new WireMockStubStrategy(createGroovyDSLfromStringContent(dslBody)).toWireMockClientStub() + String convertContent(String rootName, Contract contract) { + String dslContent = contract.path.getText(StandardCharsets.UTF_8.toString()) + return new WireMockStubStrategy(rootName, contract, createGroovyDSLfromStringContent(dslContent)).toWireMockClientStub() } } diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverter.groovy b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverter.groovy index b031acc174..d073a7af2e 100644 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverter.groovy +++ b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverter.groovy @@ -1,7 +1,6 @@ package io.codearte.accurest.wiremock -import com.google.common.collect.Multimap -import groovy.io.FileType +import com.google.common.collect.ListMultimap import groovy.transform.CompileStatic import groovy.util.logging.Slf4j import io.codearte.accurest.config.AccurestConfigProperties @@ -27,19 +26,21 @@ class RecursiveFilesConverter { void processFiles() { ContractFileScanner scanner = new ContractFileScanner(properties.contractsDslDir, properties.excludedFiles as Set, [] as Set) - Multimap contracts = scanner.findContracts() - contracts.values().each { Contract contract -> - File sourceFile = contract.path.toFile() - try { - if (!singleFileConverter.canHandleFileName(sourceFile.name)) { - return + ListMultimap contracts = scanner.findContracts() + contracts.asMap().entrySet().each { entry -> + entry.value.each { Contract contract -> + File sourceFile = contract.path.toFile() + try { + if (!singleFileConverter.canHandleFileName(sourceFile.name)) { + return + } + String convertedContent = singleFileConverter.convertContent(entry.key.last().toString(), contract) + Path absoluteTargetPath = createAndReturnTargetDirectory(sourceFile) + File newGroovyFile = createTargetFileWithProperName(absoluteTargetPath, sourceFile) + newGroovyFile.setText(convertedContent, StandardCharsets.UTF_8.toString()) + } catch (Exception e) { + throw new ConversionAccurestException("Unable to make convertion of ${sourceFile.name}", e) } - String convertedContent = singleFileConverter.convertContent(sourceFile.getText(StandardCharsets.UTF_8.toString())) - Path absoluteTargetPath = createAndReturnTargetDirectory(sourceFile) - File newGroovyFile = createTargetFileWithProperName(absoluteTargetPath, sourceFile) - newGroovyFile.setText(convertedContent, StandardCharsets.UTF_8.toString()) - } catch (Exception e) { - throw new ConversionAccurestException("Unable to make convertion of ${sourceFile.name}", e) } } } diff --git a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/SingleFileConverter.groovy b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/SingleFileConverter.groovy index 27d10c25c8..fda8aa2e82 100644 --- a/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/SingleFileConverter.groovy +++ b/accurest-converters/src/main/groovy/io/codearte/accurest/wiremock/SingleFileConverter.groovy @@ -1,13 +1,14 @@ package io.codearte.accurest.wiremock import groovy.transform.CompileStatic +import io.codearte.accurest.file.Contract @CompileStatic interface SingleFileConverter { boolean canHandleFileName(String fileName) - String convertContent(String content) + String convertContent(String rootName, Contract content) String generateOutputFileNameForInput(String inputFileName) } \ No newline at end of file diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy index 61c6b7c29b..60801e3950 100755 --- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy +++ b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/DslToWireMockClientConverterSpec.groovy @@ -1,15 +1,22 @@ package io.codearte.accurest.wiremock +import io.codearte.accurest.file.Contract +import org.junit.Rule +import org.junit.rules.TemporaryFolder import org.skyscreamer.jsonassert.JSONAssert import spock.lang.Specification class DslToWireMockClientConverterSpec extends Specification { + @Rule + public TemporaryFolder tmpFolder = new TemporaryFolder(); + def "should convert DSL file to WireMock JSON"() { given: def converter = new DslToWireMockClientConverter() and: - String dslBody = """ + File file = tmpFolder.newFile("dsl1.groovy") + file.write(""" io.codearte.accurest.dsl.GroovyDsl.make { request { method('PUT') @@ -19,9 +26,9 @@ class DslToWireMockClientConverterSpec extends Specification { status 200 } } -""" +""") when: - String json = converter.convertContent(dslBody) + String json = converter.convertContent("Test", new Contract(file.toPath(), false, 0, null)) then: JSONAssert.assertEquals(''' {"request":{"method":"PUT","urlPattern":"/[0-9]{2}"},"response":{"status":200}} @@ -33,7 +40,8 @@ class DslToWireMockClientConverterSpec extends Specification { given: def converter = new DslToWireMockClientConverter() and: - String dslBody = """ + File file = tmpFolder.newFile("dsl2.groovy") + file.write(""" io.codearte.accurest.dsl.GroovyDsl.make { request { method 'PUT' @@ -77,9 +85,9 @@ class DslToWireMockClientConverterSpec extends Specification { status 200 } } -""" +""") when: - String json = converter.convertContent(dslBody) + String json = converter.convertContent("Test", new Contract(file.toPath(), false, 0, null)) then: JSONAssert.assertEquals(''' { diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverterSpec.groovy b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverterSpec.groovy index f5f9022b97..fc0a0014b6 100755 --- a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverterSpec.groovy +++ b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/RecursiveFilesConverterSpec.groovy @@ -73,7 +73,7 @@ class RecursiveFilesConverterSpec extends Specification { and: def singleFileConverterStub = Stub(SingleFileConverter) singleFileConverterStub.canHandleFileName(_) >> { true } - singleFileConverterStub.convertContent(_) >> { throw new NullPointerException("Test conversion error") } + singleFileConverterStub.convertContent(_, _) >> { throw new NullPointerException("Test conversion error") } singleFileConverterStub.generateOutputFileNameForInput(_) >> { String inputFileName -> "${inputFileName}2" } AccurestConfigProperties properties = new AccurestConfigProperties() properties.contractsDslDir = tmpFolder.root diff --git a/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WiremockScenarioConverterSpec.groovy b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WiremockScenarioConverterSpec.groovy new file mode 100755 index 0000000000..e7911c1303 --- /dev/null +++ b/accurest-converters/src/test/groovy/io/codearte/accurest/wiremock/WiremockScenarioConverterSpec.groovy @@ -0,0 +1,46 @@ +package io.codearte.accurest.wiremock + +import io.codearte.accurest.file.Contract +import spock.lang.Specification + +import java.nio.file.Path +import java.nio.file.Paths + +class WiremockScenarioConverterSpec extends Specification { + + def "should generate first scenario step"() { + given: + DslToWireMockClientConverter converter = new DslToWireMockClientConverter() + Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/01_login.groovy").toURI()) + when: + String content = converter.convertContent("Test", new Contract(dsl, false, 3, 0)) + then: + content.contains('"requiredScenarioState" : "Started"') + content.contains('"newScenarioState" : "Step1"') + content.contains('"scenarioName" : "Scenario_Test"') + } + + def "should generate mid scenario step"() { + given: + DslToWireMockClientConverter converter = new DslToWireMockClientConverter() + Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/02_showCart.groovy").toURI()) + when: + String content = converter.convertContent("Test", new Contract(dsl, false, 3, 1)) + then: + content.contains('"requiredScenarioState" : "Step1"') + content.contains('"newScenarioState" : "Step2"') + content.contains('"scenarioName" : "Scenario_Test"') + } + + def "should generate last scenario step"() { + given: + DslToWireMockClientConverter converter = new DslToWireMockClientConverter() + Path dsl = Paths.get(this.getClass().getResource("/converter/scenario/main_scenario/03_logout.groovy").toURI()) + when: + String content = converter.convertContent("Test", new Contract(dsl, false, 3, 2)) + then: + content.contains('"requiredScenarioState" : "Step2"') + !content.contains('"newScenarioState"') + content.contains('"scenarioName" : "Scenario_Test"') + } +} diff --git a/accurest-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy b/accurest-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy new file mode 100644 index 0000000000..1a30790fc3 --- /dev/null +++ b/accurest-converters/src/test/resources/converter/scenario/main_scenario/01_login.groovy @@ -0,0 +1,9 @@ +io.codearte.accurest.dsl.GroovyDsl.make { + request { + method('POST') + url '/login' + } + response { + status 200 + } +} diff --git a/accurest-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy b/accurest-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy new file mode 100644 index 0000000000..712c7ef584 --- /dev/null +++ b/accurest-converters/src/test/resources/converter/scenario/main_scenario/02_showCart.groovy @@ -0,0 +1,9 @@ +io.codearte.accurest.dsl.GroovyDsl.make { + request { + method('GET') + url '/cart' + } + response { + status 200 + } +} diff --git a/accurest-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy b/accurest-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy new file mode 100644 index 0000000000..33e948e602 --- /dev/null +++ b/accurest-converters/src/test/resources/converter/scenario/main_scenario/03_logout.groovy @@ -0,0 +1,9 @@ +io.codearte.accurest.dsl.GroovyDsl.make { + request { + method('POST') + url '/logout' + } + response { + status 200 + } +} diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy index d950bd345c..b90e794d71 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/SingleTestGenerator.groovy @@ -21,8 +21,7 @@ class SingleTestGenerator { @PackageScope String buildClass(Collection listOfFiles, String className, String classPackage) { - ClassBuilder clazz = createClass(capitalize(className), classPackage, - configProperties) + ClassBuilder clazz = createClass(capitalize(className), classPackage, configProperties) if (configProperties.imports) { configProperties.imports.each { @@ -30,8 +29,8 @@ class SingleTestGenerator { } } - if (listOfFiles.ignored.find {it}) { - clazz.addImport("org.junit.Ignore") + if (listOfFiles.ignored.find { it }) { + clazz.addImport(configProperties.targetFramework.getIgnoreClass()) } if (configProperties.staticImports) { @@ -40,6 +39,11 @@ class SingleTestGenerator { } } + if (isScenarioClass(listOfFiles)) { + clazz.addImport(configProperties.targetFramework.getOrderAnnotationImport()) + clazz.addClassLevelAnnotation(configProperties.targetFramework.getOrderAnnotation()) + } + if (configProperties.testMode == TestMode.JAXRSCLIENT) { clazz.addStaticImport('javax.ws.rs.client.Entity.*') } else if (configProperties.testMode == TestMode.MOCKMVC) { @@ -66,10 +70,14 @@ class SingleTestGenerator { return clazz.build() } + private boolean isScenarioClass(Collection listOfFiles) { + listOfFiles.find({ it.order != null }) != null + } + private ClassBuilder addJsonPathRelatedImports(ClassBuilder clazz) { clazz.addImport(['com.jayway.jsonpath.DocumentContext', - 'com.jayway.jsonpath.JsonPath', - 'net.minidev.json.JSONArray']) + 'com.jayway.jsonpath.JsonPath', + 'net.minidev.json.JSONArray']) } } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/TestGenerator.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/TestGenerator.groovy index 6c97397b5a..d0e9f15346 100755 --- a/accurest-core/src/main/groovy/io/codearte/accurest/TestGenerator.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/TestGenerator.groovy @@ -1,6 +1,6 @@ package io.codearte.accurest -import com.google.common.collect.Multimap +import com.google.common.collect.ListMultimap import groovy.transform.PackageScope import io.codearte.accurest.config.AccurestConfigProperties import io.codearte.accurest.file.Contract @@ -53,7 +53,7 @@ class TestGenerator { @PackageScope void generateTestClasses(final String basePackageName) { - Multimap contracts = contractFileScanner.findContracts() + ListMultimap contracts = contractFileScanner.findContracts() contracts.asMap().entrySet().each { Map.Entry> entry -> processIncludedDirectory(relativizeContractPath(entry), entry.getValue(), basePackageName) } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/ClassBuilder.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/builder/ClassBuilder.groovy index 3e3a8ce1c0..8975faa18f 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/ClassBuilder.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/builder/ClassBuilder.groovy @@ -16,6 +16,7 @@ class ClassBuilder { private final List staticImports = [] private final List rules = [] private final List methods = [] + private final List classLevelAnnotations = [] private final TestFramework lang private ClassBuilder(String className, String packageName, String baseClass, TestFramework lang) { @@ -83,6 +84,10 @@ class ClassBuilder { clazz.addEmptyLine() } + classLevelAnnotations.sort().each { + clazz.addLine(it) + } + def classLine = "${lang.classModifier}class $className" if (baseClass) { classLine += " extends $baseClass" @@ -107,4 +112,8 @@ class ClassBuilder { clazz.addLine('}') clazz.toString() } + + void addClassLevelAnnotation(String annotation) { + classLevelAnnotations << annotation + } } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBuilder.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBuilder.groovy index 2007d05b1b..9f0ba231d7 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBuilder.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/builder/MethodBuilder.groovy @@ -43,7 +43,7 @@ class MethodBuilder { if (ignored) { blockBuilder.addLine('@Ignore') } - blockBuilder.addLine(configProperties.targetFramework.methodModifier + "$methodName() {") + blockBuilder.addLine(configProperties.targetFramework.methodModifier + "validate_$methodName() {") getMethodBodyBuilder().appendTo(blockBuilder) blockBuilder.addLine('}') } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/config/TestFramework.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/config/TestFramework.groovy index 79758327f3..c1014f19de 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/config/TestFramework.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/config/TestFramework.groovy @@ -4,21 +4,28 @@ package io.codearte.accurest.config * @author Jakub Kubrynski */ enum TestFramework { - JUNIT("public ", "public void ", ";", ".java", "Test"), - SPOCK("", "def ", "", ".groovy", "Spec") + JUNIT("public ", "public void ", ";", ".java", "Test", "org.junit.Ignore", "org.junit.FixMethodOrder", "@FixMethodOrder(MethodSorters.NAME_ASCENDING)"), + SPOCK("", "def ", "", ".groovy", "Spec", "spock.lang.Ignore", "spock.lang.Stepwise", "@Stepwise") private final String classModifier private final String methodModifier private final String lineSuffix private final String classExtension; private final String classNameSuffix; + private final String ignoreClass + private final String orderAnnotationImport + private final String orderAnnotation - TestFramework(String classModifier, String methodModifier, String lineSuffix, String classExtension, String classNameSuffix) { + TestFramework(String classModifier, String methodModifier, String lineSuffix, String classExtension, String classNameSuffix, + String ignoreClass, String orderAnnotationImport, String orderAnnotation) { this.classModifier = classModifier this.lineSuffix = lineSuffix this.methodModifier = methodModifier this.classExtension = classExtension this.classNameSuffix = classNameSuffix + this.ignoreClass = ignoreClass + this.orderAnnotationImport = orderAnnotationImport + this.orderAnnotation = orderAnnotation } String getClassModifier() { @@ -40,4 +47,16 @@ enum TestFramework { String getClassNameSuffix() { return classNameSuffix } + + String getIgnoreClass() { + return ignoreClass + } + + String getOrderAnnotationImport() { + return orderAnnotationImport + } + + String getOrderAnnotation() { + return orderAnnotation + } } \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockStubStrategy.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockStubStrategy.groovy index 337f7b8557..9133b85067 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockStubStrategy.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/dsl/WireMockStubStrategy.groovy @@ -5,15 +5,22 @@ import com.github.tomakehurst.wiremock.matching.RequestPattern import com.github.tomakehurst.wiremock.stubbing.StubMapping import groovy.transform.CompileDynamic import groovy.transform.CompileStatic +import io.codearte.accurest.file.Contract @CompileStatic class WireMockStubStrategy { + private static final String STEP_START = "Started" + private static final String STEP_PREFIX = "Step" private final WireMockRequestStubStrategy wireMockRequestStubStrategy private final WireMockResponseStubStrategy wireMockResponseStubStrategy private final Integer priority + private final Contract contract + private final String rootName - WireMockStubStrategy(GroovyDsl groovyDsl) { + WireMockStubStrategy(String rootName, Contract contract, GroovyDsl groovyDsl) { + this.rootName = rootName + this.contract = contract this.wireMockRequestStubStrategy = new WireMockRequestStubStrategy(groovyDsl) this.wireMockResponseStubStrategy = new WireMockResponseStubStrategy(groovyDsl) this.priority = groovyDsl.priority @@ -29,6 +36,15 @@ class WireMockStubStrategy { } stubMapping.request = request stubMapping.response = response + + if (contract.order != null) { + stubMapping.scenarioName = "Scenario_" + rootName + stubMapping.requiredScenarioState = contract.order == 0 ? STEP_START : STEP_PREFIX + contract.order + if (contract.order < contract.groupSize - 1) { + stubMapping.newScenarioState = STEP_PREFIX + (contract.order + 1) + } + } + return StubMapping.buildJsonStringFor(stubMapping) } } \ No newline at end of file diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/file/Contract.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/file/Contract.groovy index 6d7289b24d..d5cbcfea1c 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/file/Contract.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/file/Contract.groovy @@ -8,10 +8,23 @@ import java.nio.file.Path class Contract { final Path path; final boolean ignored; + final int groupSize + final Integer order; - Contract(Path path, boolean ignored) { + Contract(Path path, boolean ignored, int groupSize, Integer order) { + this.groupSize = groupSize this.path = path this.ignored = ignored + this.order = order } + @Override + public String toString() { + return "Contract{" + + "fileName=" + path.fileName + + ", ignored=" + ignored + + ", groupSize=" + groupSize + + ", order=" + order + + '}'; + } } diff --git a/accurest-core/src/main/groovy/io/codearte/accurest/file/ContractFileScanner.groovy b/accurest-core/src/main/groovy/io/codearte/accurest/file/ContractFileScanner.groovy index 421b89a4b8..1e1e27c310 100644 --- a/accurest-core/src/main/groovy/io/codearte/accurest/file/ContractFileScanner.groovy +++ b/accurest-core/src/main/groovy/io/codearte/accurest/file/ContractFileScanner.groovy @@ -1,6 +1,7 @@ package io.codearte.accurest.file import com.google.common.collect.ArrayListMultimap +import com.google.common.collect.ListMultimap import com.google.common.collect.Multimap import org.apache.commons.io.FilenameUtils @@ -8,13 +9,15 @@ import java.nio.file.FileSystem import java.nio.file.FileSystems import java.nio.file.Path import java.nio.file.PathMatcher +import java.util.regex.Pattern /** * @author Jakub Kubrynski */ class ContractFileScanner { - private final String MATCH_PREFIX = "glob:" + private static final String MATCH_PREFIX = "glob:" + private static final Pattern SCENARIO_STEP_FILENAME_PATTERN = Pattern.compile("[0-9]+_.*") private final File baseDir private final Set excludeMatchers private final Set ignoreMatchers @@ -32,26 +35,37 @@ class ContractFileScanner { }) as Set } - Multimap findContracts() { - Multimap result = ArrayListMultimap.create() + ListMultimap findContracts() { + ListMultimap result = ArrayListMultimap.create() appendRecursively(baseDir, result) return result } - private void appendRecursively(File baseDir, Multimap result) { - for (File file : baseDir.listFiles()) { - if (matchesPattern(file, excludeMatchers)) { - break; - } - if (isContractFile(file)) { - Path path = file.toPath() - result.put(file.parentFile.toPath(), new Contract(path, matchesPattern(file, ignoreMatchers))) - } else { - appendRecursively(file, result) + private void appendRecursively(File baseDir, ListMultimap result) { + File[] files = baseDir.listFiles() + if (!files) { + return; + } + files.sort().eachWithIndex { File file, int index -> + if (!matchesPattern(file, excludeMatchers)) { + if (isContractFile(file)) { + Path path = file.toPath() + Integer order = null + if (hasScenarioFilenamePattern(path)) { + order = index + } + result.put(file.parentFile.toPath(), new Contract(path, matchesPattern(file, ignoreMatchers), files.size(), order)) + } else { + appendRecursively(file, result) + } } } } + private boolean hasScenarioFilenamePattern(Path path) { + SCENARIO_STEP_FILENAME_PATTERN.matcher(path.fileName.toString()).matches() + } + boolean matchesPattern(File file, Set excludeMatchers) { for (PathMatcher matcher : excludeMatchers) { if (matcher.matches(file.toPath())) { diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy index a8daa0af22..77abde0e80 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/JaxRsClientSpockMethodBuilderSpec.groovy @@ -3,6 +3,7 @@ package io.codearte.accurest.builder import io.codearte.accurest.dsl.GroovyDsl import io.codearte.accurest.dsl.WireMockStubStrategy import io.codearte.accurest.dsl.WireMockStubVerifier +import io.codearte.accurest.file.Contract import spock.lang.Issue import spock.lang.Specification @@ -31,7 +32,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") blockBuilder.toString().contains("\$[?(@.property2 == 'b')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#187") @@ -60,7 +61,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$[?(@.property2 == null)]") blockBuilder.toString().contains("\$[?(@.property3 == false)]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#79") @@ -91,7 +92,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$.property2[*][?(@.a == 'sth')]") blockBuilder.toString().contains("\$.property2[*][?(@.b == 'sthElse')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#82") @@ -116,7 +117,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc then: blockBuilder.toString().contains("entity('{\"items\":[\"HOP\"]}', 'application/json')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#88") @@ -141,7 +142,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc then: blockBuilder.toString().contains("entity('property1=VAL1', 'application/octet-stream')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate assertions for array in response body"() { @@ -170,7 +171,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$[*][?(@.property1 == 'a')]") blockBuilder.toString().contains("\$[*][?(@.property2 == 'b')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate assertions for array inside response body element"() { @@ -198,7 +199,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$.property1[*][?(@.property3 == 'test2')]") blockBuilder.toString().contains("\$.property1[*][?(@.property2 == 'test1')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate assertions for nested objects in response body"() { @@ -226,7 +227,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$.property2[?(@.property3 == 'b')]") blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate regex assertions for map objects in response body"() { @@ -260,7 +261,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$[?(@.property2 =~ /[0-9]{3}/)]") blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate regex assertions for string objects in response body"() { @@ -288,7 +289,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("\$[?(@.property2 =~ /[0-9]{3}/)]") blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should ignore 'Accept' header and use 'request' method"() { @@ -312,7 +313,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc then: blockBuilder.toString().contains("request('text/plain')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should ignore 'Content-Type' header and use 'entity' method"() { @@ -340,7 +341,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc blockBuilder.toString().contains("header('Timer', '123')") !blockBuilder.toString().contains("header('Content-Type'") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate a call with an url path and query parameters"() { @@ -390,7 +391,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc spockTest.contains('$[?(@.property2 == \'b\')]') spockTest.contains('$[?(@.property1 == \'a\')]') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue('#169') @@ -441,7 +442,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc spockTest.contains('$[?(@.property2 == \'b\')]') spockTest.contains('$[?(@.property1 == \'a\')]') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate test for empty body"() { @@ -464,7 +465,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc then: spockTest.contains("entity('', 'application/octet-stream')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate test for String in response body"() { @@ -488,7 +489,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc spockTest.contains('String responseAsString = response.readEntity(String)') spockTest.contains('responseBody == "test"') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue('#171') @@ -517,7 +518,7 @@ class JaxRsClientSpockMethodBuilderSpec extends Specification implements WireMoc then: spockTest.contains(".method('GET')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } } diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy index ba403adcde..b02b507a4f 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/builder/MockMvcSpockMethodBuilderSpec.groovy @@ -3,6 +3,7 @@ package io.codearte.accurest.builder import io.codearte.accurest.dsl.GroovyDsl import io.codearte.accurest.dsl.WireMockStubStrategy import io.codearte.accurest.dsl.WireMockStubVerifier +import io.codearte.accurest.file.Contract import spock.lang.Issue import spock.lang.Specification import spock.lang.Unroll @@ -37,7 +38,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") blockBuilder.toString().contains("\$[?(@.property2 == 'b')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#187") @@ -66,7 +67,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$[?(@.property2 == null)]") blockBuilder.toString().contains("\$[?(@.property3 == false)]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#79") @@ -97,7 +98,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$.property2[*][?(@.a == 'sth')]") blockBuilder.toString().contains("\$.property2[*][?(@.b == 'sthElse')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#82") @@ -122,7 +123,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu then: blockBuilder.toString().contains(".body('''{\"items\":[\"HOP\"]}''')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("#88") @@ -147,7 +148,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu then: blockBuilder.toString().contains(".body('''property1=VAL1''')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue("185") @@ -176,7 +177,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$.property[?(@.7 == 0.0)]") blockBuilder.toString().contains("\$.property[?(@.14 == 0.0)]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate assertions for array in response body"() { @@ -205,7 +206,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$[*][?(@.property1 == 'a')]") blockBuilder.toString().contains("\$[*][?(@.property2 == 'b')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate assertions for array inside response body element"() { @@ -233,7 +234,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$.property1[*][?(@.property3 == 'test2')]") blockBuilder.toString().contains("\$.property1[*][?(@.property2 == 'test1')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate assertions for nested objects in response body"() { @@ -261,7 +262,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$.property2[?(@.property3 == 'b')]") blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate regex assertions for map objects in response body"() { @@ -295,7 +296,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$[?(@.property2 =~ /[0-9]{3}/)]") blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate regex assertions for string objects in response body"() { @@ -323,7 +324,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu blockBuilder.toString().contains("\$[?(@.property2 =~ /[0-9]{3}/)]") blockBuilder.toString().contains("\$[?(@.property1 == 'a')]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue(["#126", "#143"]) @@ -349,7 +350,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu then: blockBuilder.toString().contains("\$[?(@.property =~ /\\d+/)]") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate a call with an url path and query parameters"() { @@ -392,7 +393,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu spockTest.contains('$[?(@.property2 == \'b\')]') spockTest.contains('$[?(@.property1 == \'a\')]') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue('#169') @@ -436,7 +437,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu spockTest.contains('$[?(@.property2 == \'b\')]') spockTest.contains('$[?(@.property1 == \'a\')]') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate test for empty body"() { @@ -459,7 +460,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu then: spockTest.contains(".body('''''')") and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should generate test for String in response body"() { @@ -483,7 +484,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu spockTest.contains('def responseBody = (response.body.asString())') spockTest.contains('responseBody == "test"') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue('113') @@ -518,7 +519,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu then: spockTest.contains('''response.header('Location') ==~ java.util.regex.Pattern.compile('http://localhost/partners/[0-9]+/users/[0-9]+')''') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } @Issue('115') @@ -553,7 +554,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu then: spockTest.contains('''response.header('Location') ==~ java.util.regex.Pattern.compile('^((http[s]?|ftp):\\/)\\/?([^:\\/\\s]+)(:[0-9]{1,5})?/partners/[0-9]+/users/[0-9]+')''') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should work with more complex stuff and jsonpaths"() { @@ -590,7 +591,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu spockTest.contains('''$.errors[*][?(@.property == 'bank_account_number')]''') spockTest.contains('''$.errors[*][?(@.message == 'incorrect_format')]''') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should work properly with GString url"() { @@ -619,7 +620,7 @@ class MockMvcSpockMethodBuilderSpec extends Specification implements WireMockStu then: spockTest.contains('''/partners/11/agents/11/customers/09665703Z''') and: - stubMappingIsValidWireMockStub(new WireMockStubStrategy(contractDsl).toWireMockClientStub()) + stubMappingIsValidWireMockStub(new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub()) } def "should resolve properties in GString with regular expression"() { diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy index 866a451f47..43324a794c 100755 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockGroovyDslSpec.groovy @@ -2,6 +2,7 @@ package io.codearte.accurest.dsl import groovy.json.JsonBuilder import groovy.json.JsonSlurper +import io.codearte.accurest.file.Contract import io.codearte.accurest.util.AssertionUtil import spock.lang.Issue import spock.lang.Specification @@ -36,7 +37,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -81,7 +82,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -129,7 +130,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -181,7 +182,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -228,7 +229,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual(''' { @@ -276,7 +277,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -560,7 +561,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -615,7 +616,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -963,7 +964,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1136,7 +1137,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1170,7 +1171,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1218,7 +1219,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1269,7 +1270,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1298,7 +1299,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie @Unroll def 'should generate stub without optional parameters'() { when: - String wireMockStub = new WireMockStubStrategy(contractDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub() then: AssertionUtil.assertThatJsonsAreEqual((''' { @@ -1396,7 +1397,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } String toWireMockClientJsonStub(groovyDsl) { - new WireMockStubStrategy(groovyDsl).toWireMockClientStub() + new WireMockStubStrategy("Test", new Contract(null, false, 0, null), groovyDsl).toWireMockClientStub() } @Issue('180') @@ -1420,7 +1421,7 @@ class WireMockGroovyDslSpec extends Specification implements WireMockStubVerifie } } when: - String wireMockStub = new WireMockStubStrategy(contractDsl).toWireMockClientStub() + String wireMockStub = new WireMockStubStrategy("Test", new Contract(null, false, 0, null), contractDsl).toWireMockClientStub() then: println wireMockStub AssertionUtil.assertThatJsonsAreEqual((''' diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockStubVerifier.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockStubVerifier.groovy index 537fb78ea2..6665a642e9 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockStubVerifier.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/dsl/WireMockStubVerifier.groovy @@ -1,4 +1,5 @@ package io.codearte.accurest.dsl + import com.github.tomakehurst.wiremock.stubbing.StubMapping import java.util.regex.Pattern diff --git a/accurest-core/src/test/groovy/io/codearte/accurest/file/ContractFileScannerSpec.groovy b/accurest-core/src/test/groovy/io/codearte/accurest/file/ContractFileScannerSpec.groovy index d6c0fdd1d2..e02e06cc56 100644 --- a/accurest-core/src/test/groovy/io/codearte/accurest/file/ContractFileScannerSpec.groovy +++ b/accurest-core/src/test/groovy/io/codearte/accurest/file/ContractFileScannerSpec.groovy @@ -1,5 +1,6 @@ package io.codearte.accurest.file +import com.google.common.collect.ListMultimap import com.google.common.collect.Multimap import spock.lang.Specification @@ -17,7 +18,7 @@ class ContractFileScannerSpec extends Specification { Set ignored = ["other/different/**"] as Set ContractFileScanner scanner = new ContractFileScanner(baseDir, excluded, ignored) when: - Multimap result = scanner.findContracts() + ListMultimap result = scanner.findContracts() then: result.keySet().size() == 3 result.get(baseDir.toPath().resolve("different")).size() == 1 @@ -27,4 +28,18 @@ class ContractFileScannerSpec extends Specification { ignoredSet.size() == 1 ignoredSet.ignored == [true] } + + def "should find contracts group in scenario"() { + given: + File baseDir = new File(this.getClass().getResource("/directory/with/scenario").toURI()) + ContractFileScanner scanner = new ContractFileScanner(baseDir, [] as Set, [] as Set) + when: + ListMultimap contracts = scanner.findContracts() + then: + contracts.values().size() == 3 + contracts.values().find { it.path.fileName.toString().startsWith('01') }.groupSize == 3 + contracts.values().find { it.path.fileName.toString().startsWith('01') }.order == 0 + contracts.values().find { it.path.fileName.toString().startsWith('02') }.order == 1 + contracts.values().find { it.path.fileName.toString().startsWith('03') }.order == 2 + } } diff --git a/accurest-core/src/test/resources/directory/with/scenario/01_login.groovy b/accurest-core/src/test/resources/directory/with/scenario/01_login.groovy new file mode 100644 index 0000000000..e69de29bb2 diff --git a/accurest-core/src/test/resources/directory/with/scenario/02_showCart.groovy b/accurest-core/src/test/resources/directory/with/scenario/02_showCart.groovy new file mode 100644 index 0000000000..e69de29bb2 diff --git a/accurest-core/src/test/resources/directory/with/scenario/03_logout.groovy b/accurest-core/src/test/resources/directory/with/scenario/03_logout.groovy new file mode 100644 index 0000000000..e69de29bb2 diff --git a/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/ScenarioProjectSpec.groovy b/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/ScenarioProjectSpec.groovy new file mode 100755 index 0000000000..ea7d0e27e3 --- /dev/null +++ b/accurest-gradle-plugin/src/test/groovy/io/codearte/accurest/plugin/ScenarioProjectSpec.groovy @@ -0,0 +1,21 @@ +package io.codearte.accurest.plugin + +import nebula.test.IntegrationSpec +import spock.lang.Stepwise + +@Stepwise +class ScenarioProjectSpec extends IntegrationSpec { + + void setup() { + copyResources("functionalTest/scenarioProject", "") + runTasksSuccessfully('clean') //delete accidental output when previously importing SimpleBoot into Idea to tweak it + } + + def "should pass basic flow"() { + given: + assert fileExists('build.gradle') + expect: + runTasksSuccessfully('check') + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle new file mode 100644 index 0000000000..25ca064fc4 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/build.gradle @@ -0,0 +1,92 @@ +buildscript { + repositories { + mavenCentral() + mavenLocal() + } + dependencies { + classpath("org.springframework.boot:spring-boot-gradle-plugin:1.2.6.RELEASE") + } +} + +ext { + restAssuredVersion = '2.5.0' + spockVersion = '1.0-groovy-2.4' + wiremockVersion = '2.0.5-beta' + + accurestStubsBaseDirectory = 'src/test/resources/stubs' +} + +subprojects { + apply plugin: 'groovy' + + repositories { + mavenCentral() + mavenLocal() + } + + dependencies { + testCompile "org.codehaus.groovy:groovy-all:2.4.5" + testCompile "org.spockframework:spock-core:$spockVersion" + testCompile("junit:junit:4.12") + testCompile "com.github.tomakehurst:wiremock:$wiremockVersion" + } +} + +configure([project(':fraudDetectionService'), project(':loanApplicationService')]) { + apply plugin: 'spring-boot' + apply plugin: 'accurest' + + ext { + wireMockStubsOutputDirRoot = file("${project.buildDir}/production/${project.name}-stubs/") + wireMockStubsOutputDir = new File(wireMockStubsOutputDirRoot, 'mappings/') + } + + accurest { + targetFramework = 'Spock' + testMode = 'MockMvc' + baseClassForTests = 'com.blogspot.toomuchcoding.MvcSpec' + contractsDslDir = file("${project.projectDir.absolutePath}/mappings/") + generatedTestSourcesDir = file("${project.buildDir}/generated-sources/") + stubsOutputDir = wireMockStubsOutputDir + } + + jar { + version = '0.0.1' + } + + dependencies { + compile("org.springframework.boot:spring-boot-starter-web") { + exclude module: "spring-boot-starter-tomcat" + } + compile("org.springframework.boot:spring-boot-starter-jetty") + compile("org.springframework.boot:spring-boot-starter-actuator") + + testRuntime "org.spockframework:spock-spring:$spockVersion" + testCompile "org.springframework:spring-test" + testCompile "com.jayway.restassured:rest-assured:$restAssuredVersion" + testCompile "com.jayway.restassured:spring-mock-mvc:$restAssuredVersion" + } + + task cleanup(type: Delete) { + delete 'src/test/resources/mappings', 'src/test/resources/stubs' + } + + clean.dependsOn('cleanup') + +} + +configure(project(':fraudDetectionService')) { + test.dependsOn('generateWireMockClientStubs') +} + +configure(project(':loanApplicationService')) { + + task copyCollaboratorStubs(type: Copy) { + File fraudBuildDir = project(':fraudDetectionService').buildDir + from(new File(fraudBuildDir, "/production/${project(':fraudDetectionService').name}-stubs/")) + into "src/test/resources/" + } + + generateAccurest.dependsOn('copyCollaboratorStubs') +} + diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy new file mode 100644 index 0000000000..7bc64d0dac --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/1_shouldMarkClientAsNotFraud.groovy @@ -0,0 +1,28 @@ +io.codearte.accurest.dsl.GroovyDsl.make { + request { + method 'PUT' + url '/fraudcheck' + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":123.123 + } + """ + ) + headers { + header('Content-Type', 'application/vnd.fraud.v1+json') + } + + } + response { + status 200 + body( + fraudCheckStatus: "OK", + rejectionReason: $(client(null), server(execute('assertThatRejectionReasonIsNull($it)'))) + ) + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy new file mode 100644 index 0000000000..44b1c08604 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/mappings/fraudDetectionService/2_shouldMarkClientAsFraud.groovy @@ -0,0 +1,27 @@ +io.codearte.accurest.dsl.GroovyDsl.make { + request { + method """PUT""" + url """/fraudcheck""" + body(""" + { + "clientPesel":"${value(client(regex('[0-9]{10}')), server('1234567890'))}", + "loanAmount":99999} + """ + ) + headers { + header("""Content-Type""", """application/vnd.fraud.v1+json""") + } + + } + response { + status 200 + body( """{ + "fraudCheckStatus": "${value(client('FRAUD'), server(regex('[A-Z]{5}')))}", + "rejectionReason": "Amount too high" +}""") + headers { + header('Content-Type': 'application/vnd.fraud.v1+json') + } + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java new file mode 100644 index 0000000000..5a1a60244e --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java @@ -0,0 +1,17 @@ +package com.blogspot.toomuchcoding.frauddetection; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAutoConfiguration +@ComponentScan +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java new file mode 100644 index 0000000000..e264462cce --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/FraudDetectionController.java @@ -0,0 +1,39 @@ +package com.blogspot.toomuchcoding.frauddetection; + +import com.blogspot.toomuchcoding.frauddetection.model.FraudCheck; +import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckResult; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.math.BigDecimal; + +import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.FRAUD; +import static com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus.OK; +import static org.springframework.web.bind.annotation.RequestMethod.PUT; + +@RestController +public class FraudDetectionController { + + private static final String FRAUD_SERVICE_JSON_VERSION_1 = "application/vnd.fraud.v1+json"; + private static final String NO_REASON = null; + private static final String AMOUNT_TOO_HIGH = "Amount too high"; + private static final BigDecimal MAX_AMOUNT = new BigDecimal("5000"); + + @RequestMapping( + value = "/fraudcheck", + method = PUT, + consumes = FRAUD_SERVICE_JSON_VERSION_1, + produces = FRAUD_SERVICE_JSON_VERSION_1) + public FraudCheckResult fraudCheck(@RequestBody FraudCheck fraudCheck) { + if (amountGreaterThanThreshold(fraudCheck)) { + return new FraudCheckResult(FRAUD, AMOUNT_TOO_HIGH); + } + return new FraudCheckResult(OK, NO_REASON); + } + + private boolean amountGreaterThanThreshold(FraudCheck fraudCheck) { + return MAX_AMOUNT.compareTo(fraudCheck.getLoanAmount()) < 0; + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java new file mode 100644 index 0000000000..77471aee19 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheck.java @@ -0,0 +1,29 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +import java.math.BigDecimal; + +public class FraudCheck { + + private String clientPesel; + + private BigDecimal loanAmount; + + public FraudCheck() { + } + + public String getClientPesel() { + return clientPesel; + } + + public void setClientPesel(String clientPesel) { + this.clientPesel = clientPesel; + } + + public BigDecimal getLoanAmount() { + return loanAmount; + } + + public void setLoanAmount(BigDecimal loanAmount) { + this.loanAmount = loanAmount; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java new file mode 100644 index 0000000000..28efc573f5 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckResult.java @@ -0,0 +1,32 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +public class FraudCheckResult { + + private FraudCheckStatus fraudCheckStatus; + + private String rejectionReason; + + public FraudCheckResult() { + } + + public FraudCheckResult(FraudCheckStatus fraudCheckStatus, String rejectionReason) { + this.fraudCheckStatus = fraudCheckStatus; + this.rejectionReason = rejectionReason; + } + + public FraudCheckStatus getFraudCheckStatus() { + return fraudCheckStatus; + } + + public void setFraudCheckStatus(FraudCheckStatus fraudCheckStatus) { + this.fraudCheckStatus = fraudCheckStatus; + } + + public String getRejectionReason() { + return rejectionReason; + } + + public void setRejectionReason(String rejectionReason) { + this.rejectionReason = rejectionReason; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..b87c365d51 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,5 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/resources/application.yml b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/resources/application.yml new file mode 100644 index 0000000000..a30a91f034 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/main/resources/application.yml @@ -0,0 +1 @@ +server.port=8085 \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy new file mode 100644 index 0000000000..bcb6ef1579 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/fraudDetectionService/src/test/groovy/com/blogspot/toomuchcoding/MvcSpec.groovy @@ -0,0 +1,15 @@ +package com.blogspot.toomuchcoding + +import com.blogspot.toomuchcoding.frauddetection.FraudDetectionController +import com.jayway.restassured.module.mockmvc.RestAssuredMockMvc +import spock.lang.Specification + +class MvcSpec extends Specification { + def setup() { + RestAssuredMockMvc.standaloneSetup(new FraudDetectionController()) + } + + void assertThatRejectionReasonIsNull(def rejectionReason) { + assert !rejectionReason + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.jar b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000000..667288ad6c Binary files /dev/null and b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.jar differ diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000000..b4603dcb69 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,6 @@ +#Wed Jan 28 00:32:44 CET 2015 +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists +distributionUrl=http\://services.gradle.org/distributions/gradle-2.4-all.zip diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew new file mode 100755 index 0000000000..91a7e269e1 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew @@ -0,0 +1,164 @@ +#!/usr/bin/env bash + +############################################################################## +## +## Gradle start up script for UN*X +## +############################################################################## + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + +APP_NAME="Gradle" +APP_BASE_NAME=`basename "$0"` + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD="maximum" + +warn ( ) { + echo "$*" +} + +die ( ) { + echo + echo "$*" + echo + exit 1 +} + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +case "`uname`" in + CYGWIN* ) + cygwin=true + ;; + Darwin* ) + darwin=true + ;; + MINGW* ) + msys=true + ;; +esac + +# For Cygwin, ensure paths are in UNIX format before anything is touched. +if $cygwin ; then + [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` +fi + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >&- +APP_HOME="`pwd -P`" +cd "$SAVED" >&- + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD="java" + which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." +fi + +# Increase the maximum file descriptors if we can. +if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then + MAX_FD_LIMIT=`ulimit -H -n` + if [ $? -eq 0 ] ; then + if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then + MAX_FD="$MAX_FD_LIMIT" + fi + ulimit -n $MAX_FD + if [ $? -ne 0 ] ; then + warn "Could not set maximum file descriptor limit: $MAX_FD" + fi + else + warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" + fi +fi + +# For Darwin, add options to specify how the application appears in the dock +if $darwin; then + GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" +fi + +# For Cygwin, switch paths to Windows format before running java +if $cygwin ; then + APP_HOME=`cygpath --path --mixed "$APP_HOME"` + CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + + # We build the pattern for arguments to be converted via cygpath + ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` + SEP="" + for dir in $ROOTDIRSRAW ; do + ROOTDIRS="$ROOTDIRS$SEP$dir" + SEP="|" + done + OURCYGPATTERN="(^($ROOTDIRS))" + # Add a user-defined pattern to the cygpath arguments + if [ "$GRADLE_CYGPATTERN" != "" ] ; then + OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" + fi + # Now convert the arguments - kludge to limit ourselves to /bin/sh + i=0 + for arg in "$@" ; do + CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` + CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option + + if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition + eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` + else + eval `echo args$i`="\"$arg\"" + fi + i=$((i+1)) + done + case $i in + (0) set -- ;; + (1) set -- "$args0" ;; + (2) set -- "$args0" "$args1" ;; + (3) set -- "$args0" "$args1" "$args2" ;; + (4) set -- "$args0" "$args1" "$args2" "$args3" ;; + (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + esac +fi + +# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules +function splitJvmOpts() { + JVM_OPTS=("$@") +} +eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS +JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" + +exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew.bat b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew.bat new file mode 100644 index 0000000000..8a0b282aa6 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/gradlew.bat @@ -0,0 +1,90 @@ +@if "%DEBUG%" == "" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + +set DIRNAME=%~dp0 +if "%DIRNAME%" == "" set DIRNAME=. +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if "%ERRORLEVEL%" == "0" goto init + +echo. +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto init + +echo. +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% +echo. +echo Please set the JAVA_HOME variable in your environment to match the +echo location of your Java installation. + +goto fail + +:init +@rem Get command-line arguments, handling Windowz variants + +if not "%OS%" == "Windows_NT" goto win9xME_args +if "%@eval[2+2]" == "4" goto 4NT_args + +:win9xME_args +@rem Slurp the command line arguments. +set CMD_LINE_ARGS= +set _SKIP=2 + +:win9xME_args_slurp +if "x%~1" == "x" goto execute + +set CMD_LINE_ARGS=%* +goto execute + +:4NT_args +@rem Get arguments from the 4NT Shell from JP Software +set CMD_LINE_ARGS=%$ + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% + +:end +@rem End local scope for the variables with windows NT shell +if "%ERRORLEVEL%"=="0" goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 +exit /b 1 + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/mappings/.gitkeep b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/mappings/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java new file mode 100644 index 0000000000..5a1a60244e --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/Application.java @@ -0,0 +1,17 @@ +package com.blogspot.toomuchcoding.frauddetection; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.context.annotation.ComponentScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAutoConfiguration +@ComponentScan +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java new file mode 100644 index 0000000000..a2d8ce1e74 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/LoanApplicationService.java @@ -0,0 +1,68 @@ +package com.blogspot.toomuchcoding.frauddetection; + +import com.blogspot.toomuchcoding.frauddetection.model.FraudCheckStatus; +import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceRequest; +import com.blogspot.toomuchcoding.frauddetection.model.FraudServiceResponse; +import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication; +import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult; +import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Service; +import org.springframework.web.client.RestTemplate; + +@Service +public class LoanApplicationService { + + private static final String FRAUD_SERVICE_JSON_VERSION_1 = + "application/vnd.fraud.v1+json"; + + private final RestTemplate restTemplate; + + private int port = 8080; + + public LoanApplicationService() { + this.restTemplate = new RestTemplate(); + } + + public LoanApplicationResult loanApplication(LoanApplication loanApplication) { + FraudServiceRequest request = + new FraudServiceRequest(loanApplication); + + FraudServiceResponse response = + sendRequestToFraudDetectionService(request); + + return buildResponseFromFraudResult(response); + } + + private FraudServiceResponse sendRequestToFraudDetectionService( + FraudServiceRequest request) { + HttpHeaders httpHeaders = new HttpHeaders(); + httpHeaders.add(HttpHeaders.CONTENT_TYPE, FRAUD_SERVICE_JSON_VERSION_1); + + ResponseEntity response = + restTemplate.exchange("http://localhost:" + port + "/fraudcheck", HttpMethod.PUT, + new HttpEntity<>(request, httpHeaders), + FraudServiceResponse.class); + + return response.getBody(); + } + + private LoanApplicationResult buildResponseFromFraudResult(FraudServiceResponse response) { + LoanApplicationStatus applicationStatus = null; + if (FraudCheckStatus.OK == response.getFraudCheckStatus()) { + applicationStatus = LoanApplicationStatus.LOAN_APPLIED; + } else if (FraudCheckStatus.FRAUD == response.getFraudCheckStatus()) { + applicationStatus = LoanApplicationStatus.LOAN_APPLICATION_REJECTED; + } + + return new LoanApplicationResult(applicationStatus, response.getRejectionReason()); + } + + public void setPort(int port) { + this.port = port; + } + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java new file mode 100644 index 0000000000..5e91273eda --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/Client.java @@ -0,0 +1,14 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +public class Client { + + private String pesel; + + public String getPesel() { + return pesel; + } + + public void setPesel(String pesel) { + this.pesel = pesel; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java new file mode 100644 index 0000000000..b87c365d51 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudCheckStatus.java @@ -0,0 +1,5 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +public enum FraudCheckStatus { + OK, FRAUD +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java new file mode 100644 index 0000000000..ac595998bc --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceRequest.java @@ -0,0 +1,34 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +import java.math.BigDecimal; + +public class FraudServiceRequest { + + private String clientPesel; + + private BigDecimal loanAmount; + + public FraudServiceRequest() { + } + + public FraudServiceRequest(LoanApplication loanApplication) { + this.clientPesel = loanApplication.getClient().getPesel(); + this.loanAmount = loanApplication.getAmount(); + } + + public String getClientPesel() { + return clientPesel; + } + + public void setClientPesel(String clientPesel) { + this.clientPesel = clientPesel; + } + + public BigDecimal getLoanAmount() { + return loanAmount; + } + + public void setLoanAmount(BigDecimal loanAmount) { + this.loanAmount = loanAmount; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java new file mode 100644 index 0000000000..9f3353ecbf --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/FraudServiceResponse.java @@ -0,0 +1,27 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +public class FraudServiceResponse { + + private FraudCheckStatus fraudCheckStatus; + + private String rejectionReason; + + public FraudServiceResponse() { + } + + public FraudCheckStatus getFraudCheckStatus() { + return fraudCheckStatus; + } + + public void setFraudCheckStatus(FraudCheckStatus fraudCheckStatus) { + this.fraudCheckStatus = fraudCheckStatus; + } + + public String getRejectionReason() { + return rejectionReason; + } + + public void setRejectionReason(String rejectionReason) { + this.rejectionReason = rejectionReason; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java new file mode 100644 index 0000000000..816087988b --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplication.java @@ -0,0 +1,36 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +import java.math.BigDecimal; + +public class LoanApplication { + + private Client client; + + private BigDecimal amount; + + private String loanApplicationId; + + public Client getClient() { + return client; + } + + public void setClient(Client client) { + this.client = client; + } + + public BigDecimal getAmount() { + return amount; + } + + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + public String getLoanApplicationId() { + return loanApplicationId; + } + + public void setLoanApplicationId(String loanApplicationId) { + this.loanApplicationId = loanApplicationId; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java new file mode 100644 index 0000000000..523f4f2ea3 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationResult.java @@ -0,0 +1,32 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +public class LoanApplicationResult { + + private LoanApplicationStatus loanApplicationStatus; + + private String rejectionReason; + + public LoanApplicationResult() { + } + + public LoanApplicationResult(LoanApplicationStatus loanApplicationStatus, String rejectionReason) { + this.loanApplicationStatus = loanApplicationStatus; + this.rejectionReason = rejectionReason; + } + + public LoanApplicationStatus getLoanApplicationStatus() { + return loanApplicationStatus; + } + + public void setLoanApplicationStatus(LoanApplicationStatus loanApplicationStatus) { + this.loanApplicationStatus = loanApplicationStatus; + } + + public String getRejectionReason() { + return rejectionReason; + } + + public void setRejectionReason(String rejectionReason) { + this.rejectionReason = rejectionReason; + } +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java new file mode 100644 index 0000000000..7f7f86e0ea --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/java/com/blogspot/toomuchcoding/frauddetection/model/LoanApplicationStatus.java @@ -0,0 +1,5 @@ +package com.blogspot.toomuchcoding.frauddetection.model; + +public enum LoanApplicationStatus { + LOAN_APPLIED, LOAN_APPLICATION_REJECTED +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/resources/application.yml b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/resources/application.yml new file mode 100644 index 0000000000..e86bbd0e0f --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/main/resources/application.yml @@ -0,0 +1 @@ +server.port=8090 \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy new file mode 100644 index 0000000000..5a7d0ae9a9 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/groovy/com/blogspot/toomuchcoding/LoanApplicationServiceSpec.groovy @@ -0,0 +1,58 @@ +package com.blogspot.toomuchcoding + +import com.blogspot.toomuchcoding.frauddetection.Application +import com.blogspot.toomuchcoding.frauddetection.LoanApplicationService +import com.blogspot.toomuchcoding.frauddetection.model.Client +import com.blogspot.toomuchcoding.frauddetection.model.LoanApplication +import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationResult +import com.blogspot.toomuchcoding.frauddetection.model.LoanApplicationStatus +import com.github.tomakehurst.wiremock.junit.WireMockClassRule +import org.junit.ClassRule +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.boot.test.SpringApplicationContextLoader +import org.springframework.test.context.ContextConfiguration +import spock.lang.Shared +import spock.lang.Specification +import spock.lang.Stepwise + +@ContextConfiguration(loader = SpringApplicationContextLoader, classes = Application) +@Stepwise +class LoanApplicationServiceSpec extends Specification { + + public static int port = org.springframework.util.SocketUtils.findAvailableTcpPort() + + @ClassRule + @Shared + WireMockClassRule wireMockRule = new WireMockClassRule(port) + + @Autowired + LoanApplicationService sut + + def setup() { + sut.port = port + } + + def 'should successfully apply for loan'() { + given: + LoanApplication application = + new LoanApplication(client: new Client(pesel: '1234567890'), amount: 123.123) + when: + LoanApplicationResult loanApplication = sut.loanApplication(application) + then: + loanApplication.loanApplicationStatus == LoanApplicationStatus.LOAN_APPLIED + loanApplication.rejectionReason == null + } + + def 'should be rejected due to abnormal loan amount'() { + given: + LoanApplication application = + new LoanApplication(client: new Client(pesel: '1234567890'), amount: 99_999) + when: + LoanApplicationResult loanApplication = sut.loanApplication(application) + then: + loanApplication.loanApplicationStatus == LoanApplicationStatus.LOAN_APPLICATION_REJECTED + loanApplication.rejectionReason == 'Amount too high' + } + + +} diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json new file mode 100644 index 0000000000..157726ca2e --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsFraud.json @@ -0,0 +1,23 @@ +{ + "request": { + "method": "PUT", + "headers": { + "Content-Type": { + "equalTo": "application/vnd.fraud.v1+json" + } + }, + "url": "/fraudcheck", + "bodyPatterns": [ + { + "matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"99999\"}" + } + ] + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/vnd.fraud.v1+json" + }, + "body": "{\"fraudCheckStatus\":\"FRAUD\",\"rejectionReason\":\"Amount too high\"}" + } +} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json new file mode 100644 index 0000000000..afa27159d9 --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/loanApplicationService/src/test/resources/mappings/fraudDetectionService/shouldMarkClientAsNotFraud.json @@ -0,0 +1,23 @@ +{ + "request": { + "method": "PUT", + "headers": { + "Content-Type": { + "equalTo": "application/vnd.fraud.v1+json" + } + }, + "url": "/fraudcheck", + "bodyPatterns": [ + { + "matches": "{\"clientPesel\":\"[0-9]{10}\",\"loanAmount\":\"123.123\"}" + } + ] + }, + "response": { + "status": 200, + "headers": { + "Content-Type": "application/vnd.fraud.v1+json" + }, + "body": "{\"fraudCheckStatus\":\"OK\",\"rejectionReason\":null}" + } +} \ No newline at end of file diff --git a/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle new file mode 100644 index 0000000000..6a42a6c7ce --- /dev/null +++ b/accurest-gradle-plugin/src/test/resources/functionalTest/scenarioProject/settings.gradle @@ -0,0 +1,2 @@ +include ':fraudDetectionService' +include ':loanApplicationService'