mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-14 19:49:38 +02:00
Rework Bits of Binary implementation
This commit is contained in:
parent
c688acaa0f
commit
9328182912
12 changed files with 166 additions and 300 deletions
|
@ -1,67 +0,0 @@
|
|||
/**
|
||||
*
|
||||
* 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());
|
||||
}
|
||||
|
||||
}
|
|
@ -20,11 +20,9 @@ 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 {
|
||||
|
||||
|
@ -37,12 +35,6 @@ public class BoBIQTest extends SmackTestSuite {
|
|||
|
||||
@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);
|
||||
|
@ -55,14 +47,10 @@ public class BoBIQTest extends SmackTestSuite {
|
|||
|
||||
@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);
|
||||
BoBIQ bobIQ = PacketParserUtils.parseStanza(sampleBoBIQResponse);
|
||||
|
||||
BoBHash bobHash = new BoBHash("8f35fef110ffc5df08d579a50083ff9308fb6242", "sha1");
|
||||
BoBData bobData = new BoBData(86400, "image/png", "sarasade2354j2".getBytes());
|
||||
BoBData bobData = new BoBData("image/png", "sarasade2354j2".getBytes(), 86400);
|
||||
|
||||
BoBIQ createdBoBIQ = new BoBIQ(bobHash, bobData);
|
||||
createdBoBIQ.setStanzaId("sarasa");
|
||||
|
@ -73,7 +61,7 @@ public class BoBIQTest extends SmackTestSuite {
|
|||
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.getBoBData().getContentBase64Encoded(), createdBoBIQ.getBoBData().getContentBase64Encoded());
|
||||
Assert.assertEquals(bobIQ.toXML().toString(), createdBoBIQ.toXML().toString());
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue