mirror of
https://github.com/vanitasvitae/Smack.git
synced 2025-09-11 01:59:38 +02:00
Add initializer tests and move classpath files
The initializer tests verify that every non-optional initializer, this includes Providers, is loadable. Creating files under META-INF is not considered best practice. Smack's configuration and provider files reside now in classpath directory qualified by Smack's package namespace.
This commit is contained in:
parent
8d3814a8a7
commit
2ad517b6dd
30 changed files with 411 additions and 141 deletions
|
@ -1,16 +0,0 @@
|
|||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.provider.UrlProviderFileInitializer;
|
||||
|
||||
/**
|
||||
* Loads the default provider file for the Smack extensions on initialization.
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class ExtensionInitializer extends UrlProviderFileInitializer {
|
||||
@Override
|
||||
protected String getFilePath() {
|
||||
return "classpath:META-INF/extension.providers";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.jivesoftware.smackx;
|
||||
|
||||
import org.jivesoftware.smack.initializer.UrlProviderFileInitializer;
|
||||
|
||||
/**
|
||||
* Loads the default provider file for the Smack extensions on initialization.
|
||||
*
|
||||
* @author Robin Collier
|
||||
*
|
||||
*/
|
||||
public class ExtensionsProviderInitializer extends UrlProviderFileInitializer {
|
||||
@Override
|
||||
protected String getFilePath() {
|
||||
return "classpath:org.jivesoftware.smackx/extensions.providers";
|
||||
}
|
||||
}
|
|
@ -0,0 +1,65 @@
|
|||
package org.jivesoftware.smackx;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.jivesoftware.smack.SmackConfiguration;
|
||||
import org.jivesoftware.smack.initializer.SmackInitializer;
|
||||
import org.jivesoftware.smack.util.FileUtils;
|
||||
import org.xmlpull.mxp1.MXParser;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
|
||||
public class ExtensionsStartupClasses implements SmackInitializer {
|
||||
|
||||
private static final String EXTENSIONS_XML = "classpath:org.jivesoftware.smackx/extensions.xml";
|
||||
|
||||
private List<Exception> exceptions = new LinkedList<Exception>();
|
||||
// TODO log
|
||||
|
||||
@Override
|
||||
public void initialize() {
|
||||
InputStream is;
|
||||
XmlPullParser parser;
|
||||
int eventType;
|
||||
try {
|
||||
is = FileUtils.getStreamForUrl(EXTENSIONS_XML, null);
|
||||
parser = new MXParser();
|
||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||
parser.setInput(is, "UTF-8");
|
||||
eventType = parser.getEventType();
|
||||
}
|
||||
catch (Exception e) {
|
||||
exceptions.add(e);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
do {
|
||||
String name = parser.getName();
|
||||
if (eventType == XmlPullParser.START_TAG) {
|
||||
if ("startupClasses".equals(name)) {
|
||||
try {
|
||||
SmackConfiguration.parseClassesToLoad(parser, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
eventType = parser.next();
|
||||
}
|
||||
while (eventType != XmlPullParser.END_DOCUMENT);
|
||||
is.close();
|
||||
}
|
||||
catch (Exception e) {
|
||||
exceptions.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Exception> getExceptions() {
|
||||
return Collections.unmodifiableList(exceptions);
|
||||
}
|
||||
|
||||
}
|
|
@ -442,4 +442,11 @@
|
|||
<className>org.jivesoftware.smackx.forward.provider.ForwardedProvider</className>
|
||||
</extensionProvider>
|
||||
|
||||
<!-- Ping (XEP-199) Manager -->
|
||||
<iqProvider>
|
||||
<elementName>ping</elementName>
|
||||
<namespace>urn:xmpp:ping</namespace>
|
||||
<className>org.jivesoftware.smackx.ping.provider.PingProvider</className>
|
||||
</iqProvider>
|
||||
|
||||
</smackProviders>
|
|
@ -0,0 +1,13 @@
|
|||
<smack>
|
||||
<startupClasses>
|
||||
<className>org.jivesoftware.smackx.disco.ServiceDiscoveryManager</className>
|
||||
<className>org.jivesoftware.smackx.xhtmlim.XHTMLManager</className>
|
||||
<className>org.jivesoftware.smackx.muc.MultiUserChat</className>
|
||||
<className>org.jivesoftware.smackx.bytestreams.ibb.InBandBytestreamManager</className>
|
||||
<className>org.jivesoftware.smackx.bytestreams.socks5.Socks5BytestreamManager</className>
|
||||
<className>org.jivesoftware.smackx.filetransfer.FileTransferManager</className>
|
||||
<className>org.jivesoftware.smackx.iqlast.LastActivityManager</className>
|
||||
<className>org.jivesoftware.smackx.commands.AdHocCommandManager</className>
|
||||
<className>org.jivesoftware.smackx.ping.PingManager</className>
|
||||
</startupClasses>
|
||||
</smack>
|
|
@ -0,0 +1,16 @@
|
|||
package org.jivesoftware.smackx;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtensionsProviderInitializerTest {
|
||||
|
||||
@Test
|
||||
public void testExtensionProviderInitializer() {
|
||||
ExtensionsProviderInitializer ei = new ExtensionsProviderInitializer();
|
||||
ei.initialize();
|
||||
assertTrue(ei.getExceptions().size() == 0);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.jivesoftware.smackx;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class ExtensionsStartupClassesTest {
|
||||
|
||||
@Test
|
||||
public void testExtensiosnStartupClasses() {
|
||||
ExtensionsStartupClasses esc = new ExtensionsStartupClasses();
|
||||
esc.initialize();
|
||||
assertTrue(esc.getExceptions().size() == 0);
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue