Integration tests não estão fazendo Rollback
25/09/2020 15:21
import org.springframework.test.annotation.Rollback
@Integration
@grails.transaction.Rollback
class CmbIdControllerSpec extends Specification {
@Value('${local.server.port}')
Integer serverPort
String accessToken
String baseUrl
JSONObject documentPropertiesForTesting
JSONObject documentForTesting
String partTest
String userTest
String typeIdTest
String documentIdTest
def sessionFactory
def controller
void setup(){
baseUrl = "http://localhost:${serverPort}/cmbid/api/v1"
partTest = "partTest"
accessToken = "Bearer examplefXk"
}
void "Saving a new and valid document properties"() {
given:
documentPropertiesForTesting = createNewTestDocumentProperties()
typeIdTest = documentPropertiesForTesting.get("message").toString().substring(20,52)
expect:
documentPropertiesForTesting.get("status") == "ok"
documentPropertiesForTesting.get("message").contains("properly saved!")
}
@Rollback
def createNewTestDocumentProperties(){
CloseableHttpClient httpClient = HttpClients.createDefault();
def httpPost = setHttpPost(baseUrl + "/parts/${partTest}/metas")
JSONObject entireBody = new JSONObject()
entireBody.accumulate("highlights",setHighlightsDP())
entireBody.accumulate("screens", setScreensDP())
entireBody.accumulate("photo", "")
entireBody.accumulate("style", setStyleDP())
StringEntity jsonBody = new StringEntity(entireBody.toString())
httpPost.setEntity(jsonBody)
CloseableHttpResponse httpResponse = httpClient.execute(httpPost)
JSONObject responseBody = new JSONObject(EntityUtils.toString(httpResponse.getEntity()))
httpClient.close()
return responseBody
}
Para se registrar, clique aqui.