Search in sources :

Example 6 with MultipartForm

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

the class GetMultipartScriptTest method createTextForm.

private void createTextForm() {
    final MultipartForm form = Mockito.mock(MultipartForm.class);
    final MultipartItem item1 = createItem("item1", 10, "txt", "text/plain");
    Mockito.when(item1.getAsString()).thenReturn("Some text");
    Mockito.when(form.iterator()).thenReturn(List.of(item1).iterator());
    Mockito.when(form.get("item1", 0)).thenReturn(item1);
    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 7 with MultipartForm

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

the class GetMultipartScriptTest method createForm.

private void createForm() {
    final MultipartForm form = Mockito.mock(MultipartForm.class);
    final MultipartItem item1 = createItem("item1", 10, "jpg", "image/png");
    final MultipartItem item2 = createItem("item2", 20, "jpg", "image/png");
    Mockito.when(form.iterator()).thenReturn(List.of(item1, item2).iterator());
    Mockito.when(form.get("item1", 0)).thenReturn(item1);
    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 8 with MultipartForm

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

the class ApplicationResourceTest method install.

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

Example 9 with MultipartForm

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

the class ApplicationResourceTest method install_missing_file_item.

@Test
public void install_missing_file_item() throws Exception {
    ApplicationResource resource = getResourceInstance();
    MultipartForm multipartForm = Mockito.mock(MultipartForm.class);
    final RuntimeException ex = assertThrows(RuntimeException.class, () -> {
        resource.install(multipartForm);
    });
    assertEquals("Missing file item", ex.getMessage());
}
Also used : MultipartForm(com.enonic.xp.web.multipart.MultipartForm) Test(org.junit.jupiter.api.Test)

Example 10 with MultipartForm

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

the class MultipartServiceImplTest method testParse_noMultipart.

@Test
public void testParse_noMultipart() throws Exception {
    final Part part = Mockito.mock(Part.class);
    Mockito.when(part.getName()).thenReturn("part");
    Mockito.when(this.req.getParts()).thenReturn(List.of(part));
    Mockito.when(this.req.getContentType()).thenReturn("multipart/form-data");
    final MultipartForm form = this.service.parse(this.req);
    assertNotNull(form);
    assertEquals(false, form.isEmpty());
    assertEquals(1, form.getSize());
}
Also used : Part(javax.servlet.http.Part) 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