TestUtils.endSession(true);
testWeblog = TestUtils.getManagedWebsite(testWeblog);
rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());
MediaFile mediaFile = new MediaFile();
mediaFile.setName("test5.jpg");
mediaFile.setDescription("This is a test image 5");
mediaFile.setCopyrightText("test 5 copyright text");
mediaFile.setSharedForGallery(false);
mediaFile.setLength(3000);
mediaFile.setDirectory(rootDirectory);
mediaFile.setWeblog(testWeblog);
mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
mediaFile.setContentType("image/jpeg");
rootDirectory.getMediaFiles().add(mediaFile);
MediaFileTag tag1 = new MediaFileTag("tst5work", mediaFile);
MediaFileTag tag2 = new MediaFileTag("tst5home", 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);
mediaFile1.setWeblog(testWeblog);
mediaFile1.setName("updated.gif");
mediaFile1.setDescription("updated desc");
mediaFile1.setCopyrightText("updated copyright");
mediaFile1.setContentType("image/gif");
mediaFile1.setSharedForGallery(true);
mfMgr.updateMediaFile(testWeblog, mediaFile1);
TestUtils.endSession(true);
MediaFile mediaFile2 = mfMgr.getMediaFile(id);
assertEquals("updated.gif", mediaFile2.getName());
assertEquals("updated desc", mediaFile2.getDescription());
assertEquals("updated copyright", mediaFile2.getCopyrightText());
assertEquals("image/gif", mediaFile2.getContentType());
assertTrue(mediaFile2.isSharedForGallery());
assertNotNull(mediaFile2.getTags());
assertEquals(2, mediaFile2.getTags().size());
TestUtils.endSession(true);
TestUtils.teardownWeblog(testWeblog.getId());
TestUtils.teardownUser(testUser.getUserName());
}