Package com.philip.journal.home.bean

Examples of com.philip.journal.home.bean.Branch


     *
     */
    @Test
    public void testSave2() {
        final long beanId = Long.valueOf(TEST_BRANCH_ID);
        final Branch branch = new Branch("TestBranchUpdate", null);
        branch.setBranchId(beanId);

        final int origCount = super.getRecordCount(super.getBranchTableName());
        getLogger().debug("Update test.");
        try {
            testBaseDAOImpl.save(branch);
        } catch (final JournalException e) {
            getCommon().failUnexpectedException(e);
        }
        final Map<String, Object> saved = super.readBranch(beanId);

        assertNotNull("Update Date should not be null.", saved.get(DaoConstant.Branch.Column.UPDATE_DATE));
        assertNotNull("Update Time should not be null.", saved.get(DaoConstant.Branch.Column.UPDATE_TIME));

        assertFalse("Create Date should not be equal to Update Date.", saved.get(DaoConstant.Branch.Column.UPDATE_DATE)
                .equals(saved.get(DaoConstant.Branch.Column.CREATE_DATE)));

        assertNotNull("Update time should not be null", branch.getUpdateTime());
        assertEquals("Count check failed. Update should not increment size.", origCount,
                super.getRecordCount(super.getBranchTableName()));
    }
View Full Code Here


        final String creator = "kratos666";
        final String date = "2006-06-06";
        final String time = "06:06:06";

        try {
            final Branch read = testBaseDAOImpl.read(TEST_BRANCH_ID);
            assertNotNull("Null check on read failed.", read);
            assertEquals("Expected name check failed.", branchName, read.getName());
            assertEquals("Expected creator check failed.", creator, read.getCreator().getUsername());
            assertEquals("Expected create date check failed.", date,
                    new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault()).format(read.getCreateDate()));
            assertEquals("Expected create time check failed.", time,
                    new SimpleDateFormat("HH:mm:ss", Locale.getDefault()).format(read.getCreateTime()));
        } catch (final JournalException e) {
            getLogger().debug(e.getMessage(), e);
            fail("This scenario is not yet available.");
        }
    }
View Full Code Here

     * Case 2: Read, non existent.
     */
    @Test
    public void testRead2() {
        try {
            final Branch nonExistent = testBaseDAOImpl.read(45123);
            assertNull("Null return for non-existing check failed.", nonExistent);
        } catch (final JournalException e) {
            fail("This scenario is not yet available.");
        }
    }
