55import net .sharksystem .cmdline .ExampleASAPChunkReceivedListener ;
66import net .sharksystem .cmdline .TCPStream ;
77import org .junit .Assert ;
8+ import org .junit .Test ;
89
910import java .io .IOException ;
1011import java .util .Iterator ;
@@ -21,8 +22,8 @@ public class Workbench {
2122 public static final int EXAMPLE_PORT = 7070 ;
2223 public static final String EXAMPLE_MESSAGE_STRING = "Hi" ;
2324
24- // TODO
25- public void routeEncryptedMessageTest () throws IOException , ASAPException , InterruptedException {
25+ @ Test
26+ public void noExchangeNotSigned () throws IOException , ASAPException , InterruptedException {
2627 ASAPEngineFS .removeFolder (WORKING_SUB_DIRECTORY ); // clean previous version before
2728
2829 ///// Prepare Alice
@@ -36,10 +37,9 @@ public void routeEncryptedMessageTest() throws IOException, ASAPException, Inter
3637
3738 // setup chat on alice peer
3839 ASAPEngine aliceChatEngine = alicePeer .createEngineByFormat (APPNAME );
39- aliceChatEngine .getASAPEnginePermissionSettings ().setReceivedMessagesMustBeEncrypted (true );
40- aliceChatEngine .getASAPEnginePermissionSettings ().setReceivedMessagesMustBeSigned (true );
41- aliceChatEngine .getASAPCommunicationControl ().setSendEncryptedMessages (true );
42- aliceChatEngine .getASAPCommunicationControl ().setSendSignedMessages (true );
40+ // false is default but makes test more obvious
41+ aliceChatEngine .getASAPCommunicationControl ().setSendEncryptedMessages (false );
42+ aliceChatEngine .getASAPCommunicationControl ().setSendSignedMessages (false );
4343
4444 // create a message
4545 String messageAlice = EXAMPLE_MESSAGE_STRING ;
@@ -61,10 +61,9 @@ public void routeEncryptedMessageTest() throws IOException, ASAPException, Inter
6161
6262 // setup chat on alice peer
6363 ASAPEngine bobChatEngine = bobPeer .createEngineByFormat (APPNAME );
64- aliceChatEngine .getASAPEnginePermissionSettings ().setReceivedMessagesMustBeEncrypted (true );
65- aliceChatEngine .getASAPEnginePermissionSettings ().setReceivedMessagesMustBeSigned (true );
66- aliceChatEngine .getASAPCommunicationControl ().setSendEncryptedMessages (true );
67- aliceChatEngine .getASAPCommunicationControl ().setSendSignedMessages (true );
64+ // bob expects signed and encrypted what Alice not provides
65+ bobChatEngine .getASAPEnginePermissionSettings ().setReceivedMessagesMustBeEncrypted (true );
66+ bobChatEngine .getASAPEnginePermissionSettings ().setReceivedMessagesMustBeSigned (true );
6867
6968 /////////////// create a connection - in real apps it is presumably a bluetooth wifi direct etc. connection
7069 // TCPStream is a helper class for connection establishment
@@ -98,44 +97,7 @@ public void routeEncryptedMessageTest() throws IOException, ASAPException, Inter
9897 // bob chunk received listener must have received something
9998 List <ExampleASAPChunkReceivedListener .ASAPChunkReceivedParameters > receivedList =
10099 bobChunkListener .getReceivedList ();
100+ Assert .assertTrue (receivedList .isEmpty ());
101101
102- Assert .assertNotNull (receivedList );
103- Assert .assertFalse (receivedList .isEmpty ());
104-
105- // there must be a single entry - get it
106- Assert .assertTrue (receivedList .size () == 1 );
107- ExampleASAPChunkReceivedListener .ASAPChunkReceivedParameters parameters = receivedList .get (0 );
108-
109- // get chunk storage
110- ASAPChunkStorage receivedChunkStorage = bobChatEngine .getReceivedChunksStorage (parameters .getSender ());
111-
112- // get chunk
113- ASAPChunk chunk = receivedChunkStorage .getChunk (parameters .getUri (), parameters .getEra ());
114-
115- Iterator <byte []> messages = chunk .getMessages ();
116-
117- // there must a one and only one
118- byte [] messageBytesReceived = messages .next ();
119-
120- // convert to String
121- String receivedMessage = new String (messageBytesReceived );
122-
123- System .out .println (bobChatEngine .getOwner () + " received a message: " + receivedMessage );
124-
125- Assert .assertTrue (receivedMessage .equals (EXAMPLE_MESSAGE_STRING ));
126-
127- // make it a bit easier with a helper class
128- ASAPMessages receivedMessages =
129- Helper .getMessagesByChunkReceivedInfos (parameters .getFormat (), parameters .getSender (),
130- parameters .getUri (),
131- bobFolder , // peers' root directory!
132- parameters .getEra ());
133-
134- Iterator <byte []> msgInter = receivedMessages .getMessages ();
135- while (msgInter .hasNext ()) {
136- byte [] msgBytes = msgInter .next ();
137- String msg = new String (msgBytes );
138- System .out .println ("message received: " + msg );
139- }
140102 }
141103}
0 commit comments