Search in sources :

Example 16 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class RMTxStoreTestBase method testCreateSequenceStoreInboundMessage.

@Test
public void testCreateSequenceStoreInboundMessage() throws SQLException, IOException {
    Identifier sid1 = null;
    try {
        DestinationSequence seq = control.createMock(DestinationSequence.class);
        sid1 = new Identifier();
        sid1.setValue("sequence1");
        EndpointReferenceType epr = RMUtils.createAnonymousReference();
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
        EasyMock.expect(seq.getAcksTo()).andReturn(epr);
        EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
        EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
        control.replay();
        store.createDestinationSequence(seq);
        Collection<DestinationSequence> seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        DestinationSequence rseq = seqs.iterator().next();
        assertFalse(rseq.isAcknowledged(1));
        Collection<RMMessage> in = store.getMessages(sid1, false);
        assertEquals(0, in.size());
        control.reset();
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.getAcknowledgment()).andReturn(ack1);
        EasyMock.expect(seq.getAcksTo()).andReturn(epr);
        setupInboundMessage(seq, 1L, null);
        in = store.getMessages(sid1, false);
        assertEquals(1, in.size());
        checkRecoveredMessages(in);
        seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertTrue(rseq.isAcknowledged(1));
        assertFalse(rseq.isAcknowledged(10));
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.getAcknowledgment()).andReturn(ack2);
        EasyMock.expect(seq.getAcksTo()).andReturn(epr);
        control.replay();
        store.persistIncoming(seq, null);
        control.reset();
        seqs = store.getDestinationSequences(SERVER_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertTrue(rseq.isAcknowledged(10));
    } finally {
        if (null != sid1) {
            store.removeDestinationSequence(sid1);
        }
        Collection<Long> msgNrs = Arrays.asList(ONE);
        store.removeMessages(sid1, msgNrs, false);
    }
}
Also used : DestinationSequence(org.apache.cxf.ws.rm.DestinationSequence) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) EndpointReferenceType(org.apache.cxf.ws.addressing.EndpointReferenceType) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) Test(org.junit.Test)

Example 17 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class RMTxStoreTestBase method setupOutboundMessage.

private void setupOutboundMessage(SourceSequence seq, long mn, String to) throws IOException, SQLException {
    RMMessage msg = createRMMessage(ONE, to);
    control.replay();
    store.persistOutgoing(seq, msg);
    control.reset();
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage)

Example 18 with RMMessage

use of org.apache.cxf.ws.rm.persistence.RMMessage in project cxf by apache.

the class RMTxStoreTestBase method createRMMessage.

private RMMessage createRMMessage(Long mn, String to) throws IOException {
    RMMessage msg = control.createMock(RMMessage.class);
    EasyMock.expect(msg.getMessageNumber()).andReturn(mn).anyTimes();
    EasyMock.expect(msg.getTo()).andReturn(to).anyTimes();
    EasyMock.expect(msg.getContentType()).andReturn("text/xml").anyTimes();
    EasyMock.expect(msg.getCreatedTime()).andReturn(TIME);
    byte[] value = ("Message " + mn.longValue()).getBytes();
    ByteArrayInputStream bais = new ByteArrayInputStream(value);
    CachedOutputStream cos = new CachedOutputStream();
    IOUtils.copy(bais, cos);
    cos.flush();
    bais.close();
    EasyMock.expect(msg.getContent()).andReturn(cos).anyTimes();
    return msg;
}
Also used : RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) CachedOutputStream(org.apache.cxf.io.CachedOutputStream)

Aggregations

RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)18 CachedOutputStream (org.apache.cxf.io.CachedOutputStream)6 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 IOException (java.io.IOException)5 InputStream (java.io.InputStream)4 Message (org.apache.cxf.message.Message)4 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)4 Connection (java.sql.Connection)3 ArrayList (java.util.ArrayList)3 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)3 Method (java.lang.reflect.Method)2 SQLException (java.sql.SQLException)2 Binding (org.apache.cxf.binding.Binding)2 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)2 Endpoint (org.apache.cxf.endpoint.Endpoint)2 Exchange (org.apache.cxf.message.Exchange)2 ExchangeImpl (org.apache.cxf.message.ExchangeImpl)2 MessageImpl (org.apache.cxf.message.MessageImpl)2