Search in sources :

Example 61 with Identifier

use of org.orcid.jaxb.model.record.summary_rc1.Identifier in project cxf by apache.

the class RMTxStoreTestBase method testCreateDeleteMessages.

@Test
public void testCreateDeleteMessages() throws IOException, SQLException {
    RMMessage msg1 = control.createMock(RMMessage.class);
    RMMessage msg2 = control.createMock(RMMessage.class);
    Identifier sid1 = new Identifier();
    sid1.setValue("sequence1");
    EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE).anyTimes();
    EasyMock.expect(msg2.getMessageNumber()).andReturn(ONE).anyTimes();
    byte[] bytes = new byte[89];
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    CachedOutputStream cos = new CachedOutputStream();
    IOUtils.copy(bais, cos);
    cos.flush();
    bais.close();
    EasyMock.expect(msg1.getContent()).andReturn(cos).anyTimes();
    EasyMock.expect(msg2.getContent()).andReturn(cos).anyTimes();
    EasyMock.expect(msg1.getContentType()).andReturn("text/xml").times(1);
    control.replay();
    Connection con = getConnection();
    try {
        store.beginTransaction();
        store.storeMessage(con, sid1, msg1, true);
        store.storeMessage(con, sid1, msg2, false);
        store.commit(con);
    } finally {
        releaseConnection(con);
    }
    control.verify();
    control.reset();
    EasyMock.expect(msg1.getMessageNumber()).andReturn(ONE);
    EasyMock.expect(msg1.getContent()).andReturn(cos);
    control.replay();
    con = getConnection();
    try {
        store.beginTransaction();
        store.storeMessage(con, sid1, msg1, true);
    } catch (SQLException ex) {
        assertEquals("23505", ex.getSQLState());
        store.abort(con);
    } finally {
        releaseConnection(con);
    }
    control.verify();
    control.reset();
    EasyMock.expect(msg1.getMessageNumber()).andReturn(TEN).anyTimes();
    EasyMock.expect(msg2.getMessageNumber()).andReturn(TEN).anyTimes();
    EasyMock.expect(msg1.getContent()).andReturn(cos).anyTimes();
    EasyMock.expect(msg2.getContent()).andReturn(cos).anyTimes();
    control.replay();
    con = getConnection();
    try {
        store.beginTransaction();
        store.storeMessage(con, sid1, msg1, true);
        store.storeMessage(con, sid1, msg2, false);
        store.commit(con);
    } finally {
        releaseConnection(con);
    }
    control.verify();
    Collection<Long> messageNrs = Arrays.asList(ZERO, TEN, ONE, TEN);
    store.removeMessages(sid1, messageNrs, true);
    store.removeMessages(sid1, messageNrs, false);
    Identifier sid2 = new Identifier();
    sid1.setValue("sequence2");
    store.removeMessages(sid2, messageNrs, true);
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) RMMessage(org.apache.cxf.ws.rm.persistence.RMMessage) ByteArrayInputStream(java.io.ByteArrayInputStream) SQLException(java.sql.SQLException) Connection(java.sql.Connection) CachedOutputStream(org.apache.cxf.io.CachedOutputStream) Test(org.junit.Test)

Example 62 with Identifier

use of org.orcid.jaxb.model.record.summary_rc1.Identifier in project cxf by apache.

the class RMTxStoreTestBase method testGetSourceSequences.

