IDE: IntelliJ IdEA 2017.2.4 Language: Groovy 2.4.11 Test Framework: Spock 1.1-groovy-2.4
New to all of the above. No prior experience in Java either. First post here and I actually read the intro and guidelines and trying my best to follow.
JSON request:
{
"source": "source",
"quoteId": null,
"quoteVersion": null,
"quote": {
"globalTransactionId": "k2o4-6969-1fie-poef",
"quoteStatus": "Not Uploaded",
"events": {
"eventDescription": "event description",
"eventTypeName": "Event Type"
},
"someReport": {
"acceptResultsFlag": "Y",
"orderDate": "2017-06-14",
"orderStatus": "string"
},
"anotherReport": {
"id": 627311,
"orderDate": "2017-06-14"
},
"attributes": [
{
"appliedFlag": "Y",
"attributeDetail": {
"name": "attribute1",
"value": "value1"
},
"attributeName": "attribute1"
}
]
}
}
When I attempt to change quote.attributes.appliedFlag I get:
java.lang.IllegalArgumentException: argument type mismatch at com.serviceSpecIdeaNo2.NULL values: verify response codes and message content.(serviceSpecIdeaNo2.groovy:23)
Code:
class serviceSpecIdeaNo2 extends Specification {
def 'NULL values: verify response codes and message content.'() {
given: 'a JSON request with null field values'
def url = 'http://someservice.com:1234'
def path = '/endPoint'
def client = new RESTClient(url)
client.handler.failure = client.handler.success
def inputFile = new File('input.json')
def json = new JsonSlurper().parse(inputFile)
def changeValueTo = null
def (lvl1, lvl2, lvl3, lvl4, lvl5) = data.fullPath.tokenize('.')
if (lvl5 != null) {
json."$lvl1"."$lvl2"."$lvl3"."$lvl4"."$lvl5" = changeValueTo
} else if (lvl4 != null) {
json."$lvl1"."$lvl2"."$lvl3"."$lvl4" = changeValueTo
} else if (lvl3 != null) {
json."$lvl1"."$lvl2"."$lvl3" = changeValueTo
} else if (lvl2 != null) {
json."$lvl1"."$lvl2" = changeValueTo
} else {
json."$lvl1" = changeValueTo
}
when: 'the request is submitted'
def response = client.post([
path : path,
requestContentType: JSON,
body : json
])
Stacktrace
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
DUMMY.groovy: 1: unexpected token: DUMMY @ line 1, column 30.
java.util.LinkedHashMapclass DUMMY { public groovy.lang.Closure _JETGROOVY_EVAL_ = {json->((java.util.LinkedHashMap)json).entrySet().toArray()[2]}}
^
1 error
at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:310)
at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:150)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:120)
at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:132)
at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:350)
at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:144)
at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:110)
at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:234)
at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:168)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:943)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(CompilationUnit.java:605)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(CompilationUnit.java:581)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:558)
at groovy.lang.GroovyClassLoader.doParseClass(GroovyClassLoader.java:298)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:268)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:254)
at groovy.lang.GroovyClassLoader.parseClass(GroovyClassLoader.java:211)
at com.serviceSpecIdeaNo2.$spock_feature_0_0(serviceSpecIdeaNo2.groovy:62)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.spockframework.util.ReflectionUtil.invokeMethod(ReflectionUtil.java:188)
at org.spockframework.runtime.model.MethodInfo.invoke(MethodInfo.java:84)
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
at org.spockframework.runtime.BaseSpecRunner.runFeatureMethod(BaseSpecRunner.java:406)
at org.spockframework.runtime.BaseSpecRunner.doRunIteration(BaseSpecRunner.java:324)
at org.spockframework.runtime.BaseSpecRunner$6.invoke(BaseSpecRunner.java:309)
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
at org.spockframework.runtime.BaseSpecRunner.runIteration(BaseSpecRunner.java:288)
at org.spockframework.runtime.BaseSpecRunner.initializeAndRunIteration(BaseSpecRunner.java:278)
at org.spockframework.runtime.ParameterizedSpecRunner.runIterations(ParameterizedSpecRunner.java:139)
at org.spockframework.runtime.ParameterizedSpecRunner.runParameterizedFeature(ParameterizedSpecRunner.java:41)
at org.spockframework.runtime.BaseSpecRunner.doRunFeature(BaseSpecRunner.java:262)
at org.spockframework.runtime.BaseSpecRunner$5.invoke(BaseSpecRunner.java:246)
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:238)
at org.spockframework.runtime.BaseSpecRunner.runFeatures(BaseSpecRunner.java:188)
at org.spockframework.runtime.BaseSpecRunner.doRunSpec(BaseSpecRunner.java:98)
at org.spockframework.runtime.BaseSpecRunner$1.invoke(BaseSpecRunner.java:84)
at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:481)
at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:464)
at org.spockframework.runtime.BaseSpecRunner.runSpec(BaseSpecRunner.java:76)
at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:67)
at org.spockframework.runtime.Sputnik.run(Sputnik.java:63)
at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
java.lang.IllegalArgumentException: argument type mismatch
at com.qa.ServiceSpecIdeaNo2.NULL values: verify response codes and message content.(serviceSpecIdeaNo2.groovy:23)