All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.seleniumtests.connectors.tms.squash.entities.TestCase Maven / Gradle / Ivy

There is a newer version: 4.23.18
Show newest version
package com.seleniumtests.connectors.tms.squash.entities;

import com.seleniumtests.customexception.ScenarioException;

import kong.unirest.UnirestException;
import kong.unirest.json.JSONException;
import kong.unirest.json.JSONObject;

/**
 * Object representing a test case in Squash TM
 * @author S047432
 *
 */
public class TestCase extends Entity {
	
	private static final String TEST_CASE_URL = "test-cases/%s";

	public TestCase(int id) {
		super("", id, null);
	}

	public TestCase(int id, String url) {
		super(url, id, null);
	}
	

	public static TestCase fromJson(JSONObject json) {
		try {
			return new TestCase (
					json.getInt(FIELD_ID), 
					json.getJSONObject("_links").getJSONObject("self").getString("href")
					);
		} catch (JSONException e) {
			throw new ScenarioException(String.format("Cannot create TestCase from JSON [%s] data: %s", json.toString(), e.getMessage()));
		}
	}
	
	public static TestCase get(int id) {
		try {
			return fromJson(getJSonResponse(buildGetRequest(apiRootUrl + String.format(TEST_CASE_URL, id))));
		} catch (UnirestException e) {
			throw new ScenarioException(String.format("Test Case %d does not exist", id));
		}	
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy