View Javadoc

1   /**
2    * Copyright 2011 The Kuali Foundation Licensed under the Educational Community
3    * License, Version 2.0 (the "License"); you may not use this file except in
4    * compliance with the License. You may obtain a copy of the License at
5    *
6    * http://www.osedu.org/licenses/ECL-2.0
7    *
8    * Unless required by applicable law or agreed to in writing, software
9    * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
10   * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
11   * License for the specific language governing permissions and limitations under
12   * the License.
13   */
14  package org.kuali.mobility.news.dao;
15  
16  import static org.junit.Assert.*;
17  
18  import java.util.List;
19  
20  import org.apache.commons.collections.CollectionUtils;
21  import org.apache.log4j.Logger;
22  import org.junit.BeforeClass;
23  import org.junit.Test;
24  import org.kuali.mobility.news.entity.NewsSource;
25  import org.kuali.mobility.news.util.NewsSourcePredicate;
26  import org.springframework.context.ApplicationContext;
27  import org.springframework.context.support.FileSystemXmlApplicationContext;
28  
29  /**
30   * @author Kuali Mobility Team (mobility.collab@kuali.org)
31   */
32  public class NewsDaoImplTest {
33  
34      private static final Logger LOG = Logger.getLogger(NewsDaoImplTest.class);
35      private static ApplicationContext applicationContext;
36  
37      @BeforeClass
38      public static void createApplicationContext() {
39          NewsDaoImplTest.setApplicationContext(new FileSystemXmlApplicationContext(getConfigLocations()));
40      }
41  
42      private static String[] getConfigLocations() {
43          return new String[]{"classpath:/SpringBeans.xml"};
44      }
45  
46      @Test
47      public void testFindAllActiveNewsSources() {
48          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
49          List<NewsSource> sources = (List<NewsSource>)dao.findAllActiveNewsSources();
50          assertTrue("Failed to find news sources.", sources != null && sources.size() > 0);
51      }
52  
53      @Test
54      public void testFindAllNewsSources() {
55          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
56          List<NewsSource> sources = (List<NewsSource>)dao.findAllNewsSources();
57          assertTrue("Failed to find news sources.", sources != null && sources.size() > 0);
58      }
59      
60      @Test
61      public void testFindNewsSources() {
62          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
63          List<NewsSource> sources = (List<NewsSource>)dao.findNewsSources( Long.valueOf(0), new Boolean(true) );
64          assertTrue("Failed to find news sources.", sources != null && sources.size() > 0);
65      }
66  
67      @Test
68      public void testLookup() {
69          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
70          NewsSource source = dao.lookup(new Long(2));
71          assertTrue("Failed to find news source.", source != null && "BBC - News".equalsIgnoreCase(source.getName()));
72      }
73  
74      public static ApplicationContext getApplicationContext() {
75          return applicationContext;
76      }
77  
78      public static void setApplicationContext(ApplicationContext applicationContext) {
79          NewsDaoImplTest.applicationContext = applicationContext;
80      }
81  }