@@ -91,4 +91,88 @@ public void twoHops() throws IOException, ASAPException, InterruptedException {
9191 boolean same = messageAlice2Clara .equalsIgnoreCase (message .toString ());
9292 Assert .assertTrue (same );
9393 }
94+
95+ @ Test
96+ public void twoHopsNonOpenStorage () throws IOException , ASAPException , InterruptedException {
97+ CmdLineUI ui = new CmdLineUI (System .out );
98+
99+ ui .doResetASAPStorages ();
100+
101+ // create storages
102+ ui .doCreateASAPStorage ("Alice twoHops" );
103+ ui .doCreateASAPStorage ("Bob twoHops" );
104+ ui .doCreateASAPStorage ("Clara twoHops" );
105+
106+ ui .doAddRecipient ("Alice:twoHops Bob" );
107+ ui .doAddRecipient ("Alice:twoHops Clara" );
108+
109+ Assert .fail ("test case implementation not yet finished" );
110+
111+ ui .doSetSendReceivedMessage ("Alice:twoHops on" );
112+ ui .doSetSendReceivedMessage ("Bob:twoHops on" );
113+ ui .doSetSendReceivedMessage ("Clara:twoHops on" );
114+
115+ // add message to alice storage
116+ String messageAlice2Clara = "HiClara" ;
117+ String parameters = "Alice twoHops abcChat " + messageAlice2Clara ;
118+ ui .doCreateASAPMessage (parameters );
119+
120+ System .out .println ("**************************************************************************" );
121+ System .out .println ("** connect Alice with Bob **" );
122+ System .out .println ("**************************************************************************" );
123+ // connect alice with bob
124+ ui .doCreateASAPMultiEngine ("Alice" );
125+ ui .doOpen ("7070 Alice" );
126+ // wait a moment to give server socket time to be created
127+ Thread .sleep (10 );
128+ ui .doCreateASAPMultiEngine ("Bob" );
129+
130+ ui .doConnect ("7070 Bob" );
131+
132+ // alice should be in era 1 (content has changed before connection) and bob era is 0 - no changes
133+
134+ // wait a moment
135+ Thread .sleep (1000 );
136+
137+ // kill connections
138+ ui .doKill ("all" );
139+
140+ // alice should stay in era 1 (no content change), bob should be in era 1 received something
141+
142+ // wait a moment
143+ Thread .sleep (1000 );
144+
145+ System .out .println ("**************************************************************************" );
146+ System .out .println ("** connect Bob with Clara **" );
147+ System .out .println ("**************************************************************************" );
148+ ui .doCreateASAPMultiEngine ("Clara" );
149+ ui .doOpen ("8080 Clara" );
150+ // wait a moment to give server socket time to be created
151+ Thread .sleep (10 );
152+ ui .doConnect ("8080 Bob" );
153+
154+ // bob should remain in era 1 o changes, clara is era 0
155+
156+ // wait a moment
157+ Thread .sleep (1000 );
158+ // kill connections
159+ ui .doKill ("all" );
160+
161+ // get Clara storage
162+ String rootFolder = ui .getEngineRootFolderByStorageName ("Clara:twoHops" );
163+ ASAPStorage clara = ASAPEngineFS .getExistingASAPEngineFS (rootFolder );
164+
165+ /* message was actually from Bob but originated from Alice. It is put
166+ into a incoming folder as it would have been directly received from Alice.
167+ Signatures would allow ensuring if origin was really who mediator claims to be.
168+ */
169+ ASAPChunkStorage claraBob = clara .getIncomingChunkStorage ("Alice" );
170+
171+ // clara era was increased after connection terminated - message from bob is in era before current one
172+ int eraToLook = ASAPEngine .previousEra (clara .getEra ());
173+ ASAPChunk claraABCChat = claraBob .getChunk ("abcChat" , eraToLook );
174+ CharSequence message = claraABCChat .getMessages ().next ();
175+ boolean same = messageAlice2Clara .equalsIgnoreCase (message .toString ());
176+ Assert .assertTrue (same );
177+ }
94178}
0 commit comments