Package org.apache.rave.portal.model

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


    }

    @Override
    @Transactional
    public void saveWidgetRating(Long widgetId, Integer score, Long userId) {
        WidgetRating rating = getByWidgetIdAndUserId(widgetId, userId);
        if (rating == null) {
            rating = new WidgetRating();
            rating.setScore(score);
            rating.setUserId(userId);
            rating.setWidgetId(widgetId);
        } else {
            rating.setScore(score);
        }
        repository.save(rating);
    }
View Full Code Here


    }

    @Override
    @Transactional
    public void removeWidgetRating(Long widgetId, Long userId) {
        WidgetRating widgetRating = repository.getByWidgetIdAndUserId(widgetId, userId);
        if (widgetRating == null) {
            return;
        }
        repository.delete(widgetRating);
    }
View Full Code Here

    @Test
    public void getByWidgetIdAndUserId_found() {
        Long widgetId = 1L;
        Long userId = 1L;
        WidgetRating widgetRating = repository.get(1L);
        WidgetRating byWidgetAndUser = repository.getByWidgetIdAndUserId(widgetId, userId);
        assertEquals(widgetRating, byWidgetAndUser);
    }
View Full Code Here

    @Test
    public void getByWidgetIdAndUserId_missing() {
        Long widgetId = 123L;
        Long userId = 234L;
        WidgetRating byWidgetAndUser = repository.getByWidgetIdAndUserId(widgetId, userId);
        assertNull("Don't expect a WidgetRating for widgetId 123 and userId 234", byWidgetAndUser);
    }
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());
    }
View Full Code Here

        assertEquals("Score is 5", Integer.valueOf(5), rating.getScore());
    }

    @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);

        expect(repository.getByWidgetIdAndUserId(1L, 1L)).andReturn(existingRating);
        expect(repository.save(existingRating)).andReturn(existingRating);
        replay(repository);

        service.saveWidgetRating(1L, 10, 1L);
        verify(repository);

        assertEquals("Updated score", Integer.valueOf(10), existingRating.getScore());
    }
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

   
    @Test
    public void getUserWidgetRatings() {
        Map<Long, WidgetRating> widgetRatings = repository.getUsersWidgetRatings(1L);
       
        WidgetRating gadgetOne = widgetRatings.get(1L);
        assertEquals(WidgetRating.DISLIKE, gadgetOne.getScore());
        assertEquals(new Long(1), gadgetOne.getUserId());
        assertEquals(new Long(1), gadgetOne.getEntityId());
       
        WidgetRating gadgetTwo = widgetRatings.get(2L);
        assertEquals(WidgetRating.LIKE, gadgetTwo.getScore());
        assertEquals(new Long(1), gadgetTwo.getUserId());
        assertEquals(new Long(2), gadgetTwo.getEntityId());
    }
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.