Changeset 1895


Ignore:
Timestamp:
04/20/12 12:59:56 (12 years ago)
Author:
twagoo
Message:

CommentsDao?.getById takes Id as Number. Added test for this method

Location:
ComponentRegistry/trunk/ComponentRegistry/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/CommentsDao.java

    r1697 r1895  
    5959     * @throws DataAccessException
    6060     */
    61     public Comment getById(String id) throws DataAccessException {
     61    public Comment getById(Number id) throws DataAccessException {
    6262        return getFirstOrNull(SELECT_BASE + " WHERE " + COLUMN_ID + " = ?", id);
    6363    }
     
    202202    }
    203203
    204     /**
    205      * Retrieve comment Id From a comment
    206      * @param cmdId
    207      * @return query for database access to id
    208      */
    209     public Number getDbId(String cmdId) {
    210         StringBuilder query = new StringBuilder("SELECT " + COLUMN_ID + " FROM ").append(getTableName());
    211         query.append(" WHERE ").append(COLUMN_ID).append(" = ?");
    212         return getSimpleJdbcTemplate().queryForInt(query.toString(), cmdId);
    213     }
    214 
    215204    private Timestamp extractTimestamp(Comment comment) {
    216205        if (comment.getCommentDate() != null) {
  • ComponentRegistry/trunk/ComponentRegistry/src/main/java/clarin/cmdi/componentregistry/impl/database/ComponentRegistryDbImpl.java

    r1892 r1895  
    653653            ComponentRegistryException, UserUnauthorizedException, DeleteFailedException {
    654654        try {
    655             Comment comment = commentsDao.getById(commentId);
     655            Comment comment = commentsDao.getById(Integer.parseInt(commentId));
    656656            if (comment != null
    657657                    // Comment must have an existing (in this registry) componentId or profileId
     
    666666        } catch (DataAccessException ex) {
    667667            throw new DeleteFailedException("Database access error while trying to delete component", ex);
     668        } catch (NumberFormatException ex) {
     669            throw new DeleteFailedException("Illegal comment ID, cannot parse integer", ex);
    668670        }
    669671    }
  • ComponentRegistry/trunk/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/CommentsDaoTest.java

    r1697 r1895  
    7878        assertEquals(TEST_COMMENT_USER_NAME, comments.get(0).getUserName());
    7979        assertEquals(Integer.toString(TEST_COMMENT_USER_ID), comments.get(0).getUserId());
     80    }
     81
     82    @Test
     83    public void testGetById() {
     84        Comment comment1 = createTestComment();
     85        comment1.setProfileDescriptionId(TEST_COMMENT_PROFILE_ID);
     86        Number commentId = commentsDao.insertComment(comment1, TEST_COMMENT_USER_ID);
     87        Comment commentById = commentsDao.getById(commentId);
     88        assertEquals(TEST_COMMENT_PROFILE_ID, commentById.getProfileDescriptionId());
     89        assertEquals(TEST_COMMENT_NAME, commentById.getComment());
    8090    }
    8191
Note: See TracChangeset for help on using the changeset viewer.