01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18: package org.apache.lenya.notification;
19:
20: import org.apache.lenya.ac.User;
21: import org.apache.lenya.ac.impl.AbstractAccessControlTest;
22: import org.apache.lenya.inbox.Inbox;
23: import org.apache.lenya.inbox.InboxManager;
24: import org.apache.lenya.inbox.InboxMessage;
25:
26: /**
27: * Base class for notification tests.
28: */
29: public abstract class AbstractNotificationTest extends
30: AbstractAccessControlTest {
31:
32: protected Inbox getInbox(User user) throws Exception {
33: InboxManager inboxManager = null;
34: try {
35: inboxManager = (InboxManager) getManager().lookup(
36: InboxManager.ROLE);
37: return inboxManager.getInbox(user);
38: } finally {
39: if (inboxManager != null) {
40: getManager().release(inboxManager);
41: }
42: }
43: }
44:
45: protected boolean containsMessage(Inbox inbox, String subject) {
46: InboxMessage[] messages = inbox.getMessages();
47: if (messages.length == 0) {
48: return false;
49: }
50: return messages[messages.length - 1].getMessage().getSubject()
51: .equals(subject);
52: }
53:
54: protected InboxMessage getMessage(Inbox inbox, String subject) {
55: InboxMessage[] messages = inbox.getMessages();
56: for (int i = 0; i < messages.length; i++) {
57: if (messages[i].getMessage().getSubject().equals(subject)) {
58: return messages[i];
59: }
60: }
61: return null;
62: }
63:
64: protected void cleanUp(Inbox inbox, String subject) {
65: InboxMessage[] messages = inbox.getMessages();
66: for (int i = 0; i < messages.length; i++) {
67: if (messages[i].getMessage().getSubject().equals(subject)) {
68: inbox.remove(messages[i]);
69: }
70: }
71: }
72: }
|