Search in sources :

Example 1 with GetRequest

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);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) JSONObject(org.json.JSONObject) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 2 with GetRequest

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);
}
Also used : GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 3 with GetRequest

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);
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest) DeleteRequest(org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)

Example 4 with GetRequest

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());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Example 5 with GetRequest

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());
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Aggregations

GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)182 Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)171 JSONObject (org.json.JSONObject)141 JSONArray (org.json.JSONArray)89 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)25 HashMap (java.util.HashMap)23 JSONTokener (org.json.JSONTokener)23 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)21 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)17 NodeRef (org.alfresco.service.cmr.repository.NodeRef)14 Serializable (java.io.Serializable)13 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)13 QName (org.alfresco.service.namespace.QName)13 ArrayList (java.util.ArrayList)12 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)12 Date (java.util.Date)11 WorkflowTask (org.alfresco.service.cmr.workflow.WorkflowTask)11 JSONStringer (org.json.JSONStringer)7 Calendar (java.util.Calendar)6 UserTransaction (javax.transaction.UserTransaction)6