Skip to content

Instantly share code, notes, and snippets.

@BlainMaguire
Created November 21, 2017 15:30
Show Gist options
  • Save BlainMaguire/aef4e549ae8dc98f921c2e8e82a13613 to your computer and use it in GitHub Desktop.
Save BlainMaguire/aef4e549ae8dc98f921c2e8e82a13613 to your computer and use it in GitHub Desktop.
RestAsssured Groovy Example
package ie.aib.test.automation
import com.jayway.restassured.RestAssured
import org.librucha.ServerApp
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.test.SpringApplicationConfiguration
import org.springframework.boot.test.WebIntegrationTest
import spock.lang.Specification
import spock.lang.Unroll
@SpringApplicationConfiguration(classes = ServerApp.class)
@WebIntegrationTest(randomPort = true) // probably can be made as dynamic free port, like WireMock
class Test extends Specification {
@Value('${local.server.port}')
private int port
def setup() throws Exception {
RestAssured.port = port
}
@Unroll
def "Get accounts as '#accessor.permission' [#iterationCount]"() {
given:
def request = given()
.accept(JSON)
.auth().oauth2(getToken(accessor.name)) // put logic of getting an oauth token (if needed) into a helper
.log().all()
when:
def response = request.with().get("/api/v1/account/transactions")
then:
response.then().log().all()
.statusCode(status)
.spec(specification)
where:
accessor || status || specification
[name: 'TPP-1', permission: 'ReadBalances'] || SC_FORBIDDEN || expect().body('code', equalTo(403), 'message', equalTo('Access is denied'))
[name: 'TPP-2', permission: 'ReadTransactionsDetail'] || SC_OK || expect().body('data', contains('foo'))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment