1 /**
2 * Copyright 2005-2006 the original author or authors.
3 *
4 * Licensed under the Gnu General Pubic License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 *
8 * http://www.opensource.org/licenses/gpl-license.php
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the Gnu General Public License for more details.
14 */
15 package org.figure8.join.businessobjects.reporting.persistence;
16
17 import org.figure8.join.util.SpringTestCase;
18 import org.figure8.join.businessobjects.reporting.Event;
19 import org.figure8.join.businessobjects.reporting.MailingList;
20 /**
21 * JUnit test case for testing the MailingListDao implementation.
22 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
23 * @version $Revision: 1.1 $
24 */
25 public class MailingListDaoTest extends SpringTestCase{
26
27
28
29 /** Spring configuration files */
30 private String[] configLocations = new String[]{"classpath:/org/figure8/join/businessobjects/reporting/persistence/spring.xml"};
31
32
33
34
35 /** The EventDao implementation we need */
36 protected EventDao eventDao = null;
37 /** The MailingListDao implementation to test */
38 protected MailingListDao dao = null;
39
40
41
42
43 /** Retrieve the daos after having initialized context */
44 public void setUp(){
45 super.setUp();
46
47 eventDao = (EventDao)context.getBean("eventDao");
48 dao = (MailingListDao)context.getBean("mailingListDao");
49 }
50
51
52
53
54 /** Test mailing list creation */
55 public void testMailingListCreation(){
56
57 Event event = new Event("keyML", "labelML");
58 MailingList list = new MailingList("name", "title", "content", event);
59 int size = getMailingListListSize();
60 eventDao.save(event);
61 dao.save(list);
62
63 assertEquals("MailingList is successfully created", size + 1, dao.findAll().size());
64 }
65
66 /** Test the findByName() on dao */
67 public void testFindByName(){
68
69 Event event = new Event("keyMLFind", "labelMLFind");
70 MailingList list1 = new MailingList("name1", "title1", "content1", event);
71 MailingList list2 = new MailingList("name2", "title2", "content2", event);
72 int size = getMailingListListSize();
73 eventDao.save(event);
74 dao.save(list1);
75 dao.save(list2);
76
77 assertEquals("MailingLists are successfully created", size + 2, dao.findAll().size());
78
79 MailingList found = dao.getMailingList("name2");
80 assertNotNull("Found a mailing list using its name", found);
81 assertEquals("Found the correct list", list2.getId(), found.getId());
82 assertEquals("Found the correct list", "title2", found.getMsgTitleTemplate());
83 assertEquals("Found the correct list", "keyMLFind", found.getEvent().getKey());
84 }
85
86
87
88
89 /** Test the findAll on mailing list */
90 protected int getMailingListListSize(){
91 return dao.findAll().size();
92 }
93
94
95
96
97 /** @return configLocations inner field */
98 public String[] getConfigLocations(){
99 return configLocations;
100 }
101 }