/**
 *
 */
package fr.emse.gitlab.saref.entities.tests;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

/**
 * @author Omar Qawasmeh
 *
 *
 */
@XmlRootElement(name = "testsuite")
@XmlType(propOrder = { "name", "tests", "failures", "errors", "testCases" })
public class TestSuite implements Serializable {

	@XmlAttribute
	private String name = "";

	@XmlAttribute
	private int tests = 0;

	@XmlAttribute
	private int failures = 0;
	
	@XmlAttribute
	private int errors = 0;
	
	@XmlElement(name = "testcase")
	private List<TestCase> testCases = new ArrayList<>();
	
	private transient TestSuites testSuites;

	TestSuite() {}
	
	TestSuite(TestSuites testSuites, String name) {
		this.testSuites = testSuites;
		this.name = name;
	}
	
	public String getName() {
		return name;
	}

	public int getTests() {
		return tests;
	}

	public int getFailures() {
		return failures;
	}

	public int getErrors() {
		return errors;
	}

	public void addTestcase(TestCase testCase) {
		testCases.add(testCase);
		tests++;
		testSuites.tests++;
		if(testCase.isFailure()) {
			failures++;
			testSuites.failures++;
		}
		if(testCase.isError()) {
			errors++;
			testSuites.errors++;
		}
	}
	
	public List<TestCase> getTestCases() {
		return testCases;
	}
	
}