001: /* Copyright 2005 The JA-SIG Collaborative. All rights reserved.
002: * See license distributed with this file and
003: * available online at http://www.uportal.org/license.html
004: */
005:
006: package org.jasig.portal.services.stats;
007:
008: import org.jasig.portal.ChannelDefinition;
009: import org.jasig.portal.UserProfile;
010: import org.jasig.portal.layout.node.IUserLayoutChannelDescription;
011: import org.jasig.portal.layout.node.IUserLayoutFolderDescription;
012: import org.jasig.portal.layout.node.UserLayoutChannelDescription;
013: import org.jasig.portal.layout.node.UserLayoutFolderDescription;
014: import org.jasig.portal.security.IPerson;
015: import org.jasig.portal.security.provider.PersonImpl;
016:
017: import junit.framework.TestCase;
018:
019: /**
020: * This testcase tests each IStatsRecorder method as implemented in ConditionalStatsRecorder
021: * verifying that when configured not to propogate the "event", it doesn't, and when configured
022: * to propogate the "event", it does.
023: * @since uPortal 2.5.2
024: */
025: public class ConditionalStatsRecorderTest extends TestCase {
026:
027: private ConditionalStatsRecorder conditionalRecorder;
028: private MockStatsRecorder mockRecorder;
029: private StatsRecorderFlagsImpl statsRecorderFlags;
030:
031: private IPerson dummyPerson = new PersonImpl();
032: private UserProfile dummyProfile = new UserProfile();
033:
034: private IUserLayoutChannelDescription dummyChannelDescription = new UserLayoutChannelDescription();
035:
036: private IUserLayoutFolderDescription dummyFolderDescription = new UserLayoutFolderDescription();
037:
038: // a channel definition with a bogus ID.
039: private ChannelDefinition dummyChannelDefinition = new ChannelDefinition(
040: 1);
041:
042: protected void setUp() {
043: this .conditionalRecorder = new ConditionalStatsRecorder();
044: MockStatsRecorder mockTarget = new MockStatsRecorder();
045: conditionalRecorder.setTargetStatsRecorder(mockTarget);
046: this .mockRecorder = mockTarget;
047: this .statsRecorderFlags = new StatsRecorderFlagsImpl();
048: conditionalRecorder.setFlags(this .statsRecorderFlags);
049: }
050:
051: public void testRecordLogin() {
052: assertEquals(0, mockRecorder.getLogins());
053:
054: this .conditionalRecorder.recordLogin(dummyPerson);
055:
056: // the conditional recorder should not have passed along event since it was not configured to do so
057: assertEquals(0, mockRecorder.getLogins());
058:
059: this .statsRecorderFlags.setRecordLogin(true);
060:
061: this .conditionalRecorder.recordLogin(dummyPerson);
062:
063: // the conditional recorder should have passed along event since it was configured to do so
064: assertEquals(1, mockRecorder.getLogins());
065: }
066:
067: public void testRecordLogout() {
068: assertEquals(0, mockRecorder.getLogouts());
069:
070: this .conditionalRecorder.recordLogout(dummyPerson);
071:
072: // the conditional recorder should not have passed along event since it was not configured to do so
073: assertEquals(0, mockRecorder.getLogouts());
074:
075: this .statsRecorderFlags.setRecordLogout(true);
076:
077: this .conditionalRecorder.recordLogout(dummyPerson);
078:
079: // the conditional recorder should have passed along event since it was configured to do so
080: assertEquals(1, mockRecorder.getLogouts());
081: }
082:
083: public void testRecordSessionCreated() {
084: assertEquals(0, mockRecorder.getSessionCreates());
085:
086: this .conditionalRecorder.recordSessionCreated(dummyPerson);
087:
088: // the conditional recorder should not have passed along event since it was not configured to do so
089: assertEquals(0, mockRecorder.getSessionCreates());
090:
091: this .statsRecorderFlags.setRecordSessionCreated(true);
092:
093: this .conditionalRecorder.recordSessionCreated(dummyPerson);
094:
095: // the conditional recorder should have passed along event since it was configured to do so
096: assertEquals(1, mockRecorder.getSessionCreates());
097: }
098:
099: public void testRecordSessionDestroyed() {
100: assertEquals(0, mockRecorder.getSessionDestroys());
101:
102: this .conditionalRecorder.recordSessionDestroyed(dummyPerson);
103:
104: // the conditional recorder should not have passed along event since it was not configured to do so
105: assertEquals(0, mockRecorder.getSessionDestroys());
106:
107: this .statsRecorderFlags.setRecordSessionDestroyed(true);
108:
109: this .conditionalRecorder.recordSessionDestroyed(dummyPerson);
110:
111: // the conditional recorder should have passed along the event since it was configured to do so
112: assertEquals(1, mockRecorder.getSessionDestroys());
113:
114: }
115:
116: public void testRecordChannelDefinitionPublished() {
117: assertEquals(0, mockRecorder.getChannelDefinitionPublishes());
118:
119: this .conditionalRecorder.recordChannelDefinitionPublished(
120: dummyPerson, dummyChannelDefinition);
121:
122: // the conditional recorder should not have passed along event since it was not configured to do so
123: assertEquals(0, mockRecorder.getChannelDefinitionPublishes());
124:
125: this .statsRecorderFlags
126: .setRecordChannelDefinitionPublished(true);
127:
128: this .conditionalRecorder.recordChannelDefinitionPublished(
129: dummyPerson, dummyChannelDefinition);
130:
131: // the conditional recorder should have passed along the event since it was configured to do so
132: assertEquals(1, mockRecorder.getChannelDefinitionPublishes());
133: }
134:
135: public void testRecordChannelDefinitionModified() {
136: assertEquals(0, mockRecorder.getChannelDefinitionPublishes());
137:
138: this .conditionalRecorder.recordChannelDefinitionModified(
139: dummyPerson, dummyChannelDefinition);
140:
141: // the conditional recorder should not have passed along event since it was not configured to do so
142: assertEquals(0, mockRecorder.getChannelDefinitionModifies());
143:
144: this .statsRecorderFlags
145: .setRecordChannelDefinitionModified(true);
146:
147: this .conditionalRecorder.recordChannelDefinitionModified(
148: dummyPerson, dummyChannelDefinition);
149:
150: // the conditional recorder should have passed along the event since it was configured to do so
151: assertEquals(1, mockRecorder.getChannelDefinitionModifies());
152: }
153:
154: public void testRecordChannelDefinitionRemoved() {
155: assertEquals(0, mockRecorder.getChannelDefinitionRemoves());
156:
157: this .conditionalRecorder.recordChannelDefinitionRemoved(
158: dummyPerson, dummyChannelDefinition);
159:
160: // the conditional recorder should not have passed along event since it was not configured to do so
161: assertEquals(0, mockRecorder.getChannelDefinitionRemoves());
162:
163: this .statsRecorderFlags.setRecordChannelDefinitionRemoved(true);
164:
165: this .conditionalRecorder.recordChannelDefinitionRemoved(
166: dummyPerson, dummyChannelDefinition);
167:
168: // the conditional recorder should have passed along the event since it was configured to do so
169: assertEquals(1, mockRecorder.getChannelDefinitionRemoves());
170: }
171:
172: public void testRecordChannelAddedToLayout() {
173: assertEquals(0, mockRecorder.getChannelAddsToLayout());
174:
175: this .conditionalRecorder.recordChannelAddedToLayout(
176: dummyPerson, dummyProfile, dummyChannelDescription);
177:
178: // the conditional recorder should not have passed along event since it was not configured to do so
179: assertEquals(0, mockRecorder.getChannelAddsToLayout());
180:
181: this .statsRecorderFlags.setRecordChannelAddedToLayout(true);
182:
183: this .conditionalRecorder.recordChannelAddedToLayout(
184: dummyPerson, dummyProfile, dummyChannelDescription);
185:
186: // the conditional recorder should have passed along event since it was configured to do so
187: assertEquals(1, mockRecorder.getChannelAddsToLayout());
188:
189: }
190:
191: public void testRecordChannelUpdatedInLayout() {
192: assertEquals(0, mockRecorder.getChannelUpdatesInLayout());
193:
194: this .conditionalRecorder.recordChannelUpdatedInLayout(
195: dummyPerson, dummyProfile, dummyChannelDescription);
196:
197: // the conditional recorder should not have passed along event since it was not configured to do so
198: assertEquals(0, mockRecorder.getChannelUpdatesInLayout());
199:
200: this .statsRecorderFlags.setRecordChannelUpdatedInLayout(true);
201:
202: this .conditionalRecorder.recordChannelUpdatedInLayout(
203: dummyPerson, dummyProfile, dummyChannelDescription);
204:
205: // the conditional recorder should have passed along event since it was configured to do so
206: assertEquals(1, mockRecorder.getChannelUpdatesInLayout());
207:
208: }
209:
210: public void testRecordChannelMovedInLayout() {
211: assertEquals(0, mockRecorder.getChannelMovesInLayout());
212:
213: this .conditionalRecorder.recordChannelMovedInLayout(
214: dummyPerson, dummyProfile, dummyChannelDescription);
215:
216: // the conditional recorder should not have passed along event since it was not configured to do so
217: assertEquals(0, mockRecorder.getChannelMovesInLayout());
218:
219: this .statsRecorderFlags.setRecordChannelMovedInLayout(true);
220:
221: this .conditionalRecorder.recordChannelMovedInLayout(
222: dummyPerson, dummyProfile, dummyChannelDescription);
223:
224: // the conditional recorder should have passed along event since it was configured to do so
225: assertEquals(1, mockRecorder.getChannelMovesInLayout());
226:
227: }
228:
229: public void testRecordChannelRemovedFromLayout() {
230: assertEquals(0, mockRecorder.getChannelRemovesFromLayout());
231:
232: this .conditionalRecorder.recordChannelRemovedFromLayout(
233: dummyPerson, dummyProfile, dummyChannelDescription);
234:
235: // the conditional recorder should not have passed along event since it was not configured to do so
236: assertEquals(0, mockRecorder.getChannelRemovesFromLayout());
237:
238: this .statsRecorderFlags.setRecordChannelRemovedFromLayout(true);
239:
240: this .conditionalRecorder.recordChannelRemovedFromLayout(
241: dummyPerson, dummyProfile, dummyChannelDescription);
242:
243: // the conditional recorder should have passed along event since it was configured to do so
244: assertEquals(1, mockRecorder.getChannelRemovesFromLayout());
245:
246: }
247:
248: public void testRecordFolderAddedToLayout() {
249: assertEquals(0, mockRecorder.getFolderAddsToLayout());
250:
251: this .conditionalRecorder.recordFolderAddedToLayout(dummyPerson,
252: dummyProfile, dummyFolderDescription);
253:
254: // the conditional recorder should not have passed along event since it was not configured to do so
255: assertEquals(0, mockRecorder.getFolderAddsToLayout());
256:
257: this .statsRecorderFlags.setRecordFolderAddedToLayout(true);
258:
259: this .conditionalRecorder.recordFolderAddedToLayout(dummyPerson,
260: dummyProfile, dummyFolderDescription);
261:
262: // the conditional recorder should have passed along event since it was configured to do so
263: assertEquals(1, mockRecorder.getFolderAddsToLayout());
264:
265: }
266:
267: public void testRecordFolderUpdatedInLayout() {
268: assertEquals(0, mockRecorder.getFolderUpdatesInLayout());
269:
270: this .conditionalRecorder.recordFolderUpdatedInLayout(
271: dummyPerson, dummyProfile, dummyFolderDescription);
272:
273: // the conditional recorder should not have passed along event since it was not configured to do so
274: assertEquals(0, mockRecorder.getFolderUpdatesInLayout());
275:
276: this .statsRecorderFlags.setRecordFolderUpdatedInLayout(true);
277:
278: this .conditionalRecorder.recordFolderUpdatedInLayout(
279: dummyPerson, dummyProfile, dummyFolderDescription);
280:
281: // the conditional recorder should have passed along event since it was configured to do so
282: assertEquals(1, mockRecorder.getFolderUpdatesInLayout());
283:
284: }
285:
286: public void testRecordFolderMovedInLayout() {
287: assertEquals(0, mockRecorder.getFolderMovesInLayout());
288:
289: this .conditionalRecorder.recordFolderMovedInLayout(dummyPerson,
290: dummyProfile, dummyFolderDescription);
291:
292: // the conditional recorder should not have passed along event since it was not configured to do so
293: assertEquals(0, mockRecorder.getFolderMovesInLayout());
294:
295: this .statsRecorderFlags.setRecordFolderMovedInLayout(true);
296:
297: this .conditionalRecorder.recordFolderMovedInLayout(dummyPerson,
298: dummyProfile, dummyFolderDescription);
299:
300: // the conditional recorder should have passed along event since it was configured to do so
301: assertEquals(1, mockRecorder.getFolderMovesInLayout());
302:
303: }
304:
305: public void testRecordFolderRemovedFromLayout() {
306: assertEquals(0, mockRecorder.getFolderRemovesFromLayout());
307:
308: this .conditionalRecorder.recordFolderRemovedFromLayout(
309: dummyPerson, dummyProfile, dummyFolderDescription);
310:
311: // the conditional recorder should not have passed along event since it was not configured to do so
312: assertEquals(0, mockRecorder.getFolderRemovesFromLayout());
313:
314: this .statsRecorderFlags.setRecordFolderRemovedFromLayout(true);
315:
316: this .conditionalRecorder.recordFolderRemovedFromLayout(
317: dummyPerson, dummyProfile, dummyFolderDescription);
318:
319: // the conditional recorder should have passed along event since it was configured to do so
320: assertEquals(1, mockRecorder.getFolderRemovesFromLayout());
321:
322: }
323:
324: public void testRecordChannelInstantiated() {
325: assertEquals(0, mockRecorder.getChannelInstantiates());
326:
327: this .conditionalRecorder.recordChannelInstantiated(dummyPerson,
328: dummyProfile, dummyChannelDescription);
329:
330: // the conditional recorder should not have passed along event since it was not configured to do so
331: assertEquals(0, mockRecorder.getChannelInstantiates());
332:
333: this .statsRecorderFlags.setRecordChannelInstantiated(true);
334:
335: this .conditionalRecorder.recordChannelInstantiated(dummyPerson,
336: dummyProfile, dummyChannelDescription);
337:
338: // the conditional recorder should have passed along event since it was configured to do so
339: assertEquals(1, mockRecorder.getChannelInstantiates());
340:
341: }
342:
343: public void testRecordChannelRendered() {
344: assertEquals(0, mockRecorder.getChannelRenders());
345:
346: this .conditionalRecorder.recordChannelRendered(dummyPerson,
347: dummyProfile, dummyChannelDescription);
348:
349: // the conditional recorder should not have passed along event since it was not configured to do so
350: assertEquals(0, mockRecorder.getChannelRenders());
351:
352: this .statsRecorderFlags.setRecordChannelRendered(true);
353:
354: this .conditionalRecorder.recordChannelRendered(dummyPerson,
355: dummyProfile, dummyChannelDescription);
356:
357: // the conditional recorder should have passed along event since it was configured to do so
358: assertEquals(1, mockRecorder.getChannelRenders());
359:
360: }
361:
362: public void testRecordChannelTargetted() {
363:
364: assertEquals(0, mockRecorder.getChannelTargets());
365:
366: this .conditionalRecorder.recordChannelTargeted(dummyPerson,
367: dummyProfile, dummyChannelDescription);
368:
369: // the conditional recorder should not have passed along event since it was not configured to do so
370: assertEquals(0, mockRecorder.getChannelTargets());
371:
372: this .statsRecorderFlags.setRecordChannelTargeted(true);
373:
374: this .conditionalRecorder.recordChannelTargeted(dummyPerson,
375: dummyProfile, dummyChannelDescription);
376:
377: // the conditional recorder should have passed along event since it was configured to do so
378: assertEquals(1, mockRecorder.getChannelTargets());
379: }
380:
381: }
|