Search in sources :

Example 1 with ResourceWebScriptDelete

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

the class ParamsExtractorTests method testDeleteExtractor.

@Test
public void testDeleteExtractor() throws IOException {
    ParamsExtractor extractor = new ResourceWebScriptDelete();
    Map<String, String> templateVars = new HashMap<String, String>();
    WebScriptRequest request = mock(WebScriptRequest.class);
    when(request.getServiceMatch()).thenReturn(new Match(null, templateVars, null));
    Params params = null;
    params = extractor.extractParams(mockEntity(), request);
    assertNotNull(params);
    assertNull(params.getEntityId());
    assertNull(params.getRelationshipId());
    assertNotNull(params.getFilter());
    assertTrue("Default filter is BeanPropertiesFilter.AllProperties", BeanPropertiesFilter.AllProperties.class.equals(params.getFilter().getClass()));
    templateVars.put(ResourceLocator.ENTITY_ID, "1234");
    params = extractor.extractParams(mockRelationship(), request);
    assertNotNull(params);
    assertEquals("1234", params.getEntityId());
    assertNull(params.getRelationshipId());
    assertNotNull(params.getFilter());
    assertTrue("Default filter is BeanPropertiesFilter.AllProperties", BeanPropertiesFilter.AllProperties.class.equals(params.getFilter().getClass()));
    templateVars.put(ResourceLocator.RELATIONSHIP_ID, "45678");
    params = extractor.extractParams(mockRelationship(), request);
    assertNotNull(params);
    assertEquals("1234", params.getEntityId());
    assertEquals("45678", params.getRelationshipId());
    assertNotNull(params.getFilter());
    assertTrue("Default filter is BeanPropertiesFilter.AllProperties", BeanPropertiesFilter.AllProperties.class.equals(params.getFilter().getClass()));
    testExtractAddressedParams(templateVars, request, extractor);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) HashMap(java.util.HashMap) Params(org.alfresco.rest.framework.resource.parameters.Params) ResourceWebScriptDelete(org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete) ParamsExtractor(org.alfresco.rest.framework.webscripts.ParamsExtractor) Match(org.springframework.extensions.webscripts.Match) Test(org.junit.Test)

Example 2 with ResourceWebScriptDelete

use of org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete 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

ResourceWebScriptDelete (org.alfresco.rest.framework.webscripts.ResourceWebScriptDelete)2 Test (org.junit.Test)2 HashMap (java.util.HashMap)1 Params (org.alfresco.rest.framework.resource.parameters.Params)1 ApiAssistant (org.alfresco.rest.framework.tools.ApiAssistant)1 AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)1 ParamsExtractor (org.alfresco.rest.framework.webscripts.ParamsExtractor)1 WithResponse (org.alfresco.rest.framework.webscripts.WithResponse)1 Match (org.springframework.extensions.webscripts.Match)1 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)1 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)1