Skip to content

Commit

Permalink
Create the Portrait model
Browse files Browse the repository at this point in the history
Signed-off-by: GabrielFleicher <[email protected]>
  • Loading branch information
GabrielFleischer committed Jan 12, 2024
1 parent bca8391 commit b638331
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 0 deletions.
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
}
}
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.

0 comments on commit b638331

Please sign in to comment.