package org.opennms.netmgt.ping;

import java.net.InetAddress;

import org.opennms.netmgt.ping.Pinger;
import org.opennms.netmgt.ping.StatisticalArrayList;

import junit.framework.TestCase;

public class PingTest extends TestCase {
	Pinger pinger        = null;
	InetAddress goodHost = null;
	InetAddress badHost  = null;
	
	public void setUp() throws Exception {
		super.setUp();
		/*
		System.setProperty("opennms.library.jicmp", "/sw/lib/libjicmp.jnilib");
		pinger = new Pinger();
		goodHost = InetAddress.getByName("truename.dyndns.org");
		badHost  = InetAddress.getByName("1.1.1.1");
		*/
	}
	
	public void testStatisticalArrayList() throws Exception {
		StatisticalArrayList sal = new StatisticalArrayList();
		
		assertNull(sal.percentNotNull());
		assertNull(sal.percentNull());
		
		sal.add(null);
		sal.add(1);
		sal.add(100);
		sal.add(15);
		sal.add(null);
		
		assertEquals(sal.countNotNull(), 3);
		assertEquals(sal.countNull(), 2);
		assertTrue(sal.percentNotNull().equals(new Integer(60)));
		assertTrue(sal.percentNull().equals(new Integer(40)));
	}
	
	/*
	public void testSinglePing() throws Exception {
		assertTrue(pinger.ping(goodHost) > 0);
		Thread.sleep(1000);
	}
	
	public void testSinglePingFailure() throws Exception {
		assertNull(pinger.ping(badHost));
		Thread.sleep(1000);
	}

	public void testParallelPing() throws Exception {
		StatisticalArrayList ret = pinger.parallelPing(goodHost, 10);
		System.out.println("pings = " + ret.size() + ", passed = " + ret.countNotNull() + " (" + ret.percentNotNull() + "%), failed = " + ret.countNull() + " (" + ret.percentNull() + "%), average = " + (ret.averageAsFloat() / 1000) + "ms");
		Thread.sleep(1000);
		assertTrue(ret.countNotNull() > 0);
	}
	
	public void testParallelPingFailure() throws Exception {
		StatisticalArrayList ret = pinger.parallelPing(badHost, 10);
		System.out.println("pings = " + ret.size() + ", passed = " + ret.countNotNull() + " (" + ret.percentNotNull() + "%), failed = " + ret.countNull() + " (" + ret.percentNull() + "%), average = " + (ret.averageAsFloat() / 1000) + "ms");
		Thread.sleep(1000);
		assertTrue(ret.countNotNull() == 0);
	}
	*/
}

@@ -378,13 +378,8 @@
 ();%0A
-%09%09/*%0A
 %09%09Sy
@@ -513,27 +513,21 @@
 me(%22
-truename.dyndns.org
+192.168.211.1
 %22);%0A
@@ -577,13 +577,8 @@
 %22);%0A
-%09%09*/%0A
 %09%7D%0A%09
@@ -1352,32 +1352,38 @@
 isticalArrayList
+%3CLong%3E
  ret = pinger.pa
@@ -1400,32 +1400,123 @@
 (goodHost, 10);%0A
+%09%09for (int i = 0; i %3C ret.size(); i++) %7B%0A%09%09%09System.out.println(i + %22: %22 + ret.get(i));%0A%09%09%7D%0A
 %09%09System.out.pri

print the individual response times when testing