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  public class NewsDaoImplTest {
30  
31      private static final Logger LOG = Logger.getLogger(NewsDaoImplTest.class);
32      private static ApplicationContext applicationContext;
33  
34      @BeforeClass
35      public static void createApplicationContext() {
36          NewsDaoImplTest.setApplicationContext(new FileSystemXmlApplicationContext(getConfigLocations()));
37      }
38  
39      private static String[] getConfigLocations() {
40          return new String[]{"classpath:/SpringBeans.xml"};
41      }
42  
43      @Test
44      public void testFindAllActiveNewsSources() {
45          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
46          List<NewsSource> sources = (List<NewsSource>)dao.findAllActiveNewsSources();
47          assertTrue("Failed to find news sources.", sources != null && sources.size() > 0);
48      }
49  
50      @Test
51      public void testFindAllNewsSources() {
52          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
53          List<NewsSource> sources = (List<NewsSource>)dao.findAllNewsSources();
54          assertTrue("Failed to find news sources.", sources != null && sources.size() > 0);
55      }
56      
57      @Test
58      public void testFindNewsSources() {
59          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
60          List<NewsSource> sources = (List<NewsSource>)dao.findNewsSources( Long.valueOf(0), new Boolean(true) );
61          assertTrue("Failed to find news sources.", sources != null && sources.size() > 0);
62      }
63  
64      @Test
65      public void testLookup() {
66          NewsDao dao = (NewsDao) getApplicationContext().getBean("newsDao");
67          NewsSource source = dao.lookup(new Long(2));
68          assertTrue("Failed to find news source.", source != null && "BBC - News".equalsIgnoreCase(source.getName()));
69      }
70  
71      public static ApplicationContext getApplicationContext() {
72          return applicationContext;
73      }
74  
75      public static void setApplicationContext(ApplicationContext applicationContext) {
76          NewsDaoImplTest.applicationContext = applicationContext;
77      }
78  }