TestUtils.endSession(true);
testWeblog = TestUtils.getManagedWebsite(testWeblog);
rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
MediaFile mediaFile = new MediaFile();
mediaFile.setName("test4.jpg");
mediaFile.setDescription("This is a test image 4");
mediaFile.setCopyrightText("test 4 copyright text");
mediaFile.setSharedForGallery(false);
mediaFile.setLength(3000);
mediaFile.setDirectory(rootDirectory);
mediaFile.setWeblog(testWeblog);
mediaFile.setContentType("image/jpeg");
mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
MediaFileTag tag1 = new MediaFileTag("tst4work", mediaFile);
MediaFileTag tag2 = new MediaFileTag("tst4home", mediaFile);
Set<MediaFileTag> tags = new HashSet<MediaFileTag>();
tags.add(tag1);
tags.add(tag2);
mediaFile.setTags(tags);
mfMgr.createMediaFile(testWeblog, mediaFile, new RollerMessages());
String id = mediaFile.getId();
TestUtils.endSession(true);
assertNotNull(id);
assertNotNull(id.length() > 0);
testWeblog = TestUtils.getManagedWebsite(testWeblog);
MediaFile mediaFile1 = mfMgr.getMediaFile(id);
assertEquals("test4.jpg", mediaFile1.getName());
assertNotNull(mediaFile1.getTags());
assertEquals(2, mediaFile1.getTags().size());
try {
mfMgr.removeMediaFile(testWeblog, mediaFile1);
} catch (Exception ignorable) {
log.debug("ERROR removing media file", ignorable);
}
TestUtils.endSession(true);
MediaFile mediaFile2 = mfMgr.getMediaFile(id);
assertNull(mediaFile2);
TestUtils.endSession(true);
TestUtils.teardownWeblog(testWeblog.getId());