Package org.apache.rave.portal.model

Examples of org.apache.rave.portal.model.WidgetRating


    }
   
    @Test public void updateWidgetRating() {
        Widget widget = repository.get(4L);
        assertNotNull(widget.getRatings());
        WidgetRating widgetRating = new WidgetRating();
        widgetRating.setScore(10);
        widgetRating.setUserId(1L);
        widgetRating.setWidgetId(widget.getEntityId());
        widget.getRatings().add(widgetRating);
       
        repository.save(widget);
       
        Widget reloadedWidget = repository.get(4L);
        List<WidgetRating> widgetRatings = reloadedWidget.getRatings();
        assertNotNull(widgetRatings);
        assertEquals(1, widgetRatings.size());
        WidgetRating reloadedWidgetRating = widgetRatings.get(0);
        assertNotNull(reloadedWidgetRating);
        assertEquals(widgetRating.getScore(), reloadedWidgetRating.getScore());
        assertEquals(widgetRating.getUserId(), reloadedWidgetRating.getUserId());
        assertEquals(widget.getEntityId(), reloadedWidgetRating.getWidgetId());
       
        reloadedWidgetRating.setScore(0);
       
        repository.save(reloadedWidget);
        reloadedWidget = repository.get(4L);
        widgetRatings = reloadedWidget.getRatings();
        assertNotNull(widgetRatings);
        assertEquals(1, widgetRatings.size());
        reloadedWidgetRating = widgetRatings.get(0);
        assertNotNull(reloadedWidgetRating);
        assertEquals(widgetRating.getScore(), reloadedWidgetRating.getScore());
        assertEquals(widgetRating.getUserId(), reloadedWidgetRating.getUserId());
        assertEquals(widget.getEntityId(), reloadedWidgetRating.getWidgetId());
    }
View Full Code Here


    @Before
    public void setUp() {
        mockWidgetRatingRepository = createMock(WidgetRatingRepository.class);
        defaultWidgetRatingPermissionEvaluator = new DefaultWidgetRatingPermissionEvaluator(mockWidgetRatingRepository);

        widgetRating = new WidgetRating();
        widgetRating.setUserId(VALID_USER_ID);
        widgetRating.setWidgetId(VALID_WIDGET_ID);
        widgetRating.setEntityId(VALID_WIDGET_ID);

        user = new User();
View Full Code Here

    }

    // returns a trusted WidgetRating object, either from the WidgetRatingRepository, or the
    // cached container list
    private WidgetRating getTrustedWidgetRating(long widgetRatingId, List<WidgetRating> trustedWidgetRatingContainer) {
        WidgetRating widgetRating = null;
        if (trustedWidgetRatingContainer.isEmpty()) {
            widgetRating = widgetRatingRepository.get(widgetRatingId);
            trustedWidgetRatingContainer.add(widgetRating);
        } else {
            widgetRating = trustedWidgetRatingContainer.get(0);
View Full Code Here

    // checks to see if the Authentication object principal is the owner of the supplied widgetRating object
    // if trustedDomainObject is false, pull the entity from the database first to ensure
    // the model object is trusted and hasn't been modified
    private boolean isWidgetRatingOwner(Authentication authentication, WidgetRating widgetRating, List<WidgetRating> trustedWidgetRatingContainer, boolean trustedDomainObject) {
        WidgetRating trustedWidgetRating = null;
        if (trustedDomainObject) {
            trustedWidgetRating = widgetRating;
        } else {
            trustedWidgetRating = getTrustedWidgetRating(widgetRating.getEntityId(), trustedWidgetRatingContainer);
        }
        return isWidgetRatingOwnerById(authentication, trustedWidgetRating.getUserId());
    }
View Full Code Here

    @Before
    public void setUp() {
        mockWidgetRatingRepository = createMock(WidgetRatingRepository.class);
        defaultWidgetRatingPermissionEvaluator = new DefaultWidgetRatingPermissionEvaluator(mockWidgetRatingRepository);

        widgetRating = new WidgetRating();
        widgetRating.setUserId(VALID_USER_ID);
        widgetRating.setWidgetId(VALID_WIDGET_ID);
        widgetRating.setEntityId(VALID_WIDGET_ID);

        user = new User();
View Full Code Here

        service = new DefaultWidgetRatingService(repository);
    }

    @Test
    public void testGetByWidgetIdAndUserId() {
        WidgetRating widgetRating = new WidgetRating(1L, 2L, 3L, 5);
        expect(repository.getByWidgetIdAndUserId(2L, 3L)).andReturn(widgetRating);
        replay(repository);
        final WidgetRating rating = service.getByWidgetIdAndUserId(2L, 3L);
        assertEquals("Score is 5", Integer.valueOf(5), rating.getScore());
        verify(repository);
    }
View Full Code Here

        verify(repository);
    }

    @Test
    public void updateScore() {
        WidgetRating widgetRating = createMock(WidgetRating.class);
        widgetRating.setScore(10);

        expectLastCall().once();
        expect(repository.save(widgetRating)).andReturn(widgetRating);
        replay(repository, widgetRating);
        service.updateScore(widgetRating, 10);
View Full Code Here

        verify(repository, widgetRating);
    }

    @Test
    public void saveWidgetRating_new() {
        WidgetRating newRating = new WidgetRating();
        newRating.setWidgetId(2L);
        newRating.setUserId(1L);
        newRating.setScore(10);

        expect(repository.getByWidgetIdAndUserId(2L, 1L)).andReturn(null);
        expect(repository.save(newRating)).andReturn(newRating);
        replay(repository);
View Full Code Here

        verify(repository);
    }

    @Test
    public void saveWidgetRating_existing() {
        WidgetRating existingRating = new WidgetRating(1L, 1L, 1L, 5);
        WidgetRating newRating = new WidgetRating();
        newRating.setWidgetId(1L);
        newRating.setUserId(1L);
        newRating.setScore(10);

        expect(repository.getByWidgetIdAndUserId(1L, 1L)).andReturn(existingRating);
        expect(repository.save(existingRating)).andReturn(existingRating);
        replay(repository);
View Full Code Here

        assertEquals("Updated score", Integer.valueOf(10), existingRating.getScore());
    }

    @Test
    public void removeWidgetRating_existingRating() {
        final WidgetRating widgetRating = new WidgetRating(1L, 1L, 1L, 5);

        expect(repository.getByWidgetIdAndUserId(1L, 1L)).andReturn(widgetRating);
        repository.delete(widgetRating);
        expectLastCall();
        replay(repository);
View Full Code Here

TOP

Related Classes of org.apache.rave.portal.model.WidgetRating

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.