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.Sender;
32  import org.springframework.beans.factory.annotation.Autowired;
33  import org.springframework.beans.factory.annotation.Qualifier;
34  import org.springframework.test.context.ContextConfiguration;
35  import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
36  
37  /**
38   * @author Kuali Mobility Team (mobility.collab@kuali.org)
39   */
40  @RunWith(SpringJUnit4ClassRunner.class)
41  @ContextConfiguration(value = "classpath:TestSpringBeans.xml")
42  public class SenderDaoImplTest {
43  
44  	private static final Logger LOG = Logger.getLogger(SenderDaoImplTest.class);
45  	
46  	@PersistenceContext
47  	private EntityManager entityManager;
48  
49  	/**
50  	 * There seems to be a pre-existing senderDaoImpl bean in Test, generated where, I have no idea. 
51  	 * We use this preexisting bean instead of of adding one to TestSpringBeans.xml.
52  	 */
53  	@Autowired
54  	@Qualifier("senderDaoImpl")
55  	private SenderDao dao;
56  
57  	@BeforeClass
58  	public static void setUpClass() throws Exception {
59  	}
60  
61  	@AfterClass
62  	public static void tearDownClass() throws Exception {
63  	}
64  
65  	@Before
66  	public void preTest() {
67  	}
68  
69  	@Test
70  	public void testNothing() {
71  		
72  	}
73  
74  	@Test
75  	public void testFindAllSenders() {
76  		List<Sender> senders = getDao().findAllSenders();
77  		assertFalse("FindAllSenders returned null and should not have.",null==senders);
78  		assertTrue("FindAllSenders returned no devices.", senders.size() > 0);
79  		assertTrue("FindAllSenders failed to find the pre-loaded data.",senders.size()==3);
80  	}
81  
82  	@Test
83  	public void testFindAllUnhiddenSenders() {
84  		List<Sender> senders = getDao().findAllUnhiddenSenders();
85  		assertFalse("FindAllUnhiddenSenders returned null and should not have.",null==senders);
86  		assertTrue("FindAllUnhiddenSenders returned no devices.", senders.size() > 0);
87  		assertTrue("FindAllUnhiddenSenders failed to find the pre-loaded data.",senders.size()==1);
88  	}
89  
90  	@Test
91  	public void testFindSenderById() {
92  		Sender senders = getDao().findSenderById(1L);
93  		assertFalse("FindSenderById returned null and should not have.",null==senders);
94  	}
95  
96  	@Test
97  	public void testFindSenderByWrongId() {
98  		Sender senders = getDao().findSenderById(123L);
99  		assertTrue("FindSenderById shouldn't return Sender, but did.",null==senders);
100 	}
101 
102 	@Test
103 	public void testFindSenderByName(){
104 //		Sender senders = getDao().findSenderByName("KME_PUSH");
105 //		assertFalse("FindSenderByName returned null and should not have.",null==senders);		
106 	}
107 	
108 	@Test
109 	public void testFindSenderByWrongName(){
110 		Sender senders = getDao().findSenderByName("FALSE_KME_PUSH");
111 		assertTrue("FindSenderByWrongName should have returned null, but didn't.",null==senders);				
112 	}
113 	
114 	@Test
115 	public void testFindSenderBySenderKey(){
116 		Sender senders = getDao().findSenderBySenderKey("3AbHRDjirFn2hvii4Pq3");
117 		assertFalse("FindSenderById returned null and should not have.",null==senders);				
118 	}
119 
120 	@Test
121 	public void testFindSenderByWrongSenderKey(){
122 		Sender senders = getDao().findSenderBySenderKey("FALSE_SENDER_KEY");
123 		assertTrue("FindSenderById should have returned null, but didn't.",null==senders);				
124 	}
125 	
126 	/**
127 	 * @return the entityManager
128 	 */
129 	public EntityManager getEntityManager() {
130 		return entityManager;
131 	}
132 
133 	/**
134 	 * @param entityManager the entityManager to set
135 	 */
136 	public void setEntityManager(EntityManager entityManager) {
137 		this.entityManager = entityManager;
138 	}
139 
140 	/**
141 	 * @return the dao
142 	 */
143 	public SenderDao getDao() {
144 		return dao;
145 	}
146 
147 	/**
148 	 * @param dao the dao to set
149 	 */
150 	public void setDao(SenderDao dao) {
151 		this.dao = dao;
152 	}
153 	
154 	
155 }