99import net .sharksystem .asap .mockAndTemplates .ASAPMessageReceivedListenerExample ;
1010import net .sharksystem .asap .mockAndTemplates .TestUtils ;
1111import org .junit .jupiter .api .Assertions ;
12+ import org .junit .jupiter .api .BeforeAll ;
1213import org .junit .jupiter .api .BeforeEach ;
1314import org .junit .jupiter .api .Test ;
1415
@@ -45,31 +46,21 @@ public class MultipleEncounterTests {
4546 private static final int PORT = 7777 ;
4647 private static int port = 0 ;
4748
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 );
5152 }
5253
53- //ASAPPeerFSTestHelper testHelper;
5454 private ASAPTestPeerFS aliceTestPeer , bobTestPeer ;
5555
5656 @ BeforeEach
5757 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-
6458 // create a new folder for each test - avoids conflicts when removal does not work due to race condition
6559 String rootfolder = TestHelper .getFullTempFolderName (TEST_FOLDER , true );
6660
6761 formats = new ArrayList <>();
6862 formats .add (EXAMPLE_APP_FORMAT );
6963
70- // helper class with useful testing functions
71- // testHelper = new ASAPPeerFSTestHelper(rootfolder, EXAMPLE_APP_FORMAT);
72-
7364 this .aliceTestPeer = new ASAPTestPeerFS (
7465 TestConstants .ALICE_ID , rootfolder + "/" + TestConstants .ALICE_NAME , formats );
7566 this .bobTestPeer = new ASAPTestPeerFS (
@@ -95,10 +86,6 @@ public void singleEncounter_differentURIs() throws InterruptedException, IOExcep
9586 this .senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , uriBob , 0 ));
9687 Assertions .assertTrue (
9788 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- */
10289 }
10390
10491 @ Test
@@ -119,10 +106,6 @@ public void singleEncounter_sameURIs() throws InterruptedException, IOException,
119106 // each message should have created a new era, so there should be a meta and content file in each subfolder
120107 Assertions .assertTrue (
121108 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- */
126109 }
127110
128111 @ Test
@@ -140,19 +123,6 @@ public void multiEncounter_sameURIs() throws InterruptedException, IOException,
140123 Assertions .assertTrue (
141124 senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT , TestConstants .ALICE_ID , uri , era ));
142125 }
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- */
156126 }
157127
158128 @ Test
@@ -190,19 +160,6 @@ public void multiEncounter_partiallyDifferentURIs() throws InterruptedException,
190160 senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT , TestConstants .BOB_ID , HELLO_URI , era ));
191161 Assertions .assertTrue (
192162 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- */
206163 }
207164
208165 @ Test
@@ -211,15 +168,18 @@ public void multiEncounter_completelyDifferentURIs() throws InterruptedException
211168 int numberEncounter = 4 ;
212169 String [][] exchangedUris = new String [numberEncounter ][];
213170
171+ int aliceIndex = 0 ; // take index 0 for alice uri
172+ int bobIndex = 1 ; // take index 0 for bob uri
173+
214174 // 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
216176 exchangedUris [1 ] = new String [] {ALICE_URI_2 , BOB_URI_2 };
217177 exchangedUris [2 ] = new String [] {ALICE_URI_3 , BOB_URI_3 };
218178 exchangedUris [3 ] = new String [] {ALICE_URI_4 , BOB_URI_4 };
219179
220180 // run encounter
221181 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 );
223183 }
224184
225185 // test
@@ -228,35 +188,20 @@ public void multiEncounter_completelyDifferentURIs() throws InterruptedException
228188 // Alice got Bob's uri
229189 Assertions .assertTrue (
230190 senderEraShouldExist (aliceTestPeer , EXAMPLE_APP_FORMAT ,
231- TestConstants .BOB_ID , exchangedUris [era ][1 ], era ));
191+ TestConstants .BOB_ID , exchangedUris [era ][bobIndex ], era ));
232192 // Bob received Alice's uri
233193 Assertions .assertTrue (
234194 senderEraShouldExist (bobTestPeer , EXAMPLE_APP_FORMAT ,
235- TestConstants .ALICE_ID , exchangedUris [era ][0 ], era ));
195+ TestConstants .ALICE_ID , exchangedUris [era ][aliceIndex ], era ));
236196 }
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- */
251197 }
252198
253199 public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob )
254200 throws IOException , ASAPException , InterruptedException {
255201 this .simpleEncounterWithMessageExchange (uriAlice , uriBob , 0 );
256202 }
257203
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
260205 // message content is irrelevant, we don't test for it
261206 public void simpleEncounterWithMessageExchange (String uriAlice , String uriBob , int encounterNumber )
262207 throws IOException , ASAPException , InterruptedException {
0 commit comments