-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added getpermalink method, group, mocks, extensions and dtos
- Loading branch information
Showing
9 changed files
with
243 additions
and
13 deletions.
There are no files selected for viewing
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
9 changes: 7 additions & 2 deletions
9
...lack-api-client/src/main/kotlin/com/kreait/slack/api/group/chat/GetChatPermalinkMethod.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 |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package com.kreait.slack.api.group.chat | ||
|
||
//TODO Implement | ||
abstract class GetChatPermalinkMethod { | ||
import com.kreait.slack.api.contract.jackson.group.chat.ChatGetPermalinkRequest | ||
import com.kreait.slack.api.contract.jackson.group.chat.ErrorChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.SuccessfulChatGetPermalinkResponse | ||
import com.kreait.slack.api.group.ApiCallMethod | ||
|
||
abstract class ChatGetPermalinkMethod : ApiCallMethod<ChatGetPermalinkMethod, SuccessfulChatGetPermalinkResponse, ErrorChatGetPermalinkResponse, ChatGetPermalinkRequest>() { | ||
|
||
} | ||
|
37 changes: 37 additions & 0 deletions
37
...lient/src/main/kotlin/com/kreait/slack/api/spring/group/chat/DefaultGetPermalinkMethod.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,37 @@ | ||
package com.kreait.slack.api.spring.group.chat | ||
|
||
|
||
import com.kreait.slack.api.contract.jackson.group.chat.ChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.ErrorChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.SuccessfulChatGetPermalinkResponse | ||
import com.kreait.slack.api.group.ApiCallResult | ||
import com.kreait.slack.api.group.chat.ChatGetPermalinkMethod | ||
import com.kreait.slack.api.spring.group.RestTemplateFactory | ||
import com.kreait.slack.api.spring.group.SlackRequestBuilder | ||
import org.springframework.web.client.RestTemplate | ||
|
||
|
||
@Suppress("UNCHECKED_CAST") | ||
class DefaultGetPermalinkMethod(private val authToken: String, private val restTemplate: RestTemplate = RestTemplateFactory.slackTemplate()) : ChatGetPermalinkMethod() { | ||
|
||
override fun request(): ApiCallResult<SuccessfulChatGetPermalinkResponse, ErrorChatGetPermalinkResponse> { | ||
val response = SlackRequestBuilder<ChatGetPermalinkResponse>(authToken, restTemplate) | ||
.with(this.params) | ||
.toMethod("chat.getPermalink") | ||
.returnAsType(ChatGetPermalinkResponse::class.java) | ||
.postWithJsonBody() | ||
|
||
return when (response.body!!) { | ||
is SuccessfulChatGetPermalinkResponse -> { | ||
val responseEntity = response.body as SuccessfulChatGetPermalinkResponse | ||
this.onSuccess?.invoke(responseEntity) | ||
ApiCallResult(success = responseEntity) | ||
} | ||
is ErrorChatGetPermalinkResponse -> { | ||
val responseEntity = response.body as ErrorChatGetPermalinkResponse | ||
this.onFailure?.invoke(responseEntity) | ||
ApiCallResult(failure = responseEntity) | ||
} | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...t/src/test/kotlin/com/kreait/slack/api/spring/group/chat/DefaultGetPermalinkMethodTest.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,54 @@ | ||
package com.kreait.slack.api.spring.group.chat | ||
|
||
import com.kreait.slack.api.contract.jackson.group.chat.ChatGetPermalinkRequest | ||
import com.kreait.slack.api.contract.jackson.group.chat.ErrorChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.SuccessfulChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.sample | ||
import com.kreait.slack.api.spring.MockServerHelper | ||
import com.kreait.slack.api.spring.Verifier | ||
import com.kreait.slack.api.spring.group.RestTemplateFactory | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.springframework.web.client.RestTemplate | ||
|
||
class DefaultGetPermalinkMethodTest { | ||
|
||
private lateinit var mockTemplate: RestTemplate | ||
|
||
@BeforeEach | ||
fun setup() { | ||
mockTemplate = RestTemplateFactory.slackTemplate() | ||
} | ||
|
||
@Test | ||
@DisplayName("chat.getPermalink Failure") | ||
fun chatGetPermalinkFailure() { | ||
val response = ErrorChatGetPermalinkResponse.sample() | ||
val mockServer = MockServerHelper.buildMockRestServer(mockTemplate, "chat.getPermalink", response) | ||
val verifier = Verifier(response) | ||
|
||
DefaultGetPermalinkMethod("", mockTemplate) | ||
.with(ChatGetPermalinkRequest.sample()) | ||
.onFailure { verifier.set(it) } | ||
.onSuccess { } | ||
.invoke() | ||
mockServer.verify() | ||
verifier.verify() | ||
} | ||
|
||
@Test | ||
@DisplayName("chat.getPermalink Success") | ||
fun chatGetPermalinkSuccess() { | ||
val response = SuccessfulChatGetPermalinkResponse.sample() | ||
val mockServer = MockServerHelper.buildMockRestServer(mockTemplate, "chat.getPermalink", response) | ||
val verifier = Verifier(response) | ||
|
||
DefaultGetPermalinkMethod("", mockTemplate) | ||
.with(ChatGetPermalinkRequest.sample()) | ||
.onSuccess { verifier.set(it) } | ||
.invoke() | ||
mockServer.verify() | ||
verifier.verify() | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...t-api-client/src/main/kotlin/com/kreait/slack/api/test/group/chat/MockChatGetPermalink.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,25 @@ | ||
package com.kreait.slack.api.test.group.chat | ||
|
||
import com.kreait.slack.api.contract.jackson.group.chat.ChatGetPermalinkRequest | ||
import com.kreait.slack.api.contract.jackson.group.chat.ErrorChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.SuccessfulChatGetPermalinkResponse | ||
import com.kreait.slack.api.group.ApiCallResult | ||
import com.kreait.slack.api.group.chat.ChatGetPermalinkMethod | ||
import com.kreait.slack.api.test.MockMethod | ||
|
||
class MockChatGetPermalink : ChatGetPermalinkMethod(), MockMethod<SuccessfulChatGetPermalinkResponse, ErrorChatGetPermalinkResponse, ChatGetPermalinkRequest> { | ||
|
||
override fun params(): ChatGetPermalinkRequest { | ||
return params; | ||
} | ||
|
||
override var successResponse: SuccessfulChatGetPermalinkResponse? = null | ||
override var failureResponse: ErrorChatGetPermalinkResponse? = null | ||
|
||
override fun request(): ApiCallResult<SuccessfulChatGetPermalinkResponse, ErrorChatGetPermalinkResponse> { | ||
this.successResponse?.let { this.onSuccess?.invoke(it) } | ||
this.failureResponse?.let { this.onFailure?.invoke(it) } | ||
|
||
return ApiCallResult(this.successResponse, this.failureResponse) | ||
} | ||
} |
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
30 changes: 30 additions & 0 deletions
30
...ent/src/test/kotlin/com/kreait/slack/api/test/group/chat/MockChatGetPermalinkUnitTests.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,30 @@ | ||
package com.kreait.slack.api.test.group.chat | ||
|
||
import com.kreait.slack.api.contract.jackson.group.chat.ChatGetPermalinkRequest | ||
import com.kreait.slack.api.contract.jackson.group.chat.ErrorChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.SuccessfulChatGetPermalinkResponse | ||
import com.kreait.slack.api.contract.jackson.group.chat.sample | ||
import com.kreait.slack.api.test.MockMethodTestHelper | ||
import com.kreait.slack.api.test.MockSlackClient | ||
import com.nhaarman.mockitokotlin2.mock | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
|
||
|
||
@DisplayName("MockChatGetPermalinkMethod") | ||
class MockChatGetPermalinkUnitTests { | ||
|
||
|
||
@DisplayName("Mocking Successful") | ||
@Test | ||
fun testMockMethod() { | ||
val successFunction: (SuccessfulChatGetPermalinkResponse?) -> Any = mock {} | ||
val failureFunction: (ErrorChatGetPermalinkResponse?) -> Any = mock {} | ||
val mockSlackClient = MockSlackClient() | ||
|
||
MockMethodTestHelper.verify({ mockSlackClient.chat().getPermalink("") }, | ||
successFunction, SuccessfulChatGetPermalinkResponse.sample(), | ||
failureFunction, ErrorChatGetPermalinkResponse.sample(), | ||
ChatGetPermalinkRequest.sample()) | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...rc/main/kotlin/com/kreait/slack/api/contract/jackson/group/chat/GetPermalinkExtensions.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,15 @@ | ||
package com.kreait.slack.api.contract.jackson.group.chat | ||
|
||
import java.time.Instant | ||
|
||
fun ErrorChatGetPermalinkResponse.Companion.sample(): ErrorChatGetPermalinkResponse { | ||
return ErrorChatGetPermalinkResponse(false, "") | ||
} | ||
|
||
fun SuccessfulChatGetPermalinkResponse.Companion.sample(): SuccessfulChatGetPermalinkResponse { | ||
return SuccessfulChatGetPermalinkResponse(true, "", "") | ||
} | ||
|
||
fun ChatGetPermalinkRequest.Companion.sample(): ChatGetPermalinkRequest { | ||
return ChatGetPermalinkRequest("", Instant.now()) | ||
} |
40 changes: 40 additions & 0 deletions
40
...kson-dto/src/main/kotlin/com/kreait/slack/api/contract/jackson/group/chat/GetPermalink.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,40 @@ | ||
package com.kreait.slack.api.contract.jackson.group.chat | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty | ||
import com.fasterxml.jackson.annotation.JsonSubTypes | ||
import com.fasterxml.jackson.annotation.JsonTypeInfo | ||
import com.kreait.slack.api.contract.jackson.JacksonDataClass | ||
import java.time.Instant | ||
|
||
@JacksonDataClass | ||
data class ChatGetPermalinkRequest constructor(@JsonProperty("channel") val channel: String, | ||
@JsonProperty("message_ts") val timestamp: Instant) { | ||
companion object | ||
} | ||
|
||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.PROPERTY, | ||
property = "ok", | ||
visible = true) | ||
@JsonSubTypes( | ||
JsonSubTypes.Type(value = SuccessfulChatGetPermalinkResponse::class, name = "true"), | ||
JsonSubTypes.Type(value = ErrorChatGetPermalinkResponse::class, name = "false") | ||
) | ||
@JacksonDataClass | ||
sealed class ChatGetPermalinkResponse constructor(@JsonProperty("ok") open val ok: Boolean) | ||
|
||
@JacksonDataClass | ||
data class SuccessfulChatGetPermalinkResponse constructor(override val ok: Boolean, | ||
@JsonProperty("channel") val channel: String, | ||
@JsonProperty("permalink") val permalink: String) : ChatGetPermalinkResponse(ok) { | ||
companion object | ||
} | ||
|
||
@JacksonDataClass | ||
data class ErrorChatGetPermalinkResponse constructor(override val ok: Boolean, | ||
@JsonProperty("error") val error: String) | ||
: ChatGetPermalinkResponse(ok) { | ||
companion object | ||
} | ||
|
||
|