Reputation: 58531
I have a service, which I can access with the following jQuery code (from google chrome with --disable-web-security)
$.ajax({
type: 'POST',
url: "http://10.30.1.2:9234/myapp/v6/token/generate",
headers: {
"Content-Type":"application/json",
"Accept":"application/json"
},
data: JSON.stringify({
"staffId" : "13254",
"password" : "JustADummyPassword"
})
}).done(function(data) {
console.log(data);
});
$.ajax({
type: 'GET',
url: "http://10.30.1.2:9234/myapp/v6/user/appl/Firstname/Lastname/[email protected]/1998-01-01",
headers: {
"Content-Type":"application/json",
"Accept":"application/json"
}
}).done(function(data) {
console.log(data);
});
The first call sets a cookie, which is required for the second call to authenticate. This works fine, and both requests return expected results.
I am trying to set up automated testing for the service, and have this written in JAVA, using RestAssured.
public class UserApplication {
public static Map<String, String> authCookies = null;
public static String JSESSIONID = null;
public static void main(String[] args) {
Response resp = hello();
resp = apiUserApplication();
}
public static Response apiUserApplication() {
String userAppl = "http://10.30.1.2:9234/myapp/v6/user/appl/Firstname/Lastname/[email protected]/1998-01-01";
Response response = RestAssured.given()
.cookie("JSESSIONID", JSESSIONID).and()
.header("Accept", "application/json").and()
.header("Content-Type", "application/json").and()
.when().get(userAppl);
return response;
}
public static Response hello() {
String helloUrl = "http://10.30.1.2:9234/myapp/v6/hello";
Response response = RestAssured.given().cookies(authCookies)
.contentType("application/json").when().get(helloUrl);
return response;
}
}
The first call (hello) works fine, and returns 200 code, and gets a valid token for use in the second call. The error I am getting from the second call with a 400 status code is...
{"errors":["Content type 'null' not supported"]}
Upvotes: 2
Views: 3373
Reputation: 8650
I'm not experienced with RestAssured
, but your code is set up to first call, hello
, then apiUserApplication
. You have some class level variables that you default to null
, but you never explicitly give them a value. In particular, it looks in the second call, apiUserApplication
, you are setting the value of the cookie to a null value.
I also do not see why you are returning this response object? It would make sense if you were to examine it, ensure that the response has data as you expected and that you then set this session ID for the second request.
Upvotes: 1
Reputation: 1559
It looks like JSESSIONID
and authCookies
are initialized as null
and not changing in this code.
Upvotes: 0