Search in sources :

Example 11 with Farmer

use of org.alfresco.rest.framework.tests.api.mocks.Farmer in project alfresco-remote-api by Alfresco.

the class ParamsExtractorTests method testPutExtractor.

@Test
public void testPutExtractor() throws IOException {
    // Put together the stubs
    ResourceWebScriptPut extractor = new ResourceWebScriptPut();
    extractor.setAssistant(assistant);
    Map<String, String> templateVars = new HashMap<String, String>();
    Content content = mock(Content.class);
    when(content.getReader()).thenReturn(new StringReader(JsonJacksonTests.FARMER_JSON));
    WebScriptRequest request = mock(WebScriptRequest.class);
    when(request.getServiceMatch()).thenReturn(new Match(null, templateVars, null));
    when(request.getContent()).thenReturn(content);
    when(request.getContentType()).thenReturn("application/pdf; charset=UTF-16BE");
    Params params = null;
    try {
        params = extractor.extractParams(mockEntity(), request);
        fail("Should not get here. PUT is executed against the instance URL");
    } catch (UnsupportedResourceOperationException uoe) {
        // Must throw this exception
        assertNotNull(uoe);
    }
    templateVars.put(ResourceLocator.ENTITY_ID, "1234");
    try {
        params = extractor.extractParams(mockRelationship(), request);
        fail("Should not get here. PUT is executed against the instance URL");
    } catch (UnsupportedResourceOperationException uoe) {
        // Must throw this exception
        assertNotNull(uoe);
    }
    templateVars.put(ResourceLocator.ENTITY_ID, "1234");
    // Put single entity wrapped in array
    params = extractor.extractParams(mockEntity(), request);
    assertNotNull(params);
    Object passed = params.getPassedIn();
    assertNotNull(passed);
    assertTrue("A Farmer was passed in.", Farmer.class.equals(passed.getClass()));
    assertNotNull(params.getFilter());
    assertTrue("Default filter is BeanPropertiesFilter.AllProperties", BeanPropertiesFilter.AllProperties.class.equals(params.getFilter().getClass()));
    // reset the reader
    when(content.getReader()).thenReturn(new StringReader(JsonJacksonTests.FARMER_JSON));
    params = extractor.extractParams(mockEntity(), request);
    assertNotNull(params);
    assertEquals("1234", params.getEntityId());
    passed = params.getPassedIn();
    assertNotNull(passed);
    // reset the reader
    when(content.getReader()).thenReturn(new StringReader(JsonJacksonTests.FARMER_JSON));
    templateVars.put(ResourceLocator.RELATIONSHIP_ID, "67890");
    params = extractor.extractParams(mockRelationship(), request);
    assertNotNull(params);
    assertEquals("1234", params.getEntityId());
    passed = params.getPassedIn();
    assertNotNull(passed);
    assertTrue("A Farmer was passed in.", Farmer.class.equals(passed.getClass()));
    Farmer aFarmer = (Farmer) passed;
    assertEquals("Relationship id should be automatically set on the object passed in.", aFarmer.getId(), "67890");
    // reset the reader
    when(content.getReader()).thenReturn(new StringReader(JsonJacksonTests.FARMER_JSON));
    params = testExtractAddressedParams(templateVars, request, extractor);
    assertEquals("UTF-16BE", params.getContentInfo().getEncoding());
    assertEquals(MimetypeMap.MIMETYPE_PDF, params.getContentInfo().getMimeType());
}
Also used : WebScriptRequest(org.springframework.extensions.webscripts.WebScriptRequest) HashMap(java.util.HashMap) UnsupportedResourceOperationException(org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException) Params(org.alfresco.rest.framework.resource.parameters.Params) Match(org.springframework.extensions.webscripts.Match) Content(org.springframework.extensions.surf.util.Content) StringReader(java.io.StringReader) ResourceWebScriptPut(org.alfresco.rest.framework.webscripts.ResourceWebScriptPut) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Example 12 with Farmer

use of org.alfresco.rest.framework.tests.api.mocks.Farmer in project alfresco-remote-api by Alfresco.

the class SerializeTests method testSerializeExecutionResult.

@Test
public void testSerializeExecutionResult() throws IOException {
    assertNotNull(helper);
    Object res = helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, Params.valueOf("notUsed", null, null), new Farmer("180"));
    String out = writeResponse(res);
    assertTrue("There must be json output", StringUtils.isNotBlank(out));
}
Also used : WebScriptResponse(org.springframework.extensions.webscripts.WebScriptResponse) JSONObject(org.json.JSONObject) Farmer(org.alfresco.rest.framework.tests.api.mocks.Farmer) Test(org.junit.Test)

Aggregations

Farmer (org.alfresco.rest.framework.tests.api.mocks.Farmer)12 Test (org.junit.Test)12 StringReader (java.io.StringReader)5 ExecutionResult (org.alfresco.rest.framework.jacksonextensions.ExecutionResult)5 JSONObject (org.json.JSONObject)5 HashMap (java.util.HashMap)4 Params (org.alfresco.rest.framework.resource.parameters.Params)3 Sheep (org.alfresco.rest.framework.tests.api.mocks.Sheep)3 Content (org.springframework.extensions.surf.util.Content)3 Match (org.springframework.extensions.webscripts.Match)3 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)3 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)3 List (java.util.List)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)2 Grass (org.alfresco.rest.framework.tests.api.mocks.Grass)2 ResourceWebScriptPost (org.alfresco.rest.framework.webscripts.ResourceWebScriptPost)2 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 FacetFieldContext (org.alfresco.rest.api.search.context.FacetFieldContext)1