Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make groovy request accept 404 -- Error: hudson.AbortException: Fail: the returned code 404 is not in the accepted range: [[100‥399]]

I'm writing some integration tests for my api. Now, i want to test an request that returns an 404. This is what i want, but groovy/hudson always marks my build as failed when i try it. This is, of course, because 404 is not between the accepted range.

I DO understand the error. The problem is that i don't know how to fix this.

Part of my Groovy file:

def testID = "fakeID"
response = httpRequest acceptType: "APPLICATION_JSON", 
          contentType: "APPLICATION_JSON",
          customHeaders: [[name: 'Authorization', value: token]],
          url: server+port+"/exams"+testID

Does anyone know how to make groovy accept this 404? All help beeing thanked for in advance!

like image 978
Nebulosar Avatar asked Jan 14 '18 13:01

Nebulosar


1 Answers

You can use validResponseCodes parameter to specify a range of valid response codes

response = httpRequest acceptType: "APPLICATION_JSON", 
          contentType: "APPLICATION_JSON",
          customHeaders: [[name: 'Authorization', value: token]],
          url: server+port+"/exams"+testID,
          validResponseCodes: '200:404'

See httpRequest documentation

like image 151
Vitalii Vitrenko Avatar answered Oct 18 '22 09:10

Vitalii Vitrenko