Package org.apache.rave.model

Examples of org.apache.rave.model.Category


    @Autowired
    private JpaCategoryConverter categoryConverter;

    @Test
    public void noConversion() {
        Category category = new JpaCategory();
        assertThat(categoryConverter.convert(category), is(sameInstance(category)));
    }
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());
        return categoryRepository.save(category);
    }
View Full Code Here

        assertThat(categoryConverter.convert(category), is(sameInstance(category)));
    }

    @Test
    public void nullConversion() {
        Category category = null;
        assertThat(categoryConverter.convert(category), is(nullValue()));
    }
View Full Code Here

        assertThat(categoryConverter.convert(category), is(nullValue()));
    }

    @Test
    public void newCategory() {
        Category category = new CategoryImpl();
        category.setCreatedDate(new Date());
        category.setId("9");
        category.setLastModifiedDate(new Date());
        category.setText("hello");
        category.setCreatedUserId("1");
        category.setLastModifiedUserId("1");
        category.setWidgets(new ArrayList<Widget>());

        JpaCategory converted = categoryConverter.convert(category);
        assertThat(converted, is(not(sameInstance(category))));
        assertThat(converted, is(instanceOf(JpaCategory.class)));
        assertThat(converted.getCreatedDate(), is(equalTo(category.getCreatedDate())));
        assertThat(converted.getCreatedUserId(), is(equalTo(category.getCreatedUserId())));
        assertThat(converted.getEntityId().toString(), is(equalTo(category.getId())));
        assertThat(converted.getId(), is(equalTo(category.getId())));
        assertThat(converted.getLastModifiedDate(), is(equalTo(category.getLastModifiedDate())));
        assertThat(converted.getLastModifiedUserId(), is(equalTo(category.getLastModifiedUserId())));
        assertThat(converted.getText(), is(equalTo(category.getText())));
        assertThat(converted.getWidgets(), is(equalTo(category.getWidgets())));
    }
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

    @Test
    @Rollback(true)
    public void save_existingEntity() {
        final String UPDATED_TEXT = "changed the text";
        Category category = repository.get(VALID_ENTITY_ID.toString());
        assertThat(category.getText(), is(not(UPDATED_TEXT)));
        category.setText(UPDATED_TEXT);
        repository.save(category);
        // fetch again and verify update
        Category modCategory = repository.get(VALID_ENTITY_ID.toString());
        assertThat(modCategory.getText(), is(UPDATED_TEXT));
    }
View Full Code Here

    }

    @Test
    @Rollback(true)
    public void delete() {
        Category entity = repository.get(VALID_ENTITY_ID.toString());
        assertThat(entity, is(notNullValue()));
        repository.delete(entity);
        assertThat(repository.get(VALID_ENTITY_ID.toString()), is(nullValue()));
    }
View Full Code Here

TOP

Related Classes of org.apache.rave.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.