use of com.enonic.xp.web.multipart.MultipartItem in project xp by enonic.
the class MultipartFormImplTest method testGetWithIndex.
@Test
public void testGetWithIndex() {
final MultipartItem item1 = this.form.get("upload1", 0);
assertNotNull(item1);
assertEquals("upload1", item1.getName());
assertEquals("hello1", item1.getAsString());
final MultipartItem item1B = this.form.get("upload1", 1);
assertNotNull(item1B);
assertEquals("upload1", item1B.getName());
assertEquals("bye1", item1B.getAsString());
final MultipartItem item1C = this.form.get("upload1", 2);
assertNull(item1C);
}
use of com.enonic.xp.web.multipart.MultipartItem 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.MultipartItem in project xp by enonic.
the class ApplicationResource method install.
@POST
@Path("install")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public ApplicationInstallResultJson install(final MultipartForm form) {
final MultipartItem appFile = form.get("file");
if (appFile == null) {
throw new RuntimeException("Missing file item");
}
final ByteSource byteSource = appFile.getBytes();
return installApplication(byteSource, appFile.getFileName());
}
use of com.enonic.xp.web.multipart.MultipartItem in project xp by enonic.
the class GetMultipartScriptTest method createItem.
private MultipartItem createItem(final String name, final String fileName, final long size, final String ext, final String type) {
final MultipartItem item = Mockito.mock(MultipartItem.class);
Mockito.when(item.getName()).thenReturn(name);
Mockito.when(item.getFileName()).thenReturn(fileName + "." + ext);
Mockito.when(item.getContentType()).thenReturn(MediaType.parse(type));
Mockito.when(item.getSize()).thenReturn(size);
Mockito.when(item.getBytes()).thenReturn(ByteSource.wrap(name.getBytes()));
return item;
}
use of com.enonic.xp.web.multipart.MultipartItem 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);
}
Aggregations