1 package org.sourceforge.vlibrary.user.actions;
2
3 import java.util.Locale;
4
5 import org.apache.log4j.Logger;
6
7 import org.sourceforge.vlibrary.Constants;
8 import org.sourceforge.vlibrary.VlibraryActionTestCase;
9 import org.sourceforge.vlibrary.user.dao.ReaderDAOSpringJDBCImpl;
10 import org.sourceforge.vlibrary.user.domain.Reader;
11 import org.sourceforge.vlibrary.user.logic.LibraryManager;
12
13
14
15
16
17
18 public class SaveReaderActionTest extends VlibraryActionTestCase {
19
20 private static Logger logger =
21 Logger.getLogger(VlibraryActionTestCase.class.getName());
22
23 private ReaderDAOSpringJDBCImpl readerInstance = null;
24 private LibraryManager libraryManagerInstance = null;
25
26 private Reader newbie = new Reader(
27 "Newbie",
28 "Joe",
29 "joe@schmoe.com",
30 "48012345678",
31 "60212345678",
32 "123",
33 "TheExplorer",
34 "123",
35 "newbie",
36 "sdsdsd",
37 false);
38
39 private Reader changed = new Reader(
40 "Changer",
41 "Moe",
42 "moe@schmoe.com",
43 "48012345679",
44 "60212345679",
45 "123",
46 "TheExplorer",
47 "123",
48 "newbie",
49 "sdsdsd",
50 false);
51
52 public SaveReaderActionTest(String testName) {
53 super(testName);
54 }
55
56 public void setUp() throws Exception {
57 super.setUp();
58 readerInstance = (ReaderDAOSpringJDBCImpl) springContext.getBean(
59 "ReaderDAO", ReaderDAOSpringJDBCImpl.class);
60 libraryManagerInstance =
61 (LibraryManager) springContext.getBean(
62 "LibraryManager", LibraryManager.class);
63
64 }
65
66 protected void tearDown() throws Exception {
67 super.tearDown();
68 }
69
70
71
72
73
74 public void testSuccessfulCreate() throws Exception {
75
76 logger.info(" in testSuccessfulCheckout");
77
78
79 setRequestPathInfo("/a/saveReader");
80 addRequestParameter(Constants.ACTION, Constants.CREATE);
81 insertBeanAsParameters(newbie);
82 addRequestParameter("confirmPwd", newbie.getPwd());
83 actionPerform();
84
85
86 verifyForward("success");
87 verifyNoActionErrors();
88
89
90 Reader newbie2 = libraryManagerInstance.retrieveByUid("newbie");
91
92 assertTrue(newbie2.getId() > 0);
93
94 newbie2.setId(newbie.getId());
95
96 assertEquals(newbie2, newbie);
97 }
98
99 public void testCreateValidationFailure() throws Exception {
100
101 logger.info(" in testCreateValidationFailure");
102
103
104 setRequestPathInfo("/a/saveReader");
105 addRequestParameter(Constants.ACTION, Constants.CREATE);
106 insertBeanAsParameters(newbie);
107 addRequestParameter("confirmPwd", newbie.getPwd() + "junk");
108 actionPerform();
109
110
111 verifyInputForward();
112 verifyActionErrors(new String[] {"error.reader.confirmPwdFailed"});
113 }
114
115 public void testCreateMissingUidFailure() throws Exception {
116
117 logger.info(" in testCreateValidationFailure");
118
119
120 setRequestPathInfo("/a/saveReader");
121 addRequestParameter(Constants.ACTION, Constants.CREATE);
122 newbie.setUid(null);
123 insertBeanAsParameters(newbie);
124 addRequestParameter("confirmPwd", newbie.getPwd());
125 actionPerform();
126
127
128 verifyInputForward();
129 verifyActionErrors(new String[] {"error.reader.uid.required"});
130 }
131
132
133
134 public void testCreateDuplicateFailure() throws Exception {
135
136 logger.info(" in testCreateDuplicateUidFailure");
137
138
139 readerInstance.insert(newbie);
140
141
142 setRequestPathInfo("/a/saveReader");
143 addRequestParameter(Constants.ACTION, Constants.CREATE);
144 insertBeanAsParameters(newbie);
145 addRequestParameter("confirmPwd", newbie.getPwd());
146 actionPerform();
147
148
149 verifyInputForward();
150 verifyActionErrors(new String[] {"error.reader.idTaken",
151 "error.reader.already.registered"});
152 }
153
154 public void testUpdateSuccessful() throws Exception {
155
156 logger.info(" in testUpdateSuccessful");
157
158
159 readerInstance.insert(newbie);
160 changed.setId(newbie.getId());
161
162
163 setRequestPathInfo("/a/saveReader");
164 addRequestParameter(Constants.ACTION, Constants.UPDATE);
165
166 insertBeanAsParameters(changed);
167 actionPerform();
168
169
170 verifyForward("success");
171 verifyNoActionErrors();
172
173
174 Reader reader = libraryManagerInstance.retrieveByUid("newbie");
175 assertEquals(reader, changed);
176 }
177
178 }