1
0
mirror of https://github.com/owncloud/android-library.git synced 2026-08-11 16:33:03 +00:00

add moshi classes for webfinger responses

This commit is contained in:
Christian Schabesberger
2022-04-20 15:12:38 +02:00
committed by Abel García de Prada
parent 2c225d8e66
commit c966bf14d0
9 changed files with 202 additions and 0 deletions
@@ -25,6 +25,7 @@
package com.owncloud.android.lib.resources.shares.responses
import com.owncloud.android.lib.resources.CommonOcsResponse
import com.owncloud.android.lib.resources.webfinger.responses.WebfingerJrdResponse
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.Moshi
import com.squareup.moshi.Types
@@ -0,0 +1,11 @@
package com.owncloud.android.lib.resources.webfinger
import android.os.Build
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [Build.VERSION_CODES.O], manifest = Config.NONE)
class GetOCInstanceViaWebfingerOperationTest {
}
@@ -0,0 +1,51 @@
package com.owncloud.android.lib.resources.webfinger.responses
import com.squareup.moshi.JsonAdapter
import com.squareup.moshi.JsonDataException
import com.squareup.moshi.Moshi
import org.junit.Assert
import org.junit.Assert.assertThrows
import org.junit.Before
import org.junit.Test
import java.io.File
class WebfingerResponseTest {
lateinit var adapter: JsonAdapter<WebfingerJrdResponse>
private fun loadResponses(fileName: String) =
adapter.fromJson(File(fileName).readText())
@Before
fun prepare() {
val moshi = Moshi.Builder().build()
adapter = moshi.adapter(WebfingerJrdResponse::class.java)
}
@Test
fun `check rel in to much information - ok - correct rell is returned`() {
val response = loadResponses(TO_MUCH_INFORMATION_JSON)!!
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
Assert.assertEquals("http://webfinger.owncloud/rel/server-instance", response.links[0].rel)
}
@Test(expected = JsonDataException::class)
fun `check key value pairs - ko - no href key`() {
val response = loadResponses(BROKEN_JSON)!!
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
}
@Test(expected = JsonDataException::class)
fun `check key value pairs - ko - no rel key`() {
val response = loadResponses(BROKEN_JSON)!!
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
}
companion object {
val RESOURCES_PATH =
"src/test/responses/com.owncloud.android.lib.resources.webfinger.responses"
val EXAMPLE_RESPONSE_JSON = "$RESOURCES_PATH/simple_response.json"
val TO_MUCH_INFORMATION_JSON = "$RESOURCES_PATH/to_much_information_response.json"
val BROKEN_JSON = "$RESOURCES_PATH/broken_response.json"
val NOT_CONTAINING_RELEVANT_INFORMATION_JSON = "$RESOURCES_PATH/not_containing_relevant_info_response.json"
}
}
@@ -0,0 +1,15 @@
{
"subject": "acct:bob@example.com",
"aliases": [
"https://www.example.com/~bob/"
],
"properties": {
"http://example.com/ns/role": "employee"
},
"links": [
{
"lel": "http://webfinger.example/rel/profile-page",
"foo": "https://www.example.com/~bob/"
}
]
}
@@ -0,0 +1,10 @@
{
"subject": "acct:peter.sine@gurken.xxx",
"links" :
[
{
"rel" : "http://webfinger.example/rel/businesscard",
"href" : "https://www.example.com/~bob/bob.vcf"
}
]
}
@@ -0,0 +1,9 @@
{
"links": [
{
"href": "https://gast.somedomain.de",
"rel": "http://webfinger.owncloud/rel/server-instance"
}
],
"subject": "acct:peter.sine@gurken.xxx"
}
@@ -0,0 +1,27 @@
{
"subject": "acct:peter.sine@gurken.xxx",
"aliases" :
[
"https://www.example.com/~bob/"
],
"properties" :
{
"http://example.com/ns/role" : "employee"
},
"gurken": {
"whatever": 42
},
"links" :
[
{
"gurken": "sallat",
"href": "https://gast.somedomain.de",
"rel": "http://webfinger.owncloud/rel/server-instance"
},
{
"gurken": "sallat",
"rel" : "http://webfinger.example/rel/businesscard",
"href" : "https://www.example.com/~bob/bob.vcf"
}
]
}