aboutsummaryrefslogtreecommitdiff
path: root/java/android/OlmLibSdk/olm-sdk/src/androidTest
diff options
context:
space:
mode:
authorpedroGitt <pedro.contreiras@amdocs.com>2016-10-23 23:55:45 +0200
committerpedroGitt <pedro.contreiras@amdocs.com>2016-10-23 23:55:45 +0200
commit332d9d0c09c1f1f60bf970ea2b9a30cc95b9f5f5 (patch)
treefb9b26723a7c4b48b0c8ae37e7b9e6bce1094af8 /java/android/OlmLibSdk/olm-sdk/src/androidTest
parentfae857582c445ce89f527f6331aeac4eb66bc692 (diff)
Add serialization for inbound group session
- remove compiler warnings when logs are not enabled - new getInstanceId() function to refactor code
Diffstat (limited to 'java/android/OlmLibSdk/olm-sdk/src/androidTest')
-rw-r--r--java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java86
1 files changed, 81 insertions, 5 deletions
diff --git a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
index d49ebd4..c2a266b 100644
--- a/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
+++ b/java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmGroupSessionTest.java
@@ -28,7 +28,8 @@ import static org.junit.Assert.assertTrue;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class OlmGroupSessionTest {
private static final String LOG_TAG = "OlmSessionTest";
- private final String FILE_NAME_SERIAL_SESSION = "SerialGroupSession";
+ private final String FILE_NAME_SERIAL_OUT_SESSION = "SerialOutGroupSession";
+ private final String FILE_NAME_SERIAL_IN_SESSION = "SerialInGroupSession";
private static OlmManager mOlmManager;
private static OlmOutboundGroupSession mAliceOutboundGroupSession;
@@ -158,27 +159,26 @@ public class OlmGroupSessionTest {
OlmOutboundGroupSession outboundGroupSessionRef=null;
OlmOutboundGroupSession outboundGroupSessionSerial=null;
- // alice creates OUTBOUND GROUP SESSION
+ // create one OUTBOUND GROUP SESSION
try {
outboundGroupSessionRef = new OlmOutboundGroupSession();
} catch (OlmException e) {
assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
}
-
assertNotNull(outboundGroupSessionRef);
// serialize alice session
Context context = getInstrumentation().getContext();
try {
- FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_SESSION, Context.MODE_PRIVATE);
+ FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_OUT_SESSION, Context.MODE_PRIVATE);
ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput);
objectOutput.writeObject(outboundGroupSessionRef);
objectOutput.flush();
objectOutput.close();
// deserialize session
- FileInputStream fileInput = context.openFileInput(FILE_NAME_SERIAL_SESSION);
+ FileInputStream fileInput = context.openFileInput(FILE_NAME_SERIAL_OUT_SESSION);
ObjectInputStream objectInput = new ObjectInputStream(fileInput);
outboundGroupSessionSerial = (OlmOutboundGroupSession) objectInput.readObject();
objectInput.close();
@@ -204,6 +204,9 @@ public class OlmGroupSessionTest {
// session IDs comparison
assertTrue(sessionIdRef.equals(sessionIdSerial));
+
+ outboundGroupSessionRef.releaseSession();
+ outboundGroupSessionSerial.releaseSession();
}
catch (FileNotFoundException e) {
Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage());
@@ -223,5 +226,78 @@ public class OlmGroupSessionTest {
}
+ @Test
+ public void test15SerializeInboundSession() {
+ OlmOutboundGroupSession aliceOutboundGroupSession=null;
+ OlmInboundGroupSession bobInboundGroupSessionRef=null;
+ OlmInboundGroupSession bobInboundGroupSessionSerial=null;
+
+ // alice creates OUTBOUND GROUP SESSION
+ try {
+ aliceOutboundGroupSession = new OlmOutboundGroupSession();
+ } catch (OlmException e) {
+ assertTrue("Exception in OlmOutboundGroupSession, Exception code=" + e.getExceptionCode(), false);
+ }
+ assertNotNull(aliceOutboundGroupSession);
+
+ // get the session key from the outbound group session
+ String sessionKeyRef = aliceOutboundGroupSession.sessionKey();
+ assertNotNull(sessionKeyRef);
+
+ // bob creates INBOUND GROUP SESSION
+ try {
+ bobInboundGroupSessionRef = new OlmInboundGroupSession(sessionKeyRef);
+ } catch (OlmException e) {
+ assertTrue("Exception in OlmInboundGroupSession, Exception code=" + e.getExceptionCode(), false);
+ }
+ assertNotNull(bobInboundGroupSessionRef);
+
+
+ // serialize alice session
+ Context context = getInstrumentation().getContext();
+ try {
+ FileOutputStream fileOutput = context.openFileOutput(FILE_NAME_SERIAL_IN_SESSION, Context.MODE_PRIVATE);
+ ObjectOutputStream objectOutput = new ObjectOutputStream(fileOutput);
+ objectOutput.writeObject(bobInboundGroupSessionRef);
+ objectOutput.flush();
+ objectOutput.close();
+
+ // deserialize session
+ FileInputStream fileInput = context.openFileInput(FILE_NAME_SERIAL_OUT_SESSION);
+ ObjectInputStream objectInput = new ObjectInputStream(fileInput);
+ bobInboundGroupSessionSerial = (OlmInboundGroupSession)objectInput.readObject();
+ objectInput.close();
+
+ // get sessions IDs
+ String aliceSessionId = aliceOutboundGroupSession.sessionIdentifier();
+ String sessionIdRef = bobInboundGroupSessionRef.sessionIdentifier();
+ String sessionIdSerial = bobInboundGroupSessionSerial.sessionIdentifier();
+
+ // session ID sanity check
+ assertFalse(TextUtils.isEmpty(aliceSessionId));
+ assertFalse(TextUtils.isEmpty(sessionIdRef));
+ assertFalse(TextUtils.isEmpty(sessionIdSerial));
+
+ // session IDs comparison
+ assertTrue(aliceSessionId.equals(sessionIdSerial));
+ assertTrue(sessionIdRef.equals(sessionIdSerial));
+ }
+ catch (FileNotFoundException e) {
+ Log.e(LOG_TAG, "## test03SessionSerialization(): Exception FileNotFoundException Msg=="+e.getMessage());
+ }
+ catch (ClassNotFoundException e) {
+ Log.e(LOG_TAG, "## test03SessionSerialization(): Exception ClassNotFoundException Msg==" + e.getMessage());
+ }
+ catch (IOException e) {
+ Log.e(LOG_TAG, "## test03SessionSerialization(): Exception IOException Msg==" + e.getMessage());
+ }
+ /*catch (OlmException e) {
+ Log.e(LOG_TAG, "## test03SessionSerialization(): Exception OlmException Msg==" + e.getMessage());
+ }*/
+ catch (Exception e) {
+ Log.e(LOG_TAG, "## test03SessionSerialization(): Exception Msg==" + e.getMessage());
+ }
+
+ }
}