adds list functionality
- adds rest connection with gets a JSON Object with a "messages" list inside it. - test case, which pushes a new message and gets an entire list. checking that the first element is "hello" and the last element to be the new element just pushed
This commit is contained in:
@ -2,6 +2,7 @@ package com.example.bump
|
||||
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4
|
||||
import org.json.JSONArray
|
||||
import org.json.JSONObject
|
||||
|
||||
import org.junit.Test
|
||||
@ -38,10 +39,10 @@ class RestCryptTest{
|
||||
val lock = CountDownLatch(1)
|
||||
|
||||
|
||||
fun messageTester(messageEncrypted: String) {
|
||||
fun messageTester(messageEncrypted: JSONObject) {
|
||||
val message = MessageProcessor(code)
|
||||
|
||||
val messageData: String = JSONObject(messageEncrypted).get("data").toString()
|
||||
val messageData: String = messageEncrypted.get("data").toString()
|
||||
assertEquals(messageData, encrypted)
|
||||
val data = message.decrypt(messageData)
|
||||
assertEquals(data, testMessage)
|
||||
@ -55,8 +56,42 @@ class RestCryptTest{
|
||||
}
|
||||
|
||||
lock.await(200000, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun pushListAndDecrypt() {
|
||||
val code = "dydoes-unknowledgeable-indiscretion-househusbands-pot-walloper-indiscretion-discophorous-transcriptions-dydoes-poodle-faker-transcriptions-budlike"
|
||||
val testMessage = getRandomString(32)
|
||||
val context = InstrumentationRegistry.getInstrumentation().targetContext
|
||||
var encrypted = ""
|
||||
|
||||
val lock = CountDownLatch(1)
|
||||
|
||||
|
||||
fun listTester(resultList: JSONObject) {
|
||||
val message = MessageProcessor(code)
|
||||
val messages: JSONArray = resultList.get("messages") as JSONArray
|
||||
|
||||
var messageEncoded = messages[0] as JSONObject
|
||||
var messageData = messageEncoded.get("data").toString()
|
||||
var data = message.decrypt(messageData)
|
||||
assertEquals(data, "hello")
|
||||
|
||||
messageEncoded = messages[messages.length()-1] as JSONObject
|
||||
messageData = messageEncoded.get("data").toString()
|
||||
data = message.decrypt(messageData)
|
||||
assertEquals(data, testMessage)
|
||||
lock.countDown()
|
||||
|
||||
}
|
||||
|
||||
val message = MessageProcessor(code)
|
||||
encrypted = message.encrypt(testMessage)
|
||||
RestSingleton.getInstance(context).push(message.sender, encrypted) {
|
||||
RestSingleton.getInstance(context).list(message.sender) { i -> listTester(i) }
|
||||
}
|
||||
|
||||
lock.await(200000, TimeUnit.MILLISECONDS)
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user