Search in sources :

Example 26 with ResourceWithMetadata

use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.

the class SerializeTests method testInvokeMultiPartEntity.

@Test
public void testInvokeMultiPartEntity() throws IOException {
    ResourceWithMetadata entityResource = locator.locateEntityResource(api, "multiparttest", HttpMethod.POST);
    assertNotNull(entityResource);
    MultiPartResourceAction.Create<?> resource = (MultiPartResourceAction.Create<?>) entityResource.getResource();
    File file = TempFileProvider.createTempFile("ParamsExtractorTests-", ".txt");
    PrintWriter writer = new PrintWriter(file);
    writer.println("Multipart Mock test2.");
    writer.close();
    MultiPartRequest reqBody = MultiPartBuilder.create().setFileData(new FileData(file.getName(), file, MimetypeMap.MIMETYPE_TEXT_PLAIN)).build();
    MockHttpServletRequest mockRequest = new MockHttpServletRequest("POST", "");
    mockRequest.setContent(reqBody.getBody());
    mockRequest.setContentType(reqBody.getContentType());
    String out = writeResponse(helper.processAdditionsToTheResponse(mock(WebScriptResponse.class), api, null, NOT_USED, resource.create(new FormData(mockRequest), NOT_USED, callBack)));
    assertTrue("There must be json output", StringUtils.startsWith(out, "{\"entry\":"));
}
Also used : FormData(org.springframework.extensions.webscripts.servlet.FormData) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MultiPartResourceAction(org.alfresco.rest.framework.resource.actions.interfaces.MultiPartResourceAction) MultiPartRequest(org.alfresco.rest.api.tests.util.MultiPartBuilder.MultiPartRequest) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) File(java.io.File) FileData(org.alfresco.rest.api.tests.util.MultiPartBuilder.FileData) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 27 with ResourceWithMetadata

use of org.alfresco.rest.framework.core.ResourceWithMetadata in project alfresco-remote-api by Alfresco.

the class WriterTests method testWriters.

@Test
public void testWriters() throws IOException {
    ResourceDictionary resourceDic = locator.getDictionary();
    Map<String, ResourceWithMetadata> apiResources = resourceDic.getAllResources().get(api);
    String writtenOut = testWriter(defaultMetaWriter, apiResources.get("/sheep"), apiResources);
    assertTrue(writtenOut.startsWith("{\"list\":{\"pagination\":{\"count\":5"));
// ResourceMetaDataWriter wadlWriter = new WebScriptOptionsMetaData();
// writtenOut = testWriter(wadlWriter, apiResources.get("/sheep"), apiResources);
// assertTrue(writtenOut.startsWith("{\"list\":{\"pagination\":{\"count\":4"));
}
Also used : ResourceDictionary(org.alfresco.rest.framework.core.ResourceDictionary) ResourceWithMetadata(org.alfresco.rest.framework.core.ResourceWithMetadata) Test(org.junit.Test)

Aggregations

ResourceWithMetadata (org.alfresco.rest.framework.core.ResourceWithMetadata)27 Test (org.junit.Test)21 HashMap (java.util.HashMap)10 Api (org.alfresco.rest.framework.Api)7 WebScriptResponse (org.springframework.extensions.webscripts.WebScriptResponse)7 AbstractResourceWebScript (org.alfresco.rest.framework.webscripts.AbstractResourceWebScript)5 NotFoundException (org.alfresco.rest.framework.core.exceptions.NotFoundException)4 UnsupportedResourceOperationException (org.alfresco.rest.framework.core.exceptions.UnsupportedResourceOperationException)4 Read (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.Read)4 RelationshipResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceAction)4 WebScriptRequest (org.springframework.extensions.webscripts.WebScriptRequest)4 ResourceDictionary (org.alfresco.rest.framework.core.ResourceDictionary)3 EntityResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 InvalidArgumentException (org.alfresco.rest.framework.core.exceptions.InvalidArgumentException)2 ExecutionResult (org.alfresco.rest.framework.jacksonextensions.ExecutionResult)2 BinaryResourceAction (org.alfresco.rest.framework.resource.actions.interfaces.BinaryResourceAction)2 ReadById (org.alfresco.rest.framework.resource.actions.interfaces.EntityResourceAction.ReadById)2 RelationshipResourceBinaryAction (org.alfresco.rest.framework.resource.actions.interfaces.RelationshipResourceBinaryAction)2