Forked from edgardo001/ScriptParaValidacionDeApiRestSOAPUI.groovy
Created
November 9, 2017 10:51
-
-
Save arcanoix/6fb9625b28542eb8e5d039676b1b5652 to your computer and use it in GitHub Desktop.
Este script permite leer una peticion del tipo json y verificar si su contenido es correcto o no, si es correcto debera escribir en disco el contenido de json.respuesta
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Ref: https://community.smartbear.com/t5/SoapUI-Pro/How-to-parse-JSON-or-XML-in-Assertions/m-p/149830#M34177 | |
* This is script assertion for reading json response and get the size of the array and print array data | |
* Also see the demo : https://ideone.com/Z3wyfh | |
**/ | |
//VER posibles respuestas de API REST al final de este script | |
//Obtengo la data retornada por el servidor y la convierto en json para luego recorrerlo como un objeto | |
def json = new groovy.json.JsonSlurper().parseText(context.response); | |
//Genero un uuid dinamico | |
def verCode = UUID.randomUUID().toString(); | |
//Consulto si el json obtenido contiene un atributo llamado "codigo" y si es igual a 1 | |
if (json.codigo == 1){ | |
//Dejo un log en SOAPUI mostando el detalle de la peticion | |
log.info json.respuesta + " - " + json.detalle; | |
//Desde la peticion obtengo el base64 y lo almaceno en un byte array | |
byte[] decoded = json.zipDocument.decodeBase64(); | |
//Genero un nuevo archivo en la ruta indicada | |
def f = new File('C:\\Users\\edgardo\\Desktop\\demo\\'+verCode+'.zip'); | |
//Almaceno el byte array en el archivo creado | |
f.bytes = decoded; | |
//Retorno a SOAPUI el exito de la peticion | |
assert true; | |
}else{ | |
//En caso de error, dejo un log en SOAPUI y aviso a SOAPUI con "assert false" el error de la peticion | |
log.error json.respuesta + " - " + json.detalle; | |
assert false; | |
} | |
/** | |
//CASO DE EXITO | |
{ | |
"codigo": 1, | |
"respuesta": "Documento XML Firmado con exito", | |
"detalle": "Documento creado y firmado con éxito", | |
"horafecha": "Wed Nov 08 15:47:08 CLST 2017", | |
"zipDocument": "...data.." | |
} | |
//CASO DE ERROR | |
{ | |
"codigo": 0, | |
"respuesta": "Error al Realizar Firma de Documento", | |
"detalle": "nameServicio no existe", | |
"horafecha": "Wed Nov 08 15:48:10 CLST 2017", | |
"zipDocument": null | |
} | |
**/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment