Package org.apache.rave.portal.model

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


    @Test
    @Transactional(readOnly=false)
    @Rollback(true)
    public void delete() {
        WidgetRating wr = repository.getRatingById(VALID_WIDGET_ID, VALID_WIDGET_RATING_ID);
        assertThat(wr, is(notNullValue()));
        repository.deleteWidgetRating(VALID_WIDGET_ID, wr);
        wr = repository.getRatingById(VALID_WIDGET_ID, VALID_WIDGET_RATING_ID);
        assertThat(wr, is(nullValue()));
    }
View Full Code Here


    @Transactional(readOnly=false)
    @Rollback(true)
    public void save_new() {
        final int EXPECTED_SCORE = 1;

        WidgetRating wr = new JpaWidgetRating();
        wr.setScore(EXPECTED_SCORE);
        wr.setUserId(VALID_USER_ID);
        assertThat(wr.getId(), is(nullValue()));
        repository.createWidgetRating(VALID_WIDGET_ID, wr);
        String newId = wr.getId();
        assertThat(Long.parseLong(newId) > 0, is(true));
        WidgetRating newRating = repository.getRatingById(VALID_WIDGET_ID, newId);
        assertThat(newRating.getScore(), is(EXPECTED_SCORE));
        assertThat(newRating.getUserId(), is(VALID_USER_ID));
    }
View Full Code Here

    @Test
    @Transactional(readOnly=false)
    @Rollback(true)
    public void save_existing() {
        int EXPECTED_SCORE = 99;
        WidgetRating wr = repository.getRatingById(VALID_WIDGET_ID, VALID_WIDGET_RATING_ID);
        assertThat(wr.getScore(), is(not(EXPECTED_SCORE)));
        wr.setScore(99);
        repository.updateWidgetRating(VALID_WIDGET_ID, wr);
        WidgetRating updatedRating = repository.getRatingById(VALID_WIDGET_ID, VALID_WIDGET_RATING_ID);
        assertThat(updatedRating.getScore(), is(EXPECTED_SCORE));
    }
View Full Code Here

    }

    // returns a trusted WidgetRating object, either from the WidgetRatingRepository, or the
    // cached container list
    private WidgetRating getTrustedWidgetRating(String widgetRatingId, List<WidgetRating> trustedWidgetRatingContainer) {
        WidgetRating widgetRating = null;
        if (trustedWidgetRatingContainer.isEmpty()) {
            widgetRating = widgetRepository.getRatingById(null, 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.getId(), trustedWidgetRatingContainer);
        }
        return isWidgetRatingOwnerById(authentication, trustedWidgetRating.getUserId());
    }
View Full Code Here

    @Test
    public void getByWidgetIdAndUserId_Valid(){
        String widgetId = "222";
        String userId = "333";
        Widget widget = new WidgetImpl();
        WidgetRating widgetRating = new WidgetRatingImpl();
        widgetRating.setUserId(userId);
        widget.setRatings(Arrays.asList(widgetRating));
        expect(template.get(widgetId)).andReturn(widget);
        replay(template);
        assertThat(ratingRepository.getWidgetRatingsByWidgetIdAndUserId(widgetId, userId), is(sameInstance(widgetRating)));
    }
View Full Code Here

    @Test
    public void getByWidgetIdAndUserId_Diff_Id(){
        String widgetId = "222";
        String userId = "333";
        Widget widget = new WidgetImpl();
        WidgetRating widgetRating = new WidgetRatingImpl();
        widgetRating.setUserId("444");
        widget.setRatings(Arrays.asList(widgetRating));
        expect(template.get(widgetId)).andReturn(widget);
        replay(template);
        assertNull(ratingRepository.getWidgetRatingsByWidgetIdAndUserId(widgetId, userId));
    }
View Full Code Here

    @Test
    public void deleteAll_Valid(){
        String userId = "233";
        List<Widget> widgets = new ArrayList<Widget>();
        Widget delete = new WidgetImpl();
        WidgetRating rating = new WidgetRatingImpl();
        List<WidgetRating> ratings= new ArrayList<WidgetRating>();
        ratings.add(rating);
        delete.setRatings(ratings);
        rating.setUserId(userId);
        widgets.add(delete);
        expect(template.find(query(where("ratings").elemMatch(where("userId").is(userId))))).andReturn(widgets);
        expect(template.save(delete)).andReturn(null);
        replay(template);
View Full Code Here

    @Test
    public void deleteAll_Diff_Id(){
        String userId = "111";
        Widget widget = new WidgetImpl();
        List<Widget> widgets = Arrays.asList(widget);
        WidgetRating rating = new WidgetRatingImpl();
        rating.setUserId("222");
        widget.setRatings(Arrays.asList(rating));
        expect(template.find(query(where("ratings").elemMatch(where("userId").is(userId))))).andReturn(widgets);
        replay(template);

        int count = ratingRepository.deleteAllWidgetRatings(userId);
View Full Code Here

        expect(template.get(widgetId)).andReturn(widget);
        expect(template.save(widget)).andReturn(widget);
        replay(template);

        WidgetRating widgetRating = ratingRepository.updateWidgetRating(widgetId, item);

        assertThat(item.getScore(), is(equalTo(lookup.getScore())));
        assertThat(item.getUserId(), is(equalTo(lookup.getUserId())));
        assertThat(item.getScore(), is(equalTo(lookup.getScore())));
        assertThat(widgetRating, is(sameInstance((WidgetRating)lookup)));
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.