joabgonzalez
1/19/2018 - 5:53 PM

Kanoah Cambiar Estatus Test Case

Cambiar estatus de un caso de prueba en Jira para ser usado por la prueba automatizada

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

/**
 * Clase destinada para consumir Kanoah API REST Services
 */
public class KanoahRestApi {

    /**
     * @param testRunKey ID del ciclo de prueba que se va a ejecutar
     * @param testCaseKey ID del caso de prueba que se va a ejecutar
     * @param testCaseStatus Resultado de la prueba luego de la ejecucion admite los siguientes estatus:
     *                       [Not Executed, In Progress, Pass, Fail, Blocked]
     * @param TestCaseComment Comentario que justifique el estatus de la prueba
     * @return ID del caso de prueba que fue ejecutado
     */
    public static String testRunPOST(String testRunKey, String testCaseKey, String testCaseStatus, String TestCaseComment) {

        String user = "";
        String authentication = "";

        JSONArray testResultArrayJSON = new JSONArray();
        JSONObject testResultObjectJSON = new JSONObject();

        if (testCaseKey.matches("^([a-zA-Z]+([_])(\\d+))$"))
            testResultObjectJSON.put("testCaseKey", testCaseKey.replace("_", "-T"));
        else if (testCaseKey.matches("^([a-zA-Z]+([_][tT])(\\d+))$"))
            testResultObjectJSON.put("testCaseKey", testCaseKey.replace("_", "-"));
        else if (testCaseKey.matches("^([a-zA-Z]+([-][tT])(\\d+))$"))
            testResultObjectJSON.put("testCaseKey", testCaseKey);
        testResultObjectJSON.put("status", testCaseStatus);
        testResultObjectJSON.put("comment", TestCaseComment);
        testResultObjectJSON.put("userKey", user);
        testResultArrayJSON.add(testResultObjectJSON);

        Client client = ClientBuilder.newClient();
        WebTarget target = client.target(String.format("http://itproyectos.bancofalabella.cl/rest/atm/1.0/testrun/%s/testresults", testRunKey));
        Response res = target.request(MediaType.APPLICATION_JSON)
                .header("Content-Type", "application/json")
                .header("Authorization", "Basic " + authentication)
                .post(Entity.json(testResultArrayJSON));

        return res.readEntity(String.class);

    }

}