コード例 #1
0
  @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)));
  }
コード例 #2
0
  @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());
  }
コード例 #3
0
  @Test
  public void testCreateNewAlbum() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);

    // Execute
    Album createdAlbum = repository.create(album);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, createdAlbum.getAlbumId());
    assertEquals(album, actualAlbum);
    assertNull(actualAlbum.getCoverPhoto());
  }
コード例 #4
0
  @Test
  public void testFindAllAlbumsByOwner() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    // Execute
    List<Album> foundAlbums = repository.findAllByOwner(user.getUserId());

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, createdAlbum.getAlbumId());
    assertEquals(1, foundAlbums.size());
    assertTrue(foundAlbums.contains(actualAlbum));
  }
コード例 #5
0
  @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());
  }
コード例 #6
0
  @Test
  public void testModifyAlbum() throws Exception {
    Album album = new Album(TEST_ALBUM_NAME, TEST_ALBUM_DESCRIPTION);
    album.modifyUser(user);
    Album createdAlbum = repository.create(album);

    // Execute
    String modifiedName = "Modified Name";
    String modifiedDescription = "Modified Description";
    createdAlbum.setName(modifiedName);
    createdAlbum.setDescription(modifiedDescription);

    Album modifiedAlbum = repository.modify(createdAlbum);

    // Verify
    em.flush();
    em.clear();
    Album actualAlbum = em.find(Album.class, modifiedAlbum.getAlbumId());
    assertEquals(modifiedAlbum, actualAlbum);
    assertEquals(modifiedName, actualAlbum.getName());
    assertEquals(modifiedDescription, actualAlbum.getDescription());
    assertNull(actualAlbum.getCoverPhoto());
  }