1
0
Fork 0
mirror of https://github.com/vanitasvitae/Smack.git synced 2025-12-06 19:11:10 +01:00

SmackReactor/NIO, Java8/Android19, Pretty print XML, FSM connections

This commit adds
- SmackReactor / NIO
- a framework for finite state machine connections
- support for Java 8
- pretty printed XML debug output

It also
- reworks the integration test framework
- raises the minimum Android API level to 19
- introduces XmppNioTcpConnection

Furthermore fixes SMACK-801 (at least partly). Java 8 language
features are available, but not all runtime library methods. For that
we would need to raise the Android API level to 24 or higher.
This commit is contained in:
Florian Schmaus 2019-02-04 08:59:39 +01:00
parent dba12919d0
commit e98d42790a
144 changed files with 8692 additions and 1455 deletions

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2015 Florian Schmaus
* Copyright 2015-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,21 +16,39 @@
*/
package org.igniterealtime.smack.inttest;
import org.jivesoftware.smack.tcp.XMPPTCPConnection;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
public class DummySmackIntegrationTestFramework extends SmackIntegrationTestFramework {
import org.jivesoftware.smack.DummyConnection;
import org.jivesoftware.smack.DummyConnection.DummyConnectionConfiguration;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
public DummySmackIntegrationTestFramework(Configuration configuration) {
super(configuration);
public class DummySmackIntegrationTestFramework extends SmackIntegrationTestFramework<DummyConnection> {
static {
try {
XmppConnectionManager.addConnectionDescriptor(DummyConnection.class, DummyConnectionConfiguration.class);
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException e) {
throw new AssertionError(e);
}
}
public DummySmackIntegrationTestFramework(Configuration configuration) throws KeyManagementException,
InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException {
super(configuration, DummyConnection.class);
testRunResult = new TestRunResult();
}
@Override
protected SmackIntegrationTestEnvironment prepareEnvironment() {
return new SmackIntegrationTestEnvironment(null, null, null, testRunResult.getTestRunId(), config);
protected SmackIntegrationTestEnvironment<DummyConnection> prepareEnvironment() {
DummyConnection dummyConnection = new DummyConnection();
connectionManager.conOne = connectionManager.conTwo = connectionManager.conThree = dummyConnection;
return new SmackIntegrationTestEnvironment<DummyConnection>(dummyConnection, dummyConnection, dummyConnection,
testRunResult.getTestRunId(), config, null);
}
@Override
protected void disconnectAndMaybeDelete(XMPPTCPConnection connection) {
// This method is a no-op in DummySmackIntegrationTestFramework
}
}

View file

@ -0,0 +1,96 @@
/**
*
* Copyright 2019 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.igniterealtime.smack.inttest;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.lang.reflect.Method;
import java.util.List;
import org.jivesoftware.smack.AbstractXMPPConnection;
import org.junit.Test;
public class SmackIntegrationTestFrameWorkTest {
private static class ValidLowLevelList {
@SuppressWarnings("unused")
public void test(List<AbstractXMPPConnection> connections) {
}
}
private static class InvalidLowLevelList {
@SuppressWarnings("unused")
public void test(List<AbstractXMPPConnection> connections, boolean invalid) {
}
}
private static class ValidLowLevelVarargs {
@SuppressWarnings("unused")
public void test(AbstractXMPPConnection connectionOne, AbstractXMPPConnection connectionTwo,
AbstractXMPPConnection connectionThree) {
}
}
private static class InvalidLowLevelVarargs {
@SuppressWarnings("unused")
public void test(AbstractXMPPConnection connectionOne, Integer invalid, AbstractXMPPConnection connectionTwo,
AbstractXMPPConnection connectionThree) {
}
}
private static Method getTestMethod(Class<?> testClass) {
Method[] methods = testClass.getDeclaredMethods();
for (Method method : methods) {
if (method.getName().equals("test")) {
return method;
}
}
throw new IllegalArgumentException("No test method found in " + testClass);
}
@Test
public void testValidLowLevelList() {
Method testMethod = getTestMethod(ValidLowLevelList.class);
assertTrue(SmackIntegrationTestFramework.testMethodParametersIsListOfConnections(testMethod,
AbstractXMPPConnection.class));
}
@Test
public void testInvalidLowLevelList() {
Method testMethod = getTestMethod(InvalidLowLevelList.class);
assertFalse(SmackIntegrationTestFramework.testMethodParametersIsListOfConnections(testMethod,
AbstractXMPPConnection.class));
}
@Test
public void testValidLowLevelVarargs() {
Method testMethod = getTestMethod(ValidLowLevelVarargs.class);
assertTrue(SmackIntegrationTestFramework.testMethodParametersVarargsConnections(testMethod,
AbstractXMPPConnection.class));
}
@Test
public void testInvalidLowLevelVargs() {
Method testMethod = getTestMethod(InvalidLowLevelVarargs.class);
assertFalse(SmackIntegrationTestFramework.testMethodParametersVarargsConnections(testMethod,
AbstractXMPPConnection.class));
}
}

View file

@ -16,9 +16,14 @@
*/
package org.igniterealtime.smack.inttest;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import org.jivesoftware.smack.SmackException;
import org.jivesoftware.smack.XMPPException;
import org.jxmpp.jid.JidTestUtil;
public class SmackIntegrationTestUnitTestUtil {
@ -32,7 +37,12 @@ public class SmackIntegrationTestUnitTestUtil {
.setUsernamesAndPassword("dummy1", "dummy1pass", "dummy2", "dummy2pass", "dummy3", "dummy3pass")
.addEnabledTest(unitTest).build();
// @formatter:on
return new DummySmackIntegrationTestFramework(configuration);
try {
return new DummySmackIntegrationTestFramework(configuration);
} catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException
| SmackException | IOException | XMPPException | InterruptedException e) {
throw new IllegalStateException(e);
}
}
}

View file

@ -0,0 +1,45 @@
/**
*
* Copyright 2018-2019 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.igniterealtime.smack.inttest;
import static org.junit.Assert.assertEquals;
import java.lang.reflect.InvocationTargetException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import org.jivesoftware.smack.tcp.XMPPTCPConnectionConfiguration;
import org.jivesoftware.smack.tcp.XmppNioTcpConnection;
import org.junit.Test;
import org.jxmpp.stringprep.XmppStringprepException;
public class SmackIntegrationTestXmppConnectionManagerTest {
@Test
public void simpleXmppConnectionDescriptorTest() throws ClassNotFoundException, NoSuchMethodException,
SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException,
KeyManagementException, NoSuchAlgorithmException, XmppStringprepException, InstantiationException {
XmppConnectionDescriptor<XmppNioTcpConnection, XMPPTCPConnectionConfiguration, XMPPTCPConnectionConfiguration.Builder> descriptor
= new XmppConnectionDescriptor<>(XmppNioTcpConnection.class, XMPPTCPConnectionConfiguration.class);
Configuration sinttestConfiguration = Configuration.builder().setService("example.org").build();
XmppNioTcpConnection connection = descriptor.construct(sinttestConfiguration);
assertEquals("example.org", connection.getXMPPServiceDomain().toString());
}
}

View file

@ -1,6 +1,6 @@
/**
*
* Copyright 2015 Florian Schmaus
* Copyright 2015-2019 Florian Schmaus
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -22,6 +22,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
@ -37,6 +38,7 @@ import org.igniterealtime.smack.inttest.DummySmackIntegrationTestFramework;
import org.igniterealtime.smack.inttest.FailedTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTest;
import org.igniterealtime.smack.inttest.SmackIntegrationTestEnvironment;
import org.igniterealtime.smack.inttest.SmackIntegrationTestFramework;
import org.igniterealtime.smack.inttest.SmackIntegrationTestFramework.TestRunResult;
import org.junit.AfterClass;
import org.junit.BeforeClass;
@ -52,9 +54,19 @@ public class SmackIntegrationTestFrameworkUnitTest {
private static boolean beforeClassInvoked;
private static boolean afterClassInvoked;
@BeforeClass
public static void prepareSinttestUnitTest() {
SmackIntegrationTestFramework.SINTTEST_UNIT_TEST = true;
}
@AfterClass
public static void disallowSinntestUnitTest() {
SmackIntegrationTestFramework.SINTTEST_UNIT_TEST = false;
}
@Test
public void throwsRuntimeExceptionsTest() throws KeyManagementException, NoSuchAlgorithmException, SmackException,
IOException, XMPPException, InterruptedException {
IOException, XMPPException, InterruptedException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
expectedException.expect(RuntimeException.class);
expectedException.expectMessage(ThrowsRuntimeExceptionDummyTest.RUNTIME_EXCEPTION_MESSAGE);
DummySmackIntegrationTestFramework sinttest = getFrameworkForUnitTest(ThrowsRuntimeExceptionDummyTest.class);
@ -63,7 +75,7 @@ public class SmackIntegrationTestFrameworkUnitTest {
public static class ThrowsRuntimeExceptionDummyTest extends AbstractSmackIntegrationTest {
public ThrowsRuntimeExceptionDummyTest(SmackIntegrationTestEnvironment environment) {
public ThrowsRuntimeExceptionDummyTest(SmackIntegrationTestEnvironment<?> environment) {
super(environment);
}
@ -77,7 +89,8 @@ public class SmackIntegrationTestFrameworkUnitTest {
@Test
public void logsNonFatalExceptionTest() throws KeyManagementException, NoSuchAlgorithmException, SmackException,
IOException, XMPPException, InterruptedException {
IOException, XMPPException, InterruptedException, InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
DummySmackIntegrationTestFramework sinttest = getFrameworkForUnitTest(ThrowsNonFatalExceptionDummyTest.class);
TestRunResult testRunResult = sinttest.run();
List<FailedTest> failedTests = testRunResult.getFailedTests();
@ -93,7 +106,7 @@ public class SmackIntegrationTestFrameworkUnitTest {
public static final String DESCRIPTIVE_TEXT = "I'm not fatal";
public ThrowsNonFatalExceptionDummyTest(SmackIntegrationTestEnvironment environment) {
public ThrowsNonFatalExceptionDummyTest(SmackIntegrationTestEnvironment<?> environment) {
super(environment);
}
@ -107,7 +120,8 @@ public class SmackIntegrationTestFrameworkUnitTest {
@Test
public void testInvoking() throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException,
XMPPException, InterruptedException {
XMPPException, InterruptedException, InstantiationException, IllegalAccessException,
IllegalArgumentException, InvocationTargetException {
beforeClassInvoked = false;
afterClassInvoked = false;
@ -120,7 +134,7 @@ public class SmackIntegrationTestFrameworkUnitTest {
public static class BeforeAfterClassTest extends AbstractSmackIntegrationTest {
public BeforeAfterClassTest(SmackIntegrationTestEnvironment environment) {
public BeforeAfterClassTest(SmackIntegrationTestEnvironment<?> environment) {
super(environment);
}