@Test
  public void testModifyAlbumRemovePhoto() throws Exception {
    // Setup
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
    photo.setUploadTime(new Date());
    createdAlbum.addToPhotos(photo);
    createdAlbum = repository.modify(createdAlbum);
    em.flush();

    // Execute
    createdAlbum.removeFromPhotos(photo);
    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    assertEquals(modifiedAlbum, actualAlbum);
    assertFalse(actualAlbum.getPhotos().contains(photo));
    assertNull(actualAlbum.getCoverPhoto());
  }
  public String toString() {
    StringBuilder sb = new StringBuilder();
    sb.append("FlickrPhotos[page=" + page + ", ");
    sb.append("pages=" + pages + ", ");
    sb.append("perpage=" + perpage + ", ");
    sb.append("total=" + total + ", ");
    sb.append("photos=(");

    for (Photo photo : photos) {
      sb.append(photo.toString());
      sb.append(' ');
    }

    sb.append(")]");

    return sb.toString();
  }
Example #3
0
 public boolean isPhotoOwner(Photo photo) {
   boolean result = false;
   Client client = getClient();
   if ((photo != null) && (client instanceof User)) {
     User user = (User) client;
     result = photo.getOwnerName().equals(user.getName());
   }
   return result;
 }
 @Override
 public void setResourceOn(String curPackage) {
   super.setResourceOn(curPackage);
   for (int i = 0; i < GlobalResource.PARTITION_PIECE; i++) {
     ((ImageView) ((Activity) photoContext).findViewById(GlobalResource.partviewID[i]))
         .setBackgroundResource(
             getContext().getResources().getIdentifier(blackfiles.get(i), "drawable", curPackage));
   }
 }
  @Test
  public void testModifyAlbumRemoveMultiplePhotos() throws Exception {
    // Setup
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
    photo.setUploadTime(new Date());
    createdAlbum.addToPhotos(photo);
    Photo secondPhoto = new Photo("Photo #2", "Photo Content #2".getBytes());
    secondPhoto.setUploadTime(new Date());
    createdAlbum.addToPhotos(secondPhoto);
    Photo thirdPhoto = new Photo("Photo #3", "Photo Content #3".getBytes());
    thirdPhoto.setUploadTime(new Date());
    createdAlbum.addToPhotos(thirdPhoto);
    createdAlbum = repository.modify(createdAlbum);
    em.flush();

    // Execute
    createdAlbum.removeFromPhotos(photo);
    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    assertEquals(modifiedAlbum, actualAlbum);
    assertThat(actualAlbum.getPhotos(), hasItems(secondPhoto, thirdPhoto));
    assertThat(actualAlbum.getCoverPhoto(), either(equalTo(secondPhoto)).or(equalTo(thirdPhoto)));
  }
  @Test
  public void testModifyAlbumModifyPhoto() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
    photo.setUploadTime(new Date());
    createdAlbum.addToPhotos(photo);
    createdAlbum = repository.modify(createdAlbum);
    em.flush();

    // Execute
    String modifiedTitle = "New Title";
    String modifiedDescription = "New Description";

    long photoId = 0;
    for (Photo eachPhoto : createdAlbum.getPhotos()) {
      if (eachPhoto.equals(photo)) {
        photoId = eachPhoto.getPhotoId();
        eachPhoto.setTitle(modifiedTitle);
        eachPhoto.setDescription(modifiedDescription);
        break;
      }
    }
    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    Photo actualPhoto = em.find(Photo.class, photoId);
    assertEquals(modifiedAlbum, actualAlbum);
    assertTrue(actualAlbum.getPhotos().contains(photo));
    assertEquals(modifiedTitle, actualPhoto.getTitle());
    assertEquals(modifiedDescription, actualPhoto.getDescription());
    assertEquals(actualAlbum.getCoverPhoto(), actualPhoto);
    assertEquals(photo, actualAlbum.getCoverPhoto());
  }
  @Test
  public void testDeleteAlbumWithPhoto() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    em.persist(album);
    em.flush();

    Photo photo = new Photo(TEST_PHOTO_NAME, TEST_PHOTO_CONTENT);
    photo.setUploadTime(new Date());
    album.addToPhotos(photo);
    album = repository.modify(album);
    em.flush();

    // Execute
    long albumId = album.getAlbumId();
    repository.delete(album);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, albumId);
    assertNull(actualAlbum);
  }