Search in sources :

Example 11 with File

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

the class FileRepositoryTest method findAllByFilename.

@Test
public void findAllByFilename() {
    save();
    File originalFile1 = orginalEntities.get(0);
    @SuppressWarnings("unchecked") List<File> files = IteratorUtils.toList(fileRepository.findAllByFilename(originalFile1.getFilename()).iterator());
    Assert.assertEquals(1, files.size());
    Assert.assertEquals(0, entityComparator.compare(originalFile1, files.get(0)));
}
Also used : File(org.survey.model.file.File) Test(org.junit.Test) CrudRepositoryTest(org.survey.repository.CrudRepositoryTest)

Example 12 with File

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

the class FileControllerTest method deleteFile.

@Test
public void deleteFile() throws Exception {
    MockHttpServletRequestBuilder request = MockMvcRequestBuilders.post("/file/delete/" + 1);
    ResultActions resultActions = mockMvc.perform(request);
    resultActions.andExpect(MockMvcResultMatchers.status().is3xxRedirection());
    resultActions.andExpect(MockMvcResultMatchers.redirectedUrl("/file/files"));
    ModelAndView modelAndView = resultActions.andReturn().getModelAndView();
    File[] files = (File[]) modelAndView.getModel().get("files");
    Assert.assertNull(files);
}
Also used : MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ModelAndView(org.springframework.web.servlet.ModelAndView) ResultActions(org.springframework.test.web.servlet.ResultActions) File(org.survey.model.file.File) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Test(org.junit.Test)

Example 13 with File

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

the class FileServiceTestBase method findOne.

@Test
public void findOne() {
    create();
    for (int i = 0; i < ENTITY_COUNT; i++) {
        File savedEntity = savedEntities.get(i);
        File foundEntity = entityService.findOne(savedEntity.getId());
        assertEntity(savedEntities.get(i), foundEntity);
    }
// TODO how to test a non-existent entity?
}
Also used : File(org.survey.model.file.File) Test(org.junit.Test)

Example 14 with File

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

the class FileServiceTestBase method create.

@Test
public void create() {
    orginalEntities = entityFactory.getEntities(ENTITY_COUNT);
    for (int i = 0; i < ENTITY_COUNT; i++) {
        File originalEntity = orginalEntities.get(i);
        File savedEntity = entityService.create(originalEntity);
        savedEntities.add(savedEntity);
        assertEntity(originalEntity, savedEntity);
    }
}
Also used : File(org.survey.model.file.File) Test(org.junit.Test)

Example 15 with File

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

the class FileServiceTestBase method tearDown.

@After
public void tearDown() throws SQLException {
    File[] users = entityService.findAll();
    if (users != null) {
        for (File fileToDelete : users) {
            entityService.delete(fileToDelete.getId());
        }
    }
    userService.delete(user.getUsername());
}
Also used : File(org.survey.model.file.File) After(org.junit.After)

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