Package org.jtalks.common.model.entity

Examples of org.jtalks.common.model.entity.Section


    @Test
    public void getLastPostsForSectionShouldReturnEmptyListWhenThereIsNoPostsInTheSection() {
        final int count = 42;
        JCUser user = new JCUser(USER_NAME, EMAIL, USER_PASSWORD);
        Section section = new Section(SECTION_NAME);
        when(userService.getCurrentUser()).thenReturn(user);
        when(sectionDao.getAvailableBranchIds(eq(user), anyList())).thenReturn(Collections.<Long>emptyList());
        when(postDao.getLastPostsFor(anyList(), eq(count))).thenReturn(Collections.<Post>emptyList());

        List<Post> posts = sectionService.getLastPostsForSection(section, count);
View Full Code Here


    @Test
    public void getLastPostsForSectionShouldReturnListOfTheLatestPosts() {
        final int count = 42;
        JCUser user = new JCUser(USER_NAME, EMAIL, USER_PASSWORD);
        Section section = new Section(SECTION_NAME);
        Branch branch1 = new Branch("my branch", "1");
        branch1.setId(42);
        Branch branch2 = new Branch("my branch2", "2");
        branch2.setId(43);
        section.addOrUpdateBranch(branch1);
        section.addOrUpdateBranch(branch2);
        when(userService.getCurrentUser()).thenReturn(user);
        List<Long> branchIds = Arrays.asList(branch1.getId());
        when(sectionDao.getAvailableBranchIds(user, section.getBranches())).thenReturn(branchIds);

        List<Post> posts = new ArrayList<>();
        posts.add(new Post(user, "post1"));
        posts.add(new Post(user, "post2"));
View Full Code Here

    /*===== Common methods =====*/

    @Test
    public void testSave() {
        Section section = ObjectsFactory.getDefaultSection();

        dao.saveOrUpdate(section);

        assertNotSame(section.getId(), 0, "Id not created");

        session.evict(section);
        Section result = (Section) session.get(Section.class, section.getId());

        assertReflectionEquals(section, result);
    }
View Full Code Here

        assertReflectionEquals(section, result);
    }

    @Test(expectedExceptions = ConstraintViolationException.class)
    public void testSaveSectionWithNameNotNullViolation() {
        Section section = ObjectsFactory.getDefaultSection();
        session.save(section);
        section.setName(null);

        dao.saveOrUpdate(section);
        session.flush();
    }
View Full Code Here

        session.flush();
    }

    @Test
    public void testGet() {
        Section section = ObjectsFactory.getDefaultSection();
        session.save(section);

        Section result = dao.get(section.getId());

        assertNotNull(result);
        assertEquals(result.getId(), section.getId());
    }
View Full Code Here

        assertEquals(result.getId(), section.getId());
    }

    @Test
    public void testGetInvalidId() {
        Section result = dao.get(-567890L);

        assertNull(result);
    }
View Full Code Here

    }

    @Test
    public void testBranchesCascadingDeletesFromSection() {
        Branch actualBranch = ObjectsFactory.getDefaultBranch();
        Section section = ObjectsFactory.getDefaultSection();
        section.addOrUpdateBranch(actualBranch);
        branchDao.saveOrUpdate(actualBranch);
        dao.saveOrUpdate(section);
        session.flush();
        Branch expectedBranch = branchDao.get(actualBranch.getId());
        assertEquals(expectedBranch.getName(), actualBranch.getName());
        section.deleteBranch(actualBranch);
        dao.saveOrUpdate(section);
        session.flush();
        session.clear();
        expectedBranch = branchDao.get(actualBranch.getId());
        assertNull(expectedBranch);
View Full Code Here

    }


    private void saveAndEvict(Branch branch) {
        saveAndEvict(branch.getModeratorsGroup());
        Section section = ObjectsFactory.getDefaultSection();
        branch.setSection(section);
        session.save(section);
        session.save(branch);
        session.evict(branch);
        session.evict(section);
View Full Code Here

    }

    @Test
    public void testUpdate() {
        String newName = "new name";
        Section section = ObjectsFactory.getDefaultSection();
        session.save(section);
        section.setName(newName);

        dao.saveOrUpdate(section);
        session.flush();
        session.evict(section);
        Section result = (Section) session.get(Section.class, section.getId());

        assertEquals(result.getName(), newName);
    }
View Full Code Here

        assertEquals(result.getName(), newName);
    }

    @Test(expectedExceptions = javax.validation.ConstraintViolationException.class)
    public void testUpdateNotNullViolation() {
        Section section = ObjectsFactory.getDefaultSection();
        session.save(section);
        section.setName(null);
        dao.saveOrUpdate(section);
        session.flush();
    }
View Full Code Here

TOP

Related Classes of org.jtalks.common.model.entity.Section

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.