]> sjero.net Git - linphone/blob - p2pproxy/test-src/org/linphone/p2pproxy/test/P2pAutoConfigTester.java
3ef51d0b7df7ce0a93b2b76c9b2d576f9f0bf3df
[linphone] / p2pproxy / test-src / org / linphone / p2pproxy / test / P2pAutoConfigTester.java
1 /*
2 p2pproxy
3 Copyright (C) 2007  Jehan Monnier ()
4
5 P2pAutoConfigTester.java - .
6
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.
11
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.
16
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.
20 */
21 package org.linphone.p2pproxy.test;
22
23
24 import java.net.InetAddress;
25 import java.net.InetSocketAddress;
26 import java.net.SocketAddress;
27
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;
36
37 public class P2pAutoConfigTester extends TestCase {
38    static private P2pProxyInstance mP2pProxyInstance;
39    private final static Logger mLog = Logger.getLogger(P2pAutoConfigTester.class);
40    //@BeforeClass
41    public static void setUpBeforeClass() throws Exception {
42       // setup logging
43       PropertyConfigurator.configure("log4j.properties");
44  
45 //      // 1 setup relays
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);
55
56      
57       // setup edge
58       mP2pProxyInstance = new P2pProxyInstanceImpl();
59       mP2pProxyInstance.setMode(Mode.edge);
60       mP2pProxyInstance.setIndex(1);
61       mP2pProxyInstance.start();
62       while (mP2pProxyInstance.isStarted() == false) Thread.sleep(500);
63       
64    }
65
66    //@Before
67    public void setUp() throws Exception {
68       if (mP2pProxyInstance == null) {
69          setUpBeforeClass();
70       }
71    }
72    /**
73     * 
74     */
75    public void testGetPublicAddress() {
76       try {
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());
82       }  
83    }
84    /**
85     * 
86     */
87    public void testProbeTcpSocket() {
88       try {
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());
95       }  
96    }
97    /**
98     * 
99     */
100    public void testProbeUdpSocket() {
101       try {
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());
108       }  
109    }
110 }