diff --git a/android/app/src/main/java/com/epfl/dedis/hbt/data/document/Portrait.kt b/android/app/src/main/java/com/epfl/dedis/hbt/data/document/Portrait.kt new file mode 100644 index 00000000..acedff0a --- /dev/null +++ b/android/app/src/main/java/com/epfl/dedis/hbt/data/document/Portrait.kt @@ -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 + } +} diff --git a/android/app/src/test/java/com/epfl/dedis/hbt/service/document/DocumentServiceTest.kt b/android/app/src/test/java/com/epfl/dedis/hbt/service/document/DocumentServiceTest.kt new file mode 100644 index 00000000..9958352a --- /dev/null +++ b/android/app/src/test/java/com/epfl/dedis/hbt/service/document/DocumentServiceTest.kt @@ -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()) + } +} \ No newline at end of file diff --git a/android/app/src/test/resources/mock-portrait.jpeg b/android/app/src/test/resources/mock-portrait.jpeg new file mode 100644 index 00000000..caad2c03 Binary files /dev/null and b/android/app/src/test/resources/mock-portrait.jpeg differ