1
0
Fork 0
mirror of https://codeberg.org/Mercury-IM/Smack synced 2025-12-06 05:01:12 +01:00

Prefix subprojects with 'smack-'

instead of using the old baseName=smack appendix=project.name approach,
we are now going convention over configuration and renaming the
subprojects directories to the proper name.

Having a prefix is actually very helpful, because the resulting
libraries will be named like the subproject. And a core-4.0.0-rc1.jar is
not as explicit about what it actually *is* as a
smack-core-4.0.0-rc1.jar.

SMACK-265
This commit is contained in:
Florian Schmaus 2014-04-28 19:27:53 +02:00
parent b6fb1f3743
commit 91fd15ad86
758 changed files with 42 additions and 42 deletions

View file

@ -0,0 +1,31 @@
/**
*
* 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.smackx;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
public class ExperimentalProviderInitializerTest {
@Test
public void testExperimentalProviderInitialzer() {
ExperimentalProviderInitializer epi = new ExperimentalProviderInitializer();
epi.initialize();
assertTrue(epi.getExceptions().size() == 0);
}
}

View file

@ -0,0 +1,114 @@
/**
*
* Copyright the original author or authors
*
* 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.carbons;
import static org.junit.Assert.assertEquals;
import java.util.Properties;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.carbons.packet.CarbonExtension;
import org.jivesoftware.smackx.carbons.provider.CarbonManagerProvider;
import org.jivesoftware.smackx.forward.Forwarded;
import org.jivesoftware.smackx.forward.provider.ForwardedProvider;
import org.junit.BeforeClass;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import com.jamesmurty.utils.XMLBuilder;
public class CarbonTest {
private static Properties outputProperties = new Properties();
static {
outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes");
}
@BeforeClass
public static void setup() {
ProviderManager.getInstance().addExtensionProvider("forwarded", "urn:xmpp:forward:0", new ForwardedProvider());
}
@Test
public void carbonSentTest() throws Exception {
XmlPullParser parser;
String control;
CarbonExtension cc;
Forwarded fwd;
control = XMLBuilder.create("sent")
.e("forwarded")
.a("xmlns", "urn:xmpp:forwarded:0")
.e("message")
.a("from", "romeo@montague.com")
.asString(outputProperties);
parser = TestUtils.getParser(control, "sent");
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
fwd = cc.getForwarded();
// meta
assertEquals(CarbonExtension.Direction.sent, cc.getDirection());
// no delay in packet
assertEquals(null, fwd.getDelayInfo());
// check message
assertEquals("romeo@montague.com", fwd.getForwardedPacket().getFrom());
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("sent", parser.getName());
}
@Test
public void carbonReceivedTest() throws Exception {
XmlPullParser parser;
String control;
CarbonExtension cc;
control = XMLBuilder.create("received")
.e("forwarded")
.a("xmlns", "urn:xmpp:forwarded:0")
.e("message")
.a("from", "romeo@montague.com")
.asString(outputProperties);
parser = TestUtils.getParser(control, "received");
cc = (CarbonExtension) new CarbonManagerProvider().parseExtension(parser);
assertEquals(CarbonExtension.Direction.received, cc.getDirection());
// check end of tag
assertEquals(XmlPullParser.END_TAG, parser.getEventType());
assertEquals("received", parser.getName());
}
@Test(expected=Exception.class)
public void carbonEmptyTest() throws Exception {
XmlPullParser parser;
String control;
control = XMLBuilder.create("sent")
.a("xmlns", "urn:xmpp:forwarded:0")
.asString(outputProperties);
parser = TestUtils.getParser(control, "sent");
new CarbonManagerProvider().parseExtension(parser);
}
}

View file

@ -0,0 +1,203 @@
/**
*
* Copyright 2014 Andriy Tsykholyas
*
* 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.hoxt.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.hoxt.packet.AbstractHttpOverXmpp;
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
import org.jivesoftware.smackx.shim.packet.Header;
import org.jivesoftware.smackx.shim.packet.HeadersExtension;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import java.util.Collection;
import java.util.HashMap;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
/**
* Tests correct headers and data parsing in 'req' and 'resp' elements.
*/
public class AbstractHttpOverXmppProviderTest {
@Test
public void areRespHeadersParsedCorrectly() throws Exception {
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>"
+ "<headers xmlns='http://jabber.org/protocol/shim'>"
+ "<header name='Date'>Fri, 03 May 2013 13:52:10 GMT-4</header>"
+ "<header name='Allow'>OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE</header>"
+ "<header name='Content-Length'>0</header>"
+ "</headers>"
+ "</resp>";
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Date", "Fri, 03 May 2013 13:52:10 GMT-4");
expectedHeaders.put("Allow", "OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE");
expectedHeaders.put("Content-Length", "0");
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = TestUtils.getParser(string, "resp");
IQ iq = provider.parseIQ(parser);
assertTrue(iq instanceof HttpOverXmppResp);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
checkHeaders(body.getHeaders(), expectedHeaders);
}
@Test
public void areReqHeadersParsedCorrectly() throws Exception {
String string = "<req xmlns='urn:xmpp:http' method='GET' resource='/rdf/xep' version='1.1'>"
+ "<headers xmlns='http://jabber.org/protocol/shim'>"
+ "<header name='Host'>clayster.com</header>"
+ "</headers>"
+ "</req>";
Map<String, String> expectedHeaders = new HashMap<String, String>();
expectedHeaders.put("Host", "clayster.com");
AbstractHttpOverXmppProvider provider = new HttpOverXmppReqProvider();
XmlPullParser parser = TestUtils.getParser(string, "req");
IQ iq = provider.parseIQ(parser);
assertTrue(iq instanceof HttpOverXmppReq);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppReq) iq).getReq();
checkHeaders(body.getHeaders(), expectedHeaders);
}
@Test
public void isTextDataParsedCorrectly() throws Exception {
String expectedText = "@prefix dc: <http://purl.org/dc/elements/1.1/>."
+ "@base <http://clayster.com/>."
+ "<xep> dc:title \"HTTP over XMPP\";"
+ "dc:creator <PeterWaher>;"
+ "dc:publisher <XSF>.";
String encodedText = "@prefix dc: &lt;http://purl.org/dc/elements/1.1/&gt;."
+ "@base &lt;http://clayster.com/&gt;."
+ "&lt;xep&gt; dc:title \"HTTP over XMPP\";"
+ "dc:creator &lt;PeterWaher&gt;;"
+ "dc:publisher &lt;XSF&gt;.";
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>"
+ "<headers xmlns='http://jabber.org/protocol/shim'><header name='Server'>Clayster</header></headers>"
+ "<data><text>"
+ encodedText
+ "</text></data></resp>";
AbstractHttpOverXmpp.Text text = (AbstractHttpOverXmpp.Text) parseAbstractBody(
string, "resp").getData().getChild();
assertEquals(expectedText, text.getText());
}
@Test
public void isXmlDataParsedCorrectly() throws Exception {
String expectedXml = "<sparql><head><variable name=\"title\"/><variable name=\"creator\"/>" // no xmlns here
+ "</head><results><result>"
+ "<binding name=\"title\">"
+ "<literal>HTTP over XMPP</literal>"
+ "</binding>"
+ "<binding name=\"creator\">"
+ "<uri>http://clayster.com/PeterWaher</uri>"
+ "</binding>"
+ "</result>"
+ "</results>"
+ "</sparql>";
String encodedXml = "<sparql xmlns=\"http://www.w3.org/2005/sparql-results#\"><head><variable name=\"title\"/><variable name=\"creator\"/>"
+ "</head><results><result>"
+ "<binding name=\"title\">"
+ "<literal>HTTP over XMPP</literal>"
+ "</binding>"
+ "<binding name=\"creator\">"
+ "<uri>http://clayster.com/PeterWaher</uri>"
+ "</binding>"
+ "</result>"
+ "</results>"
+ "</sparql>";
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>"
+ "<headers xmlns='http://jabber.org/protocol/shim'><header name='Server'>Clayster</header></headers>"
+ "<data><xml>"
+ encodedXml
+ "</xml></data></resp>";
AbstractHttpOverXmpp.Xml xmlProviderValue = (AbstractHttpOverXmpp.Xml) parseAbstractBody(
string, "resp").getData().getChild();
assertEquals(expectedXml, xmlProviderValue.getText());
}
@Test
public void isBase64DataParsedCorrectly() throws Exception {
String base64Data = "iVBORw0KGgoAAAANSUhEUgAAASwAAAGQCAYAAAAUdV17AAAAAXNSR0 ... tVWJd+e+y1AAAAABJRU5ErkJggg==";
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>"
+ "<headers xmlns='http://jabber.org/protocol/shim'><header name='Server'>Clayster</header></headers>"
+ "<data><base64>"
+ base64Data
+ "</base64></data></resp>";
AbstractHttpOverXmpp.Base64 base64ProviderValue = (AbstractHttpOverXmpp.Base64) parseAbstractBody(
string, "resp").getData().getChild();
assertEquals(base64Data, base64ProviderValue.getText());
}
@Test
public void isChunkedBase64DataParsedCorrectly() throws Exception {
String streamId = "Stream0001";
String chunkBase64Data = " <chunkedBase64 streamId='" + streamId + "'/>";
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>"
+ "<headers xmlns='http://jabber.org/protocol/shim'><header name='Server'>Clayster</header></headers>"
+ "<data>"
+ chunkBase64Data
+ "</data></resp>";
AbstractHttpOverXmpp.ChunkedBase64 chunkedBase64Value = (AbstractHttpOverXmpp.ChunkedBase64) parseAbstractBody(
string, "resp").getData().getChild();
assertEquals(streamId, chunkedBase64Value.getStreamId());
}
@Test
public void isIbbDataParsedCorrectly() throws Exception {
String sid = "Stream0002";
String ibbData = " <ibb sid='" + sid + "'/>";
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'>"
+ "<headers xmlns='http://jabber.org/protocol/shim'><header name='Server'>Clayster</header></headers>"
+ "<data>"
+ ibbData
+ "</data></resp>";
AbstractHttpOverXmpp.Ibb ibbValue = (AbstractHttpOverXmpp.Ibb) parseAbstractBody(
string, "resp").getData().getChild();
assertEquals(sid, ibbValue.getSid());
}
private AbstractHttpOverXmpp.AbstractBody parseAbstractBody(String string, String tag) throws Exception {
AbstractHttpOverXmppProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = TestUtils.getParser(string, tag);
IQ iq = provider.parseIQ(parser);
assertTrue(iq instanceof HttpOverXmppResp);
AbstractHttpOverXmpp.AbstractBody body = ((HttpOverXmppResp) iq).getResp();
return body;
}
private void checkHeaders(HeadersExtension headers, Map<String, String> expectedHeaders) {
Collection<Header> collection = headers.getHeaders();
assertEquals(collection.size(), expectedHeaders.size());
for (Header header : collection) {
assertTrue(expectedHeaders.containsKey(header.getName()));
assertEquals(expectedHeaders.get(header.getName()), header.getValue());
}
}
}

