Skip to content

Commit

Permalink
tests: add integration tests for credential schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Anton Baliasnikov committed Dec 9, 2022
1 parent bb22d58 commit 86fa3a8
Show file tree
Hide file tree
Showing 6 changed files with 250 additions and 2 deletions.
2 changes: 1 addition & 1 deletion infrastructure/local/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MERCURY_MEDIATOR_VERSION=0.2.0
IRIS_SERVICE_VERSION=0.1.0
PRISM_AGENT_VERSION=0.10.0
PRISM_AGENT_VERSION=0.15.0
PORT=80
11 changes: 11 additions & 0 deletions tests/e2e-tests/src/main/kotlin/api_models/CredentialSchema.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package api_models

data class CredentialSchema(
var id: String? = null,
var name: String? = null,
var version: String? = null,
var description: String? = null,
var author: String? = null,
var attributes: List<String>? = listOf(""),
var tags: List<String>? = listOf("")
)
18 changes: 18 additions & 0 deletions tests/e2e-tests/src/test/kotlin/common/TestConstants.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package common

import api_models.CredentialSchema
import java.util.*

object TestConstants {

val CREDENTIAL_SCHEMA = CredentialSchema(
author = "University",
name = "Student schema",
description = "Simple student credentials schema",
attributes = listOf("name", "age"),
tags = listOf("school", "students"),
version = "1.0"
)

val RANDOM_UUID = UUID.randomUUID().toString()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
package features.credential_schemas

import common.Agents.Acme
import common.TestConstants
import common.Utils.lastResponse
import io.cucumber.java.en.Then
import io.cucumber.java.en.When
import net.serenitybdd.screenplay.rest.interactions.Get
import net.serenitybdd.screenplay.rest.interactions.Post
import net.serenitybdd.screenplay.rest.questions.ResponseConsequence
import org.apache.http.HttpStatus.*
import org.hamcrest.CoreMatchers.*
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.emptyString
import java.util.*

class CredentialSchemasSteps {

@When("Acme creates a new credential schema")
fun acmeCreatesANewCredentialSchema() {
Acme.attemptsTo(
Post.to("/schema-registry/schemas")
.with {
it.header("Content-Type", "application/json")
it.body(TestConstants.CREDENTIAL_SCHEMA)
}
)
}

@Then("New credential schema is available")
fun newCredentialSchemaIsAvailable() {
Acme.should(
ResponseConsequence.seeThatResponse("New schema created") {
it.statusCode(SC_CREATED)
it.body("id", not(emptyString()))
it.body("authored", not(emptyString()))
it.body("kind", containsString("VerifiableCredentialSchema"))
it.body("name", containsString(TestConstants.CREDENTIAL_SCHEMA.name))
it.body("description", containsString(TestConstants.CREDENTIAL_SCHEMA.description))
it.body("version", containsString(TestConstants.CREDENTIAL_SCHEMA.version))
TestConstants.CREDENTIAL_SCHEMA.tags!!.forEach { tag ->
it.body("tags", hasItem(tag))
}
TestConstants.CREDENTIAL_SCHEMA.attributes!!.forEach { attr ->
it.body("attributes", hasItem(attr))
}
}
)
}

@When("Acme creates {int} schemas")
fun acmeCreatesMultipleSchemas(numberOfSchemes: Int) {
for (i in 0 until numberOfSchemes) {
Acme.attemptsTo(
Post.to("/schema-registry/schemas")
.with {
it.header("Content-Type", "application/json")
it.body(TestConstants.CREDENTIAL_SCHEMA)
}
)
Acme.should(
ResponseConsequence.seeThatResponse("New schema created") {
it.statusCode(SC_CREATED)
}
)
}
}

@Then("All {int} schemas can be accessed with pagination {int}")
fun theyCanBeAccessedWithPagination(numberOfSchemes: Int, pagination: Int) {
for (i in 0 until numberOfSchemes / 2) {
val resource = lastResponse().get("next") ?: "/schema-registry/schemas?limit=$pagination"
Acme.attemptsTo(
Get.resource(resource)
)
Acme.should(
ResponseConsequence.seeThatResponse("Schemas achieved") {
it.statusCode(SC_OK)
}
)
}
}

@When("Acme tries to get schemas with negative limit")
fun acmeTriesToGetSchemasWithNegativeLimit() {
Acme.attemptsTo(
Get.resource("/schema-registry/schemas?offset=999")
)
Acme.should(
ResponseConsequence.seeThatResponse("Schemas get failure") {
it.statusCode(SC_OK)
}
)
}

@When("Acme creates a new schema with empty id")
fun acmeCreatesANewSchemaWithEmptyId() {
val wrongSchema = TestConstants.CREDENTIAL_SCHEMA
wrongSchema.id = ""
Acme.attemptsTo(
Post.to("/schema-registry/schemas")
.with {
it.header("Content-Type", "application/json")
it.body(wrongSchema)
}
)
}

@Then("New schema creation is failed with empty id error")
fun newSchemaCreationIsFailedWithEmptyIdError() {
Acme.should(
ResponseConsequence.seeThatResponse("Get schema invalid id failure") {
it.statusCode(SC_BAD_REQUEST)
it.body("msg", containsString("Invalid UUID: at 'id'"))
}
)
}

@When("Acme creates a new schema with zero attributes")
fun acmeCreatesANewSchemaWithZeroAttributes() {
val wrongSchema = TestConstants.CREDENTIAL_SCHEMA
wrongSchema.attributes = null
Acme.attemptsTo(
Post.to("/schema-registry/schemas")
.with {
it.header("Content-Type", "application/json")
it.body(wrongSchema)
}
)
}

@Then("New schema creation is failed with zero attributes error")
fun newSchemaCreationIsFailedWithZeroAttributesError() {
Acme.should(
ResponseConsequence.seeThatResponse("Get schema invalid attributes failure") {
it.statusCode(SC_BAD_REQUEST)
}
)
}

@When("Acme creates a new schema with fixed id")
fun acmeCreatesANewSchemaWithFixedId() {
val wrongSchema = TestConstants.CREDENTIAL_SCHEMA
wrongSchema.id = TestConstants.RANDOM_UUID
Acme.attemptsTo(
Post.to("/schema-registry/schemas")
.with {
it.header("Content-Type", "application/json")
it.body(wrongSchema)
}
)
Acme.should(
ResponseConsequence.seeThatResponse("New schema created") {
it.statusCode(SC_CREATED)
}
)
}

@When("Acme tries to create a new schema with same id")
fun acmeTriesToCreateANewSchemaWithSameId() {
val wrongSchema = TestConstants.CREDENTIAL_SCHEMA
wrongSchema.id = TestConstants.RANDOM_UUID
Acme.attemptsTo(
Post.to("/schema-registry/schemas")
.with {
it.header("Content-Type", "application/json")
it.body(wrongSchema)
}
)
}

@Then("Id duplicate error is thrown")
fun idDuplicateErrorIsThrown() {
Acme.should(
ResponseConsequence.seeThatResponse("New schema creation error: same UUID") {
it.statusCode(SC_BAD_REQUEST)
}
)
}
}
2 changes: 1 addition & 1 deletion tests/e2e-tests/src/test/kotlin/runners/E2eTestsRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import org.junit.runner.RunWith

@CucumberOptions(
features = [
"src/test/resources/features"
"src/test/resources/features/credential_schemas"
],
glue = ["features", "extentions"],
snippets = CucumberOptions.SnippetType.CAMELCASE,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
Feature: Credential schemas

Scenario: Successful schema creation
When Acme creates a new credential schema
Then New credential schema is available

Scenario: Multiple schema creation
When Acme creates 6 schemas
Then All 6 schemas can be accessed with pagination 2

Scenario: Schema creation failure with empty id
When Acme creates a new schema with empty id
Then New schema creation is failed with empty id error

# # Not working for now (can be successfully created)
# Scenario: Schema creation with 2 same IDs fails
# When Acme creates a new schema with fixed id
# And Acme tries to create a new schema with same id
# Then Id duplicate error is thrown

# # Not working for now (can be created with "" list)
# Scenario: Schema creation failure with zero attributes
# When Acme creates a new schema with zero attributes
# Then New schema creation is failed with zero attributes error

# # Not working for now (returns empty result with success)
# Scenario: Get schemas with negative limit
# When Acme tries to get schemas with negative limit
# Then Negative limit error is thrown in response

# # Not working for now (returns empty result with success)
# Scenario: Get schemas with negative offset
# When Acme tries to get schemas with negative offset
# Then Wrong offset error is thrown in response
#
# # Not working for now (returns empty result with success)
# Scenario: Get schemas with offset greater than amount of schemas
# When Acme tries to get schemas with offset greater than amount of schemas
# Then Wrong offset error is thrown in response

0 comments on commit 86fa3a8

Please sign in to comment.