Search in sources :

Example 11 with MockMultipartHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project vorto by eclipse.

the class IntegrationTestBase method createImage.

protected ResultActions createImage(String filename, String modelId, SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor user, Integer size) throws Exception {
    MockMultipartFile file = null;
    if (size == null) {
        file = new MockMultipartFile("file", filename, MediaType.IMAGE_PNG_VALUE, getClass().getClassLoader().getResourceAsStream("models/" + filename));
    } else {
        file = new MockMultipartFile("file", filename, MediaType.IMAGE_PNG_VALUE, new byte[size]);
    }
    MockMultipartHttpServletRequestBuilder builder = MockMvcRequestBuilders.fileUpload("/rest/models/" + modelId + "/images");
    return repositoryServer.perform(builder.file(file).with(request -> {
        request.setMethod("POST");
        return request;
    }).contentType(MediaType.MULTIPART_FORM_DATA).with(user));
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) OperationResult(org.eclipse.vorto.repository.web.api.v1.dto.OperationResult) Autowired(org.springframework.beans.factory.annotation.Autowired) ActiveProfiles(org.springframework.test.context.ActiveProfiles) GsonBuilder(com.google.gson.GsonBuilder) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) ResultActions(org.springframework.test.web.servlet.ResultActions) ObjectMapperFactory(org.eclipse.vorto.plugin.generator.adapter.ObjectMapperFactory) Gson(com.google.gson.Gson) VortoRepository(org.eclipse.vorto.repository.web.VortoRepository) SpringRunner(org.springframework.test.context.junit4.SpringRunner) TypeReference(com.fasterxml.jackson.core.type.TypeReference) LocalServerPort(org.springframework.boot.context.embedded.LocalServerPort) MediaType(org.springframework.http.MediaType) UserService(org.eclipse.vorto.repository.services.UserService) WebApplicationContext(org.springframework.web.context.WebApplicationContext) TestPropertySource(org.springframework.test.context.TestPropertySource) ModelId(org.eclipse.vorto.model.ModelId) Sql(org.springframework.test.context.jdbc.Sql) Sets(com.google.common.collect.Sets) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Configuration(org.springframework.context.annotation.Configuration) IOUtils(org.apache.commons.io.IOUtils) SecurityMockMvcConfigurers.springSecurity(org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SecurityMockMvcRequestPostProcessors(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors) java.util(java.util) BeforeClass(org.junit.BeforeClass) RunWith(org.junit.runner.RunWith) ClassPathResource(org.springframework.core.io.ClassPathResource) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) MockMvcResultMatchers.content(org.springframework.test.web.servlet.result.MockMvcResultMatchers.content) ModelLink(org.eclipse.vorto.repository.web.api.v1.dto.ModelLink) Value(org.springframework.beans.factory.annotation.Value) MockMvc(org.springframework.test.web.servlet.MockMvc) MockMvcResultMatchers.status(org.springframework.test.web.servlet.result.MockMvcResultMatchers.status) ConfigFileApplicationContextInitializer(org.springframework.boot.test.context.ConfigFileApplicationContextInitializer) PropertySourcesPlaceholderConfigurer(org.springframework.context.support.PropertySourcesPlaceholderConfigurer) MockMvcBuilders(org.springframework.test.web.servlet.setup.MockMvcBuilders) INotificationService(org.eclipse.vorto.repository.notification.INotificationService) Collaborator(org.eclipse.vorto.repository.web.api.v1.dto.Collaborator) Before(org.junit.Before) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) PolicyEntry(org.eclipse.vorto.repository.core.PolicyEntry) Profile(org.springframework.context.annotation.Profile) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) SecurityMockMvcRequestPostProcessors.user(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.user) ModelType(org.eclipse.vorto.model.ModelType) IModelPolicyManager(org.eclipse.vorto.repository.core.IModelPolicyManager) UserRepository(org.eclipse.vorto.repository.repositories.UserRepository) ContextConfiguration(org.springframework.test.context.ContextConfiguration) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder) Bean(org.springframework.context.annotation.Bean) Assert.assertEquals(org.junit.Assert.assertEquals) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder)

Aggregations

MockMultipartHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder)11 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)6 Test (org.junit.Test)3 ResultActions (org.springframework.test.web.servlet.ResultActions)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Sets (com.google.common.collect.Sets)2 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 java.util (java.util)2 IOUtils (org.apache.commons.io.IOUtils)2 ModelId (org.eclipse.vorto.model.ModelId)2 ModelType (org.eclipse.vorto.model.ModelType)2 ObjectMapperFactory (org.eclipse.vorto.plugin.generator.adapter.ObjectMapperFactory)2 IModelPolicyManager (org.eclipse.vorto.repository.core.IModelPolicyManager)2 PolicyEntry (org.eclipse.vorto.repository.core.PolicyEntry)2 INotificationService (org.eclipse.vorto.repository.notification.INotificationService)2 UserRepository (org.eclipse.vorto.repository.repositories.UserRepository)2 UserService (org.eclipse.vorto.repository.services.UserService)2 VortoRepository (org.eclipse.vorto.repository.web.VortoRepository)2