Search in sources :

Example 6 with WithResponse

use of org.alfresco.rest.framework.webscripts.WithResponse in project alfresco-remote-api by Alfresco.

the class WithResponseTest method testSetResponse.

@Test
public void testSetResponse() throws Exception {
    AbstractResourceWebScript responseWriter = new ResourceWebScriptDelete();
    responseWriter.setAssistant(new ApiAssistant());
    WithResponse wr = new WithResponse(Status.STATUS_OK, ResponseWriter.DEFAULT_JSON_CONTENT, ResponseWriter.CACHE_NEVER);
    WebScriptResponse response = mock(WebScriptResponse.class);
    responseWriter.setResponse(response, wr.getStatus(), wr.getCache(), wr.getContentInfo(), wr.getHeaders());
    verify(response, times(1)).setStatus(anyInt());
    verify(response, times(1)).setCache((Cache) any());
    verify(response, times(1)).setContentType(anyString());
    verify(response, times(0)).setHeader(anyString(), anyString());
    response = mock(WebScriptResponse.class);
    responseWriter.setResponse(response, wr.getStatus(), null, null, null);
    verify(response, times(1)).setStatus(anyInt());
    verify(response, times(0)).setCache((Cache) any());
    verify(response, times(0)).setContentType(anyString());
    verify(response, times(0)).setHeader(anyString(), anyString());
    response = mock(WebScriptResponse.class);
    wr.addHeader("king", "can");
    wr.addHeader("king", "kong");
    responseWriter.setResponse(response, wr.getStatus(), null, null, wr.getHeaders());
    verify(response, times(1)).setStatus(anyInt());
    verify(response, times(0)).setCache((Cache) any());
    verify(response, times(0)).setContentType(anyString());
    verify(response, times(1)).setHeader(eq("king"), anyString());
    verify(response, times(1)).addHeader(eq("king"), anyString());
    response = mock(WebScriptResponse.class);
    wr.addHeader("king", "kin");
    wr.setHeader("ping", "ping");
    responseWriter.setResponse(response, wr.getStatus(), null, null, wr.getHeaders());
    verify(response, times(1)).setStatus(anyInt());
    verify(response, times(0)).setCache((Cache) any());
    verify(response, times(0)).setContentType(anyString());
    verify(response, times(1)).setHeader(eq("king"), anyString());
    verify(response, times(1)).setHeader(eq("ping"), anyString());
    verify(response, times(2)).addHeader(eq("king"), anyString());
}
Also used : ApiAssistant(org.alfresco.rest.framework.tools.ApiAssistant) WithResponse(org.alfresco.rest.framework.webscripts.WithResponse) AbstractResourceWebScript(org.alfresco.rest.framework.webscripts.AbstractResourceWebScript) WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) ResourceWebScriptDelete(org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete) Test(org.junit.Test)

Aggregations

WithResponse (org.alfresco.rest.framework.webscripts.WithResponse)6 Test (org.junit.Test)6 Matchers.anyString (org.mockito.Matchers.anyString)2 Method (java.lang.reflect.Method)1 ArrayList (java.util.ArrayList)1 Api (org.alfresco.rest.framework.Api)1 OperationResourceMetaData (org.alfresco.rest.framework.core.OperationResourceMetaData)1 ResourceMetadata (org.alfresco.rest.framework.core.ResourceMetadata)1 ResourceOperation (org.alfresco.rest.framework.core.ResourceOperation)1 ContentInfo (org.alfresco.rest.framework.resource.content.ContentInfo)1 ContentInfoImpl (org.alfresco.rest.framework.resource.content.ContentInfoImpl)1 GrassEntityResource (org.alfresco.rest.framework.tests.api.mocks.GrassEntityResource)1 ApiAssistant (org.alfresco.rest.framework.tools.ApiAssistant)1 AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)1 ResourceWebScriptDelete (org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete)1 Cache (org.springframework.extensions.webscripts.Cache)1 Description (org.springframework.extensions.webscripts.Description)1 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)1 HttpMethod (org.springframework.http.HttpMethod)1