Search in sources :

Example 1 with ParamsExtractor

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

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

the class ParamsExtractorTests method testGetExtractor.

@Test
public void testGetExtractor() {
    ParamsExtractor extractor = new ResourceWebScriptGet();
    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) ParamsExtractor(org.alfresco.rest.framework.webscripts.ParamsExtractor) Match(org.springframework.extensions.webscripts.Match) Test(org.junit.Test)

Aggregations

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