Search in sources :

Example 11 with Data

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Data in project Smack by igniterealtime.

the class InBandBytestreamSessionTest method shouldConfirmReceivedDataPacket.

/**
     * Valid data packets should be confirmed.
     * 
     * @throws Exception should not happen
     */
@Test
public void shouldConfirmReceivedDataPacket() throws Exception {
    // verify data packet confirmation is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID);
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);
    listener.processStanza(data);
    protocol.verifyAll();
}
Also used : DataPacketExtension(org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension) InputStream(java.io.InputStream) StanzaListener(org.jivesoftware.smack.StanzaListener) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data) Test(org.junit.Test)

Example 12 with Data

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Data in project Smack by igniterealtime.

the class InBandBytestreamSessionTest method shouldNotCloseBothStreamsIfOutputStreamIsClosed.

/**
     * If the input stream is closed the output stream should not be closed as well.
     * 
     * @throws Exception should not happen
     */
@Test
public void shouldNotCloseBothStreamsIfOutputStreamIsClosed() throws Exception {
    InBandBytestreamSession session = new InBandBytestreamSession(connection, initBytestream, initiatorJID);
    OutputStream outputStream = session.getOutputStream();
    outputStream.close();
    // verify data packet confirmation is of type RESULT
    protocol.addResponse(null, Verification.requestTypeRESULT);
    // insert data to read
    InputStream inputStream = session.getInputStream();
    StanzaListener listener = Whitebox.getInternalState(inputStream, StanzaListener.class);
    String base64Data = Base64.encode("Data");
    DataPacketExtension dpe = new DataPacketExtension(sessionID, 0, base64Data);
    Data data = new Data(dpe);
    listener.processStanza(data);
    // verify no packet send
    protocol.verifyAll();
    try {
        outputStream.flush();
        fail("should throw an exception");
    } catch (IOException e) {
        assertTrue(e.getMessage().contains("closed"));
    }
    assertTrue(inputStream.read() != 0);
}
Also used : DataPacketExtension(org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) StanzaListener(org.jivesoftware.smack.StanzaListener) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data) IOException(java.io.IOException) Test(org.junit.Test)

Example 13 with Data

use of org.jivesoftware.smackx.bytestreams.ibb.packet.Data in project Smack by igniterealtime.

the class DataListenerTest method shouldReplyErrorIfSessionIsUnknown.

/**
     * If a data stanza(/packet) of an unknown session is received it should be replied
     * with an <item-not-found/> error.
     * 
     * @throws Exception should not happen
     */
@Test
public void shouldReplyErrorIfSessionIsUnknown() throws Exception {
    // mock connection
    XMPPConnection connection = mock(XMPPConnection.class);
    // initialize InBandBytestreamManager to get the DataListener
    InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection);
    // get the DataListener from InBandByteStreamManager
    DataListener dataListener = Whitebox.getInternalState(byteStreamManager, DataListener.class);
    DataPacketExtension dpe = new DataPacketExtension("unknownSessionID", 0, "Data");
    Data data = new Data(dpe);
    data.setFrom(initiatorJID);
    data.setTo(targetJID);
    dataListener.handleIQRequest(data);
    // wait because packet is processed in an extra thread
    Thread.sleep(200);
    // capture reply to the In-Band Bytestream close request
    ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class);
    verify(connection).sendStanza(argument.capture());
    // assert that reply is the correct error packet
    assertEquals(initiatorJID, argument.getValue().getTo());
    assertEquals(IQ.Type.error, argument.getValue().getType());
    assertEquals(XMPPError.Condition.item_not_found, argument.getValue().getError().getCondition());
}
Also used : DataPacketExtension(org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension) IQ(org.jivesoftware.smack.packet.IQ) Data(org.jivesoftware.smackx.bytestreams.ibb.packet.Data) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Test(org.junit.Test)

Aggregations

Data (org.jivesoftware.smackx.bytestreams.ibb.packet.Data)13 Test (org.junit.Test)11 IQ (org.jivesoftware.smack.packet.IQ)10 DataPacketExtension (org.jivesoftware.smackx.bytestreams.ibb.packet.DataPacketExtension)10 InputStream (java.io.InputStream)9 StanzaListener (org.jivesoftware.smack.StanzaListener)9 IOException (java.io.IOException)4 Random (java.util.Random)3 OutputStream (java.io.OutputStream)2 SmackException (org.jivesoftware.smack.SmackException)1 NotConnectedException (org.jivesoftware.smack.SmackException.NotConnectedException)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 XMPPException (org.jivesoftware.smack.XMPPException)1 Open (org.jivesoftware.smackx.bytestreams.ibb.packet.Open)1 Protocol (org.jivesoftware.util.Protocol)1 Verification (org.jivesoftware.util.Verification)1 Before (org.junit.Before)1