Package org.apache.rave.portal.model

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


    @Test
    public void update() {
        final String UPDATED_TEXT = "modified category";

        Category expectedSaveCategory = new CategoryImpl();
        expectedSaveCategory.setId(VALID_ID);
        expectedSaveCategory.setText(UPDATED_TEXT);
        expectedSaveCategory.setCreatedUser(validCreatedUser);
        expectedSaveCategory.setLastModifiedUser(validLastModifiedUser);
        expectedSaveCategory.setCreatedDate(VALID_CREATED_DATE);
        expectedSaveCategory.setLastModifiedDate(VALID_LAST_MODIFIED_DATE);

        expect(repository.get(VALID_ID)).andReturn(validCategory);
        expect(repository.save(expectedSaveCategory)).andReturn(expectedSaveCategory);
        replay(repository);

        Category updatedCategory = service.update(VALID_ID, UPDATED_TEXT, validLastModifiedUser);
        assertThat(updatedCategory.getId(), is(VALID_ID));
        assertThat(updatedCategory.getText(), is(UPDATED_TEXT));
        assertThat(updatedCategory.getCreatedUser(), is(validCreatedUser));
        assertThat(updatedCategory.getLastModifiedUser(), is(validLastModifiedUser));
        assertThat(updatedCategory.getLastModifiedDate().after(updatedCategory.getCreatedDate()), is(true));

        verify(repository);
    }
View Full Code Here


    }

    @Test
    public void create() {
        final String NEW_CATEGORY_TEXT = "new category";
        Category expectedCategory = new CategoryImpl();
        expectedCategory.setText(NEW_CATEGORY_TEXT);

        expect(repository.save(expectedCategory)).andReturn(expectedCategory);
        replay(repository);

        Category wc = service.create(NEW_CATEGORY_TEXT, validCreatedUser);
        assertThat(wc.getText(), is(NEW_CATEGORY_TEXT));
        assertThat(wc.getCreatedDate(), is(notNullValue(Date.class)));
        assertThat(wc.getCreatedDate(), is(wc.getLastModifiedDate()));
        assertThat(wc.getCreatedUserId(), is(VALID_CREATED_USER_ID));
        assertThat(wc.getLastModifiedUserId(), is(VALID_CREATED_USER_ID));

        verify(repository);
    }
View Full Code Here

    @Test
    public void update() {
        final String UPDATED_TEXT = "modified category";

        Category expectedSaveCategory = new CategoryImpl();
        expectedSaveCategory.setId(VALID_ID);
        expectedSaveCategory.setText(UPDATED_TEXT);
        expectedSaveCategory.setCreatedUserId(VALID_CREATED_USER_ID);
        expectedSaveCategory.setLastModifiedUserId(VALID_LAST_MODIFIED_USER_ID);
        expectedSaveCategory.setCreatedDate(VALID_CREATED_DATE);
        expectedSaveCategory.setLastModifiedDate(VALID_LAST_MODIFIED_DATE);

        expect(repository.get(VALID_ID)).andReturn(validCategory);
        expect(repository.save(expectedSaveCategory)).andReturn(expectedSaveCategory);
        replay(repository);

        Category updatedCategory = service.update(VALID_ID, UPDATED_TEXT, validLastModifiedUser);
        assertThat(updatedCategory.getId(), is(VALID_ID));
        assertThat(updatedCategory.getText(), is(UPDATED_TEXT));
        assertThat(updatedCategory.getCreatedUserId(), is(VALID_CREATED_USER_ID));
        assertThat(updatedCategory.getLastModifiedUserId(), is(VALID_LAST_MODIFIED_USER_ID));
        assertThat(updatedCategory.getLastModifiedDate().after(updatedCategory.getCreatedDate()), is(true));

        verify(repository);
    }
View Full Code Here

    }


    @Test
    public void convert_valid(){
        Category c = new CategoryImpl();
        c.setCreatedDate(DATE1);
        c.setCreatedUserId(USER1ID);
        c.setId(USER1ID);
        c.setLastModifiedUserId(USER2ID);
        c.setText("asdf");
        c.setWidgets(Lists.<Widget>newArrayList());
        c.setLastModifiedDate(DATE2);

        MongoDbCategory mongoC = converter.convert(c);
        assertThat(mongoC.getCreatedDate(), is(equalTo(DATE1)));
        assertThat(mongoC.getCreatedUserId(), is(equalTo(USER1ID)));
        assertThat(mongoC.getId(), is(equalTo(USER1ID)));
        assertThat(mongoC.getLastModifiedUserId(), is(equalTo(USER2ID)));
        assertThat(mongoC.getWidgetRepository(), is(nullValue()));
        assertThat(mongoC.getText(), is("asdf"));
        assertThat(c.getWidgets().size(), is(0));

    }//end convert_valid
View Full Code Here

    }//end convert_valid

    @Test
    public void convert_Null(){
        Category source = new CategoryImpl();

        MongoDbCategory converted = converter.convert(source);

        assertNull(converted.getLastModifiedUserId());
        assertNull(converted.getCreatedUserId());
View Full Code Here

    }

    @Override
    @Transactional
    public Category create(String text, User createdUser) {
        Category category = new CategoryImpl();
        Date now = new Date();
        category.setText(text);
        category.setCreatedDate(now);
        category.setCreatedUserId(createdUser.getId());
        category.setLastModifiedDate(now);
        category.setLastModifiedUserId(createdUser.getId());
        categoryRepository.save(category);
        return category;
    }
View Full Code Here

    }

    @Override
    @Transactional
    public Category update(String categoryId, String text, User lastModifiedUser) {
        Category category = categoryRepository.get(categoryId);
        category.setText(text);
        category.setLastModifiedDate(new Date());
        category.setLastModifiedUserId(lastModifiedUser.getId());
        categoryRepository.save(category);
        return category;
    }
View Full Code Here

    }

    @Override
    @Transactional
    public void delete(Category category) {
        Category categoryToBeDeleted = categoryRepository.get(category.getId());
        categoryRepository.delete(categoryToBeDeleted);
    }
View Full Code Here

    }

    // returns a trusted Category object, either from the CategoryRepository, or the
    // cached container list
    private Category getTrustedCategory(String categoryId, List<Category> trustedCategoryContainer) {
        Category p = null;
        if (trustedCategoryContainer.isEmpty()) {
            p = categoryRepository.get(categoryId);
            trustedCategoryContainer.add(p);
        } else {
            p = trustedCategoryContainer.get(0);
View Full Code Here

    // checks to see if the Authentication object principal is the owner of the supplied category 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 isCategoryCreatedUser(Authentication authentication, Category category, List<Category> trustedCategoryContainer, boolean trustedDomainObject) {
        Category trustedCategory = null;
        if (trustedDomainObject) {
            trustedCategory = category;
        } else {
            trustedCategory = getTrustedCategory(category.getId(), trustedCategoryContainer);
        }

        return isCategoryCreatedUserByUsername(authentication, trustedCategory.getCreatedUserId());
    }
View Full Code Here

TOP

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

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.