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 import org.figure8.join.businessobjects.reporting.Subscription;
21
22 import java.util.List;
23 /**
24 * JUnit test case for testing the SubscriptionDao implementation.
25 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
26 * @version Revision$
27 */
28 public class SubscriptionDaoTest extends SpringTestCase{
29
30
31
32 /** Spring configuration files */
33 private String[] configLocations = new String[]{"classpath:/org/figure8/join/businessobjects/reporting/persistence/spring.xml"};
34
35
36
37
38 /** The EventDao implementation we need */
39 protected EventDao eventDao = null;
40 /** The MailingListDao implementation we need */
41 protected MailingListDao listDao = null;
42 /** The SubscriptionDao implementation to test */
43 protected SubscriptionDao dao = null;
44
45
46
47
48 /** Retrieve the daos after having initialized context */
49 public void setUp(){
50 super.setUp();
51
52 eventDao = (EventDao)context.getBean("eventDao");
53 listDao = (MailingListDao)context.getBean("mailingListDao");
54 dao = (SubscriptionDao)context.getBean("subscriptionDao");
55 }
56
57
58
59
60 /** Test subscription creation */
61 public void testSubscriptionCreation(){
62
63 Event event = new Event("keyS", "labelS");
64 MailingList list = new MailingList("nameS", "title", "content", event);
65 eventDao.save(event);
66 listDao.save(list);
67
68 Subscription sub = new Subscription("userId", list);
69 int size = getSubscriptionListSize();
70 dao.save(sub);
71
72 assertEquals("Subscription is successfully created", size + 1, dao.findAll().size());
73 }
74
75 /** Test subscription retrieval */
76 public void testSubscriptionRetrieval(){
77
78 Event event = new Event("keyR", "labelR");
79 MailingList list = new MailingList("nameR", "title", "content", event);
80 eventDao.save(event);
81 listDao.save(list);
82
83 Subscription sub1 = new Subscription("user1", list);
84 Subscription sub2 = new Subscription("user2", list);
85 dao.save(sub1);
86 dao.save(sub2);
87
88 List subs = dao.getSubscriptionsForUser("user1");
89 assertEquals("User1 has one subscriptions", 1, subs.size());
90 }
91
92
93
94
95 /** Test the findAll on subscription */
96 protected int getSubscriptionListSize(){
97 return dao.findAll().size();
98 }
99
100
101
102
103 /** @return configLocations inner field */
104 public String[] getConfigLocations(){
105 return configLocations;
106 }
107 }