Search in sources :

Example 16 with File

use of org.survey.model.file.File in project survey by markoniemi.

the class FileServiceTestBase method delete.

@Test
public void delete() {
    create();
    for (int i = 0; i < ENTITY_COUNT; i++) {
        File entity = savedEntities.get(i);
        entityService.delete(entity.getId());
        Assert.assertFalse(entityService.exists(entity.getId()));
    }
    Assert.assertEquals(0, entityService.count());
}
Also used : File(org.survey.model.file.File) Test(org.junit.Test)

Example 17 with File

use of org.survey.model.file.File in project survey by markoniemi.

the class FileServiceTestBase method exists.

@Test
public void exists() {
    create();
    for (int i = 0; i < ENTITY_COUNT; i++) {
        File entity = savedEntities.get(i);
        entityService.exists(entity.getId());
    }
// TODO how to test if exists fails?
// Assert.assertFalse(entityRepository.exists((ID) new Object()));
}
Also used : File(org.survey.model.file.File) Test(org.junit.Test)

Example 18 with File

use of org.survey.model.file.File in project survey by markoniemi.

the class FileController method createFile.

/**
 * Create a File from Part.
 */
private File createFile(MultipartFile uploadedFile, String filename, byte[] fileContent) {
    File file = new File();
    file.setFilename(filename);
    file.setMimeType(uploadedFile.getContentType());
    file.setContent(fileContent);
    file.setOwner(userService.findOne(SecurityUtil.getUsername()));
    file.setCreateTime(System.currentTimeMillis());
    // TODO change files rest to files/:user/:filename
    file.setUrl("/survey-web/api/rest/files/");
    return file;
}
Also used : File(org.survey.model.file.File) MultipartFile(org.springframework.web.multipart.MultipartFile)

Example 19 with File

use of org.survey.model.file.File in project survey by markoniemi.

the class FileController method downloadFile.

@RequestMapping(value = "/file/{id}", method = RequestMethod.GET)
public void downloadFile(@PathVariable Long id, HttpServletResponse response) {
    File file = fileService.findOne(id);
    writeFileToResponse(response, file);
}
Also used : File(org.survey.model.file.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with File

use of org.survey.model.file.File in project survey by markoniemi.

the class FileController method newFile.

@RequestMapping(value = "/file/new", method = RequestMethod.GET)
public ModelAndView newFile() {
    File file = new File();
    ModelAndView model = new ModelAndView();
    model.setViewName("/file/file");
    model.addObject("file", file);
    return model;
}
Also used : ModelAndView(org.springframework.web.servlet.ModelAndView) File(org.survey.model.file.File) MultipartFile(org.springframework.web.multipart.MultipartFile) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

File (org.survey.model.file.File)21 Test (org.junit.Test)10 ModelAndView (org.springframework.web.servlet.ModelAndView)4 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)3 ResultActions (org.springframework.test.web.servlet.ResultActions)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CrudRepositoryTest (org.survey.repository.CrudRepositoryTest)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DataHandler (javax.activation.DataHandler)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 Attachment (org.apache.cxf.jaxrs.ext.multipart.Attachment)1 After (org.junit.After)1 DefaultStreamedContent (org.primefaces.model.DefaultStreamedContent)1 User (org.survey.model.user.User)1