public static FileTooLargeError from(IQ iq) { StanzaError error = iq.getError(); if (error == null) { return null; } return error.getExtension(ELEMENT, NAMESPACE); } }
@Override public void verify(IQ request, IQ response) { assertEquals(StanzaError.Condition.bad_request, request.getError().getCondition()); }
@Override public void verify(IQ request, IQ response) { assertEquals(StanzaError.Condition.unexpected_request, request.getError().getCondition()); }
/** * If listener for a specific user is registered it should not be notified on incoming requests * from other users. * * @throws Exception should not happen */ @Test public void shouldNotInvokeListenerForUser() throws Exception { // add listener for request of user "other_initiator" InBandBytestreamListener listener = mock(InBandBytestreamListener.class); byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // wait because packet is processed in an extra thread Thread.sleep(200); // assert listener is not called ArgumentCaptor<BytestreamRequest> byteStreamRequest = ArgumentCaptor.forClass(BytestreamRequest.class); verify(listener, never()).incomingBytestreamRequest(byteStreamRequest.capture()); // capture reply to the In-Band Bytestream open 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(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
/** * If no listeners are registered for incoming In-Band Bytestream requests, all request should * be rejected with an error. * * @throws Exception should not happen */ @Test public void shouldRespondWithError() throws Exception { // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // wait because packet is processed in an extra thread Thread.sleep(200); // capture reply to the In-Band Bytestream open 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(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
/** * If listener for a specific user is registered it should not be notified on incoming requests * from other users. * * @throws Exception should not happen */ @Test public void shouldNotInvokeListenerForUser() throws Exception { // add listener for request of user "other_initiator" Socks5BytestreamListener listener = mock(Socks5BytestreamListener.class); byteStreamManager.addIncomingBytestreamListener(listener, JidCreate.from("other_" + initiatorJID)); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // assert listener is not called ArgumentCaptor<BytestreamRequest> byteStreamRequest = ArgumentCaptor.forClass(BytestreamRequest.class); verify(listener, never()).incomingBytestreamRequest(byteStreamRequest.capture()); // capture reply to the SOCKS5 Bytestream initiation ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection, timeout(TIMEOUT)).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
/** * Open request with a block size that exceeds the maximum block size should be replied with an * resource-constraint error. * * @throws Exception should not happen */ @Test public void shouldRejectRequestWithTooBigBlockSize() throws Exception { byteStreamManager.setMaximumBlockSize(1024); // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // wait because packet is processed in an extra thread Thread.sleep(200); // capture reply to the In-Band Bytestream open 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(StanzaError.Condition.resource_constraint, argument.getValue().getError().getCondition()); }
/** * Test reject() method. * @throws NotConnectedException * @throws InterruptedException */ @Test public void shouldReplyWithErrorIfRequestIsRejected() throws NotConnectedException, InterruptedException { InBandBytestreamRequest ibbRequest = new InBandBytestreamRequest( byteStreamManager, initBytestream); // reject request ibbRequest.reject(); // capture reply to the In-Band Bytestream open 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(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
/** * If no listeners are registered for incoming SOCKS5 Bytestream requests, all request should be * rejected with an error. * * @throws Exception should not happen */ @Test public void shouldRespondWithError() throws Exception { // run the listener with the initiation packet initiationListener.handleIQRequest(initBytestream); // capture reply to the SOCKS5 Bytestream initiation ArgumentCaptor<IQ> argument = ArgumentCaptor.forClass(IQ.class); verify(connection, timeout(TIMEOUT)).sendStanza(argument.capture()); // assert that reply is the correct error packet assertEquals(initiatorJID, argument.getValue().getTo()); assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.not_acceptable, argument.getValue().getError().getCondition()); }
/** * If a close request to 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 CloseListener InBandBytestreamManager byteStreamManager = InBandBytestreamManager.getByteStreamManager(connection); // get the CloseListener from InBandByteStreamManager CloseListener closeListener = Whitebox.getInternalState(byteStreamManager, CloseListener.class); Close close = new Close("unknownSessionId"); close.setFrom(initiatorJID); close.setTo(targetJID); closeListener.handleIQRequest(close); // 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(StanzaError.Condition.item_not_found, argument.getValue().getError().getCondition()); }
assertEquals(IQ.Type.error, argument.getValue().getType()); assertEquals(StanzaError.Condition.item_not_found, argument.getValue().getError().getCondition());
triggerTransportClosed(null); throw new JingleException(iq.getError().getDescriptiveText()); } else if (iq.getType().equals(IQ.Type.result)) {
triggerMediaClosed(getBestCommonAudioPt()); throw new JingleException(iq.getError().getDescriptiveText()); } else if (iq.getType().equals(IQ.Type.result)) {
throw new XMPPErrorException(iqResponse, iqResponse.getError());
assertEquals(rejectPacket.getError(), e.getStanzaError());
/** * Test creating a error response based on an IQ request. * @throws XmppStringprepException */ @Test public void testGeneratingValidErrorResponse() throws XmppStringprepException { final StanzaError.Builder error = StanzaError.getBuilder(StanzaError.Condition.bad_request); final IQ request = new TestIQ(ELEMENT, NAMESPACE); request.setType(IQ.Type.set); request.setFrom(JidCreate.from("sender@test/Smack")); request.setTo(JidCreate.from("receiver@test/Smack")); final IQ result = IQ.createErrorResponse(request, error); assertEquals(IQ.Type.error, result.getType()); assertNotNull(result.getStanzaId()); assertEquals(request.getStanzaId(), result.getStanzaId()); assertEquals(request.getFrom(), result.getTo()); assertEquals(error.build().toXML(), result.getError().toXML()); // TODO this test was never valid // assertEquals(CHILD_ELEMENT, result.getChildElementXML()); }
XMPPError err = response.getError(); String packetID = response.getStanzaId();
XMPPError err = iq.getError();