Skip to content

Commit

Permalink
Remove warnings, improve the build
Browse files Browse the repository at this point in the history

* To address deprecation in most places not deprecated has been used.
In those specific areas where we actually want to verify that
our deprecated methods are working I added SUPPRESS annotations.
* ktlint debug has been disabled to reduce the amount of information produced
* .editorconfig file used the suggested by ktlint value
* Compile integration tests when compiling project
  • Loading branch information
kleewho authored Oct 27, 2022
1 parent fabcacb commit a639478
Show file tree
Hide file tree
Showing 73 changed files with 221 additions and 174 deletions.
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ allprojects {
ktlint {
outputToConsole = true
verbose = true
debug = true
additionalEditorconfigFile = file("check/.editorconfig")
kotlinScriptAdditionalPaths {
include fileTree("src/integrationTest/")
Expand All @@ -67,6 +66,8 @@ allprojects {
compileTestKotlin {
kotlinOptions.jvmTarget = "1.8"
}

compileKotlin.finalizedBy(task("compileIntegrationTest"))
}
sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
3 changes: 1 addition & 2 deletions check/.editorconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
root = true

[*.{kt, kts}]
disabled_rules = import-ordering
kotlin_imports_layout = idea
ij_kotlin_imports_layout = *,java.**,javax.**,kotlin.**,^
indent_size = 4
ij_kotlin_keep_blank_lines_in_declarations = 1
ij_kotlin_keep_blank_lines_in_code = 1
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.pubnub.membership

import com.pubnub.api.PNConfiguration
import com.pubnub.api.PubNub
import com.pubnub.api.SpaceId
import com.pubnub.api.UserId
Expand Down Expand Up @@ -57,7 +56,7 @@ class MembershipIntegTest {

@BeforeEach
fun setUp() {
val config = PNConfiguration(USER_ID).apply {
val config = PNConfiguration(userId = UserId(uuid)).apply {
subscribeKey = IntegTestConf.subscribeKey
publishKey = IntegTestConf.publishKey
IntegTestConf.origin?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ data class Membership(
}

internal fun PNChannelMembership.toUserMembership(userId: UserId): Membership {
@Suppress("UNCHECKED_CAST")
return Membership(
user = User(id = userId),
space = channel?.toSpace(),
Expand All @@ -61,6 +62,7 @@ internal fun PNChannelMembership.toUserMembership(userId: UserId): Membership {
}

internal fun PNMember.toSpaceMembership(spaceId: SpaceId): Membership {
@Suppress("UNCHECKED_CAST")
return Membership(
user = uuid?.toUser(),
space = Space(id = spaceId),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ data class MembershipRemoved(
fun PNObjectEventResult.toMembershipEvent(): MembershipEvent? {
return when (val m = extractedMessage) {
is PNSetMembershipEventMessage -> {
@Suppress("UNCHECKED_CAST")
MembershipModified(
data = MembershipModified.Data(
space = Space(id = SpaceId(m.data.channel)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.pubnub.space
import com.pubnub.api.PNConfiguration
import com.pubnub.api.PubNub
import com.pubnub.api.PubNubException
import com.pubnub.api.SpaceId
import com.pubnub.api.UserId
import com.pubnub.api.callbacks.SubscribeCallback
import com.pubnub.api.enums.PNLogVerbosity
import com.pubnub.api.enums.PNStatusCategory
import com.pubnub.api.models.consumer.PNStatus
import com.pubnub.api.models.consumer.objects.ResultSortKey
import com.pubnub.space.models.consumer.Space
import com.pubnub.space.models.consumer.SpaceId
import com.pubnub.space.models.consumer.SpaceKey
import com.pubnub.space.models.consumer.SpaceModified
import com.pubnub.space.models.consumer.SpacesResult
Expand Down Expand Up @@ -38,7 +38,7 @@ class SpaceIntegTest {

@BeforeEach
fun setUp() {
val config = PNConfiguration(UserId("kotlin")).apply {
val config = PNConfiguration(userId = UserId("kotlin")).apply {
subscribeKey = IntegTestConf.subscribeKey
publishKey = IntegTestConf.publishKey
IntegTestConf.origin?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ data class Space(
)

fun PNChannelMetadata.toSpace(): Space {
@Suppress("UNCHECKED_CAST")
return Space(
id = SpaceId(id),
name = name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ data class SpaceRemoved(
fun PNObjectEventResult.toSpaceEvent(): SpaceEvent? {
return when (val m = extractedMessage) {
is PNSetChannelMetadataEventMessage -> {
@Suppress("UNCHECKED_CAST")
SpaceModified(
spaceId = SpaceId(channel), timetoken = timetoken ?: 0,
data = SpaceModified.Data(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class UserIntegTest {

@BeforeEach
fun setUp() {
val config = PNConfiguration(UserId("kotlin")).apply {
val config = PNConfiguration(userId = UserId("kotlin")).apply {
subscribeKey = IntegTestConf.subscribeKey
publishKey = IntegTestConf.publishKey
IntegTestConf.origin?.let {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ data class User(
)

fun PNUUIDMetadata.toUser(): User {
@Suppress("UNCHECKED_CAST")
return User(
id = UserId(id),
name = name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ data class UserRemoved(
fun PNObjectEventResult.toUserEvent(): UserEvent? {
return when (val m = extractedMessage) {
is PNSetUUIDMetadataEventMessage -> {
@Suppress("UNCHECKED_CAST")
UserModified(
spaceId = channel,
timetoken = timetoken ?: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.pubnub.api.integration

import com.pubnub.api.Keys
import com.pubnub.api.PNConfiguration
import com.pubnub.api.PubNub
import com.pubnub.api.UserId
import com.pubnub.api.callbacks.SubscribeCallback
import com.pubnub.api.enums.PNLogVerbosity
import com.pubnub.api.enums.PNOperationType
Expand Down Expand Up @@ -31,7 +31,7 @@ class AppTest {
@Before
fun initPubnub() {
pubnub = PubNub(
PNConfiguration(PubNub.generateUUID()).apply {
PNConfiguration(userId = UserId(PubNub.generateUUID())).apply {
subscribeKey = Keys.subKey
publishKey = Keys.pubKey
logVerbosity = PNLogVerbosity.BODY
Expand Down Expand Up @@ -128,7 +128,7 @@ class AppTest {
.with()
.until {
pubnub.whereNow(
uuid = pubnub.configuration.uuid
uuid = pubnub.configuration.userId.value
).sync()!!
.channels
.containsAll(expectedChannels)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.pubnub.api.CommonUtils.createInterceptor
import com.pubnub.api.Keys
import com.pubnub.api.PNConfiguration
import com.pubnub.api.PubNub
import com.pubnub.api.UserId
import com.pubnub.api.enums.PNLogVerbosity
import org.junit.After
import org.junit.Before
Expand Down Expand Up @@ -55,7 +56,7 @@ abstract class BaseIntegrationTest {
}

protected open fun getBasicPnConfiguration(): PNConfiguration {
val pnConfiguration = PNConfiguration(PubNub.generateUUID())
val pnConfiguration = PNConfiguration(userId = UserId(PubNub.generateUUID()))
if (!needsServer()) {
pnConfiguration.subscribeKey = Keys.subKey
pnConfiguration.publishKey = Keys.pubKey
Expand All @@ -67,19 +68,19 @@ abstract class BaseIntegrationTest {
pnConfiguration.logVerbosity = PNLogVerbosity.NONE
pnConfiguration.httpLoggingInterceptor = createInterceptor(logger)

pnConfiguration.uuid = "client-${UUID.randomUUID()}"
pnConfiguration.userId = UserId("client-${UUID.randomUUID()}")
return pnConfiguration
}

private fun getServerPnConfiguration(): PNConfiguration {
val pnConfiguration = PNConfiguration(PubNub.generateUUID())
val pnConfiguration = PNConfiguration(userId = UserId(PubNub.generateUUID()))
pnConfiguration.subscribeKey = Keys.pamSubKey
pnConfiguration.publishKey = Keys.pamPubKey
pnConfiguration.secretKey = Keys.pamSecKey
pnConfiguration.logVerbosity = PNLogVerbosity.NONE
pnConfiguration.httpLoggingInterceptor = createInterceptor(logger)

pnConfiguration.uuid = "server-${UUID.randomUUID()}"
pnConfiguration.userId = UserId("server-${UUID.randomUUID()}")
return pnConfiguration
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class HeartbeatIntegrationTest : BaseIntegrationTest() {
val expectedStatePayload = generatePayload()

val observer = createPubNub().apply {
configuration.uuid = "observer_${System.currentTimeMillis()}"
configuration.userId.value = "observer_${System.currentTimeMillis()}"
}

pubnub.configuration.presenceTimeout = 20
Expand All @@ -51,7 +51,7 @@ class HeartbeatIntegrationTest : BaseIntegrationTest() {
}

override fun presence(p: PubNub, pnPresenceEventResult: PNPresenceEventResult) {
if (pnPresenceEventResult.uuid.equals(pubnub.configuration.uuid) &&
if (pnPresenceEventResult.uuid.equals(pubnub.configuration.userId.value) &&
pnPresenceEventResult.channel.equals(expectedChannel)
) {
when (pnPresenceEventResult.event) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class PresenceEventsIntegrationTests : BaseIntegrationTest() {

override fun presence(pubnub: PubNub, pnPresenceEventResult: PNPresenceEventResult) {
if (pnPresenceEventResult.event == "state-change") {
assertEquals(pubnub.configuration.uuid, pnPresenceEventResult.uuid)
assertEquals(pubnub.configuration.userId.value, pnPresenceEventResult.uuid)
success.set(true)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class PresenceIntegrationTests : BaseIntegrationTest() {
assertTrue(value.occupants.size >= expectedClientsCount)

assertEquals(
clients.map { it.configuration.uuid }.toList(),
clients.map { it.configuration.userId.value }.toList(),
value.occupants.map { it.uuid }.toList()
)
}
Expand Down Expand Up @@ -113,7 +113,7 @@ class PresenceIntegrationTests : BaseIntegrationTest() {
val uuid = occupant.uuid
var contains = false
for (client in clients) {
if (client.configuration.uuid == uuid) {
if (client.configuration.userId.value == uuid) {
contains = true
break
}
Expand All @@ -136,7 +136,7 @@ class PresenceIntegrationTests : BaseIntegrationTest() {
override fun presence(pubnub: PubNub, pnPresenceEventResult: PNPresenceEventResult) {
if (pnPresenceEventResult.event == "state-change" &&
pnPresenceEventResult.channel == expectedChannel &&
pnPresenceEventResult.uuid == pubnub.configuration.uuid
pnPresenceEventResult.uuid == pubnub.configuration.userId.value
) {
assertEquals(expectedStatePayload, pnPresenceEventResult.state)
hits.incrementAndGet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class PublishIntegrationTests : BaseIntegrationTest() {
message = generatePayload()
).await { _, status ->
assertFalse(status.error)
assertEquals(status.uuid, pubnub.configuration.uuid)
assertEquals(status.uuid, pubnub.configuration.userId.value)
}
}

Expand Down Expand Up @@ -82,7 +82,7 @@ class PublishIntegrationTests : BaseIntegrationTest() {
shouldStore = false
).await { _, status ->
assertFalse(status.error)
assertEquals(status.uuid, pubnub.configuration.uuid)
assertEquals(status.uuid, pubnub.configuration.userId.value)
}

pubnub.history(
Expand Down Expand Up @@ -118,7 +118,7 @@ class PublishIntegrationTests : BaseIntegrationTest() {

override fun message(pubnub: PubNub, pnMessageResult: PNMessageResult) {
assertEquals(expectedChannel, pnMessageResult.channel)
assertEquals(observer.configuration.uuid, pnMessageResult.publisher)
assertEquals(observer.configuration.userId.value, pnMessageResult.publisher)
assertEquals(messagePayload, pnMessageResult.message)
success.set(true)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import java.util.Locale
import java.util.UUID

class PushIntegrationTest : BaseIntegrationTest() {
Expand All @@ -16,7 +17,7 @@ class PushIntegrationTest : BaseIntegrationTest() {

override fun onBefore() {
expectedChannels =
generateSequence { UUID.randomUUID().toString().substring(0, 8).toUpperCase() }.take(3).toList()
generateSequence { UUID.randomUUID().toString().substring(0, 8).uppercase(Locale.getDefault()) }.take(3).toList()
expectedDeviceId =
generateSequence { (0..9).random() }.take(70).toList().shuffled().joinToString(separator = "")
expectedTopic = UUID.randomUUID().toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SignalIntegrationTests : BaseIntegrationTest() {
).await { result, status ->
assertFalse(status.error)
assertEquals(PNOperationType.PNSignalOperation, status.operation)
assertEquals(status.uuid, pubnub.configuration.uuid)
assertEquals(status.uuid, pubnub.configuration.userId.value)
assertNotNull(result)
}
}
Expand Down Expand Up @@ -66,14 +66,14 @@ class SignalIntegrationTests : BaseIntegrationTest() {
).async { result, status ->
assertFalse(status.error)
assertEquals(PNOperationType.PNSignalOperation, status.operation)
assertEquals(status.uuid, pubnub.configuration.uuid)
assertEquals(status.uuid, pubnub.configuration.userId.value)
assertNotNull(result)
}
}
}

override fun signal(pubnub: PubNub, pnSignalResult: PNSignalResult) {
assertEquals(pubnub.configuration.uuid, pnSignalResult.publisher)
assertEquals(pubnub.configuration.userId.value, pnSignalResult.publisher)
assertEquals(expectedChannel, pnSignalResult.channel)
assertEquals(expectedPayload, Gson().fromJson(pnSignalResult.message, String::class.java))
success.set(true)
Expand Down
Loading

0 comments on commit a639478

Please sign in to comment.