-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
94c3234
commit cbb2802
Showing
103 changed files
with
4,418 additions
and
598 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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 +1,3 @@ | ||
* @kleewho @bartk @qsoftdevelopment @Chesteer89 | ||
* @kleewho @bartk @Chesteer89 | ||
.travis/* @parfeon @kleewho @bartk @Chesteer89 | ||
README.md @polarweasel @samiahmedsiddiqui @techwritermat |
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
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,13 @@ | ||
## [v5.1.0](https://github.com/pubnub/kotlin/releases/tag/v5.1.0) | ||
December 16 2020 | ||
|
||
[Full Changelog](https://github.com/pubnub/kotlin/compare/v5.0.2...v5.1.0) | ||
|
||
- Files support includes sending, downloading, listing, deleting together with notifications about file events. | ||
- New methods can set and remove memberships/channelMembers in one call. | ||
- New field `page` can be returned from the backend in case there's more data to fetch for the original query. This new field can be used directly in new `fetchMessages` and `getMessagesActions` method versions. The old versions in which paging information was in separate arguments has been deprecated. | ||
- FetchMessages has a default limit of 100 for single-channel call. | ||
- Make PNMessageActionResultevent accessible (no longer internal). | ||
- Method `addMemberships` has been deprecated and shouldn't be used in the future. | ||
|
||
|
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
106 changes: 106 additions & 0 deletions
106
src/integrationTest/kotlin/com/pubnub/api/integration/FilesIntegrationTest.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,106 @@ | ||
package com.pubnub.api.integration | ||
|
||
import com.pubnub.api.CommonUtils.randomChannel | ||
import com.pubnub.api.PubNub | ||
import com.pubnub.api.callbacks.SubscribeCallback | ||
import com.pubnub.api.enums.PNStatusCategory | ||
import com.pubnub.api.models.consumer.PNStatus | ||
import com.pubnub.api.models.consumer.files.PNFileUploadResult | ||
import com.pubnub.api.models.consumer.pubsub.PNMessageResult | ||
import com.pubnub.api.models.consumer.pubsub.PNPresenceEventResult | ||
import com.pubnub.api.models.consumer.pubsub.PNSignalResult | ||
import com.pubnub.api.models.consumer.pubsub.files.PNFileEventResult | ||
import com.pubnub.api.models.consumer.pubsub.message_actions.PNMessageActionResult | ||
import com.pubnub.api.models.consumer.pubsub.objects.PNObjectEventResult | ||
import org.junit.Assert | ||
import org.junit.Test | ||
import java.io.ByteArrayInputStream | ||
import java.io.InputStream | ||
import java.nio.charset.StandardCharsets | ||
import java.util.Scanner | ||
import java.util.concurrent.CountDownLatch | ||
import java.util.concurrent.TimeUnit | ||
|
||
class FilesIntegrationTest : BaseIntegrationTest() { | ||
@Test | ||
fun uploadListDownloadDeleteWithCipher() { | ||
uploadListDownloadDelete(true) | ||
} | ||
|
||
@Test | ||
fun uploadListDownloadDeleteWithoutCipher() { | ||
uploadListDownloadDelete(false) | ||
} | ||
|
||
private fun uploadListDownloadDelete(withCipher: Boolean) { | ||
if (withCipher) { | ||
pubnub.configuration.cipherKey = "enigma" | ||
} | ||
val channel: String = randomChannel() | ||
val content = "This is content" | ||
val message = "This is message" | ||
val meta = "This is meta" | ||
val fileName = "fileName$channel.txt" | ||
val connectedLatch = CountDownLatch(1) | ||
val fileEventReceived = CountDownLatch(1) | ||
pubnub.addListener(object : LimitedListener() { | ||
override fun status(pubnub: PubNub, pnStatus: PNStatus) { | ||
if (pnStatus.category === PNStatusCategory.PNConnectedCategory) { | ||
connectedLatch.countDown() | ||
} | ||
} | ||
|
||
override fun file(pubnub: PubNub, pnFileEventResult: PNFileEventResult) { | ||
if (pnFileEventResult.file.name == fileName) { | ||
fileEventReceived.countDown() | ||
} | ||
} | ||
}) | ||
pubnub.subscribe(channels = listOf(channel)) | ||
connectedLatch.await(10, TimeUnit.SECONDS) | ||
val sendResult: PNFileUploadResult? = ByteArrayInputStream(content.toByteArray(StandardCharsets.UTF_8)).use { | ||
pubnub.sendFile( | ||
channel = channel, | ||
fileName = fileName, | ||
inputStream = it, | ||
message = message, | ||
meta = meta | ||
).sync() | ||
} | ||
|
||
if (sendResult == null) { | ||
Assert.fail() | ||
return | ||
} | ||
fileEventReceived.await(10, TimeUnit.SECONDS) | ||
val (_, _, _, data) = pubnub.listFiles(channel = channel).sync()!! | ||
val fileFoundOnList = data.find { it.id == sendResult.file.id } != null | ||
|
||
Assert.assertTrue(fileFoundOnList) | ||
val (_, byteStream) = pubnub.downloadFile( | ||
channel = channel, | ||
fileName = fileName, | ||
fileId = sendResult.file.id | ||
) | ||
.sync()!! | ||
byteStream?.use { | ||
Assert.assertEquals(content, readToString(it)) | ||
} | ||
pubnub.deleteFile(channel = channel, | ||
fileName = fileName, | ||
fileId = sendResult.file.id) | ||
.sync() | ||
} | ||
|
||
private fun readToString(inputStream: InputStream): String { | ||
Scanner(inputStream).useDelimiter("\\A").use { s -> return if (s.hasNext()) s.next() else "" } | ||
} | ||
|
||
private abstract class LimitedListener : SubscribeCallback() { | ||
override fun presence(pubnub: PubNub, pnPresenceEventResult: PNPresenceEventResult) {} | ||
override fun message(pubnub: PubNub, pnMessageResult: PNMessageResult) {} | ||
override fun signal(pubnub: PubNub, pnSignalResult: PNSignalResult) {} | ||
override fun objects(pubnub: PubNub, objectEvent: PNObjectEventResult) {} | ||
override fun messageAction(pubnub: PubNub, pnMessageActionResult: PNMessageActionResult) {} | ||
} | ||
} |
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
Oops, something went wrong.