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);
}
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);
}
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());
}
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());
}
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());
}
Aggregations