1   /***
2    * 
3    * Copyright 2004 Protique Ltd
4    * 
5    * Licensed under the Apache License, Version 2.0 (the "License"); 
6    * you may not use this file except in compliance with the License. 
7    * You may obtain a copy of the License at 
8    * 
9    * 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.codehaus.activemq.service;
19  
20  import org.codehaus.activemq.message.ActiveMQDestination;
21  import org.codehaus.activemq.message.ActiveMQMessage;
22  import org.codehaus.activemq.message.ActiveMQQueue;
23  import org.codehaus.activemq.message.MessageAck;
24  
25  import javax.jms.JMSException;
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  /***
30   * @version $Revision: 1.3 $
31   */
32  public abstract class QueueMessageStoreTestSupport extends MessageStoreTestSupport {
33  
34      protected void acknowledgeMessage(int i) throws JMSException {
35          getQueueMessageContainer().delete(getMessage(i).getJMSMessageIdentity(), createMessageAck(getMessage(i).getJMSMessageIdentity()));
36      }
37  
38      protected QueueMessageContainer getQueueMessageContainer() {
39          return (QueueMessageContainer) container;
40      }
41  
42      protected ActiveMQDestination createDestination() {
43          return new ActiveMQQueue(getSubject());
44      }
45  
46      protected void recover() throws JMSException {
47      }
48  
49      protected MessageAck createMessageAck(MessageIdentity messageIdentity) {
50          MessageAck answer = new MessageAck();
51          answer.setConsumerId("James");
52          answer.setMessageID(messageIdentity.getMessageID());
53          answer.setMessageRead(true);
54          return answer;
55      }
56  
57      protected ActiveMQMessage[] getMessagesToDispatch() throws JMSException {
58          List list = new ArrayList();
59          while (true) {
60              ActiveMQMessage message = getQueueMessageContainer().poll();
61              if (message == null) {
62                  break;
63              }
64              list.add(message);
65          }
66          ActiveMQMessage[] answer = new ActiveMQMessage[list.size()];
67          list.toArray(answer);
68          return answer;
69      }
70  }