Search in sources :

Example 1 with ResourceWebScriptGet

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

the class ParamsExtractorTests method testGetExtractor.

@Test
public void testGetExtractor() {
    ResourceWebScriptGet extractor = new ResourceWebScriptGet();
    extractor.setLocator(locator);
    Map<String, String> templateVars = new HashMap<String, String>();
    WebScriptRequest request = mock(WebScriptRequest.class);
    when(request.getServiceMatch()).thenReturn(new Match(null, templateVars, null));
    Params params = extractor.extractParams(mockEntity(), request);
    assertNull("For getting a Collection there should be no entity params.", params.getEntityId());
    assertNull("For getting a Collection there should be no passed params.", params.getPassedIn());
    assertNull("For getting a Collection there should be no relationshipId params.", params.getRelationshipId());
    assertEquals(Paging.DEFAULT_SKIP_COUNT, params.getPaging().getSkipCount());
    assertEquals(Paging.DEFAULT_MAX_ITEMS, params.getPaging().getMaxItems());
    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(mockEntity(), request);
    assertNotNull(params);
    assertNotNull(params.getRelationsFilter());
    assertFalse(params.includeSource());
    templateVars.put(ResourceLocator.RELATIONSHIP_RESOURCE, "codfish");
    params = extractor.extractParams(mockRelationship(), request);
    assertNotNull(params);
    assertNull("For getting a Collection there should be no relationshipId params.", params.getRelationshipId());
    templateVars.put(ResourceLocator.RELATIONSHIP_ID, "45678");
    params = extractor.extractParams(mockRelationship(), request);
    assertNotNull(params);
    assertEquals("1234", params.getEntityId());
    assertEquals("45678", params.getRelationshipId());
    assertFalse(params.includeSource());
    testExtractAddressedParams(templateVars, request, extractor);
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) ResourceWebScriptGet(org.alfresco.rest.framework.webscripts.ResourceWebScriptGet) HashMap(java.util.HashMap) Params(org.alfresco.rest.framework.resource.parameters.Params) Match(org.springframework.extensions.webscripts.Match) Test(org.junit.Test)

Example 2 with ResourceWebScriptGet

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

the class ParamsExtractorTests method testSpecialChars.

@Test
public void testSpecialChars() throws IOException {
    String specialChars = new String(new char[] { (char) '香' }) + " 香蕉";
    ResourceWebScriptPost extractor = new ResourceWebScriptPost();
    extractor.setAssistant(assistant);
    extractor.setLocator(locator);
    Map<String, String> templateVars = new HashMap<String, String>();
    String mockMe = "{\"name\":\"" + specialChars + "\",\"created\":\"2012-03-23T15:56:18.552+0000\",\"age\":54,\"id\":\"1234A3\",\"farm\":\"LARGE\"}";
    Content content = mock(Content.class);
    when(content.getReader()).thenReturn(new StringReader(mockMe));
    WebScriptRequest request = mock(WebScriptRequest.class);
    when(request.getServiceMatch()).thenReturn(new Match(null, templateVars, null));
    when(request.getContent()).thenReturn(content);
    Params params = extractor.extractParams(mockEntity(), request);
    assertNotNull(params);
    Object passed = params.getPassedIn();
    assertTrue(List.class.isAssignableFrom(passed.getClass()));
    @SuppressWarnings("unchecked") List<Object> passedObjs = (List<Object>) passed;
    assertTrue(passedObjs.size() == 1);
    assertTrue("A Farmer was passed in.", Farmer.class.equals(passedObjs.get(0).getClass()));
    Farmer f = (Farmer) passedObjs.get(0);
    assertTrue(f.getName().equals("香 香蕉"));
    // Test passing in special characters as a param.
    ResourceWebScriptGet getExtractor = new ResourceWebScriptGet();
    getExtractor.setAssistant(assistant);
    getExtractor.setLocator(locator);
    Map<String, String> getTemplateVars = new HashMap<String, String>();
    WebScriptRequest getRequest = mock(WebScriptRequest.class);
    when(getRequest.getServiceMatch()).thenReturn(new Match(null, getTemplateVars, null));
    when(getRequest.getParameterNames()).thenReturn(new String[] { "aParam" });
    when(getRequest.getParameterValues("aParam")).thenReturn(new String[] { specialChars });
    Params pGet = getExtractor.extractParams(mockEntity(), getRequest);
    assertNotNull(pGet);
    String pVal = pGet.getParameter("aParam");
    assertTrue(pVal.equals("香 香蕉"));
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) ResourceWebScriptGet(org.alfresco.rest.framework.webscripts.ResourceWebScriptGet) HashMap(java.util.HashMap) Params(org.alfresco.rest.framework.resource.parameters.Params) Match(org.springframework.extensions.webscripts.Match) ResourceWebScriptPost(org.alfresco.rest.framework.webscripts.ResourceWebScriptPost) Content(org.springframework.extensions.surf.util.Content) StringReader(java.io.StringReader) List(java.util.List) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)2 Params (org.alfresco.rest.framework.resource.parameters.Params)2 ResourceWebScriptGet (org.alfresco.rest.framework.webscripts.ResourceWebScriptGet)2 Test (org.junit.Test)2 Match (org.springframework.extensions.webscripts.Match)2 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)2 StringReader (java.io.StringReader)1 List (java.util.List)1 Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)1 ResourceWebScriptPost (org.alfresco.rest.framework.webscripts.ResourceWebScriptPost)1 Content (org.springframework.extensions.surf.util.Content)1