source: simplerunner/src/test/java/geniusweb/simplerunner/ClassPathConnectionFactoryTest.java@ 52

Last change on this file since 52 was 52, checked in by ruud, 14 months ago

Fixed small issues in domaineditor.

File size: 2.8 KB
Line 
1package geniusweb.simplerunner;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertNotNull;
5
6import java.io.IOException;
7import java.net.URISyntaxException;
8
9import org.junit.Before;
10import org.junit.Test;
11
12import geniusweb.actions.Action;
13import geniusweb.connection.ConnectionEnd;
14import geniusweb.inform.Inform;
15import geniusweb.references.PartyRef;
16
17public class ClassPathConnectionFactoryTest {
18 private ClassPathConnectionFactory factory;
19 private PartyRef PARTYREF;
20
21 @Before
22 public void before() throws URISyntaxException {
23 factory = new ClassPathConnectionFactory();
24 PARTYREF = new PartyRef(
25 "classpath:geniusweb.exampleparties.randomparty.RandomParty");
26
27 }
28
29 @Test(expected = IllegalArgumentException.class)
30 public void testWrongURI() throws IOException, URISyntaxException {
31 factory.connect(new PartyRef("http://blabla"));
32 }
33
34 @Test(expected = IllegalArgumentException.class)
35 public void testNullPath() throws IOException, URISyntaxException {
36 // bad because classpath should not start with //
37 factory.connect(new PartyRef("http://some.class.path"));
38 }
39
40 @Test(expected = IllegalArgumentException.class)
41 public void testUnknownParty() throws IOException, URISyntaxException {
42 factory.connect(new PartyRef("classpath:blabla.bla"));
43 }
44
45 @Test
46 public void testRandomParty() throws IOException, URISyntaxException {
47 ConnectionEnd<Action, Inform> party = factory.connect(PARTYREF);
48 assertNotNull(party);
49 }
50
51 @Test
52 public void testConnectionPairProtocolClosesNormally()
53 throws InterruptedException {
54 ConnectionPair cpair = new ConnectionPair(PARTYREF);
55 assertEquals(2, cpair.getOpenConnections().size());
56 cpair.getProtocolToPartyConn().close();
57 Thread.sleep(100);
58
59 assertEquals(0, cpair.getOpenConnections().size());
60
61 }
62
63 @Test
64 public void testConnectionPairProtocolClosesWithExc()
65 throws InterruptedException {
66 ConnectionPair cpair = new ConnectionPair(PARTYREF);
67 assertEquals(2, cpair.getOpenConnections().size());
68 cpair.getProtocolToPartyConn().setError(new Error("test"));
69 Thread.sleep(100);
70 assertEquals(0, cpair.getOpenConnections().size());
71 }
72
73 @Test
74 public void testConnectionPairPartyClosesNormally()
75 throws InterruptedException {
76 ConnectionPair cpair = new ConnectionPair(PARTYREF);
77 assertEquals(2, cpair.getOpenConnections().size());
78 cpair.getPartyToProtocolConn().close();
79 Thread.sleep(100);
80
81 assertEquals(0, cpair.getOpenConnections().size());
82
83 }
84
85 @Test
86 public void testConnectionPairPartyClosesWithExc()
87 throws InterruptedException {
88 ConnectionPair cpair = new ConnectionPair(PARTYREF);
89 assertEquals(2, cpair.getOpenConnections().size());
90 cpair.getPartyToProtocolConn().setError(new Error("test"));
91 Thread.sleep(100);
92 assertEquals(0, cpair.getOpenConnections().size());
93 }
94
95}
Note: See TracBrowser for help on using the repository browser.