View file

@ -0,0 +1,65 @@
/**
*
* Copyright 2014 Andriy Tsykholyas
*
* 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.hoxt.provider;
import org.jivesoftware.smack.packet.PacketExtension;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.hoxt.packet.Base64BinaryChunk;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import static org.junit.Assert.*;
/**
* Tests correct parsing of 'chunk' elements in Message stanza.
*/
public class Base64BinaryChunkProviderTest {
@Test
public void isNonLatsChunkParsedCorrectly() throws Exception {
String base64Text = "iVBORw0KGgoAAAANSUhEUgAAASwAAAGQCAYAA";
String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001'>" + base64Text + "</chunk>";
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
XmlPullParser parser = TestUtils.getParser(string, "chunk");
PacketExtension extension = provider.parseExtension(parser);
assertTrue(extension instanceof Base64BinaryChunk);
Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
assertEquals("Stream0001", chunk.getStreamId());
assertFalse(chunk.isLast());
assertEquals(base64Text, chunk.getText());
}
@Test
public void isLatsChunkParsedCorrectly() throws Exception {
String base64Text = "2uPzi9u+tVWJd+e+y1AAAAABJRU5ErkJggg==";
String string = "<chunk xmlns='urn:xmpp:http' streamId='Stream0001' last='true'>" + base64Text + "</chunk>";
Base64BinaryChunkProvider provider = new Base64BinaryChunkProvider();
XmlPullParser parser = TestUtils.getParser(string, "chunk");
PacketExtension extension = provider.parseExtension(parser);
assertTrue(extension instanceof Base64BinaryChunk);
Base64BinaryChunk chunk = (Base64BinaryChunk) extension;
assertEquals("Stream0001", chunk.getStreamId());
assertTrue(chunk.isLast());
assertEquals(base64Text, chunk.getText());
}
}

