PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 6ms RepoModel.GetById 34ms app.codeStats 0ms

/src/test/java/com/google/ie/business/dao/impl/UserDaoImplTest.java

http://thoughtsite.googlecode.com/
Java | 85 lines | 48 code | 11 blank | 26 comment | 0 complexity | 6c05cc581639535bfeb476181abea517 MD5 | raw file
 1// Copyright 2009 Google Inc. All Rights Reserved.
 2/**
 3 * 
 4 */
 5package com.google.ie.business.dao.impl;
 6
 7import static org.junit.Assert.assertEquals;
 8import static org.junit.Assert.assertNotNull;
 9
10import com.google.ie.business.domain.User;
11import com.google.ie.dto.RetrievalInfo;
12import com.google.ie.test.DatastoreTest;
13
14import org.junit.Before;
15import org.junit.Test;
16
17/**
18 * Test case for UserDaoImpl class
19 * 
20 * @author ssbains
21 * 
22 */
23public class UserDaoImplTest extends DatastoreTest {
24    private UserDaoImpl userDaoImpl;
25
26    /**
27     * @throws java.lang.Exception
28     */
29    @Before
30    public void setUp() {
31        super.setUp();
32        userDaoImpl = new UserDaoImpl();
33        userDaoImpl.setPersistenceManagerFactory(pmf);
34    }
35
36    /**
37     * Test method for
38     * {@link com.google.ie.business.dao.impl.UserDaoImpl#saveUser(com.google.ie.business.domain.User)}
39     * .
40     */
41    @Test
42    public void testSaveUser() {
43        User userToBeSaved = new User();
44        userToBeSaved.setDisplayName("test user");
45        User savedUser = userDaoImpl.saveUser(userToBeSaved);
46        assertNotNull(savedUser);
47        assertEquals(userToBeSaved.getDisplayName(), savedUser.getDisplayName());
48    }
49
50    /**
51     * Test method for
52     * {@link com.google.ie.business.dao.impl.UserDaoImpl#getUserById(java.lang.String)}
53     * .
54     */
55    @Test
56    public void getUserById() {
57        User userToBeSaved = new User();
58        userToBeSaved.setDisplayName("test user");
59        userToBeSaved.setId("IDString");
60        userDaoImpl.saveUser(userToBeSaved);
61        User fetchedUser = userDaoImpl.getUserById(userToBeSaved.getId());
62        assertNotNull(fetchedUser);
63        assertEquals(userToBeSaved.getUserKey(), fetchedUser.getUserKey());
64    }
65
66    /**
67     * 
68     */
69    @Test
70    public void getUsers() {
71        User userToBeSaved = new User();
72        userToBeSaved.setDisplayName("test user");
73        userToBeSaved.setRoleName("admin");
74        userDaoImpl.saveUser(userToBeSaved);
75
76        User userToBeSaved2 = new User();
77        userToBeSaved2.setDisplayName("test user");
78        userToBeSaved2.setRoleName("user");
79        userDaoImpl.saveUser(userToBeSaved2);
80
81        RetrievalInfo retrievalInfo = createDummyRetrievalParam(0, 10, "createdOn", "asc");
82        assertEquals(1, userDaoImpl.getUsers(retrievalInfo, "user", null).size());
83
84    }
85}