Skip to content

Commit

Permalink
Object v2 contract tests mc (#247)
Browse files Browse the repository at this point in the history
* Contract tests for UUID against object V2 REST
  • Loading branch information
marcin-cebo authored Oct 6, 2022
1 parent b05fc6e commit 248e848
Show file tree
Hide file tree
Showing 14 changed files with 249 additions and 7 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/run_acceptance_tests.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: run_acceptance_tests
name: Acceptance tests

on: [push]

Expand Down Expand Up @@ -29,6 +29,8 @@ jobs:
export pamSecKey=someSecKey
export serverHostPort=localhost:8090
export serverMock=true
export dataFileLocation=src/test/resources/sdk-specifications/features/data
ln -s /home/runner/work/java/java/sdk-specifications src/test/resources/sdk-specifications
./gradlew cucumber --tests RunBetaCucumberTest -Dcucumber.features="sdk-specifications/features/" -i
continue-on-error: true
- name: Run acceptance tests (required)
Expand All @@ -40,6 +42,8 @@ jobs:
export pamSecKey=someSecKey
export serverHostPort=localhost:8090
export serverMock=true
export dataFileLocation=src/test/resources/sdk-specifications/features/data
ln -s /home/runner/work/java/java/sdk-specifications src/test/resources/sdk-specifications
./gradlew cucumber --tests RunMainCucumberTest -Dcucumber.features="sdk-specifications/features/" -i
- name: Expose acceptance tests reports
uses: actions/upload-artifact@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,4 @@ gradlew.bat
# GitHub Actions #
##################
.github/.release
src/test/resources/sdk-specification
3 changes: 3 additions & 0 deletions src/test/java/com/pubnub/contract/ContractTestConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ interface ContractTestConfig : Config {

@Config.Key("serverMock")
fun serverMock(): Boolean

@Config.Key("dataFileLocation")
fun dataFileLocation(): String
}

val CONTRACT_TEST_CONFIG: ContractTestConfig = ConfigFactory.create(ContractTestConfig::class.java, System.getenv())
5 changes: 3 additions & 2 deletions src/test/java/com/pubnub/contract/RunMainCucumberTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import org.junit.runner.RunWith

@RunWith(Cucumber::class)
@CucumberOptions(
tags = "not @skip and not @na=ruby and not @beta",
features = ["src/test/resources"],
tags = "not @skip and not @na=java and not @beta",
plugin = ["pretty", "summary", "junit:build/reports/cucumber-reports/main.xml"]
)
class RunMainCucumberTest

@RunWith(Cucumber::class)
@CucumberOptions(
features = ["../service-contract-mock/contract/features/access"],
//tags = "not @skip and not @na=ruby and @beta",
tags = "not @skip and not @na=java and @beta",
plugin = ["pretty", "summary", "junit:build/reports/cucumber-reports/beta.xml"]
)
class RunBetaCucumberTest
7 changes: 3 additions & 4 deletions src/test/java/com/pubnub/contract/access/step/GivenSteps.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.pubnub.contract.access.step

import com.pubnub.contract.access.parameter.PermissionType
import com.pubnub.contract.access.parameter.ResourceType
import com.pubnub.contract.access.state.GrantTokenState
import com.pubnub.api.models.consumer.access_manager.v3.ChannelGrant
import com.pubnub.api.models.consumer.access_manager.v3.ChannelGroupGrant
import com.pubnub.api.models.consumer.access_manager.v3.PNGrantTokenResult
import com.pubnub.api.models.consumer.access_manager.v3.UUIDGrant
import com.pubnub.contract.access.parameter.PermissionType
import com.pubnub.contract.access.parameter.ResourceType
import com.pubnub.contract.access.state.GrantTokenState
import com.pubnub.contract.state.World
import io.cucumber.java.PendingException
import io.cucumber.java.en.And
import io.cucumber.java.en.Given
import kotlin.random.Random
Expand Down
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
}
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
}
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
}
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 src/test/java/com/pubnub/contract/objectV2/step/GivenSteps.kt
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 src/test/java/com/pubnub/contract/objectV2/step/ThenSteps.kt
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))
}
}
13 changes: 13 additions & 0 deletions src/test/java/com/pubnub/contract/objectV2/step/Utils.kt
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 src/test/java/com/pubnub/contract/objectV2/step/WhenSteps.kt
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
}

}
1 change: 1 addition & 0 deletions src/test/java/com/pubnub/contract/state/World.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ class World {
val pubnub: PubNub by lazy { PubNub(configuration) }
var pnException: PubNubException? = null
var tokenString: String? = null
var responseStatus: Int? = null
}

0 comments on commit 248e848

Please sign in to comment.