forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Contract tests for UUID against object V2 REST
- Loading branch information
1 parent
b05fc6e
commit 248e848
Showing
14 changed files
with
249 additions
and
7 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
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 |
---|---|---|
|
@@ -56,3 +56,4 @@ gradlew.bat | |
# GitHub Actions # | ||
################## | ||
.github/.release | ||
src/test/resources/sdk-specification |
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
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
10 changes: 10 additions & 0 deletions
10
src/test/java/com/pubnub/contract/objectV2/state/GetAllUUIDMetadataState.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,10 @@ | ||
package com.pubnub.contract.objectV2.state | ||
|
||
import com.pubnub.api.models.consumer.objects_api.uuid.PNGetAllUUIDMetadataResult | ||
import com.pubnub.api.models.consumer.objects_api.uuid.PNUUIDMetadata | ||
|
||
class GetAllUUIDMetadataState { | ||
var id: String? = null | ||
var pnUUIDMetadataList: List<PNUUIDMetadata>? = null | ||
var result: PNGetAllUUIDMetadataResult? = null | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/java/com/pubnub/contract/objectV2/state/GetUUIDMetadataState.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,10 @@ | ||
package com.pubnub.contract.objectV2.state | ||
|
||
import com.pubnub.api.models.consumer.objects_api.uuid.PNGetUUIDMetadataResult | ||
import com.pubnub.api.models.consumer.objects_api.uuid.PNUUIDMetadata | ||
|
||
class GetUUIDMetadataState { | ||
var id: String? = null //in PNUUIDMetadata id is val so it can't be reassigned and here we want to set it | ||
var pnUUIDMetadata: PNUUIDMetadata? = null | ||
var result: PNGetUUIDMetadataResult? = null | ||
} |
8 changes: 8 additions & 0 deletions
8
src/test/java/com/pubnub/contract/objectV2/state/RemoveUUIDMetadataState.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,8 @@ | ||
package com.pubnub.contract.objectV2.state | ||
|
||
import com.pubnub.api.models.consumer.objects_api.uuid.PNRemoveUUIDMetadataResult | ||
|
||
class RemoveUUIDMetadataState { | ||
var id: String? = null | ||
var result: PNRemoveUUIDMetadataResult? = null | ||
} |
10 changes: 10 additions & 0 deletions
10
src/test/java/com/pubnub/contract/objectV2/state/SetUUIDMetadataState.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,10 @@ | ||
package com.pubnub.contract.objectV2.state | ||
|
||
import com.pubnub.api.models.consumer.objects_api.uuid.PNSetUUIDMetadataResult | ||
import com.pubnub.api.models.consumer.objects_api.uuid.PNUUIDMetadata | ||
|
||
class SetUUIDMetadataState { | ||
var id: String? = null | ||
var pnUUIDMetadata: PNUUIDMetadata = PNUUIDMetadata() | ||
var result: PNSetUUIDMetadataResult? = null | ||
} |
55 changes: 55 additions & 0 deletions
55
src/test/java/com/pubnub/contract/objectV2/step/GivenSteps.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,55 @@ | ||
package com.pubnub.contract.objectV2.step | ||
|
||
import com.pubnub.contract.CONTRACT_TEST_CONFIG | ||
import com.pubnub.contract.objectV2.state.GetUUIDMetadataState | ||
import com.pubnub.contract.objectV2.state.RemoveUUIDMetadataState | ||
import com.pubnub.contract.objectV2.state.SetUUIDMetadataState | ||
import com.pubnub.contract.state.World | ||
import io.cucumber.java.en.Given | ||
import org.hamcrest.MatcherAssert | ||
import org.hamcrest.Matchers | ||
|
||
class GivenSteps( | ||
private val getUUIDMetadataState: GetUUIDMetadataState, | ||
private val setUUIDMetadataState: SetUUIDMetadataState, | ||
private val removeUUIDMetadataState: RemoveUUIDMetadataState, | ||
private val world: World | ||
) { | ||
|
||
@Given("I have a keyset with Objects V2 enabled") | ||
fun i_have_a_keyset_with_access_manager_enabled() { | ||
MatcherAssert.assertThat(CONTRACT_TEST_CONFIG.pubKey(), Matchers.notNullValue()) | ||
MatcherAssert.assertThat(CONTRACT_TEST_CONFIG.subKey(), Matchers.notNullValue()) | ||
world.configuration.apply { | ||
subscribeKey = CONTRACT_TEST_CONFIG.subKey() | ||
publishKey = CONTRACT_TEST_CONFIG.pubKey() | ||
} | ||
} | ||
|
||
@Given("the id for {string} persona") | ||
fun the_id_for_persona(personaName: String) { | ||
val pnUUIDMetadata = loadPersonaUUIDMetadata(personaName) | ||
val uuidId = pnUUIDMetadata.id | ||
getUUIDMetadataState.id = uuidId | ||
removeUUIDMetadataState.id = uuidId | ||
} | ||
|
||
@Given("current user is {string} persona") | ||
fun current_user_is_persona(personaName: String) { | ||
val pnUUIDMetadata = loadPersonaUUIDMetadata(personaName) | ||
val id = pnUUIDMetadata.id | ||
world.configuration.uuid = id | ||
} | ||
|
||
@Given("the data for {string} persona") | ||
fun the_data_for_persona(personaName: String) { | ||
val pnUUIDMetadata = loadPersonaUUIDMetadata(personaName) | ||
val id = pnUUIDMetadata.id | ||
setUUIDMetadataState.id = id | ||
setUUIDMetadataState.pnUUIDMetadata.name = pnUUIDMetadata.name | ||
setUUIDMetadataState.pnUUIDMetadata.email = pnUUIDMetadata.email | ||
setUUIDMetadataState.pnUUIDMetadata.externalId = pnUUIDMetadata.externalId | ||
setUUIDMetadataState.pnUUIDMetadata.profileUrl = pnUUIDMetadata.profileUrl | ||
setUUIDMetadataState.pnUUIDMetadata.custom = pnUUIDMetadata.custom | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/test/java/com/pubnub/contract/objectV2/step/ThenSteps.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,50 @@ | ||
package com.pubnub.contract.objectV2.step | ||
|
||
import com.pubnub.api.models.consumer.objects_api.uuid.PNUUIDMetadata | ||
import com.pubnub.contract.objectV2.state.GetAllUUIDMetadataState | ||
import com.pubnub.contract.objectV2.state.GetUUIDMetadataState | ||
import com.pubnub.contract.objectV2.state.SetUUIDMetadataState | ||
import com.pubnub.contract.state.World | ||
import io.cucumber.java.en.Then | ||
import org.hamcrest.MatcherAssert.assertThat | ||
import org.hamcrest.Matchers | ||
import org.junit.Assert.assertEquals | ||
|
||
class ThenSteps( | ||
private val getUUIDMetadataState: GetUUIDMetadataState, | ||
private val setUUIDMetadataState: SetUUIDMetadataState, | ||
private val getAllUUIDMetadataState: GetAllUUIDMetadataState, | ||
private val world: World | ||
) { | ||
|
||
@Then("I receive a successful response") | ||
fun I_receive_a_successful_response() { | ||
val status = world.responseStatus | ||
assertEquals(status, 200) | ||
} | ||
|
||
@Then("the UUID metadata for {string} persona") | ||
fun the_UUID_metadata_for_persona(personaName: String) { | ||
val expectedPNUUIDMetadata: PNUUIDMetadata = loadPersonaUUIDMetadata(personaName) | ||
val actualPNUUIDMetadata = getUUIDMetadataState.result!!.data | ||
|
||
assertEquals(expectedPNUUIDMetadata, actualPNUUIDMetadata) | ||
} | ||
|
||
@Then("the UUID metadata for {string} persona contains updated") | ||
fun the_UUID_metadata_for_persona_contains_updated(personaName: String) { | ||
val expectedPNUUIDMetadata: PNUUIDMetadata = loadPersonaUUIDMetadata(personaName) | ||
|
||
val actualPNUUIDMetadata = setUUIDMetadataState.result!!.data | ||
|
||
assertEquals(expectedPNUUIDMetadata, actualPNUUIDMetadata) | ||
} | ||
|
||
@Then("the UUID metadata for {string} and {string} persona") | ||
fun the_UUID_metadata_for_first_and_second_persona(persona01Name: String, persona02Name: String) { | ||
val expectedPNUUIDMetadataForFirstPersona: PNUUIDMetadata = loadPersonaUUIDMetadata(persona01Name) | ||
val expectedPNUUIDMetadataForSecondPersona: PNUUIDMetadata = loadPersonaUUIDMetadata(persona02Name) | ||
|
||
assertThat(getAllUUIDMetadataState.result!!.data, Matchers.containsInAnyOrder(expectedPNUUIDMetadataForFirstPersona, expectedPNUUIDMetadataForSecondPersona)) | ||
} | ||
} |
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 @@ | ||
package com.pubnub.contract.objectV2.step | ||
|
||
import com.google.gson.Gson | ||
import com.pubnub.api.models.consumer.objects_api.uuid.PNUUIDMetadata | ||
import com.pubnub.contract.CONTRACT_TEST_CONFIG | ||
import java.io.File | ||
|
||
fun loadPersonaUUIDMetadata(personaName: String): PNUUIDMetadata { | ||
val fileName = personaName.toLowerCase() + ".json" | ||
val personasLocation = CONTRACT_TEST_CONFIG.dataFileLocation() | ||
val personaAsString = File("$personasLocation/$fileName").readText(Charsets.UTF_8) | ||
return Gson().fromJson(personaAsString, PNUUIDMetadata::class.java) | ||
} |
77 changes: 77 additions & 0 deletions
77
src/test/java/com/pubnub/contract/objectV2/step/WhenSteps.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,77 @@ | ||
package com.pubnub.contract.objectV2.step | ||
|
||
import com.pubnub.contract.objectV2.state.GetAllUUIDMetadataState | ||
import com.pubnub.contract.objectV2.state.GetUUIDMetadataState | ||
import com.pubnub.contract.objectV2.state.RemoveUUIDMetadataState | ||
import com.pubnub.contract.objectV2.state.SetUUIDMetadataState | ||
import com.pubnub.contract.state.World | ||
import io.cucumber.java.en.When | ||
|
||
|
||
class WhenSteps( | ||
private val getUUIDMetadataState: GetUUIDMetadataState, | ||
private val setUUIDMetadataState: SetUUIDMetadataState, | ||
private val removeUUIDMetadataState: RemoveUUIDMetadataState, | ||
private val getAllUUIDMetadataState: GetAllUUIDMetadataState, | ||
private val world: World | ||
) { | ||
|
||
|
||
@When("I get the UUID metadata") | ||
fun I_get_the_UUID_metadata() { | ||
getUUIDMetadataState.result = world.pubnub.getUUIDMetadata() | ||
.uuid(getUUIDMetadataState.id) | ||
.sync() | ||
world.responseStatus = getUUIDMetadataState.result?.status | ||
} | ||
|
||
@When("I get the UUID metadata with custom for current user") | ||
fun I_get_the_UUID_metadata_with_custom_for_current_user() { | ||
getUUIDMetadataState.result = world.pubnub.getUUIDMetadata() | ||
.includeCustom(true) | ||
.sync() | ||
world.responseStatus = getUUIDMetadataState.result?.status | ||
} | ||
|
||
|
||
@When("I set the UUID metadata") | ||
fun I_set_the_UUID_metadata() { | ||
setUUIDMetadataState.result = world.pubnub.setUUIDMetadata() | ||
.uuid(setUUIDMetadataState.id) | ||
.name(setUUIDMetadataState.pnUUIDMetadata.name) | ||
.email(setUUIDMetadataState.pnUUIDMetadata.email) | ||
.profileUrl(setUUIDMetadataState.pnUUIDMetadata.profileUrl) | ||
.externalId(setUUIDMetadataState.pnUUIDMetadata.externalId) | ||
.sync() | ||
world.responseStatus = setUUIDMetadataState.result?.status | ||
} | ||
|
||
@When("I remove the UUID metadata") | ||
fun I_remove_the_UUID_metadata() { | ||
removeUUIDMetadataState.result = world.pubnub.removeUUIDMetadata() | ||
.uuid(removeUUIDMetadataState.id) | ||
.sync() | ||
world.responseStatus = removeUUIDMetadataState.result?.status | ||
} | ||
|
||
@When("I remove the UUID metadata for current user") | ||
fun I_remove_the_UUID_metadata_for_current_user() { | ||
removeUUIDMetadataState.result = world.pubnub.removeUUIDMetadata().sync() | ||
world.responseStatus = removeUUIDMetadataState.result?.status | ||
} | ||
|
||
@When("I get all UUID metadata") | ||
fun I_get_all_UUID_metadata() { | ||
getAllUUIDMetadataState.result = world.pubnub.getAllUUIDMetadata().sync() | ||
world.responseStatus = getAllUUIDMetadataState.result?.status | ||
} | ||
|
||
@When("I get all UUID metadata with custom") | ||
fun I_get_all_UUID_metadata_with_custom() { | ||
getAllUUIDMetadataState.result = world.pubnub.getAllUUIDMetadata() | ||
.includeCustom(true) | ||
.sync() | ||
world.responseStatus = getAllUUIDMetadataState.result?.status | ||
} | ||
|
||
} |
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