Package org.richfaces.photoalbum.model

Examples of org.richfaces.photoalbum.model.Image


    }

    @Test
    public void areCommentsDeletedWithImage() throws Exception {
        String commentById = "select c from Comment c where image_id = :id";
        Image image = helper.getAllImages(em).get(0);

        Assert.assertNotNull(image);

        int allCommentsSize = helper.getAllComments(em).size();
        int commentsSize = em.createQuery(commentById, Comment.class).setParameter("id", image.getId()).getResultList().size();

        ia.deleteImage(image);

        Assert.assertFalse(helper.getAllImages(em).contains(image));

        List<Comment> comments = em.createQuery(commentById, Comment.class).setParameter("id", image.getId()).getResultList();

        Assert.assertTrue(comments.isEmpty());
        Assert.assertEquals(allCommentsSize - commentsSize, helper.getAllComments(em).size());
    }
View Full Code Here


    }

    @Test
    public void areMetaTagsNotPointingToDeletedImage() throws Exception {
        String metaTagById = "select m from MetaTag m join m.images i where i.id = :id";
        Image image = helper.getAllImages(em).get(0);
        Assert.assertNotNull(image);

        List<MetaTag> existingMetaTags = em.createQuery(metaTagById, MetaTag.class).setParameter("id", image.getId())
            .getResultList();
        Assert.assertFalse("size: " + existingMetaTags.size(), existingMetaTags.isEmpty());

        ia.deleteImage(image);

        List<MetaTag> metaTags = em.createQuery(metaTagById, MetaTag.class).setParameter("id", image.getId()).getResultList();
        Assert.assertTrue(metaTags.isEmpty());
    }
View Full Code Here

        int originalSize = helper.getAllImages(em).size();

        Album album = em.createQuery("select a from Album a where a.id = :id", Album.class).setParameter("id", (long) 0)
            .getSingleResult();
        Image newImage = new Image();

        newImage.setName("839245545_5db77619d5_o.jpg");
        newImage.setPath("839245545_5db77619d5_o.jpg");
        newImage.setDescription("Animals - 839245545_5db77619d5_o.jpg image");
        newImage.setCreated(new Date());
        newImage.setAlbum(album);
        newImage.setCameraModel("Canon PowerShot SX110 IS");
        newImage.setSize(1917);
        newImage.setWidth(1024);
        newImage.setHeight(768);
        newImage.setAllowComments(true);
        newImage.setShowMetaInfo(true);

        ia.addImage(newImage);

        List<Image> images = helper.getAllImages(em);
        Assert.assertTrue(images.contains(newImage));
View Full Code Here

        Assert.assertEquals(originalSize + 1, images.size());
    }

    @Test
    public void isCommentAdded() throws Exception {
        Image image = helper.getAllImages(em).get(0);
        User user = em.createQuery("select u from User u where u.id = :id", User.class).setParameter("id", (long) 1)
            .getSingleResult();

        int originalSize = helper.getAllComments(em).size();

        Comment comment = new Comment();
        comment.setAuthor(user);
        comment.setDate(new Date());
        comment.setMessage("beautiful");
        comment.setImage(image);

        if (!image.isAllowComments()) {
            image.setAllowComments(true);
        }

        ia.addComment(comment);

        Assert.assertTrue(getAllCommentsById(image.getId()).contains(comment));
        Assert.assertEquals(originalSize + 1, helper.getAllComments(em).size());
    }
View Full Code Here

        Assert.assertEquals(originalSize + 1, helper.getAllComments(em).size());
    }

    @Test
    public void isCommentDeleted() throws Exception {
        Image image = helper.getAllImages(em).get(0);
        int originalSize = helper.getAllComments(em).size();
        Comment comment = getAllCommentsById(image.getId()).get(0);

        ia.deleteComment(comment);

        Assert.assertFalse(getAllCommentsById(image.getId()).contains(comment));
        Assert.assertEquals(originalSize - 1, helper.getAllComments(em).size());
    }
