@@ -34,6 +34,10 @@ public void twoHops() throws IOException, ASAPException, InterruptedException {
3434 String parameters = "Alice twoHops sn2://abc " + messageAlice2Clara ;
3535 ui .doCreateASAPMessage (parameters );
3636
37+ // remember Alice' era
38+ ASAPStorage aliceStorage = this .getFreshStorageByName (ui , "Alice:twoHops" );
39+ int aliceEraWhenIssuedMessage = aliceStorage .getEra ();
40+
3741 System .out .println ("**************************************************************************" );
3842 System .out .println ("** connect Alice with Bob **" );
3943 System .out .println ("**************************************************************************" );
@@ -74,21 +78,22 @@ public void twoHops() throws IOException, ASAPException, InterruptedException {
7478 Thread .sleep (1000 );
7579 // kill connections
7680 ui .doKill ("all" );
81+ // wait a moment
82+ Thread .sleep (1000 );
7783
7884 // get Clara storage
79- String rootFolder = ui .getEngineRootFolderByStorageName ("Clara:twoHops" );
80- ASAPStorage clara = ASAPEngineFS .getExistingASAPEngineFS (rootFolder );
85+ ASAPStorage clara = this .getFreshStorageByName (ui , "Clara:twoHops" );
8186
8287 /* message was actually from Bob but originated from Alice. It is put
8388 into a incoming folder as it would have been directly received from Alice.
8489 Signatures would allow ensuring if origin was really who mediator claims to be.
8590 */
86- ASAPChunkStorage claraBob = clara .getIncomingChunkStorage ("Alice" );
91+ ASAPChunkStorage claraAlice = clara .getIncomingChunkStorage ("Alice" );
8792
8893 // clara era was increased after connection terminated - message from bob is in era before current one
8994// int eraToLook = ASAPEngine.previousEra(clara.getEra());
9095 int eraToLook = clara .getEra ();
91- ASAPChunk claraABCChat = claraBob .getChunk ("sn2://abc" , eraToLook );
96+ ASAPChunk claraABCChat = claraAlice .getChunk ("sn2://abc" , aliceEraWhenIssuedMessage );
9297 CharSequence message = claraABCChat .getMessages ().next ();
9398 boolean same = messageAlice2Clara .equalsIgnoreCase (message .toString ());
9499 Assert .assertTrue (same );
@@ -153,21 +158,68 @@ public void createNonOpenStorage() throws IOException, ASAPException, Interrupte
153158 }
154159 }
155160
161+ // closed channel created with all recipients and owner?
156162 Assert .assertTrue (aliceFound && bobFound && claraFound );
157163 Assert .assertTrue (bobClosedChannel .getOwner ().toString ().equalsIgnoreCase ("Alice" ));
158164
159- // check for a message
160- /* message was actually from Bob but originated from Alice. It is put
161- into a incoming folder as it would have been directly received from Alice.
162- Signatures would allow ensuring if origin was really who mediator claims to be.
163- */
165+ // message received?
164166 ASAPChunkStorage bobAlice = bobStorage .getIncomingChunkStorage ("Alice" );
165-
166167 // clara era was increased after connection terminated - message from bob is in era before current one
167168 int eraToLook = ASAPEngine .previousEra (bobStorage .getEra ());
168169 ASAPChunk bobABCChat = bobAlice .getChunk ("sn2://closedChannel" , eraToLook );
169170 CharSequence message = bobABCChat .getMessages ().next ();
170171 Assert .assertTrue (messageAlice2Clara .equalsIgnoreCase (message .toString ()));
172+
173+ System .out .println ("**************************************************************************" );
174+ System .out .println ("** connect Bob with Clara **" );
175+ System .out .println ("**************************************************************************" );
176+ // connect alice with bob
177+ ui .doCreateASAPMultiEngine ("Bob" );
178+ ui .doOpen ("7071 Bob" );
179+ // wait a moment to give server socket time to be created
180+ Thread .sleep (10 );
181+ ui .doCreateASAPMultiEngine ("Clara" );
182+ ui .doConnect ("7071 Clara" );
183+
184+ // alice should be in era 1 (content has changed before connection) and bob era is 0 - no changes
185+ // wait a moment
186+ Thread .sleep (1000 );
187+ // kill connections
188+ ui .doKill ("all" );
189+ // alice should stay in era 1 (no content change), bob should be in era 1 received something
190+ // wait a moment
191+ Thread .sleep (1000 );
192+ // Bob should now have created an closed asap storage with three recipients
193+ ASAPStorage claraStorage = this .getFreshStorageByName (ui , "Clara:chat" );
194+
195+ ui .doPrintChannelInformation ("Clara chat sn2://closedChannel" );
196+
197+ ASAPChannel claraClosedChannel = bobStorage .getChannel ("sn2://closedChannel" );
198+ recipientsList = bobClosedChannel .getRecipients ();
199+ aliceFound = false ;
200+ bobFound = false ;
201+ claraFound = false ;
202+ for (CharSequence recipient : recipientsList ) {
203+ String recipientString = recipient .toString ();
204+ switch (recipient .toString ()) {
205+ case "Alice" : aliceFound = true ; break ;
206+ case "Bob" : bobFound = true ; break ;
207+ case "Clara" : claraFound = true ; break ;
208+ default : Assert .fail ("found unexpected recipient: " + recipient );
209+ }
210+ }
211+
212+ // closed channel created with all recipients and owner?
213+ Assert .assertTrue (aliceFound && bobFound && claraFound );
214+ Assert .assertTrue (bobClosedChannel .getOwner ().toString ().equalsIgnoreCase ("Alice" ));
215+
216+ // message received?
217+ ASAPChunkStorage claraAlice = claraStorage .getIncomingChunkStorage ("Alice" );
218+ // clara era was increased after connection terminated - message from bob is in era before current one
219+ eraToLook = ASAPEngine .previousEra (bobStorage .getEra ());
220+ ASAPChunk claraABCChat = claraAlice .getChunk ("sn2://closedChannel" , eraToLook );
221+ message = claraABCChat .getMessages ().next ();
222+ Assert .assertTrue (messageAlice2Clara .equalsIgnoreCase (message .toString ()));
171223 }
172224
173225 private ASAPStorage getFreshStorageByName (CmdLineUI ui , String storageName ) throws ASAPException , IOException {
0 commit comments