@Test
public void testGetSourceSequences() throws SQLException {
    Identifier sid1 = null;
    Identifier sid2 = null;
    Collection<SourceSequence> seqs = store.getSourceSequences("unknown");
    assertEquals(0, seqs.size());
    try {
        sid1 = setupSourceSequence("sequence1");
        seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(1, seqs.size());
        checkRecoveredSourceSequences(seqs);
        sid2 = setupSourceSequence("sequence2");
        seqs = store.getSourceSequences(CLIENT_ENDPOINT_ID);
        assertEquals(2, seqs.size());
        checkRecoveredSourceSequences(seqs);
    } finally {
        if (null != sid1) {
            store.removeSourceSequence(sid1);
        }
        if (null != sid2) {
            store.removeSourceSequence(sid2);
        }
    }
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Test(org.junit.Test)

Example 63 with Identifier

use of org.orcid.jaxb.model.record.summary_rc1.Identifier in project cxf by apache.

the class RMTxStoreTestBase method testUpdateSourceSequence.

@Test
public void testUpdateSourceSequence() throws SQLException {
    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.getCurrentMessageNr()).andReturn(ONE);
    EasyMock.expect(seq.isLastMessage()).andReturn(false);
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    Connection con = getConnection();
    try {
        store.beginTransaction();
        store.updateSourceSequence(con, seq);
        store.abort(con);
    } finally {
        releaseConnection(con);
    }
    control.reset();
    EasyMock.expect(seq.getCurrentMessageNr()).andReturn(TEN);
    EasyMock.expect(seq.isLastMessage()).andReturn(true);
    EasyMock.expect(seq.getIdentifier()).andReturn(sid1);
    EasyMock.expect(seq.getProtocol()).andReturn(ProtocolVariation.RM10WSA200408);
    control.replay();
    con = getConnection();
    try {
        store.beginTransaction();
        store.updateSourceSequence(con, seq);
        store.abort(con);
    } finally {
        releaseConnection(con);
    }
    store.removeSourceSequence(sid1);
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) Connection(java.sql.Connection) SourceSequence(org.apache.cxf.ws.rm.SourceSequence) Test(org.junit.Test)

Example 64 with Identifier

use of org.orcid.jaxb.model.record.summary_rc1.Identifier 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 65 with Identifier

use of org.orcid.jaxb.model.record.summary_rc1.Identifier in project cxf by apache.

the class RMTxStoreTestBase method verifyDestinationSequence.

private void verifyDestinationSequence(String s, DestinationSequence seq) {
    Identifier sid = seq.getIdentifier();
    assertNotNull(sid);
    assertEquals(s, sid.getValue());
    if ("sequence1".equals(s)) {
        assertEquals(0, seq.getLastMessageNumber());
        SequenceAcknowledgement sa = seq.getAcknowledgment();
        assertNotNull(sa);
        verifyAcknowledgementRanges(sa.getAcknowledgementRange(), new long[] { 1, 1 });
        assertEquals(ProtocolVariation.RM10WSA200408, seq.getProtocol());
    } else if ("sequence2".equals(s)) {
        assertEquals(10, seq.getLastMessageNumber());
        SequenceAcknowledgement sa = seq.getAcknowledgment();
        assertNotNull(sa);
        verifyAcknowledgementRanges(sa.getAcknowledgementRange(), new long[] { 1, 1, 3, 10 });
        assertEquals(ProtocolVariation.RM11WSA200508, seq.getProtocol());
    }
}
Also used : Identifier(org.apache.cxf.ws.rm.v200702.Identifier) SequenceAcknowledgement(org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)

Aggregations

Identifier (org.apache.cxf.ws.rm.v200702.Identifier)72 Test (org.junit.Test)43 Message (org.apache.cxf.message.Message)11 SourceSequence (org.apache.cxf.ws.rm.SourceSequence)11 RMMessage (org.apache.cxf.ws.rm.persistence.RMMessage)11 SequenceAcknowledgement (org.apache.cxf.ws.rm.v200702.SequenceAcknowledgement)11 Connection (java.sql.Connection)9 AddressingProperties (org.apache.cxf.ws.addressing.AddressingProperties)8 SQLException (java.sql.SQLException)7 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 EndpointReferenceType (org.apache.cxf.ws.addressing.EndpointReferenceType)7 DestinationSequence (org.apache.cxf.ws.rm.DestinationSequence)7 Method (java.lang.reflect.Method)6 AttributedURIType (org.apache.cxf.ws.addressing.AttributedURIType)6 RMStore (org.apache.cxf.ws.rm.persistence.RMStore)6 SequenceType (org.apache.cxf.ws.rm.v200702.SequenceType)6 SoapBinding (org.apache.cxf.binding.soap.SoapBinding)5 ProtocolVariation (org.apache.cxf.ws.rm.ProtocolVariation)5 Identifier (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.bgp.linkstate.rev171207.Identifier)5