Search in sources :

Example 6 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response 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 7 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response 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 8 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response 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)

Example 9 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.

the class ReadOnlyTransactionInGetRestApiTest method testGetSiteBlog.

public void testGetSiteBlog() throws Exception {
    // TODO: Fixme - This REST API still requires a readwrite transaction to be successful
    // Also add tests for all other blog GET REST APIs
    Response response = sendRequest(new GetRequest(URL_GET_SITE_BLOG), 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)

Example 10 with Response

use of org.springframework.extensions.webscripts.TestWebScriptServer.Response in project alfresco-remote-api by Alfresco.

the class RepositoryContainerTest method testRunAsAdmin.

/**
 * Person should be current user irrespective of runas user.
 */
public void testRunAsAdmin() throws Exception {
    authenticationComponent.setCurrentUser(USER_ONE);
    // No runas specified within our webscript descriptor
    Response response = sendRequest(new GetRequest("/test/runas"), STATUS_OK);
    assertEquals(USER_ONE, response.getContentAsString());
    authenticationComponent.setCurrentUser(USER_TWO);
    // runas "Admin" specified within our webscript descriptor
    response = sendRequest(new GetRequest("/test/runasadmin"), STATUS_OK);
    assertEquals(USER_TWO, response.getContentAsString());
    authenticationComponent.setSystemUserAsCurrentUser();
}
Also used : Response(org.springframework.extensions.webscripts.TestWebScriptServer.Response) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) GetRequest(org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)

Aggregations

Response (org.springframework.extensions.webscripts.TestWebScriptServer.Response)281 JSONObject (org.json.JSONObject)228 GetRequest (org.springframework.extensions.webscripts.TestWebScriptServer.GetRequest)171 JSONArray (org.json.JSONArray)116 PostRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PostRequest)84 JSONTokener (org.json.JSONTokener)39 PutRequest (org.springframework.extensions.webscripts.TestWebScriptServer.PutRequest)37 NodeRef (org.alfresco.service.cmr.repository.NodeRef)34 DeleteRequest (org.springframework.extensions.webscripts.TestWebScriptServer.DeleteRequest)32 HashMap (java.util.HashMap)24 ArrayList (java.util.ArrayList)16 TestWebScriptServer (org.springframework.extensions.webscripts.TestWebScriptServer)16 Serializable (java.io.Serializable)14 QName (org.alfresco.service.namespace.QName)14 Date (java.util.Date)13 JSONStringer (org.json.JSONStringer)13 UserTransaction (javax.transaction.UserTransaction)12 WorkflowDefinition (org.alfresco.service.cmr.workflow.WorkflowDefinition)12 ReplicationDefinition (org.alfresco.service.cmr.replication.ReplicationDefinition)11 WorkflowPath (org.alfresco.service.cmr.workflow.WorkflowPath)11