source: ComponentRegistry/branches/jeaferversion/ComponentRegistry/src/test/java/clarin/cmdi/componentregistry/impl/database/CommentsDaoTest.java @ 1640

Last change on this file since 1640 was 1640, checked in by jeafer, 12 years ago

Jean-Charles branch ComponentRegistry commit5 (functionnal),
Changes regarding comment on the ComponentRegistry.

Modification of classes CommentsDao?
Response class has been split up. A general class ComponentRegistryResponse?
a abstractDescription response: RegisterResponse?
a comment response : CommentResponse?
Improvement of validation process for comments
Improvement of ComponentRegistryRestService?
New classes test CommentResponseTest? and CommentValidatorTest?

Documentation added to most classes
Clean up code in other classes

File size: 4.2 KB
Line 
1package clarin.cmdi.componentregistry.impl.database;
2
3import clarin.cmdi.componentregistry.model.Comment;
4import java.util.List;
5import org.junit.runner.RunWith;
6import org.junit.Test;
7import static org.junit.Assert.assertNotNull;
8import static org.junit.Assert.assertNull;
9import static org.junit.Assert.assertEquals;
10import org.junit.Before;
11
12import org.springframework.beans.factory.annotation.Autowired;
13import org.springframework.jdbc.core.JdbcTemplate;
14import org.springframework.test.context.ContextConfiguration;
15import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
16
17/**
18 *
19 * @author jean-charles FerriÚres <jean-charles.ferrieres@mpi.nl>
20 */
21@RunWith(SpringJUnit4ClassRunner.class)
22@ContextConfiguration(locations = {"/applicationContext.xml"})
23public class CommentsDaoTest {
24
25    @Autowired
26    private JdbcTemplate jdbcTemplate;
27    @Autowired
28    private CommentsDao commentsDao;
29
30    @Before
31    public void init() {
32        ComponentRegistryTestDatabase.resetDatabase(jdbcTemplate);
33        ComponentRegistryTestDatabase.createTableComments(jdbcTemplate);
34    }
35
36    @Test
37    public void testInjection() {
38        assertNotNull(jdbcTemplate);
39        assertNotNull(commentsDao);
40    }
41
42    @Test
43    public void testInsertComment() {
44        Comment comment = createTestComment();
45
46        assertEquals(0, commentsDao.getAllComments().size());
47        Number newId = commentsDao.insertComment(comment, Integer.parseInt(TEST_COMMENT_USER_ID));
48        assertNotNull(newId);
49     
50        List<Comment> comments = commentsDao.getAllComments();
51        assertNotNull(comments);
52        assertEquals(1, comments.size());
53
54        assertEquals(TEST_COMMENT_NAME, comments.get(0).getComment());
55       // assertEquals("A component1", comments.get(0).getComponentDescriptionId());
56        assertEquals(TEST_COMMENT_PROFILE_ID, comments.get(0).getProfileDescriptionId());
57        assertEquals(TEST_COMMENT_DATE, comments.get(0).getCommentDate());
58        assertEquals(TEST_COMMENT_USER_ID, comments.get(0).getUserId());
59        //assertEquals(TEST_COMMENT_ID, comments.get(0).getId());
60    }
61   
62    @Test
63    public void testGetCommentsFromProfile() {
64        List<Comment> descriptions = commentsDao.getCommentsFromProfile(TEST_COMMENT_PROFILE_ID);
65        assertNotNull(descriptions);
66    }
67   
68    @Test
69    public void testGetCommentFromComponent(){
70        List<Comment> descriptions = commentsDao.getCommentsFromComponent(TEST_COMMENT_COMPONENT_ID);
71        assertNotNull(descriptions);
72    }
73
74    @Test
75    public void testGetAllComments() {
76        assertEquals(0, commentsDao.getAllComments().size());
77    }
78
79    @Test
80    public void testGetComment() {
81        Comment comment = createTestComment();
82        commentsDao.insertComment(comment, 8);
83
84        assertNotNull(commentsDao.getByComment(TEST_COMMENT_NAME));
85        assertNull(commentsDao.getByComment("NOT_EXITING_COMMENT_NAME"));
86    }
87
88    public static Comment createTestComment() {
89        Comment testComment = new Comment();
90        testComment.setComment(TEST_COMMENT_NAME);
91        testComment.setCommentDate(TEST_COMMENT_DATE);
92        testComment.setId(TEST_COMMENT_ID);
93        //testComment.setComponentDescriptionId(TEST_COMMENT_COMPONENT_ID);
94        testComment.setProfileDescriptionId(TEST_COMMENT_PROFILE_ID);
95        testComment.setUserId(TEST_COMMENT_USER_ID);
96        return testComment;
97    }
98   
99    public void testSetDelete(){
100        Comment comment = createTestComment();
101        int count = commentsDao.getAllComments().size();
102       
103        commentsDao.insertComment(comment, 8);
104        assertEquals(count + 1, commentsDao.getAllComments().size());
105
106        commentsDao.deleteComment(comment);
107        assertEquals(count, commentsDao.getAllComments().size());
108       
109        assertNull(commentsDao.getByComment("NOT_EXISTING_COMMENT_NAME"));
110    }
111   
112    public final static String TEST_COMMENT_ID = "1";
113    public final static String TEST_COMMENT_PROFILE_ID = "clarin.eu:cr1:p_1297242111880";
114    public final static String TEST_COMMENT_COMPONENT_ID = "clarin.eu:cr1:c_1290431694600";
115    public final static String TEST_COMMENT_NAME = "test";
116    public final static String TEST_COMMENT_USER_ID = "8";
117    public final static String TEST_COMMENT_DATE = Comment.createNewDate();
118}
Note: See TracBrowser for help on using the repository browser.