Search in sources :

Example 1 with SourceSequence

use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.

the class RMTxStoreTestBase method testCreateSequenceStoreOutboundMessage.

@Test
public void testCreateSequenceStoreOutboundMessage() throws SQLException, IOException {
    Identifier sid1 = null;
    try {
        SourceSequence seq = control.createMock(SourceSequence.class);
        sid1 = new Identifier();
        sid1.setValue("sequence1");
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
        EasyMock.expect(seq.getExpires()).andReturn(null);
        EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
        EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
        EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
        control.replay();
        store.createSourceSequence(seq);
        control.reset();
        Collection<SourceSequence> seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        SourceSequence rseq = seqs.iterator().next();
        assertFalse(rseq.isLastMessage());
        Collection<RMMessage> out = store.getMessages(sid1, true);
        assertEquals(0, out.size());
        // set the last message flag
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.isLastMessage()).andReturn(true);
        setupOutboundMessage(seq, 1L, null);
        out = store.getMessages(sid1, true);
        assertEquals(1, out.size());
        checkRecoveredMessages(out);
        // verify the updated sequence
        seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertTrue(rseq.isLastMessage());
        // set the last message flag
        EasyMock.expect(seq.getIdentifier()).andReturn(sid1).anyTimes();
        EasyMock.expect(seq.getCurrentMessageNr()).andReturn(2L);
        EasyMock.expect(seq.isLastMessage()).andReturn(true);
        control.replay();
        store.persistOutgoing(seq, null);
        control.reset();
        seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        rseq = seqs.iterator().next();
        assertEquals(2, rseq.getCurrentMessageNr());
    } finally {
        if (null != sid1) {
            store.removeSourceSequence(sid1);
        }
        Collection<Long> msgNrs = new ArrayList<>();
        msgNrs.add(ONE);
        store.removeMessages(sid1, msgNrs, true);
    }
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ArrayList(java.util.ArrayList) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Test(org.junit.Test)

Example 2 with SourceSequence

use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.

the class RMTxStoreTestBase method checkRecoveredSourceSequences.

private void checkRecoveredSourceSequences(Collection<SourceSequence> seqs) {
    for (SourceSequence recovered : seqs) {
        assertTrue("sequence1".equals(recovered.getIdentifier().getValue()) || "sequence2".equals(recovered.getIdentifier().getValue()));
        if ("sequence1".equals(recovered.getIdentifier().getValue())) {
            assertFalse(recovered.isLastMessage());
            assertEquals(1, recovered.getCurrentMessageNr());
            assertNull(recovered.getExpires());
            assertNull(recovered.getOfferingSequenceIdentifier());
            assertEquals(ProtocolVariation.RM10WSA200408, recovered.getProtocol());
        } else {
            assertTrue(recovered.isLastMessage());
            assertEquals(10, recovered.getCurrentMessageNr());
            assertNotNull(recovered.getExpires());
            assertEquals("offeringSequence", recovered.getOfferingSequenceIdentifier().getValue());
            assertEquals(ProtocolVariation.RM11WSA200508, recovered.getProtocol());
        }
    }
}
Also used : SourceSequence(org.apache.cxf.ws.rm.SourceSequence)

Example 3 with SourceSequence

use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.

the class RMTxStoreTestBase method testCreateDeleteSrcSequences.

