View Javadoc

1   /**
2    * Copyright 2011-2013 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  package org.kuali.mobility.push.dao;
16  
17  import static org.junit.Assert.assertFalse;
18  import static org.junit.Assert.assertTrue;
19  
20  import java.util.List;
21  
22  import javax.persistence.EntityManager;
23  import javax.persistence.PersistenceContext;
24  
25  import org.apache.log4j.Logger;
26  import org.junit.AfterClass;
27  import org.junit.Before;
28  import org.junit.BeforeClass;
29  import org.junit.Test;
30  import org.junit.runner.RunWith;
31  import org.kuali.mobility.push.entity.Device;
32  import org.kuali.mobility.push.entity.Push;
33  import org.kuali.mobility.push.entity.PushDeviceTuple;
34  import org.springframework.beans.factory.annotation.Autowired;
35  import org.springframework.beans.factory.annotation.Qualifier;
36  import org.springframework.test.context.ContextConfiguration;
37  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
38  
39  /**
40   * @author Kuali Mobility Team (mobility.collab@kuali.org)
41   */
42  @RunWith(SpringJUnit4ClassRunner.class)
43  @ContextConfiguration(value = "classpath:TestSpringBeans.xml")
44  public class PushDaoImplTest {
45  	private static final Logger LOG = Logger.getLogger(PushDaoImplTest.class);
46  
47  	@PersistenceContext
48  	private EntityManager entityManager;
49  
50  	@Autowired
51  	@Qualifier("pushDao")
52  	private PushDao dao;
53  
54  	@BeforeClass
55  	public static void setUpClass() throws Exception {
56  	}
57  
58  	@AfterClass
59  	public static void tearDownClass() throws Exception {
60  	}
61  
62  	@Before
63  	public void preTest() {
64  	}
65  
66  	@Test
67  	public void testRemovePush() {
68  		Push push = getDao().findPushById(new Long(2));
69  		boolean removed = getDao().removePush(push);
70  		assertTrue("Should have removed a push, didn't.",removed);
71  	}
72  	
73  	@Test
74  	public void testRemovePushWithNullPush() {
75  		boolean removed = getDao().removePush(null);
76  		assertFalse("Removing a null push should've return False.",removed);
77  	}
78  	
79  	@Test
80  	public void testRemovePushWithNullPushId() {
81  		Push push = getDao().findPushById(new Long(2));
82  		push.setPushId(null);
83  		boolean removed = getDao().removePush(push);
84  		assertFalse("Removing a push with a null PushID should've return False.",removed);
85  	}
86  	
87  	@Test
88  	public void testFindAllPush() {
89  		List<Push> pushes = getDao().findAllPush();
90  		assertFalse("findAllPush returned null.",null==pushes);
91  		LOG.debug("Found "+pushes.size()+" push notification.");
92  		assertTrue("findAllPush returned incorrect number of pre-loaded pushes.",pushes.size()==6);
93  	}
94  
95  	@Test
96  	public void testCountPushes() {
97  		int count = getDao().countPushes();
98  		assertTrue("countPushes Failed to find proper count",count==5);
99  	}
100 
101 	@Test
102 	public void testFindPushByNullId() {
103 		Push push = getDao().findPushById(null);
104 		assertTrue("findPushById failed to return information for null push id.",push==null);
105 	}
106 
107 	@Test
108 	public void testFindPushById() {
109 		Push push = getDao().findPushById(new Long(3));
110 		assertTrue("findPushById failed to return information for push id = 3.", push != null);
111 		assertTrue("findPushById returned the wrong push notification.","testC".equals(push.getTitle()));
112 	}
113 
114 	@Test
115 	public void testFindDevicesForPush() {
116 		Push push = getDao().findPushById(new Long(3));
117 		List<Device> devices = getDao().findDevicesForPush(push);
118 		assertFalse("Received null device list for find devices for push id 3",devices==null);
119 		assertFalse("Received empty device list for find devices for push id 3",devices.isEmpty());
120 	}
121 
122 	@Test
123 	public void testFindUnsentPushTuples(){
124 		List<PushDeviceTuple> tuples = getDao().findUnsentPushTuples();
125 		assertFalse("Returned null tuples list, should not have been null", null==tuples);
126 		assertFalse("Returned an empty tuples list, should not have been empty.", tuples.isEmpty());
127 		assertTrue("Returned the wrong number of tuples, " + tuples.size() + " should have been 5", tuples.size() == 5);
128 		
129 	}
130 	
131 	public PushDao getDao() {
132 		return dao;
133 	}
134 
135 	public void setDao(PushDao dao) {
136 		this.dao = dao;
137 	}
138 
139 	public EntityManager getEntityManager() {
140 		return entityManager;
141 	}
142 
143 	public void setEntityManager(EntityManager entityManager) {
144 		this.entityManager = entityManager;
145 	}
146 }