View file

@ -0,0 +1,76 @@
/**
*
* Copyright 2014 Andriy Tsykholyas
*
* 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.hoxt.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.hoxt.packet.HttpMethod;
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppReq;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class HttpOverXmppReqProviderTest {
@Test
public void areAllReqAttributesCorrectlyParsed() throws Exception {
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1'/>";
HttpOverXmppReq.Req req = parseReq(string);
assertEquals(req.getVersion(), "1.1");
assertEquals(req.getMethod(), HttpMethod.OPTIONS);
assertEquals(req.getResource(), "*");
}
@Test
public void areGetRequestAttributesCorrectlyParsed() throws Exception {
String string = "<req xmlns='urn:xmpp:http' method='GET' resource='/rdf/xep' version='1.1'/>";
HttpOverXmppReq.Req req = parseReq(string);
assertEquals(req.getVersion(), "1.1");
assertEquals(req.getMethod(), HttpMethod.GET);
assertEquals(req.getResource(), "/rdf/xep");
}
@Test
public void getReqOptionAttributesCorrectlyParsed() throws Exception {
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1' maxChunkSize='256' sipub='false' ibb='true' jingle='false'/>";
HttpOverXmppReq.Req req = parseReq(string);
assertEquals(req.getMaxChunkSize(), 256);
assertEquals(req.isSipub(), false);
assertEquals(req.isIbb(), true);
assertEquals(req.isJingle(), false);
}
@Test
public void getReqOptionalAttributesDefaultValues() throws Exception {
String string = "<req xmlns='urn:xmpp:http' method='OPTIONS' resource='*' version='1.1'/>";
HttpOverXmppReq.Req req = parseReq(string);
assertEquals(req.isSipub(), true);
assertEquals(req.isIbb(), true);
assertEquals(req.isJingle(), true);
}
private HttpOverXmppReq.Req parseReq(String string) throws Exception {
HttpOverXmppReqProvider provider = new HttpOverXmppReqProvider();
XmlPullParser parser = TestUtils.getParser(string, "req");
IQ iq = provider.parseIQ(parser);
assertTrue(iq instanceof HttpOverXmppReq);
HttpOverXmppReq castedIq = (HttpOverXmppReq) iq;
return castedIq.getReq();
}
}

View file

@ -0,0 +1,63 @@
/**
*
* Copyright 2014 Andriy Tsykholyas
*
* 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.hoxt.provider;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.test.util.TestUtils;
import org.jivesoftware.smackx.hoxt.packet.HttpOverXmppResp;
import org.junit.Test;
import org.xmlpull.v1.XmlPullParser;
import static org.junit.Assert.*;
/**
* Tests correct attribute parsing in 'resp' element.
*/
public class HttpOverXmppRespProviderTest {
@Test
public void areAllRespAttributesCorrectlyParsed() throws Exception {
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200' statusMessage='OK'/>";
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = TestUtils.getParser(string, "resp");
IQ iq = provider.parseIQ(parser);
assertTrue(iq instanceof HttpOverXmppResp);
HttpOverXmppResp castedIq = (HttpOverXmppResp) iq;
HttpOverXmppResp.Resp resp = castedIq.getResp();
assertEquals(resp.getVersion(), "1.1");
assertEquals(resp.getStatusCode(), 200);
assertEquals(resp.getStatusMessage(), "OK");
}
@Test
public void areRespAttributesWothoutMessageCorrectlyParsed() throws Exception {
String string = "<resp xmlns='urn:xmpp:http' version='1.1' statusCode='200'/>";
HttpOverXmppRespProvider provider = new HttpOverXmppRespProvider();
XmlPullParser parser = TestUtils.getParser(string, "resp");
IQ iq = provider.parseIQ(parser);
assertTrue(iq instanceof HttpOverXmppResp);
HttpOverXmppResp castedIq = (HttpOverXmppResp) iq;
HttpOverXmppResp.Resp resp = castedIq.getResp();
assertEquals(resp.getVersion(), "1.1");
assertEquals(resp.getStatusCode(), 200);
assertNull(resp.getStatusMessage());
}
}