-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: GabrielFleicher <[email protected]>
- Loading branch information
1 parent
bca8391
commit b638331
Showing
3 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
android/app/src/main/java/com/epfl/dedis/hbt/data/document/Portrait.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.epfl.dedis.hbt.data.document | ||
|
||
import java.io.Serializable | ||
|
||
data class Portrait( | ||
val type: String, | ||
val data: ByteArray | ||
) : Serializable { | ||
override fun equals(other: Any?): Boolean { | ||
if (this === other) return true | ||
if (javaClass != other?.javaClass) return false | ||
|
||
other as Portrait | ||
|
||
if (type != other.type) return false | ||
return data.contentEquals(other.data) | ||
} | ||
|
||
override fun hashCode(): Int { | ||
var result = type.hashCode() | ||
result = 31 * result + data.contentHashCode() | ||
return result | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
android/app/src/test/java/com/epfl/dedis/hbt/service/document/DocumentServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.epfl.dedis.hbt.service.document | ||
|
||
import androidx.test.espresso.matcher.ViewMatchers.assertThat | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import com.epfl.dedis.hbt.data.document.Portrait | ||
import com.epfl.dedis.hbt.data.user.Role | ||
import com.epfl.dedis.hbt.data.user.User | ||
import com.epfl.dedis.hbt.di.HttpModule | ||
import com.epfl.dedis.hbt.di.JsonModule | ||
import org.junit.Ignore | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mockito.kotlin.isNull | ||
import org.mockito.kotlin.notNull | ||
import java.io.FileNotFoundException | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
class DocumentServiceTest { | ||
|
||
|
||
companion object { | ||
private val retrofit = | ||
HttpModule.provideRetrofit( | ||
"http://localhost:3000", | ||
JsonModule.provideObjectMapper() | ||
) | ||
|
||
fun getMockPortrait(): Portrait { | ||
val stream = DocumentServiceTest::class.java.getResourceAsStream("/mock-portrait.jpeg") | ||
?: throw FileNotFoundException() | ||
|
||
stream.use { | ||
return Portrait("image/jpeg", it.readBytes()) | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
@Ignore("This is merely a PoC") | ||
fun createSimpleDocumentSucceed() { | ||
val service = HttpModule.provideDocumentService(retrofit) | ||
|
||
val user = User( | ||
name = "Jon Smith", | ||
pincode = 24256, | ||
passport = "ABCDEFGHI", | ||
role = Role.BENEFICIARY | ||
) | ||
|
||
val call = service.create(user, getMockPortrait(), false) | ||
|
||
val response = call.execute() | ||
|
||
assertThat(response.errorBody(), isNull()) | ||
assertThat(response.body(), notNull()) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.