Using REST-assured framework in spock framework. This is answer to closed this closed topic
package cz.audatex.audanext.auth.endpoint.v1.member.settings
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)
class Test extends Specification {
@Value('${local.server.port}')
private int port
def setup() throws Exception {
RestAssured.port = port
}
@Unroll
def "Get services as '#accessor.role' [#iterationCount]"() {
given:
def request = given()
.accept(JSON)
.auth().oauth2(getToken(accessor.name))
.log().all()
when:
def response = request.with().get("/api/v1/services")
then:
response.then().log().all()
.statusCode(status)
.spec(specification)
where:
accessor || status || specification
[name: 'user-login', role: 'ordinary user'] || SC_FORBIDDEN || expect().body('code', equalTo('access_denied'), 'description', equalTo('Access is denied'))
[name: 'admin-login', role: 'super admin'] || SC_OK || expect().body('id', contains(1, 2, 3, 4))
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With