use of alfio.model.modification.UploadBase64FileModification in project alf.io by alfio-event.
the class FileUploadManagerIntegrationTest method testInsert.
@Test
public void testInsert() {
UploadBase64FileModification toInsert = new UploadBase64FileModification();
toInsert.setFile(FILE);
toInsert.setName("myfile.txt");
toInsert.setType("text/plain");
String id = fileUploadManager.insertFile(toInsert);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
fileUploadManager.outputFile(id, baos);
Assert.assertArrayEquals(FILE, baos.toByteArray());
Optional<FileBlobMetadata> metadata = fileUploadManager.findMetadata(id);
Assert.assertTrue(metadata.isPresent());
Assert.assertEquals("myfile.txt", metadata.get().getName());
Assert.assertEquals("text/plain", metadata.get().getContentType());
}
use of alfio.model.modification.UploadBase64FileModification in project alf.io by alfio-event.
the class FileUploadManagerIntegrationTest method testInsertImage.
@Test
public void testInsertImage() {
UploadBase64FileModification toInsert = new UploadBase64FileModification();
toInsert.setFile(ONE_PIXEL_BLACK_GIF);
toInsert.setName("image.gif");
toInsert.setType("image/gif");
String id = fileUploadManager.insertFile(toInsert);
Optional<FileBlobMetadata> metadata = fileUploadManager.findMetadata(id);
Assert.assertTrue(metadata.isPresent());
Assert.assertEquals("1", metadata.get().getAttributes().get("width"));
Assert.assertEquals("1", metadata.get().getAttributes().get("height"));
}
use of alfio.model.modification.UploadBase64FileModification in project alf.io by alfio-event.
the class UploadedResourceIntegrationTest method testEvent.
@Test
public void testEvent() {
int orgId = event.getOrganizationId();
int eventId = event.getId();
Assert.assertFalse(uploadedResourceManager.hasResource(orgId, eventId, "file_name.txt"));
Assert.assertTrue(uploadedResourceManager.findAll(orgId, eventId).isEmpty());
UploadBase64FileModification toSave = new UploadBase64FileModification();
toSave.setFile(FILE);
toSave.setName("file_name.txt");
toSave.setType("text/plain");
Assert.assertEquals(1, uploadedResourceManager.saveResource(orgId, eventId, toSave));
Assert.assertTrue(uploadedResourceManager.hasResource(orgId, eventId, "file_name.txt"));
Assert.assertEquals(1, uploadedResourceManager.findAll(orgId, eventId).size());
Assert.assertEquals(toSave.getName(), uploadedResourceManager.get(orgId, eventId, "file_name.txt").getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
uploadedResourceManager.outputResource(orgId, eventId, "file_name.txt", baos);
Assert.assertArrayEquals(FILE, baos.toByteArray());
toSave.setFile(ONE_PIXEL_BLACK_GIF);
Assert.assertEquals(1, uploadedResourceManager.saveResource(orgId, eventId, toSave));
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
uploadedResourceManager.outputResource(orgId, eventId, "file_name.txt", baos1);
Assert.assertArrayEquals(ONE_PIXEL_BLACK_GIF, baos1.toByteArray());
}
use of alfio.model.modification.UploadBase64FileModification in project alf.io by alfio-event.
the class UploadedResourceIntegrationTest method testOrganization.
@Test
public void testOrganization() {
int orgId = event.getOrganizationId();
Assert.assertFalse(uploadedResourceManager.hasResource(orgId, "file_name.txt"));
Assert.assertTrue(uploadedResourceManager.findAll(orgId).isEmpty());
UploadBase64FileModification toSave = new UploadBase64FileModification();
toSave.setFile(FILE);
toSave.setName("file_name.txt");
toSave.setType("text/plain");
Assert.assertEquals(1, uploadedResourceManager.saveResource(orgId, toSave));
Assert.assertTrue(uploadedResourceManager.hasResource(orgId, "file_name.txt"));
Assert.assertEquals(1, uploadedResourceManager.findAll(orgId).size());
Assert.assertEquals(toSave.getName(), uploadedResourceManager.get(orgId, "file_name.txt").getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
uploadedResourceManager.outputResource(orgId, "file_name.txt", baos);
Assert.assertArrayEquals(FILE, baos.toByteArray());
toSave.setFile(ONE_PIXEL_BLACK_GIF);
Assert.assertEquals(1, uploadedResourceManager.saveResource(orgId, toSave));
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
uploadedResourceManager.outputResource(orgId, "file_name.txt", baos1);
Assert.assertArrayEquals(ONE_PIXEL_BLACK_GIF, baos1.toByteArray());
}
use of alfio.model.modification.UploadBase64FileModification in project alf.io by alfio-event.
the class UploadedResourceIntegrationTest method testGlobal.
@Test
public void testGlobal() {
Assert.assertFalse(uploadedResourceManager.hasResource("file_name.txt"));
Assert.assertTrue(uploadedResourceManager.findAll().isEmpty());
UploadBase64FileModification toSave = new UploadBase64FileModification();
toSave.setFile(FILE);
toSave.setName("file_name.txt");
toSave.setType("text/plain");
Assert.assertEquals(1, uploadedResourceManager.saveResource(toSave));
Assert.assertTrue(uploadedResourceManager.hasResource("file_name.txt"));
Assert.assertEquals(1, uploadedResourceManager.findAll().size());
Assert.assertEquals(toSave.getName(), uploadedResourceManager.get("file_name.txt").getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
uploadedResourceManager.outputResource("file_name.txt", baos);
Assert.assertArrayEquals(FILE, baos.toByteArray());
toSave.setFile(ONE_PIXEL_BLACK_GIF);
Assert.assertEquals(1, uploadedResourceManager.saveResource(toSave));
ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
uploadedResourceManager.outputResource("file_name.txt", baos1);
Assert.assertArrayEquals(ONE_PIXEL_BLACK_GIF, baos1.toByteArray());
}
Aggregations