    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.4 $
    31   */
    32  public abstract class QueueMessageStoreTestSupport extends MessageStoreTestSupport {
    33
    34      protected void acknowledgeMessage(int i) throws JMSException {
    35          MessageIdentity identity = getMessage(i).getJMSMessageIdentity();
    36          getQueueMessageContainer().delete(identity, createMessageAck(identity));
    37      }
    38
    39      protected QueueMessageContainer getQueueMessageContainer() {
    40          return (QueueMessageContainer) container;
    41      }
    42
    43      protected ActiveMQDestination createDestination() {
    44          return new ActiveMQQueue(getSubject());
    45      }
    46
    47      protected void recover() throws JMSException {
    48      }
    49
    50      protected MessageAck createMessageAck(MessageIdentity messageIdentity) {
    51          MessageAck answer = new MessageAck();
    52          answer.setConsumerId("James");
    53          answer.setMessageID(messageIdentity.getMessageID());
    54          answer.setMessageRead(true);
    55          return answer;
    56      }
    57
    58      protected ActiveMQMessage[] getMessagesToDispatch() throws JMSException {
    59          List list = new ArrayList();
    60          while (true) {
    61              ActiveMQMessage message = getQueueMessageContainer().poll();
    62              if (message == null) {
    63                  break;
    64              }
    65              list.add(message);
    66          }
    67          ActiveMQMessage[] answer = new ActiveMQMessage[list.size()];
    68          list.toArray(answer);
    69          return answer;
    70      }
    71  }