3 Copyright (C) 2007 Jehan Monnier ()
5 P2pAutoConfigTester.java - .
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 package org.linphone.p2pproxy.test;
24 import java.net.InetAddress;
25 import java.net.InetSocketAddress;
26 import java.net.SocketAddress;
28 import junit.framework.Assert;
29 import junit.framework.TestCase;
30 import org.apache.log4j.Logger;
31 import org.apache.log4j.PropertyConfigurator;
32 import org.linphone.p2pproxy.api.P2pProxyInstance;
33 import org.linphone.p2pproxy.api.P2pProxyNetworkProbe;
34 import org.linphone.p2pproxy.api.P2pProxyInstance.Mode;
35 import org.linphone.p2pproxy.core.P2pProxyInstanceImpl;
37 public class P2pAutoConfigTester extends TestCase {
38 static private P2pProxyInstance mP2pProxyInstance;
39 private final static Logger mLog = Logger.getLogger(P2pAutoConfigTester.class);
41 public static void setUpBeforeClass() throws Exception {
43 PropertyConfigurator.configure("log4j.properties");
46 // String lRunString = "java -cp eclipsebuild:dependencies/*.jar ";
47 // //lRunString +=" -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n";
48 // lRunString +=" org.linphone.p2pproxy.core.P2pProxyMain";
49 // lRunString +=" -jxta " +System.getProperty("user.home")+"/P2pAutoConfigTester-seeding";
50 // lRunString +=" -sip 5040 -seeding-server ";
51 // lRunString +=" -seeding-relay http://"+InetAddress.getLocalHost().getHostAddress()+":"+P2pProxyInstance.BASE_HTTP;
52 // lRunString +=" -seeding-rdv http://"+InetAddress.getLocalHost().getHostAddress()+":"+P2pProxyInstance.BASE_HTTP;
53 // mLog.info("starting ["+lRunString+"]");
54 // Process lProcess = Runtime.getRuntime().exec(lRunString);
58 mP2pProxyInstance = new P2pProxyInstanceImpl();
59 mP2pProxyInstance.setMode(Mode.edge);
60 mP2pProxyInstance.setIndex(1);
61 mP2pProxyInstance.start();
62 while (mP2pProxyInstance.isStarted() == false) Thread.sleep(500);
67 public void setUp() throws Exception {
68 if (mP2pProxyInstance == null) {
75 public void testGetPublicAddress() {
77 Assert.assertEquals("wrong public ip" ,mP2pProxyInstance.getManager().getPublicIpAddress().getHostAddress(), InetAddress.getLocalHost().getHostAddress());
78 mLog.info("testGetPublicAddress ok");
79 } catch (Exception e) {
80 mLog.error("testGetPublicAddress ko",e);
81 Assert.fail(e.getMessage());
87 public void testProbeTcpSocket() {
89 InetSocketAddress lSocketAddress = new InetSocketAddress(InetAddress.getLocalHost(),9500);
90 Assert.assertTrue("cannot prob" ,mP2pProxyInstance.getManager().probeSocket(lSocketAddress, P2pProxyNetworkProbe.Protocol.tcp));
91 mLog.info("testProbeSocket ok");
92 } catch (Exception e) {
93 mLog.error("testProbeSocket ko",e);
94 Assert.fail(e.getMessage());
100 public void testProbeUdpSocket() {
102 InetSocketAddress lSocketAddress = new InetSocketAddress(InetAddress.getLocalHost(),9500);
103 Assert.assertTrue("cannot prob" ,mP2pProxyInstance.getManager().probeSocket(lSocketAddress, P2pProxyNetworkProbe.Protocol.udp));
104 mLog.info("testProbeSocket ok");
105 } catch (Exception e) {
106 mLog.error("testProbeSocket ko",e);
107 Assert.fail(e.getMessage());