mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-14 11:39:39 +02:00
Add XEP-0231: Bits of Binary implementation
Fixes SMACK-737
This commit is contained in:
parent
70e860fe27
commit
c688acaa0f
16 changed files with 997 additions and 0 deletions
|
@ -0,0 +1,67 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Fernando Ramirez
|
||||
*
|
||||
* 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.smackx.bob;
|
||||
|
||||
import org.jivesoftware.smack.packet.Message;
|
||||
import org.jivesoftware.smack.packet.Message.Type;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.bob.element.BoBExtension;
|
||||
import org.jivesoftware.smackx.bob.provider.BoBExtensionProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class BoBExtensionTest {
|
||||
|
||||
String sampleMessageWithBoBExtension = "<message to='macbeth@chat.shakespeare.lit' id='sarasa' type='groupchat'>"
|
||||
+ "<body>Yet here's a spot.</body>" + "<html xmlns='http://jabber.org/protocol/xhtml-im'>"
|
||||
+ "<body xmlns='http://www.w3.org/1999/xhtml'>"
|
||||
+ "<img alt='A spot' src='cid:sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org'/>" + "</body>"
|
||||
+ "</html>" + "</message>";
|
||||
|
||||
String sampleBoBExtension = "<html xmlns='http://jabber.org/protocol/xhtml-im'>"
|
||||
+ "<body xmlns='http://www.w3.org/1999/xhtml'>"
|
||||
+ "<img alt='A spot' src='cid:sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org'/>" + "</body>"
|
||||
+ "</html>";
|
||||
|
||||
@Test
|
||||
public void checkBoBMessageExtension() throws Exception {
|
||||
Message message = (Message) PacketParserUtils.parseStanza(sampleMessageWithBoBExtension);
|
||||
|
||||
BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
|
||||
|
||||
Message createdMessage = new Message(JidCreate.from("macbeth@chat.shakespeare.lit"));
|
||||
createdMessage.setStanzaId("sarasa");
|
||||
createdMessage.setType(Type.groupchat);
|
||||
createdMessage.setBody("Yet here's a spot.");
|
||||
createdMessage.addExtension(new BoBExtension(bobHash, "A spot", null));
|
||||
|
||||
Assert.assertEquals(message.toXML().toString(), createdMessage.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkBoBExtensionProvider() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(sampleBoBExtension);
|
||||
BoBExtension bobExtension = new BoBExtensionProvider().parse(parser);
|
||||
|
||||
Assert.assertEquals("A spot", bobExtension.getAlt());
|
||||
Assert.assertEquals("sha1", bobExtension.getBoBHash().getHashType());
|
||||
Assert.assertEquals("8f35fef110ffc5df08d579a50083ff9308fb6242", bobExtension.getBoBHash().getHash());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
/**
|
||||
*
|
||||
* Copyright 2016 Fernando Ramirez
|
||||
*
|
||||
* 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.smackx.bob;
|
||||
|
||||
import org.jivesoftware.smack.packet.IQ.Type;
|
||||
import org.jivesoftware.smack.test.util.SmackTestSuite;
|
||||
import org.jivesoftware.smack.util.PacketParserUtils;
|
||||
import org.jivesoftware.smackx.bob.element.BoBIQ;
|
||||
import org.jivesoftware.smackx.bob.provider.BoBIQProvider;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.jxmpp.jid.impl.JidCreate;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class BoBIQTest extends SmackTestSuite {
|
||||
|
||||
String sampleBoBIQRequest = "<iq to='ladymacbeth@shakespeare.lit/castle' id='sarasa' type='get'>"
|
||||
+ "<data xmlns='urn:xmpp:bob' cid='sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org'/>" + "</iq>";
|
||||
|
||||
String sampleBoBIQResponse = "<iq to='doctor@shakespeare.lit/pda' id='sarasa' type='result'>"
|
||||
+ "<data xmlns='urn:xmpp:bob' cid='sha1+8f35fef110ffc5df08d579a50083ff9308fb6242@bob.xmpp.org' "
|
||||
+ "max-age='86400' type='image/png'>" + "c2FyYXNhZGUyMzU0ajI=" + "</data>" + "</iq>";
|
||||
|
||||
@Test
|
||||
public void checkBoBIQRequest() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(sampleBoBIQRequest);
|
||||
BoBIQ bobIQ = new BoBIQProvider().parse(parser);
|
||||
bobIQ.setStanzaId("sarasa");
|
||||
bobIQ.setTo(JidCreate.from("ladymacbeth@shakespeare.lit/castle"));
|
||||
bobIQ.setType(Type.get);
|
||||
|
||||
BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
|
||||
|
||||
BoBIQ createdBoBIQ = new BoBIQ(bobHash);
|
||||
createdBoBIQ.setStanzaId("sarasa");
|
||||
createdBoBIQ.setTo(JidCreate.from("ladymacbeth@shakespeare.lit/castle"));
|
||||
createdBoBIQ.setType(Type.get);
|
||||
|
||||
Assert.assertEquals(sampleBoBIQRequest, createdBoBIQ.toXML().toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void checkBoBIQResponse() throws Exception {
|
||||
XmlPullParser parser = PacketParserUtils.getParserFor(sampleBoBIQResponse);
|
||||
BoBIQ bobIQ = new BoBIQProvider().parse(parser);
|
||||
bobIQ.setStanzaId("sarasa");
|
||||
bobIQ.setTo(JidCreate.from("doctor@shakespeare.lit/pda"));
|
||||
bobIQ.setType(Type.result);
|
||||
|
||||
BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
|
||||
BoBData bobData = new BoBData(86400, "image/png", "sarasade2354j2".getBytes());
|
||||
|
||||
BoBIQ createdBoBIQ = new BoBIQ(bobHash, bobData);
|
||||
createdBoBIQ.setStanzaId("sarasa");
|
||||
createdBoBIQ.setTo(JidCreate.from("doctor@shakespeare.lit/pda"));
|
||||
createdBoBIQ.setType(Type.result);
|
||||
|
||||
Assert.assertEquals(bobIQ.getBoBHash().getHash(), createdBoBIQ.getBoBHash().getHash());
|
||||
Assert.assertEquals(bobIQ.getBoBHash().getHashType(), createdBoBIQ.getBoBHash().getHashType());
|
||||
Assert.assertEquals(bobIQ.getBoBData().getMaxAge(), createdBoBIQ.getBoBData().getMaxAge());
|
||||
Assert.assertEquals(bobIQ.getBoBData().getType(), createdBoBIQ.getBoBData().getType());
|
||||
Assert.assertEquals(bobIQ.getBoBData().getBase64Encoded(), createdBoBIQ.getBoBData().getBase64Encoded());
|
||||
Assert.assertEquals(bobIQ.toXML().toString(), createdBoBIQ.toXML().toString());
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue