Search in sources :

Example 11 with MultipartItem

use of com.enonic.xp.web.multipart.MultipartItem 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 12 with MultipartItem

use of com.enonic.xp.web.multipart.MultipartItem 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)

Aggregations

MultipartItem (com.enonic.xp.web.multipart.MultipartItem)12 MultipartForm (com.enonic.xp.web.multipart.MultipartForm)6 Test (org.junit.jupiter.api.Test)4 ByteSource (com.google.common.io.ByteSource)3 ApplicationInstallResultJson (com.enonic.xp.impl.server.rest.model.ApplicationInstallResultJson)2 Application (com.enonic.xp.app.Application)1 ApplicationInstalledJson (com.enonic.xp.impl.server.rest.model.ApplicationInstalledJson)1 MediaType (com.google.common.net.MediaType)1 Consumes (javax.ws.rs.Consumes)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1