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

Renamed smack-jingle to smack-jingle-old

Also renamed package name from

org.jivesoftware.smackx.jingle

to

org.jivesoftware.smackx.jingleold
This commit is contained in:
Florian Schmaus 2014-08-20 00:25:57 +02:00
parent 6ab2bf9fe0
commit f65c0d5528
128 changed files with 300 additions and 300 deletions

View file

@ -0,0 +1,538 @@
package org.jivesoftware.smackx.jingle;
/**
* <p/>
* Copyright 2003-2006 Jive Software.
* <p/>
* 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
* <p/>
* http://www.apache.org/licenses/LICENSE-2.0
* <p/>
* 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.
*/
import org.jivesoftware.smack.TCPConnection;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener;
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.mediaimpl.jmf.AudioChannel;
import org.jivesoftware.smackx.jingle.mediaimpl.jmf.JmfMediaManager;
import org.jivesoftware.smackx.jingle.mediaimpl.jspeex.SpeexMediaManager;
import org.jivesoftware.smackx.jingle.mediaimpl.multi.MultiMediaManager;
import org.jivesoftware.smackx.jingle.mediaimpl.sshare.ScreenShareMediaManager;
import org.jivesoftware.smackx.jingle.nat.BridgedTransportManager;
import org.jivesoftware.smackx.jingle.nat.ICETransportManager;
import org.jivesoftware.smackx.jingle.nat.STUNTransportManager;
import org.jivesoftware.smackx.jingle.packet.JingleError;
import javax.media.MediaLocator;
import javax.media.format.AudioFormat;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.List;
/**
* Test the Jingle Media using the high level API
* </p>
*
* @author Thiago Camargo
*/
public class JingleMediaTest extends SmackTestCase {
public JingleMediaTest(final String name) {
super(name);
}
public void testCompleteJmf() {
XMPPTCPConnection x0 = getConnection(0);
XMPPTCPConnection x1 = getConnection(1);
for (int i = 0; i < 1; i++)
try {
ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478);
ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478);
JingleMediaManager jingleMediaManager0 = new JmfMediaManager(icetm0);
JingleMediaManager jingleMediaManager1 = new JmfMediaManager(icetm1);
List<JingleMediaManager> jml0 = new ArrayList<JingleMediaManager>();
List<JingleMediaManager> jml1 = new ArrayList<JingleMediaManager>();
jml0.add(jingleMediaManager0);
jml1.add(jingleMediaManager1);
final JingleManager jm0 = new JingleManager(x0, jml0);
final JingleManager jm1 = new JingleManager(x1, jml1);
jm0.addCreationListener(icetm0);
jm1.addCreationListener(icetm1);
JingleSessionRequestListener jingleSessionRequestListener = new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
try {
JingleSession session = request.accept();
session.startIncoming();
// session.addStateListener(new JingleSessionStateListener() {
// public void beforeChange(JingleNegotiator.State old, JingleNegotiator.State newOne)
// throws JingleNegotiator.JingleException {
// if (newOne instanceof IncomingJingleSession.Active) {
// throw new JingleNegotiator.JingleException();
// }
// }
//
// public void afterChanged(JingleNegotiator.State old, JingleNegotiator.State newOne) {
//
// }
// });
} catch (XMPPException e) {
e.printStackTrace();
}
}
};
jm1.addJingleSessionRequestListener(jingleSessionRequestListener);
JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.startOutgoing();
Thread.sleep(20000);
JingleSession incomingJingleSession = jm1.getSession(js0.getConnection().getUser());
//JingleSession.removeAllStateListeners();
Thread.sleep(15000);
js0.terminate();
jm1.removeJingleSessionRequestListener(jingleSessionRequestListener);
Thread.sleep(60000);
} catch (Exception e) {
e.printStackTrace();
}
}
public void testCompleteMulti() {
try {
XMPPTCPConnection x0 = getConnection(0);
XMPPTCPConnection x1 = getConnection(1);
ICETransportManager icetm0 = new ICETransportManager(x0, "jivesoftware.com", 3478);
ICETransportManager icetm1 = new ICETransportManager(x1, "jivesoftware.com", 3478);
MultiMediaManager jingleMediaManager0 = new MultiMediaManager(icetm0);
jingleMediaManager0.addMediaManager(new JmfMediaManager(icetm0));
jingleMediaManager0.addMediaManager(new SpeexMediaManager(icetm0));
jingleMediaManager0.setPreferredPayloadType(jingleMediaManager0.getPayloads().get(1));
List<JingleMediaManager> jml0 = new ArrayList<JingleMediaManager>();
jml0.add(jingleMediaManager0);
MultiMediaManager jingleMediaManager1 = new MultiMediaManager(icetm1);
jingleMediaManager1.addMediaManager(new JmfMediaManager(icetm1));
jingleMediaManager1.addMediaManager(new SpeexMediaManager(icetm1));
jingleMediaManager1.setPreferredPayloadType(jingleMediaManager1.getPayloads().get(2));
List<JingleMediaManager> jml1 = new ArrayList<JingleMediaManager>();
jml1.add(jingleMediaManager1);
final JingleManager jm0 = new JingleManager(x0, jml0);
final JingleManager jm1 = new JingleManager(x1, jml1);
jm0.addCreationListener(icetm0);
jm1.addCreationListener(icetm1);
jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
try {
JingleSession session = request.accept();
try {
Thread.sleep(12000);
} catch (InterruptedException e) {
e.printStackTrace();
}
session.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
for (int i = 0; i < 10; i++) {
JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
// js0.addStateListener(new JingleSessionStateListener() {
//
// public void beforeChange(JingleNegotiator.State old, JingleNegotiator.State newOne)
// throws JingleNegotiator.JingleException {
// }
//
// public void afterChanged(JingleNegotiator.State old, JingleNegotiator.State newOne) {
// if (newOne != null) {
// if ((newOne instanceof OutgoingJingleSession.Active))
// System.err.println("|||" + newOne.getClass().getCanonicalName() + "|||");
// }
// }
// });
js0.startOutgoing();
Thread.sleep(45000);
js0.terminate();
Thread.sleep(1500);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public void testCompleteSpeex() {
try {
//TCPConnection.DEBUG_ENABLED = true;
XMPPTCPConnection x0 = getConnection(0);
XMPPTCPConnection x1 = getConnection(1);
JingleMediaManager jingleMediaManager0 = new SpeexMediaManager(new STUNTransportManager());
JingleMediaManager jingleMediaManager1 = new SpeexMediaManager(new STUNTransportManager());
List<JingleMediaManager> jml0 = new ArrayList<JingleMediaManager>();
List<JingleMediaManager> jml1 = new ArrayList<JingleMediaManager>();
jml0.add(jingleMediaManager0);
jml1.add(jingleMediaManager1);
final JingleManager jm0 = new JingleManager(x0, jml0);
final JingleManager jm1 = new JingleManager(x1, jml1);
jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
try {
JingleSession session = request.accept();
session.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.startOutgoing();
Thread.sleep(150000);
js0.terminate();
Thread.sleep(6000);
x0.disconnect();
x1.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
public void testCompleteScreenShare() {
try {
XMPPTCPConnection x0 = getConnection(0);
XMPPTCPConnection x1 = getConnection(1);
ICETransportManager icetm0 = new ICETransportManager(x0, "stun.xten.net", 3478);
ICETransportManager icetm1 = new ICETransportManager(x1, "stun.xten.net", 3478);
JingleMediaManager jingleMediaManager0 = new ScreenShareMediaManager(icetm0);
JingleMediaManager jingleMediaManager1 = new ScreenShareMediaManager(icetm1);
List<JingleMediaManager> jml0 = new ArrayList<JingleMediaManager>();
List<JingleMediaManager> jml1 = new ArrayList<JingleMediaManager>();
jml0.add(jingleMediaManager0);
jml1.add(jingleMediaManager1);
final JingleManager jm0 = new JingleManager(x0, jml0);
final JingleManager jm1 = new JingleManager(x1, jml1);
jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
try {
JingleSession session = request.accept();
session.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.startOutgoing();
Thread.sleep(150000);
js0.terminate();
Thread.sleep(6000);
x0.disconnect();
x1.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
public void testCompleteWithBridge() {
for (int i = 0; i < 1; i += 2) {
final int n = i;
Thread t = new Thread(new Runnable() {
public void run() {
try {
XMPPTCPConnection x0 = getConnection(n);
XMPPTCPConnection x1 = getConnection(n + 1);
BridgedTransportManager btm0 = new BridgedTransportManager(x0);
BridgedTransportManager btm1 = new BridgedTransportManager(x1);
JingleMediaManager jingleMediaManager0 = new JmfMediaManager(btm0);
JingleMediaManager jingleMediaManager1 = new JmfMediaManager(btm1);
List<JingleMediaManager> jml0 = new ArrayList<JingleMediaManager>();
List<JingleMediaManager> jml1 = new ArrayList<JingleMediaManager>();
jml0.add(jingleMediaManager0);
jml1.add(jingleMediaManager1);
final JingleManager jm0 = new JingleManager(x0, jml0);
final JingleManager jm1 = new JingleManager(x1, jml1);
jm0.addCreationListener(btm0);
jm1.addCreationListener(btm1);
jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
try {
JingleSession session = request.accept();
session.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.startOutgoing();
Thread.sleep(20000);
//js0.sendFormattedError(JingleError.UNSUPPORTED_TRANSPORTS);
js0.sendPacket(js0.createJingleError(null, JingleError.UNSUPPORTED_TRANSPORTS));
Thread.sleep(20000);
js0.terminate();
Thread.sleep(3000);
x0.disconnect();
x1.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.start();
}
try {
Thread.sleep(250000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
public void testCompleteWithBridgeB() {
try {
//TCPConnection.DEBUG_ENABLED = true;
XMPPTCPConnection x0 = getConnection(0);
XMPPTCPConnection x1 = getConnection(1);
BridgedTransportManager btm0 = new BridgedTransportManager(x0);
BridgedTransportManager btm1 = new BridgedTransportManager(x1);
JingleMediaManager jingleMediaManager0 = new JmfMediaManager(btm0);
JingleMediaManager jingleMediaManager1 = new JmfMediaManager(btm1);
List<JingleMediaManager> jml0 = new ArrayList<JingleMediaManager>();
List<JingleMediaManager> jml1 = new ArrayList<JingleMediaManager>();
jml0.add(jingleMediaManager0);
jml1.add(jingleMediaManager1);
final JingleManager jm0 = new JingleManager(x0, jml0);
final JingleManager jm1 = new JingleManager(x1, jml1);
jm1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
public void sessionRequested(final JingleSessionRequest request) {
try {
JingleSession session = request.accept();
session.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
JingleSession js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.startOutgoing();
Thread.sleep(20000);
js0.terminate();
Thread.sleep(3000);
js0 = jm0.createOutgoingJingleSession(x1.getUser());
js0.startOutgoing();
Thread.sleep(20000);
js0.terminate();
Thread.sleep(3000);
x0.disconnect();
x1.disconnect();
} catch (Exception e) {
e.printStackTrace();
}
}
public void testAudioChannelOpenClose() {
for (int i = 0; i < 5; i++) {
try {
AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost()
.getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7002, 7020, new AudioFormat(
AudioFormat.GSM_RTP), null);
AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost()
.getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7020, 7002, new AudioFormat(
AudioFormat.GSM_RTP), null);
audioChannel0.start();
audioChannel1.start();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
audioChannel0.stop();
audioChannel1.stop();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
public void testAudioChannelStartStop() {
try {
AudioChannel audioChannel0 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost()
.getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7002, 7020,
new AudioFormat(AudioFormat.GSM_RTP), null);
AudioChannel audioChannel1 = new AudioChannel(new MediaLocator("javasound://"), InetAddress.getLocalHost()
.getHostAddress(), InetAddress.getLocalHost().getHostAddress(), 7020, 7002,
new AudioFormat(AudioFormat.GSM_RTP), null);
for (int i = 0; i < 5; i++) {
audioChannel0.start();
audioChannel1.start();
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
audioChannel0.stop();
audioChannel1.stop();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
protected int getMaxConnections() {
return 2;
}
}

View file

@ -0,0 +1,84 @@
/**
*
* 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.jingle;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager;
import org.jivesoftware.smackx.jingle.nat.FixedResolver;
import org.jivesoftware.smackx.jingle.nat.FixedTransportManager;
import java.util.ArrayList;
import java.util.List;
public class JingleSessionTest extends SmackTestCase {
public JingleSessionTest(final String name) {
super(name);
}
public void testEqualsObject() {
FixedResolver tr1 = new FixedResolver("127.0.0.1", 54222);
FixedTransportManager ftm1 = new FixedTransportManager(tr1);
TestMediaManager tmm1 = new TestMediaManager(ftm1);
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(tmm1);
JingleSession js1 = new JingleSession(getConnection(0), "res1", null, "10", trl1);
JingleSession js2 = new JingleSession(getConnection(1), "res1", null, "10", trl1);
JingleSession js3 = new JingleSession(getConnection(2), "res2", null, "11", trl1);
System.out.println(js1.getSid());
System.out.println(js2.getSid());
js1.setInitiator("js1");
js2.setInitiator("js1");
js1.setSid("10");
js2.setSid("10");
assertEquals(js1, js2);
assertEquals(js2, js1);
assertFalse(js1.equals(js3));
}
public void testGetInstanceFor() {
String ini1 = "initiator1";
String sid1 = "sid1";
String ini2 = "initiator2";
String sid2 = "sid2";
FixedResolver tr1 = new FixedResolver("127.0.0.1", 54222);
FixedTransportManager ftm1 = new FixedTransportManager(tr1);
TestMediaManager tmm1 = new TestMediaManager(ftm1);
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(tmm1);
JingleSession js1 = new JingleSession(getConnection(0), ini1, null, sid1, trl1);
JingleSession js2 = new JingleSession(getConnection(1), ini2, null, sid2, trl1);
// For a packet, we should be able to get a session that handles that...
assertNotNull(JingleSession.getInstanceFor(getConnection(0)));
assertNotNull(JingleSession.getInstanceFor(getConnection(1)));
assertEquals(JingleSession.getInstanceFor(getConnection(0)), js1);
assertEquals(JingleSession.getInstanceFor(getConnection(1)), js2);
}
protected int getMaxConnections() {
return 3;
}
}

View file

@ -0,0 +1,37 @@
/**
*
* 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.jingle;
import junit.framework.Test;
import junit.framework.TestSuite;
/**
* Test suite that runs all the Jingle support tests
*
* @author Alvaro Saurin
*/
public class JingleSupportTests {
public static Test suite() {
TestSuite suite = new TestSuite("High and low level API tests for Jingle support");
// $JUnit-BEGIN$
suite.addTest(new TestSuite(JingleManagerTest.class));
// $JUnit-END$
return suite;
}
}

View file

@ -0,0 +1,104 @@
/**
*
* 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.jingle;
import java.util.ArrayList;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.media.PayloadType.Audio;
public class PayloadTypeTest extends SmackTestCase {
public PayloadTypeTest(final String arg0) {
super(arg0);
}
public void testEqualsObject() {
PayloadType p1 = new PayloadType(0, "pt1", 2);
PayloadType p2 = new PayloadType(0, "pt1", 2);
assertTrue(p1.equals(p2));
}
/**
* Test for the difference of payloads.
*/
public void testDifference() {
ArrayList<Audio> set1 = new ArrayList<Audio>();
ArrayList<Audio> set2 = new ArrayList<Audio>();
PayloadType.Audio common1 = new PayloadType.Audio(34, "supercodec-1", 2, 14000);
PayloadType.Audio common2 = new PayloadType.Audio(56, "supercodec-2", 1, 44000);
set1.add(common1);
set1.add(common2);
set1.add(new PayloadType.Audio(36, "supercodec-3", 2, 28000));
set1.add(new PayloadType.Audio(45, "supercodec-4", 1, 98000));
set2.add(new PayloadType.Audio(27, "supercodec-3", 2, 28000));
set2.add(common2);
set2.add(new PayloadType.Audio(32, "supercodec-4", 1, 98000));
set2.add(common1);
// Get the difference
ArrayList<Audio> commonSet = new ArrayList<Audio>();
commonSet.addAll(set1);
commonSet.retainAll(set2);
assertTrue(commonSet.size() == 2);
System.out.println("Codec " + ((PayloadType.Audio)commonSet.get(0)).getId());
System.out.println("Codec " + ((PayloadType.Audio)commonSet.get(1)).getId());
assertTrue(commonSet.contains(common1));
assertTrue(commonSet.contains(common2));
}
/**
* Test for the difference of payloads when we are handling the same sets.
*/
public void testDifferenceSameSet() {
ArrayList<Audio> set1 = new ArrayList<Audio>();
ArrayList<Audio> set2 = new ArrayList<Audio>();
PayloadType.Audio common1 = new PayloadType.Audio(34, "supercodec-1", 2, 14000);
PayloadType.Audio common2 = new PayloadType.Audio(56, "supercodec-2", 1, 44000);
PayloadType.Audio common3 = new PayloadType.Audio(0, "supercodec-3", 1, 44000);
PayloadType.Audio common4 = new PayloadType.Audio(120, "supercodec-4", 2, 66060);
set1.add(common1);
set1.add(common2);
set1.add(common3);
set1.add(common4);
set2.add(common1);
set2.add(common2);
set2.add(common3);
set2.add(common4);
// Get the difference
ArrayList<Audio> commonSet = new ArrayList<Audio>();
commonSet.addAll(set1);
commonSet.retainAll(set2);
assertTrue(commonSet.size() == 4);
assertTrue(commonSet.contains(common1));
assertTrue(commonSet.contains(common2));
}
protected int getMaxConnections() {
return 0;
}
}

View file

@ -0,0 +1,117 @@
/**
*
* 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.jingle.nat;
import org.jivesoftware.smack.test.SmackTestCase;
import java.util.ArrayList;
public class BasicResolverTest extends SmackTestCase {
private int counter;
private final Object mutex = new Object();
public BasicResolverTest(String arg) {
super(arg);
}
// Counter management
private void resetCounter() {
synchronized (mutex) {
counter = 0;
}
}
private void incCounter() {
synchronized (mutex) {
counter++;
}
}
private int valCounter() {
int val;
synchronized (mutex) {
val = counter;
}
return val;
}
public void testCheckValidHostname() {
String validHostname = new String("slashdot.org");
BasicResolver br = new BasicResolver();
TransportCandidate tc = new TransportCandidate.Fixed(validHostname, 0);
resetCounter();
tc.addListener(new TransportResolverListener.Checker() {
public void candidateChecked(TransportCandidate cand, boolean result) {
if(result == true) {
System.out.println(cand.getIp() + " is reachable (as expected)");
incCounter();
}
}
public void candidateChecking(TransportCandidate cand) {
}
});
tc.check(new ArrayList<TransportCandidate>());
try {
Thread.sleep(TransportResolver.CHECK_TIMEOUT);
} catch (Exception e) {
}
assertTrue(valCounter() > 0);
}
public void testCheckInvalidHostname() {
String invalidHostname = new String("camupilosupino.org");
BasicResolver br = new BasicResolver();
TransportCandidate tc = new TransportCandidate.Fixed(invalidHostname, 0);
resetCounter();
tc.addListener(new TransportResolverListener.Checker() {
public void candidateChecked(TransportCandidate cand, boolean result) {
if(result == false) {
System.out.println(cand.getIp() + " is _not_ reachable (as expected)");
incCounter();
}
}
public void candidateChecking(TransportCandidate cand) {
}
});
tc.check(new ArrayList<TransportCandidate>());
try {
Thread.sleep(TransportResolver.CHECK_TIMEOUT);
} catch (Exception e) {
}
assertTrue(valCounter() > 0);
}
protected int getMaxConnections() {
return 0;
}
}

View file

@ -0,0 +1,119 @@
/**
*
* 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.jingle.nat;
import org.jivesoftware.smack.test.SmackTestCase;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class BridgedResolverTest extends SmackTestCase {
private int counter;
private final Object mutex = new Object();
public BridgedResolverTest(String arg) {
super(arg);
}
// Counter management
private void resetCounter() {
synchronized (mutex) {
counter = 0;
}
}
private void incCounter() {
synchronized (mutex) {
counter++;
}
}
private int valCounter() {
int val;
synchronized (mutex) {
val = counter;
}
return val;
}
public void testCheckService() {
assertTrue(RTPBridge.serviceAvailable(getConnection(0)));
}
public void testGetBridge() {
resetCounter();
RTPBridge rtpBridge = RTPBridge.getRTPBridge(getConnection(0), "001");
System.out.println(rtpBridge.getIp() + " portA:" + rtpBridge.getPortA() + " portB:" + rtpBridge.getPortB());
if (rtpBridge != null) {
if (rtpBridge.getIp() != null) incCounter();
if (rtpBridge.getPortA() != -1) incCounter();
if (rtpBridge.getPortB() != -1) incCounter();
}
assertTrue(valCounter() == 3);
}
public void testGetPublicIp() {
resetCounter();
String publicIp = RTPBridge.getPublicIP(getConnection(0));
System.out.println(publicIp);
if (publicIp != null) {
incCounter();
}
try {
InetAddress localaddr = InetAddress.getLocalHost();
System.out.println("main Local IP Address : " + localaddr.getHostAddress());
System.out.println("main Local hostname : " + localaddr.getHostName());
InetAddress[] localaddrs = InetAddress.getAllByName("localhost");
for (int i = 0; i < localaddrs.length; i++) {
if (!localaddrs[i].equals(localaddr)) {
System.out.println("alt Local IP Address : " + localaddrs[i].getHostAddress());
System.out.println("alt Local hostname : " + localaddrs[i].getHostName());
System.out.println();
}
}
}
catch (UnknownHostException e) {
System.err.println("Can't detect localhost : " + e);
}
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
e.printStackTrace();
}
assertTrue(valCounter() == 1);
}
protected int getMaxConnections() {
return 1;
}
}

View file

@ -0,0 +1,25 @@
/**
*
* 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.jingle.nat;
import junit.framework.TestCase;
public class LocalhostTest extends TestCase {
public void testGetLocalhost() {
System.out.println(BridgedResolver.getLocalHost());
}
}

View file

@ -0,0 +1,406 @@
/**
*
* 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.jingle.nat;
import de.javawi.jstun.test.demo.StunServer;
import de.javawi.jstun.test.demo.ice.Candidate;
import de.javawi.jstun.test.demo.ice.ICENegociator;
import de.javawi.jstun.util.UtilityException;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.jingle.JingleManager;
import org.jivesoftware.smackx.jingle.JingleSession;
import org.jivesoftware.smackx.jingle.JingleSessionRequest;
import org.jivesoftware.smackx.jingle.listeners.JingleSessionListener;
import org.jivesoftware.smackx.jingle.listeners.JingleSessionRequestListener;
import org.jivesoftware.smackx.jingle.media.JingleMediaManager;
import org.jivesoftware.smackx.jingle.media.PayloadType;
import org.jivesoftware.smackx.jingle.mediaimpl.test.TestMediaManager;
import org.jivesoftware.smackx.jingle.nat.STUNResolver.STUNService;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
/**
* Test the STUN IP resolver.
*
* @author Thiago Camargo
*/
public class STUNResolverTest extends SmackTestCase {
// Counter management
public STUNResolverTest(final String arg) {
super(arg);
}
private int counter;
private final Object mutex = new Object();
private void resetCounter() {
synchronized (mutex) {
counter = 0;
}
}
private void incCounter() {
synchronized (mutex) {
counter++;
}
}
private int valCounter() {
int val;
synchronized (mutex) {
val = counter;
}
return val;
}
/**
* Test for getPreferredCandidate()
*
* @throws Exception
*/
public void testGetPreferredCandidate() throws Exception {
int highestPref = 100;
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2, "password", 3468, "username1", 1, ICECandidate.Type.prflx);
TransportCandidate cand2 = new ICECandidate("192.168.5.1", 2, 10, "password", 3469, "username2", 15,
ICECandidate.Type.prflx);
TransportCandidate candH = new ICECandidate("192.168.2.11", 1, 2, "password", 3468, "usernameH", highestPref,
ICECandidate.Type.prflx);
TransportCandidate cand3 = new ICECandidate("192.168.2.10", 2, 10, "password", 3469, "username3", 2,
ICECandidate.Type.prflx);
TransportCandidate cand4 = new ICECandidate("192.168.4.1", 3, 2, "password", 3468, "username4", 78, ICECandidate.Type.prflx);
STUNResolver stunResolver = new STUNResolver() {
};
stunResolver.addCandidate(cand1);
stunResolver.addCandidate(cand2);
stunResolver.addCandidate(candH);
stunResolver.addCandidate(cand3);
stunResolver.addCandidate(cand4);
assertEquals(stunResolver.getPreferredCandidate(), candH);
}
/**
* Test for getPreferredCandidate()
*
* @throws Exception
*/
public void testGetPreferredCandidateICE() throws Exception {
int highestPref = 100;
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 3, 2, "password", 3468, "username1", 1, ICECandidate.Type.prflx);
TransportCandidate cand2 = new ICECandidate("192.168.5.1", 2, 10, "password", 3469, "username2", 15,
ICECandidate.Type.prflx);
TransportCandidate candH = new ICECandidate("192.168.2.11", 1, 2, "password", 3468, "usernameH", highestPref,
ICECandidate.Type.prflx);
TransportCandidate cand3 = new ICECandidate("192.168.2.10", 2, 10, "password", 3469, "username3", 2,
ICECandidate.Type.prflx);
TransportCandidate cand4 = new ICECandidate("192.168.4.1", 3, 2, "password", 3468, "username4", 78, ICECandidate.Type.prflx);
ICEResolver iceResolver = new ICEResolver(getConnection(0), "stun.xten.net", 3478) {
};
iceResolver.addCandidate(cand1);
iceResolver.addCandidate(cand2);
iceResolver.addCandidate(candH);
iceResolver.addCandidate(cand3);
iceResolver.addCandidate(cand4);
assertEquals(iceResolver.getPreferredCandidate(), candH);
}
/**
* Test priority generated by STUN lib
*
* @throws Exception
*/
public void testICEPriority() throws Exception {
String first = "";
for (int i = 0; i < 100; i++) {
ICENegociator cc = new ICENegociator((short) 1);
// gather candidates
cc.gatherCandidateAddresses();
// priorize candidates
cc.prioritizeCandidates();
// get SortedCandidates
for (Candidate candidate : cc.getSortedCandidates()) {
short nicNum = 0;
try {
Enumeration<NetworkInterface> nics = NetworkInterface.getNetworkInterfaces();
short tempNic = 0;
NetworkInterface nic = NetworkInterface.getByInetAddress(candidate.getAddress().getInetAddress());
while(nics.hasMoreElements()) {
NetworkInterface checkNIC = nics.nextElement();
if (checkNIC.equals(nic)) {
nicNum = tempNic;
break;
}
i++;
}
} catch (SocketException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
TransportCandidate transportCandidate = new ICECandidate(candidate.getAddress().getInetAddress()
.getHostAddress(), 1, nicNum, "1", candidate.getPort(), "1", candidate.getPriority(),
ICECandidate.Type.prflx);
transportCandidate.setLocalIp(candidate.getBase().getAddress().getInetAddress().getHostAddress());
System.out.println("C: " + candidate.getAddress().getInetAddress() + "|"
+ candidate.getBase().getAddress().getInetAddress() + " p:" + candidate.getPriority());
} catch (UtilityException e) {
e.printStackTrace();
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
Candidate candidate = cc.getSortedCandidates().get(0);
String temp = "C: " + candidate.getAddress().getInetAddress() + "|" + candidate.getBase().getAddress().getInetAddress()
+ " p:" + candidate.getPriority();
if (first.equals(""))
first = temp;
assertEquals(first, temp);
first = temp;
}
}
/**
* Test for loadSTUNServers()
*
* @throws Exception
*/
public void testLoadSTUNServers() throws Exception {
STUNResolver stunResolver = new STUNResolver() {
};
ArrayList<STUNService> stunServers = stunResolver.loadSTUNServers();
assertTrue(stunServers.size() > 0);
System.out.println(stunServers.size() + " servers loaded");
}
public void testGetSTUNServer() {
System.out.println(STUN.serviceAvailable(getConnection(0)));
STUN stun = STUN.getSTUNServer(getConnection(0));
for (STUN.StunServerAddress stunServerAddress : stun.getServers())
System.out.println(stunServerAddress.getServer() + ":" + stunServerAddress.getPort());
System.out.println(stun.getPublicIp());
}
/**
* Test for resolve()
*
* @throws Exception
*/
public void testResolve() throws Exception {
final STUNResolver stunResolver = new STUNResolver() {
};
stunResolver.addListener(new TransportResolverListener.Resolver() {
public void candidateAdded(final TransportCandidate cand) {
incCounter();
String addr = cand.getIp();
int port = cand.getPort();
System.out.println("Addr: " + addr + " port:" + port);
}
public void init() {
System.out.println("Resolution started");
}
public void end() {
System.out.println("Resolution finished");
}
});
try {
stunResolver.initializeAndWait();
Thread.sleep(55000);
assertTrue(valCounter() > 0);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* Generate a list of payload types
*
* @return A testing list
*/
private ArrayList<PayloadType> getTestPayloads1() {
ArrayList<PayloadType> result = new ArrayList<PayloadType>();
result.add(new PayloadType.Audio(34, "supercodec-1", 2, 14000));
result.add(new PayloadType.Audio(56, "supercodec-2", 1, 44000));
result.add(new PayloadType.Audio(36, "supercodec-3", 2, 28000));
result.add(new PayloadType.Audio(45, "supercodec-4", 1, 98000));
return result;
}
private ArrayList<PayloadType> getTestPayloads2() {
ArrayList<PayloadType> result = new ArrayList<PayloadType>();
result.add(new PayloadType.Audio(27, "supercodec-3", 2, 28000));
result.add(new PayloadType.Audio(56, "supercodec-2", 1, 44000));
result.add(new PayloadType.Audio(32, "supercodec-4", 1, 98000));
result.add(new PayloadType.Audio(34, "supercodec-1", 2, 14000));
return result;
}
/**
* This is a simple test where the user_2 rejects the Jingle session.
*/
public void testSTUNJingleSession() {
resetCounter();
try {
TransportResolver tr1 = new STUNResolver() {
};
TransportResolver tr2 = new STUNResolver() {
};
// Explicit resolution
tr1.resolve(null);
tr2.resolve(null);
STUNTransportManager stm0 = new STUNTransportManager();
TestMediaManager tmm0 = new TestMediaManager(stm0);
tmm0.setPayloads(getTestPayloads1());
List<JingleMediaManager> trl0 = new ArrayList<JingleMediaManager>();
trl0.add(tmm0);
STUNTransportManager stm1 = new STUNTransportManager();
TestMediaManager tmm1 = new TestMediaManager(stm1);
tmm1.setPayloads(getTestPayloads2());
List<JingleMediaManager> trl1 = new ArrayList<JingleMediaManager>();
trl1.add(tmm1);
final JingleManager man0 = new JingleManager(getConnection(0), trl0);
final JingleManager man1 = new JingleManager(getConnection(1), trl1);
man1.addJingleSessionRequestListener(new JingleSessionRequestListener() {
/**
* Called when a new session request is detected
*/
public void sessionRequested(final JingleSessionRequest request) {
System.out.println("Session request detected, from " + request.getFrom() + ": accepting.");
// We accept the request
JingleSession session1;
try {
session1 = request.accept();
session1.addListener(new JingleSessionListener() {
public void sessionClosed(String reason, JingleSession jingleSession) {
}
public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
}
public void sessionDeclined(String reason, JingleSession jingleSession) {
}
public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc,
JingleSession jingleSession) {
incCounter();
System.out.println("Responder: the session is fully established.");
System.out.println("+ Payload Type: " + pt.getId());
System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
}
public void sessionRedirected(String redirection, JingleSession jingleSession) {
}
public void sessionMediaReceived(JingleSession jingleSession, String participant) {
// Do Nothing
}
});
session1.startIncoming();
} catch (XMPPException e) {
e.printStackTrace();
}
}
});
// Session 0 starts a request
System.out.println("Starting session request, to " + getFullJID(1) + "...");
JingleSession session0 = man0.createOutgoingJingleSession(getFullJID(1));
session0.addListener(new JingleSessionListener() {
public void sessionClosed(String reason, JingleSession jingleSession) {
}
public void sessionClosedOnError(XMPPException e, JingleSession jingleSession) {
}
public void sessionDeclined(String reason, JingleSession jingleSession) {
}
public void sessionEstablished(PayloadType pt, TransportCandidate rc, TransportCandidate lc,
JingleSession jingleSession) {
incCounter();
System.out.println("Initiator: the session is fully established.");
System.out.println("+ Payload Type: " + pt.getId());
System.out.println("+ Local IP/port: " + lc.getIp() + ":" + lc.getPort());
System.out.println("+ Remote IP/port: " + rc.getIp() + ":" + rc.getPort());
}
public void sessionMediaReceived(JingleSession jingleSession, String participant) {
// Do Nothing
}
public void sessionRedirected(String redirection, JingleSession jingleSession) {
}
});
session0.startOutgoing();
Thread.sleep(60000);
assertTrue(valCounter() == 2);
} catch (Exception e) {
e.printStackTrace();
fail("An error occured with Jingle");
}
}
protected int getMaxConnections() {
return 2;
}
}

View file

@ -0,0 +1,74 @@
/**
*
* 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.jingle.nat;
import java.util.ArrayList;
import java.util.Collections;
import org.jivesoftware.smack.test.SmackTestCase;
public class TransportCandidateTest extends SmackTestCase {
public TransportCandidateTest(final String arg0) {
super(arg0);
}
/**
* Test for equals()
*/
public void testEqualsObject() {
TransportCandidate cand1 = new ICECandidate("192.168.2.1", 1, 2,
"password", 3468, "username", 25, ICECandidate.Type.prflx);
TransportCandidate cand2 = new ICECandidate("192.168.2.1", 1, 2,
"password", 3468, "username", 25, ICECandidate.Type.prflx);
TransportCandidate cand3 = new ICECandidate("192.168.2.1", 1, 2,
"password", 3469, "username", 25, ICECandidate.Type.prflx);
assertEquals(cand1, cand2);
assertFalse(cand1.equals(cand3));
}
/**
* Test for compareTo()
*/
public void testCompareTo() {
int highestPref = 100;
ICECandidate cand1 = new ICECandidate("192.168.2.1", 3, 2,
"password", 3468, "username", 1, ICECandidate.Type.prflx);
ICECandidate cand2 = new ICECandidate("192.168.5.1", 2, 10,
"password", 3469, "username", 15,ICECandidate.Type.prflx);
ICECandidate candH = new ICECandidate("192.168.2.1", 1, 2,
"password", 3468, "username", highestPref, ICECandidate.Type.prflx);
ICECandidate cand3 = new ICECandidate("192.168.2.10", 2, 10,
"password", 3469, "username", 2, ICECandidate.Type.prflx);
ICECandidate cand4 = new ICECandidate("192.168.4.1", 3, 2,
"password", 3468, "username", 78, ICECandidate.Type.prflx);
ArrayList<ICECandidate> candList = new ArrayList<ICECandidate>();
candList.add(cand1);
candList.add(cand2);
candList.add(candH);
candList.add(cand3);
candList.add(cand4);
Collections.sort(candList);
assertEquals(candList.get(candList.size() - 1), candH);
}
protected int getMaxConnections() {
return 0;
}
}

View file

@ -0,0 +1,64 @@
/**
*
* 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.jingle.nat;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.test.SmackTestCase;
public class TransportResolverTest extends SmackTestCase {
public TransportResolverTest(final String arg) {
super(arg);
}
public void testIsResolving() {
final TransportResolver tr = new BasicResolver();
tr.addListener(
new TransportResolverListener.Resolver() {
public void candidateAdded(final TransportCandidate cand) {
System.out.println("candidateAdded() called.");
assertTrue(tr.isResolving() || (!tr.isResolving() && tr.isResolved()));
}
public void end() {
System.out.println("end() called.");
assertFalse(tr.isResolving());
assertTrue(tr.isResolved());
}
public void init() {
System.out.println("init() called.");
assertTrue(tr.isResolving());
assertFalse(tr.isResolved());
}
});
assertFalse(tr.isResolving());
assertFalse(tr.isResolved());
try {
tr.resolve(null);
} catch (XMPPException e) {
e.printStackTrace();
fail("Error resolving");
}
}
protected int getMaxConnections() {
return 0;
}
}

View file

@ -0,0 +1,126 @@
/**
*
* 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.jingle.provider;
import org.jivesoftware.smack.PacketCollector;
import org.jivesoftware.smack.SmackConfiguration;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.filter.PacketTypeFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.provider.IQProvider;
import org.jivesoftware.smack.provider.ProviderManager;
import org.jivesoftware.smack.test.SmackTestCase;
import org.jivesoftware.smackx.jingle.packet.Jingle;
public class JingleProviderTest extends SmackTestCase {
public JingleProviderTest(final String name) {
super(name);
}
public void testProviderManager() {
IQProvider iqProv;
String elementNamee = Jingle.getElementName();
String nameSpace = Jingle.getNamespace();
System.out.println("Testing if the Jingle IQ provider is registered...");
// Verify that the Jingle IQProvider is registered.
iqProv = (IQProvider)ProviderManager.getInstance().getIQProvider(elementNamee, nameSpace);
assertNotNull(iqProv);
}
/**
* Test for parsing a Jingle
*/
public void testParseIQSimple() {
// Create a dummy packet for testing...
IQfake iqSent = new IQfake (
" <jingle xmlns='urn:xmpp:tmp:jingle'" +
" initiator=\"gorrino@viejo.com\"" +
" responder=\"colico@hepatico.com\"" +
" action=\"transport-info\" sid=\"\">" +
" <transport xmlns='urn:xmpp:tmp:jingle:transports:ice-udp'>" +
" <candidate generation=\"1\"" +
" ip=\"192.168.1.1\"" +
" password=\"secret\"" +
" port=\"8080\"" +
" username=\"username\"" +
" preference=\"1\"/>" +
" </transport>" +
"</jingle>");
iqSent.setTo(getFullJID(0));
iqSent.setFrom(getFullJID(0));
iqSent.setType(IQ.Type.get);
// Create a filter and a collector...
PacketFilter filter = new PacketTypeFilter(IQ.class);
PacketCollector collector = getConnection(0).createPacketCollector(filter);
System.out.println("Testing if a Jingle IQ can be sent and received...");
// Send the iq packet with an invalid namespace
getConnection(0).sendPacket(iqSent);
// Receive the packet
IQ iqReceived = (IQ)collector.nextResult(SmackConfiguration.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();
if (iqReceived == null) {
fail("No response from server");
}
else if (iqReceived.getType() == IQ.Type.error) {
fail("The server did reply with an error packet: " + iqReceived.getError().getCode());
}
else {
assertTrue(iqReceived instanceof Jingle);
Jingle jin = (Jingle) iqReceived;
System.out.println("Sent: " + iqSent.toXML());
System.out.println("Received: " + jin.toXML());
}
}
/**
* Simple class for testing an IQ...
* @author Alvaro Saurin
*/
private class IQfake extends IQ {
private String s;
public IQfake(final String s) {
super();
this.s = s;
}
public String getChildElementXML() {
StringBuilder buf = new StringBuilder();
buf.append(s);
return buf.toString();
}
}
protected int getMaxConnections() {
return 2;
}
}