Package com.philip.journal.home.dao

Examples of com.philip.journal.home.dao.BranchDAO


        getSession().put(Constant.CURRENT_USER, testUser);

        final ServiceFacade mockedFacade = Mockito.mock(ServiceFacade.class);
        getSession().put(BusinessServiceProxy.SERVICE_FACADE, mockedFacade);

        final BranchDAO mockBranchDAO = mock(BranchDAO.class);
        final EntryDAO mockEntryDAO = mock(EntryDAO.class);
        final UserDAO mockUserDAO = mock(UserDAO.class);
        final ConfigItemDAO mockConfigDAO = mock(ConfigItemDAO.class);

        when(daoFacade.getConfigItemDAO()).thenReturn(mockConfigDAO);
        when(mockConfigDAO.readAll()).thenReturn(new ArrayList<ConfigItem>());

        when(daoFacade.getBranchDAO()).thenReturn(mockBranchDAO);
        testRootBranch = new Branch(Constant.ROOT_NAME, null); //mock(Branch.class);
        testRootBranch.setBranchId(Constant.ROOT_ID);
        when(mockBranchDAO.read(Constant.ROOT_ID)).thenReturn(testRootBranch);
        /*
         * when(TEST_ROOT_BRANCH.getBranchId()).thenReturn(Constant.ROOT_ID);
         * when(TEST_ROOT_BRANCH.getName()).thenReturn(Constant.ROOT_NAME);
         */
        when(daoFacade.getEntryDAO()).thenReturn(mockEntryDAO);
