Skip to content
This repository was archived by the owner on Mar 19, 2024. It is now read-only.

Commit c966bf1

Browse files
theScrabiabelgardep
authored andcommitted
add moshi classes for webfinger responses
1 parent 2c225d8 commit c966bf1

File tree

9 files changed

+202
-0
lines changed

9 files changed

+202
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* ownCloud Android Library is available under MIT license
2+
*
3+
* Copyright (C) 2022 ownCloud GmbH.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package com.owncloud.android.lib.resources.webfinger
26+
27+
import com.owncloud.android.lib.common.OwnCloudClient
28+
import com.owncloud.android.lib.common.operations.RemoteOperation
29+
import com.owncloud.android.lib.common.operations.RemoteOperationResult
30+
31+
class GetOCInstanceViaWebfingerOperation(
32+
private val rel:String,
33+
private val resource:String
34+
) : RemoteOperation<String>() {
35+
36+
override fun run(client: OwnCloudClient?): RemoteOperationResult<String> {
37+
TODO("Not yet implemented")
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/* ownCloud Android Library is available under MIT license
2+
*
3+
* Copyright (C) 2022 ownCloud GmbH.
4+
*
5+
* Permission is hereby granted, free of charge, to any person obtaining a copy
6+
* of this software and associated documentation files (the "Software"), to deal
7+
* in the Software without restriction, including without limitation the rights
8+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
* copies of the Software, and to permit persons to whom the Software is
10+
* furnished to do so, subject to the following conditions:
11+
*
12+
* The above copyright notice and this permission notice shall be included in
13+
* all copies or substantial portions of the Software.
14+
*
15+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18+
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19+
* BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20+
* ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21+
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+
* THE SOFTWARE.
23+
*/
24+
25+
package com.owncloud.android.lib.resources.webfinger.responses
26+
27+
import com.squareup.moshi.JsonClass
28+
29+
@JsonClass(generateAdapter = true)
30+
data class WebfingerJrdResponse (
31+
val subject:String,
32+
val links:List<LinkItem>
33+
)
34+
35+
@JsonClass(generateAdapter = true)
36+
data class LinkItem(
37+
val href:String,
38+
val rel:String
39+
)

owncloudComLibrary/src/test/java/com/owncloud/android/lib/resources/shares/responses/ShareeResponseTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package com.owncloud.android.lib.resources.shares.responses
2626

2727
import com.owncloud.android.lib.resources.CommonOcsResponse
28+
import com.owncloud.android.lib.resources.webfinger.responses.WebfingerJrdResponse
2829
import com.squareup.moshi.JsonAdapter
2930
import com.squareup.moshi.Moshi
3031
import com.squareup.moshi.Types
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.owncloud.android.lib.resources.webfinger
2+
3+
import android.os.Build
4+
import org.junit.runner.RunWith
5+
import org.robolectric.RobolectricTestRunner
6+
import org.robolectric.annotation.Config
7+
8+
@RunWith(RobolectricTestRunner::class)
9+
@Config(sdk = [Build.VERSION_CODES.O], manifest = Config.NONE)
10+
class GetOCInstanceViaWebfingerOperationTest {
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package com.owncloud.android.lib.resources.webfinger.responses
2+
3+
import com.squareup.moshi.JsonAdapter
4+
import com.squareup.moshi.JsonDataException
5+
import com.squareup.moshi.Moshi
6+
import org.junit.Assert
7+
import org.junit.Assert.assertThrows
8+
import org.junit.Before
9+
import org.junit.Test
10+
import java.io.File
11+
12+
class WebfingerResponseTest {
13+
lateinit var adapter: JsonAdapter<WebfingerJrdResponse>
14+
15+
private fun loadResponses(fileName: String) =
16+
adapter.fromJson(File(fileName).readText())
17+
18+
@Before
19+
fun prepare() {
20+
val moshi = Moshi.Builder().build()
21+
adapter = moshi.adapter(WebfingerJrdResponse::class.java)
22+
}
23+
24+
@Test
25+
fun `check rel in to much information - ok - correct rell is returned`() {
26+
val response = loadResponses(TO_MUCH_INFORMATION_JSON)!!
27+
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
28+
Assert.assertEquals("http://webfinger.owncloud/rel/server-instance", response.links[0].rel)
29+
}
30+
31+
@Test(expected = JsonDataException::class)
32+
fun `check key value pairs - ko - no href key`() {
33+
val response = loadResponses(BROKEN_JSON)!!
34+
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
35+
}
36+
37+
@Test(expected = JsonDataException::class)
38+
fun `check key value pairs - ko - no rel key`() {
39+
val response = loadResponses(BROKEN_JSON)!!
40+
Assert.assertEquals("https://gast.somedomain.de", response.links[0].href)
41+
}
42+
43+
companion object {
44+
val RESOURCES_PATH =
45+
"src/test/responses/com.owncloud.android.lib.resources.webfinger.responses"
46+
val EXAMPLE_RESPONSE_JSON = "$RESOURCES_PATH/simple_response.json"
47+
val TO_MUCH_INFORMATION_JSON = "$RESOURCES_PATH/to_much_information_response.json"
48+
val BROKEN_JSON = "$RESOURCES_PATH/broken_response.json"
49+
val NOT_CONTAINING_RELEVANT_INFORMATION_JSON = "$RESOURCES_PATH/not_containing_relevant_info_response.json"
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"subject": "acct:[email protected]",
3+
"aliases": [
4+
"https://www.example.com/~bob/"
5+
],
6+
"properties": {
7+
"http://example.com/ns/role": "employee"
8+
},
9+
"links": [
10+
{
11+
"lel": "http://webfinger.example/rel/profile-page",
12+
"foo": "https://www.example.com/~bob/"
13+
}
14+
]
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"subject": "acct:[email protected]",
3+
"links" :
4+
[
5+
{
6+
"rel" : "http://webfinger.example/rel/businesscard",
7+
"href" : "https://www.example.com/~bob/bob.vcf"
8+
}
9+
]
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"links": [
3+
{
4+
"href": "https://gast.somedomain.de",
5+
"rel": "http://webfinger.owncloud/rel/server-instance"
6+
}
7+
],
8+
"subject": "acct:[email protected]"
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"subject": "acct:[email protected]",
3+
"aliases" :
4+
[
5+
"https://www.example.com/~bob/"
6+
],
7+
"properties" :
8+
{
9+
"http://example.com/ns/role" : "employee"
10+
},
11+
"gurken": {
12+
"whatever": 42
13+
},
14+
"links" :
15+
[
16+
{
17+
"gurken": "sallat",
18+
"href": "https://gast.somedomain.de",
19+
"rel": "http://webfinger.owncloud/rel/server-instance"
20+
},
21+
{
22+
"gurken": "sallat",
23+
"rel" : "http://webfinger.example/rel/businesscard",
24+
"href" : "https://www.example.com/~bob/bob.vcf"
25+
}
26+
]
27+
}

0 commit comments

Comments
 (0)