Search in sources :

Example 1 with StorageService

use of com.icthh.xm.ms.entity.service.StorageService in project xm-ms-entity by xm-online.

the class StorageResourceIntTest method storeObjectFileTooBig.

@Test
@Transactional
public void storeObjectFileTooBig() throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "TEST".getBytes());
    restStorageMockMvc.perform(fileUpload("/api/storage/objects").file(file)).andDo(result -> System.out.println(result.getResponse().getContentAsString())).andExpect(status().isBadRequest());
    verify(storageService, times(0)).store(eq(file), eq(null));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Mock(org.mockito.Mock) StorageService(com.icthh.xm.ms.entity.service.StorageService) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) TenantContextHolder(com.icthh.xm.commons.tenant.TenantContextHolder) TenantContextUtils(com.icthh.xm.commons.tenant.TenantContextUtils) WebappTenantOverrideConfiguration(com.icthh.xm.ms.entity.config.tenant.WebappTenantOverrideConfiguration) MockMvc(org.springframework.test.web.servlet.MockMvc) ApplicationProperties(com.icthh.xm.ms.entity.config.ApplicationProperties) MockitoAnnotations(org.mockito.MockitoAnnotations) ExceptionTranslator(com.icthh.xm.commons.exceptions.spring.web.ExceptionTranslator) PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) EntityApp(com.icthh.xm.ms.entity.EntityApp) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Before(org.junit.Before) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Mockito.verify(org.mockito.Mockito.verify) SecurityBeanOverrideConfiguration(com.icthh.xm.ms.entity.config.SecurityBeanOverrideConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) MockMvcRequestBuilders.fileUpload(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.fileUpload) Transactional(org.springframework.transaction.annotation.Transactional) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with StorageService

use of com.icthh.xm.ms.entity.service.StorageService in project xm-ms-entity by xm-online.

the class StorageResourceIntTest method storeObjectSuccess.

@Test
@Transactional
public void storeObjectSuccess() throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", "test.txt", "text/plain", "TE".getBytes());
    restStorageMockMvc.perform(fileUpload("/api/storage/objects").file(file)).andDo(result -> System.out.println(result.getResponse().getContentAsString())).andExpect(status().isOk());
    verify(storageService).store(eq(file), eq(null));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Mock(org.mockito.Mock) StorageService(com.icthh.xm.ms.entity.service.StorageService) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) TenantContextHolder(com.icthh.xm.commons.tenant.TenantContextHolder) TenantContextUtils(com.icthh.xm.commons.tenant.TenantContextUtils) WebappTenantOverrideConfiguration(com.icthh.xm.ms.entity.config.tenant.WebappTenantOverrideConfiguration) MockMvc(org.springframework.test.web.servlet.MockMvc) ApplicationProperties(com.icthh.xm.ms.entity.config.ApplicationProperties) MockitoAnnotations(org.mockito.MockitoAnnotations) ExceptionTranslator(com.icthh.xm.commons.exceptions.spring.web.ExceptionTranslator) PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) EntityApp(com.icthh.xm.ms.entity.EntityApp) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Before(org.junit.Before) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Mockito.verify(org.mockito.Mockito.verify) SecurityBeanOverrideConfiguration(com.icthh.xm.ms.entity.config.SecurityBeanOverrideConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) MockMvcRequestBuilders.fileUpload(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.fileUpload) Transactional(org.springframework.transaction.annotation.Transactional) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with StorageService

use of com.icthh.xm.ms.entity.service.StorageService in project xm-ms-entity by xm-online.

the class StorageResourceIntTest method storeImageSuccess.

@Test
@Transactional
public void storeImageSuccess() throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", "test.txt", "image/plain", "TE".getBytes());
    restStorageMockMvc.perform(fileUpload("/api/storage/objects?size=100").file(file)).andDo(result -> System.out.println(result.getResponse().getContentAsString())).andExpect(status().isOk());
    verify(storageService).store(eq(file), eq(100));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Mock(org.mockito.Mock) StorageService(com.icthh.xm.ms.entity.service.StorageService) RunWith(org.junit.runner.RunWith) Autowired(org.springframework.beans.factory.annotation.Autowired) TenantContextHolder(com.icthh.xm.commons.tenant.TenantContextHolder) TenantContextUtils(com.icthh.xm.commons.tenant.TenantContextUtils) WebappTenantOverrideConfiguration(com.icthh.xm.ms.entity.config.tenant.WebappTenantOverrideConfiguration) MockMvc(org.springframework.test.web.servlet.MockMvc) ApplicationProperties(com.icthh.xm.ms.entity.config.ApplicationProperties) MockitoAnnotations(org.mockito.MockitoAnnotations) ExceptionTranslator(com.icthh.xm.commons.exceptions.spring.web.ExceptionTranslator) PageableHandlerMethodArgumentResolver(org.springframework.data.web.PageableHandlerMethodArgumentResolver) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) Matchers.eq(org.mockito.Matchers.eq) After(org.junit.After) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) EntityApp(com.icthh.xm.ms.entity.EntityApp) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Before(org.junit.Before) BeforeTransaction(org.springframework.test.context.transaction.BeforeTransaction) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) Mockito.verify(org.mockito.Mockito.verify) SecurityBeanOverrideConfiguration(com.icthh.xm.ms.entity.config.SecurityBeanOverrideConfiguration) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) MappingJackson2HttpMessageConverter(org.springframework.http.converter.json.MappingJackson2HttpMessageConverter) MockMvcRequestBuilders.fileUpload(org.springframework.test.web.servlet.request.MockMvcRequestBuilders.fileUpload) Transactional(org.springframework.transaction.annotation.Transactional) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ExceptionTranslator (com.icthh.xm.commons.exceptions.spring.web.ExceptionTranslator)3 TenantContextHolder (com.icthh.xm.commons.tenant.TenantContextHolder)3 TenantContextUtils (com.icthh.xm.commons.tenant.TenantContextUtils)3 EntityApp (com.icthh.xm.ms.entity.EntityApp)3 ApplicationProperties (com.icthh.xm.ms.entity.config.ApplicationProperties)3 SecurityBeanOverrideConfiguration (com.icthh.xm.ms.entity.config.SecurityBeanOverrideConfiguration)3 WebappTenantOverrideConfiguration (com.icthh.xm.ms.entity.config.tenant.WebappTenantOverrideConfiguration)3 StorageService (com.icthh.xm.ms.entity.service.StorageService)3 After (org.junit.After)3 Before (org.junit.Before)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 Matchers.eq (org.mockito.Matchers.eq)3 Mock (org.mockito.Mock)3 Mockito.times (org.mockito.Mockito.times)3 Mockito.verify (org.mockito.Mockito.verify)3 MockitoAnnotations (org.mockito.MockitoAnnotations)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)3 PageableHandlerMethodArgumentResolver (org.springframework.data.web.PageableHandlerMethodArgumentResolver)3