summaryrefslogtreecommitdiff
path: root/same/old/SameStateTest.java
blob: 13378a41202b9be78d7171f7126fa54dbb8d7429 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// package com.orbekk.same;
// 
// import static org.junit.Assert.*;
// 
// import java.util.Map;
// import java.util.HashMap;
// import org.junit.Test;
// import org.junit.Before;
// 
// public class SameStateTest {
//     private MockConnectionManager connections;
//     private SameState state1, state2, state3;
//     private SameService service1, service2, service3;
// 
//     public static class MockConnectionManager implements ConnectionManager {
//         public Map<String, SameService> connections =
//                 new HashMap<String, SameService>();
// 
//         @Override
//         public SameService getConnection(String url) {
//             return connections.get(url);
//         }
//     }
// 
//     public SameStateTest() {
//     }
// 
//     @Before public void setUp() {
//         connections = new MockConnectionManager();
// 
//         state1 = new SameState("Network1", "Client1", connections);
//         state1.setUrl("test://client1");
//         service1 = new SameServiceImpl(state1);
//         state2 = new SameState("Network2", "Client2", connections);
//         state2.setUrl("test://client2");
//         service2 = new SameServiceImpl(state2);
//         state3 = new SameState("Network3", "Client3", connections);
//         state3.setUrl("test://client3");
//         service3 = new SameServiceImpl(state3);
// 
//         connections.connections.put(state1.getUrl(), service1);
//         connections.connections.put(state2.getUrl(), service2);
//         connections.connections.put(state3.getUrl(), service3);
//     }
// 
//     public void joinNetwork() {
//         connections.getConnection(state1.getUrl()).
//             participateNetwork("Network1", state2.getClientId(),
//                     state2.getUrl());
//         connections.getConnection(state1.getUrl()).
//             participateNetwork("Network1", state3.getClientId(),
//                     state3.getUrl());
//         state1.internalRun();
//         state2.internalRun();
//         state3.internalRun();
// 
//         assertTrue(state1.getParticipants().size() == 3);
//         assertTrue(state2.getParticipants().size() == 3);
//         assertTrue(state3.getParticipants().size() == 3);
//     }
// 
//     @Test public void testJoinNetwork() {
//         connections.getConnection(state1.getUrl()).
//             participateNetwork("Network1", state2.getClientId(),
//                     state2.getUrl());
//         assertTrue(state1.getParticipants().size() == 1);
//         assertTrue(state2.getParticipants().size() == 1);
// 
//         state1.internalRun();
//         state2.internalRun();
// 
//         assertTrue(state1.getParticipants().size() == 2);
//         assertTrue(state2.getParticipants().size() == 2);
//         assertEquals(state1.getNetworkName(), state2.getNetworkName());
// 
//         connections.getConnection(state2.getUrl()).
//             participateNetwork("Network1", state3.getClientId(),
//                     state3.getUrl());
//         state2.internalRun();
//         state1.internalRun();
//         state3.internalRun();
//         state2.internalRun();
// 
//         assertTrue(state1.getParticipants().size() == 3);
//         assertTrue(state2.getParticipants().size() == 3);
//         assertTrue(state3.getParticipants().size() == 3);
//         assertEquals(state1.getNetworkName(), state2.getNetworkName());
//         assertEquals(state2.getNetworkName(), state3.getNetworkName());
// 
//         assertEquals("Client1", state1.getMasterId());
//         assertEquals("Client1", state2.getMasterId());
//         assertEquals("Client1", state3.getMasterId());
//     }
// 
//     @Test public void setState() {
//         joinNetwork();
//         state1.librarySetNewState("New state1");
//         state1.internalRun();
//         state2.internalRun();
//         state3.internalRun();
//         assertEquals("New state1", state1.getCurrentState());
//         assertEquals("New state1", state2.getCurrentState());
//         assertEquals("New state1", state2.getCurrentState());
//     }
// }