View Full Code Here

        Assert.assertEquals(originalSize - 1, helper.getAllComments(em).size());
    }

    @Test(expected = PhotoAlbumException.class)
    public void isCommentNotAllowed() throws Exception {
        Image image = helper.getAllImages(em).get(0);
        User user = em.createQuery("select u from User u where u.id = :id", User.class).setParameter("id", (long) 1)
            .getSingleResult();

        image.setAllowComments(false);

        int originalSize = helper.getAllComments(em).size();

        Comment comment = new Comment();
        comment.setAuthor(user);
        comment.setDate(new Date());
        comment.setMessage("beautiful");
        comment.setImage(image);

        ia.addComment(comment);
        // the code below should not get executed

        Assert.assertFalse(getAllCommentsById(image.getId()).contains(comment));
        Assert.assertEquals(originalSize, helper.getAllComments(em).size());
    }
View Full Code Here

        Assert.assertEquals(originalSize, helper.getAllComments(em).size());
    }

    @Test
    public void isImageEdited() throws Exception {
        Image image = helper.getAllImages(em).get(0);

        String name = image.getName();

        image.setName("edited image");

        int originalSize = helper.getAllImages(em).size();

        // due to auto-commit this command makes no difference
        ia.editImage(image, false);

        Image editedImage = helper.getAllImages(em).get(0);
        Assert.assertEquals(image.getId(), editedImage.getId());
        Assert.assertEquals("original name: " + name, "edited image", editedImage.getName());
        Assert.assertEquals(originalSize, helper.getAllImages(em).size());
    }
View Full Code Here

        Assert.assertEquals(originalSize, helper.getAllImages(em).size());
    }

    @Test
    public void isImageEditedWithMetaTags() throws Exception {
        Image image = helper.getAllImages(em).get(0);
        List<MetaTag> tags = image.getImageTags();
        MetaTag removedTag = tags.get(0);

        String metaTagsByImageId = "select m from MetaTag m join m.images i where i.id = :id";
        List<MetaTag> _tagsById = em.createQuery(metaTagsByImageId, MetaTag.class).setParameter("id", image.getId())
            .getResultList();

        Assert.assertTrue(_tagsById.contains(removedTag));
        Assert.assertTrue(removedTag.getImages().contains(image));

        tags.remove(0);
        Assert.assertFalse(tags.contains(removedTag));

        removedTag.removeImage(image);
        Assert.assertFalse(removedTag.getImages().contains(image));
        image.setImageTags(tags);

        ia.editImage(image, true);

        List<MetaTag> tagsById = em.createQuery(metaTagsByImageId, MetaTag.class).setParameter("id", image.getId())
            .getResultList();

        Image editedImage = helper.getAllImages(em).get(0);

        String tagById = "select m from MetaTag m where id = :id";
        MetaTag m = em.createQuery(tagById, MetaTag.class).setParameter("id", removedTag.getId()).getSingleResult();

        Assert.assertFalse(tagsById.contains(removedTag));
View Full Code Here

        Assert.assertFalse(m.getImages().contains(editedImage));
    }

    @Test
    public void isIdenticalCountCorrect() throws Exception {
        Image image = helper.getAllImages(em).get(1);

        Assert.assertEquals(1, ia.getCountIdenticalImages(image.getAlbum(), image.getPath()).intValue());

        Image newImage = new Image();

        newImage.setName("new Image");
        newImage.setPath(image.getPath());
        newImage.setDescription("new description");
        newImage.setCreated(new Date());
        newImage.setAlbum(image.getAlbum());
        newImage.setCameraModel("Canon PowerShot SX110 IS");
        newImage.setSize(image.getSize());
        newImage.setWidth(image.getWidth());
        newImage.setHeight(image.getHeight());
        newImage.setAllowComments(true);
        newImage.setShowMetaInfo(true);

        ia.addImage(newImage);

        Assert.assertEquals(2, ia.getCountIdenticalImages(image.getAlbum(), image.getPath()).intValue());
    }
View Full Code Here

     * @param comment - comment to remove
     * @throws PhotoAlbumException
     */
    public void deleteComment(Comment comment) throws PhotoAlbumException {
        try {
            Image image = comment.getImage();
            image.removeComment(comment);
            em.remove(em.merge(comment));
            em.flush();
        } catch (Exception e) {
            throw new PhotoAlbumException(e.getMessage());
        }
View Full Code Here

TOP

Related Classes of org.richfaces.photoalbum.model.Image

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.