View Full Code Here

    @Before
    public final void setUp()
    {
        super.setUp();

        testSubBranch1 = new Branch(TEST_BRANCH_NAME1, getTestRootBranch());
        testSubBranch1.setBranchId(TEST_SUBBRANCH1_ID);

        testEntry = new Entry(null, null, testSubBranch1);
        testEntry.setNodeId(TEST_ENTRY_ID);
        testEntry.setTitle(TEST_ENTRY_TITLE);
        testEntry.setDescription(TEST_ENTRY_DETAIL);

        testSubBranch2 = new Branch(TEST_BRANCH_NAME2, getTestRootBranch());
        testSubBranch2.setBranchId(TEST_SUBBRANCH2_ID);

        testSubBranch11 = spy(new Branch(TEST_BRANCH_NAME11, testSubBranch1));
        testSubBranch11.setBranchId(TEST_SUBBRANCH11_ID);

        when(getDaoFacade().getEntryDAO().read(TEST_ENTRY_ID)).thenReturn(testEntry);
        when(getDaoFacade().getBranchDAO().read(TEST_SUBBRANCH1_ID)).thenReturn(testSubBranch1);
        when(getDaoFacade().getBranchDAO().read(TEST_SUBBRANCH2_ID)).thenReturn(testSubBranch2);
        when(getDaoFacade().getBranchDAO().read(TEST_SUBBRANCH11_ID)).thenReturn(testSubBranch11);

        final BranchDAO mockBranchDAO = getDaoFacade().getBranchDAO();
        when(mockBranchDAO.readAllByParent(Constant.ROOT_ID)).thenAnswer(new Answer<List<Branch>>() {

            @Override
            public List<Branch> answer(final InvocationOnMock invocation) throws Throwable
            {
                final List<Branch> retval = new ArrayList<Branch>();
                if (Long.valueOf(Constant.ROOT_ID).equals(invocation.getArguments()[0])) {
                    retval.add(testSubBranch1);
                    retval.add(testSubBranch2);
                } else if (Long.valueOf(TEST_SUBBRANCH1_ID).equals(invocation.getArguments()[0])) {
                    retval.add(testSubBranch11);
                }
                return retval;
            }
        });

        doAnswer(new Answer<Object>() {
            /** Simulate an exception if rename conflicted with a sibling. */
            public Object answer(final InvocationOnMock invocation) throws Throwable
            {
                final Branch param = (Branch) invocation.getArguments()[0];
                final Branch parent = param.getParent();
                if (parent != null) {//not Root.
                    final List<Branch> siblings = mockBranchDAO.readAllByParent(parent.getBranchId());
                    for (final Branch branch : siblings) {
                        if (branch.getBranchId() != param.getBranchId() && branch.getName().equals(param.getName())) {
                            throw new JournalException(JournalTestCommon.TEST_JRNL_ERRORMSG);
                        }
                    }
View Full Code Here

        for (final Branch nextBranch : allBranch) {
            if (nextBranch.getBranchId() != 0) {
                final StringBuilder categoryDesc = new StringBuilder(nextBranch.getName()); // NOPMD by r39 on 3/30/11 2:52 PM

                Branch branch = nextBranch;

                while (branch.getParent() != null && branch.getParent().getBranchId() != 0) { // NOPMD by r39
                    categoryDesc.insert(0, branch.getParent().getName() + " > ");
                    branch = branch.getParent();
                }
                retval.add(new Category(nextBranch.getBranchId(), categoryDesc.toString())); // NOPMD by r39
            }
        }
        return retval;
View Full Code Here

            final String title, final String description)
    {
        if (title == null || description == null) {
            throw new IllegalArgumentException(Error.IAE_NULL);
        }
        final Branch branch = getDaoFacade().getBranchDAO().read(branchId);
        if (branch == null) {
            throw new IllegalArgumentException("Branch ID: " + branchId + " was not found in the datasource.");
        }
        Entry entry = getDaoFacade().getEntryDAO().read(entryId);
        if (entry == null) {
View Full Code Here

    {
        final EntryDAO entryDao = getDaoFacade().getEntryDAO();
        final BranchDAO branchDao = getDaoFacade().getBranchDAO();

        final Entry entry = entryDao.read(entryId);
        final Branch parent = branchDao.read(newParentId);
        if (entry == null || parent == null) {
            throw new IllegalArgumentException(Error.IAE_GENERIC);
        } else {
            entry.setBranch(parent);
            entryDao.save(entry);
View Full Code Here

        } catch (final ParserConfigurationException e) {
            throw new JournalException(e.getMessage(), e);
        }
        final Document doc = docBuilder.newDocument();

        final Branch rootBranch = getDaoFacade().getBranchDAO().read(ROOT_ID);
        final Element rootElement = doc.createElement(TAG_JOURNAL);
        doc.appendChild(rootElement);
        getXmlHelper().convertNodeToXml(doc, rootElement, rootBranch);

        try {
View Full Code Here

        if (branchElement == null) {
            throw JournalException.wrapperException(new IllegalArgumentException(Error.IAE_NULL));
        }

        final Branch targetBranch = convertElementToBranch(branchElement, parentId);

        final XPath xpath = XPathFactory.newInstance().newXPath();
        final Element branchesElement = (Element) xpath.evaluate(TAG_BRANCHES, branchElement, XPathConstants.NODE);
        if (branchesElement != null) {
            final NodeList subBranchList = (NodeList) xpath.evaluate(TAG_BRANCH, branchesElement,
                    XPathConstants.NODESET);
            for (int i = 0; subBranchList != null && i < subBranchList.getLength(); i++) {
                final Element subBranchElement = (Element) subBranchList.item(i);
                extractBranchFromDocument(subBranchElement, targetBranch.getBranchId());
            }
        }
        extractEntryFromDocument(branchElement, targetBranch);
    }
View Full Code Here

            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);
            final Entry entry = new Entry();
            for (int i = 0; entryList != null && i < entryList.getLength(); i++) {
                for (final String property : entryProperties) {
                    final Object val = getElementPropValue((Element) entryList.item(i),
                            BeanUtils.getPropertyType(entry, property), property);
                    if (val != null) {
                        try {
                            org.apache.commons.beanutils.BeanUtils.setProperty(entry, property, val);
                        } catch (final Exception e) {
                            throw new JournalException(e.getMessage(), e);
                        }
                    }
                }
                if (null == entryDao.readByTitle(entry.getTitle(), subListParent.getBranchId())) {
                    entry.setBranch(subListParent);
                    entry.setNodeId(0);
                    entryDao.save(entry);
                }
            }
View Full Code Here

TOP

Related Classes of com.philip.journal.home.bean.Branch

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.