PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 7ms RepoModel.GetById 13ms app.codeStats 0ms

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

http://thoughtsite.googlecode.com/
Java | 91 lines | 61 code | 18 blank | 12 comment | 2 complexity | 39bd964723142f65d672ad69418d7832 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;
 8
 9import com.google.appengine.api.datastore.DatastoreServiceFactory;
10import com.google.appengine.api.datastore.Query;
11import com.google.ie.business.domain.AdminRequest;
12import com.google.ie.business.domain.Idea;
13import com.google.ie.dto.RetrievalInfo;
14import com.google.ie.test.DatastoreTest;
15
16import org.junit.Test;
17
18import java.util.Date;
19
20/**
21 * @author asirohi
22 * 
23 */
24public class AdminRequestDaoImplTest extends DatastoreTest {
25    private AdminRequestDaoImpl adminRequestDao;
26
27    @Override
28    public void setUp() {
29        super.setUp();
30        if (adminRequestDao == null) {
31            adminRequestDao = new AdminRequestDaoImpl();
32            adminRequestDao.setPersistenceManagerFactory(pmf);
33        }
34    }
35
36    @Test
37    public void addRequest() {
38        AdminRequest adminRequest = new AdminRequest();
39        adminRequest.setEntityKey("ideakey");
40        adminRequest.setEntityType(Idea.class.getSimpleName());
41        adminRequest.setRequesterkey("userkey");
42
43        adminRequest.setRequestType(AdminRequest.REQUEST_OBJECTIONABLE);
44        adminRequest.setCreatedOn(new Date());
45
46        /* Get title of the idea */
47        Idea idea = new Idea();
48        idea.setTitle("Great Idea");
49
50        adminRequest.setEntityTitle(idea.getTitle());
51
52        adminRequestDao.saveRequest(adminRequest);
53
54        Query query = new Query(AdminRequest.class.getSimpleName());
55        assertEquals(1, DatastoreServiceFactory.getDatastoreService().prepare(query)
56                        .countEntities());
57    }
58
59    /**
60     * 
61     */
62    @Test
63    public void getAllAdminRequests() {
64        AdminRequest adminRequest = new AdminRequest();
65        adminRequest.setEntityKey("ideakey");
66        adminRequest.setEntityType(Idea.class.getSimpleName());
67        adminRequest.setRequesterkey("userkey");
68        adminRequest.setRequestType(AdminRequest.REQUEST_OBJECTIONABLE);
69        adminRequest.setCreatedOn(new Date());
70        adminRequest.setStatus(AdminRequest.STATUS_PENDING);
71        adminRequest.setEntityTitle("idea title");
72
73        adminRequestDao.saveRequest(adminRequest);
74
75        AdminRequest adminRequest2 = new AdminRequest();
76        adminRequest2.setEntityKey("ideakey");
77        adminRequest2.setEntityType(Idea.class.getSimpleName());
78        adminRequest2.setRequesterkey("userkey");
79        adminRequest2.setRequestType(AdminRequest.REQUEST_OBJECTIONABLE);
80        adminRequest2.setCreatedOn(new Date());
81        adminRequest.setStatus(AdminRequest.STATUS_REJECTED);
82        adminRequest2.setEntityTitle("idea title2");
83
84        adminRequestDao.saveRequest(adminRequest2);
85
86        RetrievalInfo retrievalInfo = this.createDummyRetrievalParam(0, 10, "createdOn", "asc");
87        adminRequestDao.getAllAdminRequests(retrievalInfo);
88
89        assertEquals(1, adminRequestDao.getAllAdminRequests(retrievalInfo).size());
90    }
91}