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.businessobjects.reporting.Event;
18 import org.figure8.join.util.SpringTestCase;
19 /**
20 * JUnit test case for testing EventDao implementation.
21 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
22 * @version $Revision: 1.1 $
23 */
24 public class EventDaoTest extends SpringTestCase{
25
26
27
28 /** Spring configuration files */
29 private String[] configLocations = new String[]{"classpath:/org/figure8/join/businessobjects/reporting/persistence/spring.xml"};
30
31
32
33
34 /** The EventDao implementation to test */
35 protected EventDao dao = null;
36
37
38
39
40 /** Retrieve the event dao after having initialized context */
41 public void setUp(){
42 super.setUp();
43
44 dao = (EventDao)context.getBean("eventDao");
45 }
46
47
48
49
50 /** Test Event creation */
51 public void testEventCreation(){
52
53 Event event = new Event("key", "label");
54 event.setMsgLinkTemplate("link");
55 event.setMsgTitleTemplate("title");
56 event.setMsgContentTemplate("content");
57 int size = getEventListSize();
58 dao.save(event);
59
60 assertEquals("Event is successfully created", size + 1, dao.findAll().size());
61 }
62
63 /** Test the findByKey() on dao */
64 public void testFindByKey(){
65
66 Event event1 = new Event("key1", "label1");
67 Event event2 = new Event("key2", "label2");
68 event2.setMsgLinkTemplate("link2");
69 event2.setMsgTitleTemplate("title2");
70 event2.setMsgContentTemplate("content2");
71 int size = getEventListSize();
72 dao.save(event1);
73 dao.save(event2);
74
75 assertEquals("Events are successfully created", size + 2, dao.findAll().size());
76
77 Event found = dao.getEvent("key2");
78 assertNotNull("Found an event using its key", found);
79 assertEquals("Found the correct event", event2.getId(), found.getId());
80 assertEquals("Found the correct event", "key2", found.getKey());
81 assertEquals("Found the correct event", "label2", found.getLabel());
82 assertEquals("Found the correct event", "link2", found.getMsgLinkTemplate());
83 assertEquals("Found the correct event", "title2", found.getMsgTitleTemplate());
84 assertEquals("Found the correct event", "content2", found.getMsgContentTemplate());
85 }
86
87
88
89
90 /** Test the findAll on event */
91 protected int getEventListSize(){
92 return dao.findAll().size();
93 }
94
95
96
97
98 /** @return configLocations inner field */
99 public String[] getConfigLocations(){
100 return configLocations;
101 }
102 }