9
9
import net .sharksystem .asap .mockAndTemplates .ASAPMessageReceivedListenerExample ;
10
10
import net .sharksystem .asap .mockAndTemplates .TestUtils ;
11
11
import org .junit .jupiter .api .Assertions ;
12
+ import org .junit .jupiter .api .BeforeAll ;
12
13
import org .junit .jupiter .api .BeforeEach ;
13
14
import org .junit .jupiter .api .Test ;
14
15
@@ -45,31 +46,21 @@ public class MultipleEncounterTests {
45
46
private static final int PORT = 7777 ;
46
47
private static int port = 0 ;
47
48
48
- /* clear folder before launching tests */
49
- public MultipleEncounterTests () {
50
- ASAPEngineFS .removeFolder (TEST_FOLDER );
49
+ @ BeforeAll
50
+ public static void removePreviousTestFolder () {
51
+ ASAPEngineFS .removeFolder (TestConstants . ROOT_DIRECTORY + TEST_FOLDER );
51
52
}
52
53
53
- //ASAPPeerFSTestHelper testHelper;
54
54
private ASAPTestPeerFS aliceTestPeer , bobTestPeer ;
55
55
56
56
@ BeforeEach
57
57
public void setUp () throws IOException , ASAPException {
58
- // delete directory „testPeerFS” to prevent errors when running twice
59
- //FileUtils.deleteDirectory(new File("testPeerFS"));
60
-
61
- // root folder of all ASAPPeers
62
- //String rootfolder = "./testPeerFS";
63
-
64
58
// create a new folder for each test - avoids conflicts when removal does not work due to race condition
65
59
String rootfolder = TestHelper .getFullTempFolderName (TEST_FOLDER , true );
66
60
67
61
formats = new ArrayList <>();
68
62
formats .add (EXAMPLE_APP_FORMAT );
69
63
70
- // helper class with useful testing functions
71
- // testHelper = new ASAPPeerFSTestHelper(rootfolder, EXAMPLE_APP_FORMAT);
72
-
73
64
this .aliceTestPeer = new ASAPTestPeerFS (
74
65
TestConstants .ALICE_ID , rootfolder + "/" + TestConstants .ALICE_NAME , formats );
75
66
this .bobTestPeer = new ASAPTestPeerFS (
@@ -95,10 +86,6 @@ public void singleEncounter_differentURIs() throws InterruptedException, IOExcep
95
86
this .senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , uriBob , 0 ));
96
87
Assertions .assertTrue (
97
88
this .senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , uriAlice , 0 ));
98
- /*
99
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, uriBob, 0));
100
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, uriAlice, 0));
101
- */
102
89
}
103
90
104
91
@ Test
@@ -119,10 +106,6 @@ public void singleEncounter_sameURIs() throws InterruptedException, IOException,
119
106
// each message should have created a new era, so there should be a meta and content file in each subfolder
120
107
Assertions .assertTrue (
121
108
this .senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , uriBob , 0 ));
122
- /*
123
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, uriBob, 0));
124
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, uriAlice, 0));
125
- */
126
109
}
127
110
128
111
@ Test
@@ -140,19 +123,6 @@ public void multiEncounter_sameURIs() throws InterruptedException, IOException,
140
123
Assertions .assertTrue (
141
124
senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , uri , era ));
142
125
}
143
-
144
- /*
145
- // each message should have created a new era, so there should be a meta and content file in each subfolder
146
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, uri, 0));
147
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, uri, 1));
148
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, uri, 2));
149
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, uri, 3));
150
-
151
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, uri, 0));
152
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, uri, 1));
153
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, uri, 2));
154
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, uri, 3));
155
- */
156
126
}
157
127
158
128
@ Test
@@ -190,19 +160,6 @@ public void multiEncounter_partiallyDifferentURIs() throws InterruptedException,
190
160
senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , HELLO_URI , era ));
191
161
Assertions .assertTrue (
192
162
senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , ICE_CREAM , era ));
193
-
194
- /*
195
- // all eras SHOULD exists, but some are missing!
196
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, ICE_CREAM, 0));
197
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, ELEPHANT_URI, 1));
198
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, ICE_CREAM, 2));
199
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, HELLO_URI, 3));
200
-
201
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, TIGER_URI, 0));
202
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, ICE_CREAM, 1));
203
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, HELLO_URI, 2));
204
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, ICE_CREAM, 3));
205
- */
206
163
}
207
164
208
165
@ Test
@@ -211,15 +168,18 @@ public void multiEncounter_completelyDifferentURIs() throws InterruptedException
211
168
int numberEncounter = 4 ;
212
169
String [][] exchangedUris = new String [numberEncounter ][];
213
170
171
+ int aliceIndex = 0 ; // take index 0 for alice uri
172
+ int bobIndex = 1 ; // take index 0 for bob uri
173
+
214
174
// define what to exchange in each encounter
215
- exchangedUris [0 ] = new String [] {ALICE_URI_1 , BOB_URI_1 };
175
+ exchangedUris [0 ] = new String [] {ALICE_URI_1 , BOB_URI_1 }; // alice at index 0 && bob at index 1
216
176
exchangedUris [1 ] = new String [] {ALICE_URI_2 , BOB_URI_2 };
217
177
exchangedUris [2 ] = new String [] {ALICE_URI_3 , BOB_URI_3 };
218
178
exchangedUris [3 ] = new String [] {ALICE_URI_4 , BOB_URI_4 };
219
179
220
180
// run encounter
221
181
for (int i = 0 ; i < numberEncounter ; i ++) {
222
- simpleEncounterWithMessageExchange (exchangedUris [i ][0 ], exchangedUris [i ][1 ], i );
182
+ simpleEncounterWithMessageExchange (exchangedUris [i ][aliceIndex ], exchangedUris [i ][bobIndex ], i );
223
183
}
224
184
225
185
// test
@@ -228,35 +188,20 @@ public void multiEncounter_completelyDifferentURIs() throws InterruptedException
228
188
// Alice got Bob's uri
229
189
Assertions .assertTrue (
230
190
senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT ,
231
- TestConstants .BOB_ID , exchangedUris [era ][1 ], era ));
191
+ TestConstants .BOB_ID , exchangedUris [era ][bobIndex ], era ));
232
192
// Bob received Alice's uri
233
193
Assertions .assertTrue (
234
194
senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT ,
235
- TestConstants .ALICE_ID , exchangedUris [era ][0 ], era ));
195
+ TestConstants .ALICE_ID , exchangedUris [era ][aliceIndex ], era ));
236
196
}
237
-
238
- /*
239
- // we expect ALL of the uris to exist, but they don't.
240
- // only two messages of bob and one message of alice gets transmitted, then it stops transmitting for the rest..
241
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, BOB_URI_1, 0));
242
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, BOB_URI_2, 1));
243
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, BOB_URI_3, 2));
244
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.ALICE_ID, TestConstants.BOB_ID, BOB_URI_4, 3));
245
-
246
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, ALICE_URI_1, 0));
247
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, ALICE_URI_2, 1));
248
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, ALICE_URI_3, 2));
249
- Assertions.assertTrue(testHelper.senderEraShouldExist(TestConstants.BOB_ID, TestConstants.ALICE_ID, ALICE_URI_4, 3));
250
- */
251
197
}
252
198
253
199
public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob )
254
200
throws IOException , ASAPException , InterruptedException {
255
201
this .simpleEncounterWithMessageExchange (uriAlice , uriBob , 0 );
256
202
}
257
203
258
-
259
- // sends messages with given uri, starts and then stops the encounter
204
+ // send messages with given uri, starts and then stops the encounter
260
205
// message content is irrelevant, we don't test for it
261
206
public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob , int encounterNumber )
262
207
throws IOException , ASAPException , InterruptedException {
0 commit comments