package i5.las2peer.p2p;

import org.junit.Assert;
import org.junit.Test;

import i5.las2peer.testing.TestSuite;

public class PastryNodeImplTest {

	// TODO add more PastryNodeImpl tests

	@Test
	public void testSystemDefinedPort() {
		try {
			PastryNodeImpl testNode = TestSuite.launchNetwork(1).get(0);
			Assert.assertNotEquals(0, testNode.getPort());
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.toString());
		}
	}

	@Test
	public void testNodeRestart() {
		try {
			PastryNodeImpl testNode = TestSuite.launchNetwork(1).get(0);
			testNode.shutDown();
			testNode.launch();
			testNode.shutDown();
		} catch (Exception e) {
			e.printStackTrace();
			Assert.fail(e.toString());
		}
	}

}

@@ -19,16 +19,45 @@
 r.p2p;%0A%0A
+import java.util.ArrayList;%0A%0A
 import o
@@ -253,33 +253,24 @@
 nedPort() %7B%0A
-%09%09try %7B%0A%09
 %09%09PastryNode
@@ -276,32 +276,60 @@
 eImpl testNode =
+ null;%0A%09%09try %7B%0A%09%09%09testNode =
  TestSuite.launc
@@ -470,32 +470,109 @@
 (e.toString());%0A
+%09%09%7D finally %7B%0A%09%09%09testNode.shutDown();%0A%09%09%09System.out.println(%22Node stopped%22);%0A
 %09%09%7D%0A%09%7D%0A%0A%09@Test%0A%09
@@ -603,25 +603,16 @@
 art() %7B%0A
-%09%09try %7B%0A%09
 %09%09Pastry
@@ -622,32 +622,60 @@
 eImpl testNode =
+ null;%0A%09%09try %7B%0A%09%09%09testNode =
  TestSuite.launc
@@ -843,19 +843,592 @@
 ring());%0A%09%09%7D
+ finally %7B%0A%09%09%09testNode.shutDown();%0A%09%09%09System.out.println(%22Node stopped%22);%0A%09%09%7D%0A%09%7D%0A%0A%09@Test%0A%09public void testStartNetwork() %7B%0A%09%09ArrayList%3CPastryNodeImpl%3E nodes = null;%0A%09%09try %7B%0A%09%09%09// start nodes%0A%09%09%09nodes = TestSuite.launchNetwork(3);%0A%09%09%09System.out.println(%22Test network started%22);%0A%09%09%7D catch (Exception e) %7B%0A%09%09%09e.printStackTrace();%0A%09%09%09Assert.fail(e.getMessage());%0A%09%09%7D finally %7B%0A%09%09%09// stop nodes%0A%09%09%09if (nodes != null) %7B%0A%09%09%09%09for (PastryNodeImpl node : nodes) %7B%0A%09%09%09%09%09node.shutDown();%0A%09%09%09%09%09System.out.println(%22Node %22 + node.getPort() + %22 stopped%22);%0A%09%09%09%09%7D%0A%09%09%09%09nodes = null;%0A%09%09%09%7D%0A%09%09%7D%0A
 %0A%09%7D%0A%0A%7D%0A

improve PAstryNodeImplTEst