Ejemplo n.º 1
0
 /** Test utility to determine whether the list of files contains a file with given name. */
 private boolean containsFileWithName(Collection<MediaFile> files, String name) {
   for (MediaFile file : files) {
     if (name.equals(file.getName())) {
       return true;
     }
   }
   return false;
 }
Ejemplo n.º 2
0
  /** Test creation of media file. */
  public void testCreateMediaFile() throws Exception {

    User testUser = null;
    Weblog testWeblog = null;
    testUser = TestUtils.setupUser("mediaFileTestUser3");
    testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog3", testUser);

    MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();

    // no need to create root directory, that is done automatically now
    MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);

    // MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d",
    // testWeblog);
    // mfMgr.createMediaFileDirectory(rootDirectory);

    TestUtils.endSession(true);

    testWeblog = TestUtils.getManagedWebsite(testWeblog);
    rootDirectory = mfMgr.getMediaFileDirectory(rootDirectory.getId());

    MediaFile mediaFile = new MediaFile();
    mediaFile.setName("test.jpg");
    mediaFile.setDescription("This is a test image");
    mediaFile.setCopyrightText("test copyright text");
    mediaFile.setSharedForGallery(true);
    mediaFile.setLength(2000);
    mediaFile.setDirectory(rootDirectory);
    mediaFile.setWeblog(testWeblog);
    mediaFile.setInputStream(getClass().getResourceAsStream(TEST_IMAGE));
    mediaFile.setContentType("image/jpeg");
    rootDirectory.getMediaFiles().add(mediaFile);

    MediaFileTag tag1 = new MediaFileTag("work", mediaFile);
    MediaFileTag tag2 = new MediaFileTag("home", mediaFile);
    Set<MediaFileTag> tags = new HashSet<MediaFileTag>();
    tags.add(tag1);
    tags.add(tag2);
    mediaFile.setTags(tags);

    mfMgr.createMediaFile(testWeblog, mediaFile, new RollerMessages());
    TestUtils.endSession(true);
    assertNotNull(mediaFile.getId());
    assertNotNull(mediaFile.getId().length() > 0);

    testWeblog = TestUtils.getManagedWebsite(testWeblog);
    MediaFile mediaFile1 = mfMgr.getMediaFile(mediaFile.getId());
    assertEquals("test.jpg", mediaFile1.getName());
    assertEquals("This is a test image", mediaFile1.getDescription());
    assertEquals("test copyright text", mediaFile1.getCopyrightText());
    assertTrue(mediaFile1.isSharedForGallery());
    assertEquals(2000, mediaFile1.getLength());

    TestUtils.endSession(true);
    TestUtils.teardownWeblog(testWeblog.getId());
    TestUtils.teardownUser(testUser.getUserName());
  }
Ejemplo n.º 3
0
  /** Test deletion of media file */
  public void testDeleteMediaFile() throws Exception {
    User testUser = null;
    Weblog testWeblog = null;
    testUser = TestUtils.setupUser("mediaFileTestUser4");
    testWeblog = TestUtils.setupWeblog("mediaFileTestWeblog4", testUser);

    MediaFileManager mfMgr = WebloggerFactory.getWeblogger().getMediaFileManager();

    // no need to create root directory, that is done automatically now
    MediaFileDirectory rootDirectory = mfMgr.getMediaFileRootDirectory(testWeblog);

    // MediaFileDirectory rootDirectory = new MediaFileDirectory(null, "root", "root d",
    // testWeblog);
    // mfMgr.createMediaFileDirectory(rootDirectory);

    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());
    TestUtils.teardownUser(testUser.getUserName());

    String uploadsDirName = WebloggerConfig.getProperty("uploads.dir");
    File flag = new File(uploadsDirName + File.separator + "migration-status.properties");
    flag.delete();
  }