View Full Code Here


    void extractEntryFromDocument(final Element branchElement, final Branch targetBranch)
            throws XPathExpressionException
    {
        final XPath xpath = XPathFactory.newInstance().newXPath();
        final EntryDAO entryDao = getDaoFacade().getEntryDAO();
        final BranchDAO branchDao = getDaoFacade().getBranchDAO();
        final Branch subListParent = branchDao.read(targetBranch.getBranchId());
        final Element entriesElement = (Element) xpath.evaluate(TAG_ENTRIES, branchElement, XPathConstants.NODE);

        if (entriesElement != null) {
            final NodeList entryList = (NodeList) xpath.evaluate(TAG_ENTRY, entriesElement, XPathConstants.NODESET);
            final String[] entryProperties = BeanUtils.getProperties(new Entry(), EXCLUDED_PROPS);
View Full Code Here

     *                </ul>
     * @throws XPathExpressionException XPath module exception.
     */
    Branch convertElementToBranch(final Element branchElement, final long parentId) throws XPathExpressionException
    {
        final BranchDAO branchDao = getDaoFacade().getBranchDAO();
        final Branch parent = branchDao.read(parentId);
        if (parent == null || branchElement == null) {
            throw JournalException.wrapperException(new IllegalArgumentException(Messages.Error.IAE_NULL));
        }

        Branch targetBranch = new Branch();
        final String[] branchProperties = BeanUtils.getProperties(targetBranch, EXCLUDED_PROPS);
        for (final String property : branchProperties) {
            final Object val = getElementPropValue(branchElement, BeanUtils.getPropertyType(targetBranch, property),
                    property);
            if (val != null) {
                try {
                    org.apache.commons.beanutils.BeanUtils.setProperty(targetBranch, property, val);
                } catch (final Exception e) {
                    throw new JournalException(e.getMessage(), e);
                }
            }
        }

        targetBranch.setParent(parent);
        final Branch storedBranch = branchDao.readByName(targetBranch.getName(), parentId);
        if (storedBranch == null) {
            targetBranch.setBranchId(0);
            branchDao.save(targetBranch);
        } else {
            targetBranch = storedBranch;
        }
        return targetBranch;
    }
View Full Code Here

    }

    @Override
    public void moveBranch(final Map<String, Object> session, final long newParentId, final long branchId)
    {
        final BranchDAO branchDao = getDaoFacade().getBranchDAO();
        final Branch branch = branchDao.read(branchId);
        final Branch parent = branchDao.read(newParentId);

        if (branch == null || parent == null) {
            throw new JournalException(Messages.Error.JE_INV_BRANCHID);
        }
        final String newIds = Constant.BRANCHID_PREFIX + newParentId;
        final String branchIds = Constant.BRANCHID_PREFIX + branchId;
        final String branchPath = getBranchPath(session, parent);
        final int newIdx = branchPath.indexOf(newIds);
        final int parentIdx = branchPath.indexOf(branchIds);

        if (parentIdx > -1 && newIdx > parentIdx) {
            throw new JournalException(Messages.Error.JE_INV_BRANCHID);
        }

        branch.setParent(parent);
        branchDao.save(branch);
    }
View Full Code Here

     * @return {Entity, size}
     * @exception JournalException branchId is not found.
     */
    Object[] getBranchNodeProperty(final StringBuilder strBuilder, final long branchId)
    {
        final BranchDAO branchDao = getDaoFacade().getBranchDAO();
        final Branch branch = branchDao.read(branchId);
        if (branch == null) {
            throw JournalException.wrapperException(new IllegalArgumentException(Messages.Error.IAE_NULL));
        }
        final long size = branch.getName() == null ? 0 : branch.getName().length();
        if (strBuilder != null) {
View Full Code Here

     */
    @Test
    public final void testSaveEntry1()
    {
        final EntryDAO mockedEntryDAO = getDaoFacade().getEntryDAO();
        final BranchDAO mockedBranchDAO = getDaoFacade().getBranchDAO();

        final long branchId = 1L;
        final Branch testParentBranch = new Branch("Test Parent", null);
        when(mockedBranchDAO.read(branchId)).thenReturn(testParentBranch);

        final String testTitle = "Test Title";
        final String testDesc = "Test Description";

        try {
View Full Code Here

     */
    @Test
    public final void testSaveEntry2()
    {
        final EntryDAO mockedEntryDAO = getDaoFacade().getEntryDAO();
        final BranchDAO mockedBranchDAO = getDaoFacade().getBranchDAO();

        final long entryId = 1L;
        final Entry testEntry = new Entry();
        testEntry.setTitle("Test Title");
        testEntry.setDescription("Test Description");
        when(mockedEntryDAO.read(entryId)).thenReturn(testEntry);

        final long newBranchId = 666L;
        final String newTitle = "New Title";
        final String newDescription = "New Description";
        final Branch newParentBranch = new Branch("Test Parent", null);
        newParentBranch.setBranchId(newBranchId);
        when(mockedBranchDAO.read(newBranchId)).thenReturn(newParentBranch);

        final ArgumentCaptor<Entry> argument = ArgumentCaptor.forClass(Entry.class);

        try {
            entryServiceImpl.saveEntry(super.getSession(), newBranchId, entryId, newTitle, newDescription);
View Full Code Here

     * Case 3: Invalid branch ID.
     */
    @Test(expected = IllegalArgumentException.class)
    public final void testSaveEntry3()
    {
        final BranchDAO mockedBranchDAO = getDaoFacade().getBranchDAO();
        when(mockedBranchDAO.read(anyInt())).thenReturn(null);
        entryServiceImpl.saveEntry(super.getSession(), 0, 0, "title", "desc");
    }
View Full Code Here

    /** Case 4: Null title. */
    @Test(expected = IllegalArgumentException.class)
    public final void testSaveEntry4()
    {
        final BranchDAO mockedBranchDAO = getDaoFacade().getBranchDAO();
        when(mockedBranchDAO.read(anyInt())).thenReturn(new Branch());
        try {
            entryServiceImpl.saveEntry(super.getSession(), 0, 0, null, null);
            fail("Case 4: Null title.");
        } catch (final JournalException e) {
            getCommon().failUnexpectedException(e);
View Full Code Here

    public void setUp()
    {
        super.setUp();
        spyInstance = getSpyInstance();

        final BranchDAO branchDAO = getDaoFacade().getBranchDAO();
        final EntryDAO entryDAO = getDaoFacade().getEntryDAO();

        testBranch1 = new Branch("RootBranch1", getTestRootBranch());
        testBranch1.setBranchId(TEST_ID_RTBRANCH1);

        testSubBranch1 = new Branch("SubBranch1", testBranch1);
        testSubBranch1.setBranchId(TEST_ID_SUBBRANCH1);

        final Entry entry1 = new Entry("Entry Title 1", "Entry Desc 1", testBranch1);
        final Entry entry2 = new Entry("Entry Title 2", "Entry Desc 2", testBranch1);
        final Entry entry3 = new Entry("Entry Title 3", "Entry Desc 3", testSubBranch1);

        when(branchDAO.readAllByParent(Constant.ROOT_ID)).thenReturn(Arrays.asList(new Branch[] { testBranch1 }));
        when(branchDAO.readAllByParent(TEST_ID_RTBRANCH1)).thenReturn(Arrays.asList(new Branch[] { testSubBranch1 }));
        when(entryDAO.readAllByBranch(TEST_ID_RTBRANCH1)).thenReturn(Arrays.asList(new Entry[] {
                entry1,
                entry2 }));
        when(entryDAO.readAllByBranch(TEST_ID_SUBBRANCH1)).thenReturn(Arrays.asList(new Entry[] { entry3 }));
View Full Code Here

TOP

Related Classes of com.philip.journal.home.dao.BranchDAO

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.