Search in sources :

Example 1 with MultipartForm

use of com.enonic.xp.web.multipart.MultipartForm in project xp by enonic.

the class GetMultipartScriptTest method createFormWithDuplicates.

private void createFormWithDuplicates() {
    final MultipartForm form = Mockito.mock(MultipartForm.class);
    final MultipartItem item1A = createItem("file1", "text123", 10, "txt", "text/plain");
    final MultipartItem item1B = createItem("file1", "text456", 42, "txt", "application/json");
    final MultipartItem item2 = createItem("file2", 20, "jpg", "image/png");
    Mockito.when(item1A.getAsString()).thenReturn("Some text");
    Mockito.when(item1B.getAsString()).thenReturn("Other stuff");
    Mockito.when(form.iterator()).thenReturn(List.of(item1A, item1B, item2).iterator());
    Mockito.when(form.get("file1", 0)).thenReturn(item1A);
    Mockito.when(form.get("file1", 1)).thenReturn(item1B);
    Mockito.when(this.multipartService.parse(Mockito.any())).thenReturn(form);
}
Also used : MultipartItem(com.enonic.xp.web.multipart.MultipartItem) MultipartForm(com.enonic.xp.web.multipart.MultipartForm)

Example 2 with MultipartForm

use of com.enonic.xp.web.multipart.MultipartForm in project xp by enonic.

the class GetMultipartScriptTest method createFormExample.

private void createFormExample() {
    final MultipartForm form = Mockito.mock(MultipartForm.class);
    final MultipartItem item1 = createItem("item1", 10, "jpg", "image/png");
    final MultipartItem item2A = createItem("item2", "image1", 123, "png", "image/png");
    final MultipartItem item2B = createItem("item2", "image2", 456, "jpg", "image/jpeg");
    Mockito.when(form.iterator()).thenReturn(List.of(item1, item2A, item2B).iterator());
    Mockito.when(form.get("item2", 0)).thenReturn(item2A);
    Mockito.when(form.get("item2", 1)).thenReturn(item2B);
    Mockito.when(this.multipartService.parse(Mockito.any())).thenReturn(form);
}
Also used : MultipartItem(com.enonic.xp.web.multipart.MultipartItem) MultipartForm(com.enonic.xp.web.multipart.MultipartForm)

Example 3 with MultipartForm

use of com.enonic.xp.web.multipart.MultipartForm in project xp by enonic.

the class MultipartServiceImplTest method testParse_multipart.

@Test
public void testParse_multipart() throws Exception {
    Mockito.when(this.req.getContentType()).thenReturn("text/plain");
    final MultipartForm form = this.service.parse(this.req);
    assertNotNull(form);
    assertEquals(true, form.isEmpty());
    assertEquals(0, form.getSize());
}
Also used : MultipartForm(com.enonic.xp.web.multipart.MultipartForm) Test(org.junit.jupiter.api.Test)

Example 4 with MultipartForm

use of com.enonic.xp.web.multipart.MultipartForm in project xp by enonic.

the class ApplicationResourceTest method install_exception.

@Test
public void install_exception() throws Exception {
    ApplicationResource resource = getResourceInstance();
    MultipartItem multipartItem = Mockito.mock(MultipartItem.class);
    ByteSource byteSource = ByteSource.wrap("bytes".getBytes());
    String fileName = "app-name";
    Mockito.when(multipartItem.getBytes()).thenReturn(byteSource);
    Mockito.when(multipartItem.getFileName()).thenReturn(fileName);
    MultipartForm multipartForm = Mockito.mock(MultipartForm.class);
    Mockito.when(this.applicationService.installGlobalApplication(Mockito.isA(ByteSource.class), eq("app-name"))).thenThrow(new RuntimeException());
    Mockito.when(multipartForm.get("file")).thenReturn(multipartItem);
    ApplicationInstallResultJson result = resource.install(multipartForm);
    assertEquals("Failed to process application app-name", result.getFailure());
}
Also used : MultipartItem(com.enonic.xp.web.multipart.MultipartItem) ApplicationInstallResultJson(com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson) ByteSource(com.google.common.io.ByteSource) MultipartForm(com.enonic.xp.web.multipart.MultipartForm) Test(org.junit.jupiter.api.Test)

Example 5 with MultipartForm

use of com.enonic.xp.web.multipart.MultipartForm in project xp by enonic.

the class MultipartFormReaderTest method testReadFrom.

@Test
public void testReadFrom() throws Exception {
    final InputStream in = Mockito.mock(InputStream.class);
    final MultipartForm form = Mockito.mock(MultipartForm.class);
    Mockito.when(this.service.parse(this.request)).thenReturn(form);
    final MultipartForm result = readFrom(MediaType.MULTIPART_FORM_DATA_TYPE);
    assertSame(form, result);
}
Also used : InputStream(java.io.InputStream) MultipartForm(com.enonic.xp.web.multipart.MultipartForm) Test(org.junit.jupiter.api.Test)

Aggregations

MultipartForm (com.enonic.xp.web.multipart.MultipartForm)10 MultipartItem (com.enonic.xp.web.multipart.MultipartItem)6 Test (org.junit.jupiter.api.Test)6 ApplicationInstallResultJson (com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson)2 ByteSource (com.google.common.io.ByteSource)2 Application (com.enonic.xp.app.Application)1 ApplicationInstalledJson (com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson)1 InputStream (java.io.InputStream)1 Part (javax.servlet.http.Part)1