Search in sources :

Example 6 with MockMultipartHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project ArachneCentralAPI by OHDSI.

the class AnalysisControllerTests method testUpdateCodeFile.

@Test
@WithUserDetails(value = ADMIN_EMAIL)
@DatabaseSetups({ @DatabaseSetup("/data/study-with-contributor.xml"), @DatabaseSetup("/data/analysis/analysis-list.xml"), @DatabaseSetup("/data/analysis/code-file-before-deleting.xml") })
@ExpectedDatabases({ @ExpectedDatabase(value = "/data/study-with-contributor.xml", assertionMode = NON_STRICT), @ExpectedDatabase(value = "/data/analysis/code-file-after-updating.xml", assertionMode = NON_STRICT) })
public void testUpdateCodeFile() throws Exception {
    String uuid = "68b75ac9-ab29-49a6-8edb-95142456f5fc";
    String path = this.getClass().getResource("/test.jpg").getPath();
    FileInputStream fileInputStream = new FileInputStream(path);
    MockMultipartFile multipartFile = new MockMultipartFile("file", "test_updated.jpg", "image/jpeg", fileInputStream);
    MockMultipartHttpServletRequestBuilder builder = fileUpload("/api/v1/analysis-management/analyses/{analysisId}/files/{fileUuid}", ANALYSIS_ID, uuid);
    builder.with(request -> {
        request.setMethod("PUT");
        return request;
    });
    mvc.perform(builder.file(multipartFile).param("label", "labelUploadedFile").param("file", path).contentType(MULTIPART_FORM_DATA)).andExpect(NO_ERROR_CODE).andExpect(TRUE_RESULT);
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder) FileInputStream(java.io.FileInputStream) DatabaseSetups(com.github.springtestdbunit.annotation.DatabaseSetups) Test(org.junit.Test) WithUserDetails(org.springframework.security.test.context.support.WithUserDetails) ExpectedDatabases(com.github.springtestdbunit.annotation.ExpectedDatabases)

Example 7 with MockMultipartHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project TOSCAna by StuPro-TOSCAna.

the class CsarControllerTest method uploadTestArchiveAlreadyExists.

@Test
public void uploadTestArchiveAlreadyExists() throws Exception {
    // Generate 10 KiB of random data
    byte[] data = generateRandomByteArray(rnd, 10);
    String path = CSAR_BASE_URL + "apache";
    MockMultipartHttpServletRequestBuilder builder = buildMockedMultipartUploadRequest(data, path);
    ResultActions resultActions = mvc.perform(builder).andDo(print()).andExpect(status().is(201));
    resultActions.andReturn();
}
Also used : MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder) Mockito.anyString(org.mockito.Mockito.anyString) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.Test) BaseSpringTest(org.opentosca.toscana.core.BaseSpringTest)

Example 8 with MockMultipartHttpServletRequestBuilder

use of org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder in project TOSCAna by StuPro-TOSCAna.

the class CsarControllerTest method buildMockedMultipartUploadRequest.

public MockMultipartHttpServletRequestBuilder buildMockedMultipartUploadRequest(byte[] data, String path) {
    MockMultipartFile mockMultipartFile = new MockMultipartFile(MULTIPART_FILE_UPLOAD_KEY, MULTIPART_FILE_ORIGINAL_FILENAME, MediaType.APPLICATION_OCTET_STREAM_VALUE, data);
    MockMultipartHttpServletRequestBuilder builder = fileUpload(path);
    builder.with(request -> {
        request.setMethod("PUT");
        return request;
    });
    builder = (MockMultipartHttpServletRequestBuilder) builder.file(mockMultipartFile).contentType(MediaType.MULTIPART_FORM_DATA);
    return builder;
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder)

Example 9 with MockMultipartHttpServletRequestBuilder

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

the class AbstractOtaLwM2MIntegrationTest method savaData.

protected OtaPackageInfo savaData(String urlTemplate, MockMultipartFile content, String... params) throws Exception {
    MockMultipartHttpServletRequestBuilder postRequest = MockMvcRequestBuilders.multipart(urlTemplate, params);
    postRequest.file(content);
    setJwtToken(postRequest);
    return readResponse(mockMvc.perform(postRequest).andExpect(status().isOk()), OtaPackageInfo.class);
}
Also used : MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder)

Example 10 with MockMultipartHttpServletRequestBuilder

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

the class IntegrationTestBase method addAttachment.

protected ResultActions addAttachment(String modelId, SecurityMockMvcRequestPostProcessors.UserRequestPostProcessor user, String fileName, MediaType mediaType, Integer size) throws Exception {
    MockMultipartFile file = new MockMultipartFile("file", fileName, mediaType.toString(), size == null ? "{\"test\":123}".getBytes() : new byte[size]);
    MockMultipartHttpServletRequestBuilder builder = MockMvcRequestBuilders.fileUpload("/api/v1/attachments/" + modelId);
    return repositoryServer.perform(builder.file(file).with(request -> {
        request.setMethod("PUT");
        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