@Test
public void testCreateDeleteSrcSequences() {
    SourceSequence seq = control.createMock(SourceSequence.class);
    Identifier sid1 = new Identifier();
    sid1.setValue("sequence1");
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store.createSourceSequence(seq);
    control.verify();
    control.reset();
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    try {
        store.createSourceSequence(seq);
        fail("Expected RMStoreException was not thrown.");
    } catch (RMStoreException ex) {
        SQLException se = (SQLException) ex.getCause();
        // duplicate key value
        assertEquals("23505", se.getSQLState());
    }
    control.verify();
    control.reset();
    Identifier sid2 = new Identifier();
    sid2.setValue("sequence2");
    EasyMock.expect(seq.getIdentifier()).andReturn(sid2);
    EasyMock.expect(seq.getExpires()).andReturn(new Date());
    Identifier sid3 = new Identifier();
    sid3.setValue("offeringSequence3");
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(sid3);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(SERVER_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store.createSourceSequence(seq);
    control.verify();
    store.removeSourceSequence(sid1);
    store.removeSourceSequence(sid2);
    // deleting once again is a no-op
    store.removeSourceSequence(sid2);
}
Also used : RMStoreException(org.apache.cxf.ws.rm.persistence.RMStoreException) Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SQLException(java.sql.SQLException) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Date(java.util.Date) Test(org.junit.Test)

Example 4 with SourceSequence

use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.

the class RMTxStoreTestBase method setupSourceSequence.

private Identifier setupSourceSequence(String s) throws SQLException {
    SourceSequence seq = control.createMock(SourceSequence.class);
    Identifier sid = new Identifier();
    sid.setValue(s);
    Date expiry = null;
    Identifier osid = null;
    Long cmn = ONE;
    boolean lm = false;
    ProtocolVariation pv = ProtocolVariation.RM10WSA200408;
    if ("sequence2".equals(s)) {
        expiry = new Date(System.currentTimeMillis() + 3600 * 1000);
        osid = new Identifier();
        osid.setValue("offeringSequence");
        cmn = TEN;
        lm = true;
        pv = ProtocolVariation.RM11WSA200508;
    }
    EasyMock.expect(seq.getIdentifier()).andReturn(sid);
    EasyMock.expect(seq.getExpires()).andReturn(expiry);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(osid);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getCurrentMessageNr()).andReturn(cmn);
    EasyMock.expect(seq.isLastMessage()).andReturn(lm);
    EasyMock.expect(seq.getIdentifier()).andReturn(sid);
    EasyMock.expect(seq.getProtocol()).andReturn(pv);
    control.replay();
    store.createSourceSequence(seq);
    Connection con = getConnection();
    try {
        store.beginTransaction();
        store.updateSourceSequence(con, seq);
        store.commit(con);
    } finally {
        releaseConnection(con);
    }
    control.reset();
    return sid;
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) Connection(java.sql.Connection) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Date(java.util.Date) ProtocolVariation(org.apache.cxf.ws.rm.ProtocolVariation)

Example 5 with SourceSequence

use of org.apache.cxf.ws.rm.SourceSequence in project cxf by apache.

the class RMTxStoreTwoSchemasTest method testStoreIsolation.

@Test
public void testStoreIsolation() throws Exception {
    SourceSequence seq = control.createMock(SourceSequence.class);
    Identifier sid1 = new Identifier();
    sid1.setValue("sequence1");
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store1.createSourceSequence(seq);
    control.verify();
    SourceSequence rseq = store1.getSourceSequence(sid1);
    assertNotNull(rseq);
    rseq = store2.getSourceSequence(sid1);
    assertNull(rseq);
    control.reset();
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getExpires()).andReturn(null);
    EasyMock.expect(seq.getOfferingSequenceIdentifier()).andReturn(null);
    EasyMock.expect(seq.getEndpointIdentifier()).andReturn(CLIENT_ENDPOINT_ID);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    store2.createSourceSequence(seq);
    control.verify();
    rseq = store2.getSourceSequence(sid1);
    assertNotNull(rseq);
    // create another store
    RMTxStore store3 = createStore(null);
    store3.init();
    rseq = store3.getSourceSequence(sid1);
    assertNull(rseq);
    // switch to the store1's schema
    store3.setSchemaName(store1.getSchemaName());
    store3.init();
    rseq = store3.getSourceSequence(sid1);
    assertNotNull(rseq);
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Test(org.junit.Test)

Aggregations

SourceSequence (org.apache.cxf.ws.rm.SourceSequence)19 Test (org.junit.Test)12 Identifier (org.apache.cxf.ws.rm.v200702.Identifier)11 ArrayList (java.util.ArrayList)6 Connection (java.sql.Connection)4 SQLException (java.sql.SQLException)4 Date (java.util.Date)4 SoapMessage (org.apache.cxf.binding.soap.SoapMessage)4 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)4 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)3 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)3 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 Message (org.apache.cxf.common.i18n.Message)2 Client (org.apache.cxf.endpoint.Client)2 DestinationSequence (org.apache.cxf.ws.rm.DestinationSequence)2 RMManager (org.apache.cxf.ws.rm.RMManager)2 RMStoreException (org.apache.cxf.ws.rm.persistence.RMStoreException)2 Endpoint (javax.xml.ws.Endpoint)1 RMEndpoint (org.apache.cxf.ws.rm.RMEndpoint)1