use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class LoginTest method testAuthenticationGetJSON.
/**
* Positive test - login and retrieve a ticket,
* - via json method
*/
public void testAuthenticationGetJSON() throws Exception {
/**
* Login via get method to return json
*/
String loginURL = "/api/login.json?u=" + USER_ONE + "&pw=" + USER_ONE;
Response resp = sendRequest(new GetRequest(loginURL), Status.STATUS_OK);
JSONObject result = new JSONObject(resp.getContentAsString());
JSONObject data = result.getJSONObject("data");
String ticket = data.getString("ticket");
assertNotNull("ticket is null", ticket);
/**
* This is now testing the framework ... With a different format.
*/
String login2URL = "/api/login?u=" + USER_ONE + "&pw=" + USER_ONE + "&format=json";
Response resp2 = sendRequest(new GetRequest(login2URL), Status.STATUS_OK);
JSONObject result2 = new JSONObject(resp2.getContentAsString());
JSONObject data2 = result2.getJSONObject("data");
String ticket2 = data2.getString("ticket");
assertNotNull("ticket is null", ticket2);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class LoginTest method testWrongPassword.
/**
* Negative tests - wrong password
*/
public void testWrongPassword() throws Exception {
/**
* Login via get method and wrong password, should get FORBIDDEN
*/
String loginURL = "/api/login?u=" + USER_ONE + "&pw=" + "crap";
sendRequest(new GetRequest(loginURL), Status.STATUS_FORBIDDEN);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class LoginTest method testAuthentication.
/**
* Positive test - login and retrieve a ticket via get - return xml,
* - via get method
* validate ticket
* logout
* fail to validate ticket
* fail to get ticket
*/
public void testAuthentication() throws Exception {
/**
* Login via get method to return xml
*/
String loginURL = "/api/login?u=" + USER_ONE + "&pw=" + USER_ONE;
Response resp = sendRequest(new GetRequest(loginURL), Status.STATUS_OK);
String xmlFragment = resp.getContentAsString();
assertNotNull("xmlFragment");
assertTrue("xmlFragment contains ticket", xmlFragment.contains("<ticket>"));
String ticket = parseTicket(xmlFragment);
String ticketURL = "/api/login/ticket/" + ticket;
/**
* Negative test - validate as AuthenticationUtil.getAdminUserName() - should fail with a 404
*/
setDefaultRunAs(AuthenticationUtil.getAdminUserName());
sendRequest(new GetRequest(ticketURL), Status.STATUS_NOT_FOUND);
/**
* Validate the ticket - should succeed
*/
setDefaultRunAs(USER_ONE);
sendRequest(new GetRequest(ticketURL), Status.STATUS_OK);
/**
* Logout
*/
sendRequest(new DeleteRequest(ticketURL), Status.STATUS_OK);
/**
* Validate the ticket - should fail now
*/
sendRequest(new GetRequest(ticketURL), Status.STATUS_NOT_FOUND);
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class ReadOnlyTransactionInGetRestApiTest method testGetSiteLink.
public void testGetSiteLink() throws Exception {
Response response = sendRequest(new GetRequest(URL_GET_SITE_LINK), 404);
logResponse(response);
assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
}
use of org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest in project alfresco-remote-api by Alfresco.
the class ReadOnlyTransactionInGetRestApiTest method testGetSiteForumPosts.
public void testGetSiteForumPosts() throws Exception {
Response response = sendRequest(new GetRequest(URL_GET_SITE_FORUM_POSTS), 200);
logResponse(response);
assertEquals(Status.STATUS_OK, response.getStatus());
}
Aggregations