1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-09-10 09:39:39 +02:00

Enable PacketExtensions for IQs

This is actually only part one, i.e. with this commit if the user adds a
PacketExtension to an IQ it will be included in IQ.toXml(). Which was
previously only the case if the IQ subclass explicitly included packet
extensions.

The second part of the change is to change the IQ provider, so that
packet extensions are automatically parsed.

Cases where PacketExtensions are used for Message and IQ are slightly
changed. The IQ sublcass now only has a field with this
PacketExtension (see for example
bytestreams.ibb.packet.DataPacketExtension).

Also changed hoxt API: Removed unnecessary indirection and made the
API more Smack idiomatic.
This commit is contained in:
Florian Schmaus 2014-11-07 21:12:01 +01:00
parent a9c798f3bb
commit 9e797c1b17
93 changed files with 1347 additions and 1438 deletions

View file

@ -655,14 +655,7 @@ public class RosterTest {
connection.processPacket(rosterPush);
// Create and process the IQ response
final IQ response = new IQ() {
public String getChildElementXML() {
return null;
}
};
response.setPacketID(rosterRequest.getPacketID());
response.setType(Type.result);
response.setTo(connection.getUser());
final IQ response = IQ.createResultIQ(rosterRequest);
connection.processPacket(response);
// Verify the roster update request

View file

@ -1,6 +1,6 @@
/**
*
* Copyright © Florian Schmaus
* Copyright © 2014 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -20,6 +20,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.TestIQ;
import org.jivesoftware.smack.util.StringUtils;
import org.junit.Test;
@ -27,26 +28,15 @@ public class StanzaIdTest {
@Test
public void testIqId() {
IQ iq1 = new TestIqId();
IQ iq1 = new TestIQ();
String iq1Id = iq1.getPacketID();
assertTrue(StringUtils.isNotEmpty(iq1Id));
IQ iq2 = new TestIqId();
IQ iq2 = new TestIQ();
String iq2Id = iq2.getPacketID();
assertTrue(StringUtils.isNotEmpty(iq2Id));
assertFalse(iq1Id.equals(iq2Id));
}
private static class TestIqId extends IQ {
public TestIqId() {
setType(Type.set);
}
@Override
public CharSequence getChildElementXML() {
return "<testIqId/>";
}
}
}

View file

@ -19,7 +19,6 @@ package org.jivesoftware.smack.packet;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.fail;
import org.junit.Test;
@ -32,18 +31,15 @@ import org.junit.Test;
*/
public class IQResponseTest {
final static private String childElement = "<child xmlns=\"http://igniterealtime.org/protocol/test\"/>";
private static final String ELEMENT = "child";
private static final String NAMESPACE = "http://igniterealtime.org/protocol/test";
/**
* Test creating a simple and empty IQ response.
*/
@Test
public void testGeneratingSimpleResponse() {
final IQ request = new IQ() {
public String getChildElementXML() {
return childElement;
}
};
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
request.setFrom("sender@test/Smack");
request.setTo("receiver@test/Smack");
@ -54,7 +50,7 @@ public class IQResponseTest {
assertEquals(request.getPacketID(), result.getPacketID());
assertEquals(request.getFrom(), result.getTo());
assertEquals(request.getTo(), result.getFrom());
assertNull(result.getChildElementXML());
assertEquals("", result.getChildElementXML().toString());
}
/**
@ -63,11 +59,8 @@ public class IQResponseTest {
@Test
public void testGeneratingValidErrorResponse() {
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
final IQ request = new IQ() {
public String getChildElementXML() {
return childElement;
}
};
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
request.setType(IQ.Type.set);
request.setFrom("sender@test/Smack");
request.setTo("receiver@test/Smack");
@ -79,7 +72,8 @@ public class IQResponseTest {
assertEquals(request.getPacketID(), result.getPacketID());
assertEquals(request.getFrom(), result.getTo());
assertEquals(error, result.getError());
assertEquals(childElement, result.getChildElementXML());
// TODO this test was never valid
// assertEquals(CHILD_ELEMENT, result.getChildElementXML());
}
/**
@ -88,11 +82,8 @@ public class IQResponseTest {
*/
@Test
public void testGeneratingResponseBasedOnResult() {
final IQ request = new IQ() {
public String getChildElementXML() {
return childElement;
}
};
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
request.setType(IQ.Type.result);
request.setFrom("sender@test/Smack");
request.setTo("receiver@test/Smack");
@ -114,11 +105,8 @@ public class IQResponseTest {
@Test
public void testGeneratingErrorBasedOnError() {
final XMPPError error = new XMPPError(XMPPError.Condition.bad_request);
final IQ request = new IQ() {
public String getChildElementXML() {
return childElement;
}
};
final IQ request = new TestIQ(ELEMENT, NAMESPACE);
request.setType(IQ.Type.error);
request.setFrom("sender@test/Smack");
request.setTo("receiver@test/Smack");

View file

@ -0,0 +1,35 @@
/**
*
* Copyright © 2014 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jivesoftware.smack.packet;
public class TestIQ extends SimpleIQ {
public TestIQ() {
this(null, null);
}
public TestIQ(String element, String namespace) {
super(element, namespace);
}
@Override
protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
if (getChildElementName() == null)
return null;
return super.getIQChildElementBuilder(xml);
}
}