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