package org.ihtsdo.rvf.entity;

import org.ihtsdo.rvf.helper.Configuration;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * A class that records metrics about execution of an {@link org.ihtsdo.rvf.entity.Test}.
 */
public class TestRunItem {

	private String assertionText;
	private String executionId;
	private Date testTime;
	private Configuration configuration;
	private String testType;
	private String testPattern;
	private boolean failure = true;
	private long runTime;
	private String failureMessage;
	private List<String> firstNInstances = new ArrayList<>();
	private Long failureCount;

	/**
	 * Empty constructor for IOC
	 */
	public TestRunItem() {

	}

	public TestRunItem(Assertion assertion, String executionId, Date testTime, Configuration configuration,
					   String testType, String testPattern, boolean failure, long runTime, String failureMessage) {
		this.assertionText = assertion.toString();
		this.executionId = executionId;
		this.testTime = testTime;
		this.configuration = configuration;
		this.testType = testType;
		this.testPattern = testPattern;
		this.failure = failure;
		this.runTime = runTime;
		this.failureMessage = failureMessage;
	}

	public boolean isFailure() {
		return failure;
	}

	private String check(String separator, String filePath) {
		return filePath != null ? (separator + filePath) : "";
	}

	public String getExecutionId() {
		return executionId;
	}

	public Date getTestTime() {
		return testTime;
	}

	public String getTestType() {
		return testType;
	}

	public String getTestPattern() {
		return testPattern;
	}

	public String getStartDate() {
		return new SimpleDateFormat().format(testTime);
	}

	public String getFailureMessage() {
		return failureMessage;
	}

	@Override
	public String toString() {
		return "TestRunItem{" +
				"executionId='" + executionId + '\'' +
				", testType='" + testType + '\'' +
				", testPattern='" + testPattern + '\'' +
				", failure=" + (failure ? "Fail" : "Pass") +
				", testTime='" + testTime + '\'' +
				", runTime='" + runTime + '\'' +
				'}';
	}

	public void setExecutionId(String executionId) {
		this.executionId = executionId;
	}

	public void setTestTime(Date testTime) {
		this.testTime = testTime;
	}

	public void setTestType(String testType) {
		this.testType = testType;
	}

	public void setTestPattern(String testPattern) {
		this.testPattern = testPattern;
	}

	public void setFailure(boolean failure) {
		this.failure = failure;
	}

	public long getRunTime() {
		return runTime;
	}

	public void setRunTime(long runTime) {
		this.runTime = runTime;
	}

	public void setFailureMessage(String failureMessage) {
		this.failureMessage = failureMessage;
	}

	public Configuration getConfiguration() {
		return configuration;
	}

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	public List<String> getFirstNInstances() {
		return firstNInstances;
	}

	public void setFirstNInstances(List<String> firstNInstances) {
		this.firstNInstances = firstNInstances;
	}

	public void addFirstNInstance(String string){
		getFirstNInstances().add(string);
	}

	public Long getFailureCount() {
		return failureCount;
	}

	public void setFailureCount(Long failureCount) {
		this.failureCount = failureCount;
	}

	public String getAssertionText() {
		return assertionText;
	}

	public void setAssertionText(String assertionText) {
		this.assertionText = assertionText;
	}
}

@@ -29,53 +29,8 @@
 y;%0A%0A
-import org.ihtsdo.rvf.helper.Configuration;%0A%0A
 impo
@@ -135,16 +135,61 @@
 .List;%0A%0A
+import org.ihtsdo.rvf.helper.Configuration;%0A%0A
 /**%0A * A
@@ -748,16 +748,22 @@
 RunItem(
+final 
 Assertio
@@ -774,16 +774,22 @@
 sertion,
+ final
  String 
@@ -800,16 +800,22 @@
 utionId,
+ final
  Date te
@@ -821,16 +821,22 @@
 estTime,
+ final
  Configu
@@ -865,16 +865,22 @@
 %09%09%09%09%09   
+final 
 String t
@@ -887,16 +887,22 @@
 estType,
+ final
  String 
@@ -913,16 +913,22 @@
 Pattern,
+ final
  boolean
@@ -936,16 +936,22 @@
 failure,
+ final
  long ru
@@ -956,16 +956,22 @@
 runTime,
+ final
  String 
@@ -1365,16 +1365,22 @@
 g check(
+final 
 String s
@@ -1388,16 +1388,22 @@
 parator,
+ final
  String 
@@ -1918,16 +1918,64 @@
 tem%7B%22 +%0A
+%09%09%09%09%22assertionText=%22 + assertionText +  '%5C'' +%09%0A
 %09%09%09%09%22exe
@@ -2259,16 +2259,22 @@
 utionId(
+final 
 String e
@@ -2350,16 +2350,22 @@
 estTime(
+final 
 Date tes
@@ -2430,16 +2430,22 @@
 estType(
+final 
 String t
@@ -2515,16 +2515,22 @@
 Pattern(
+final 
 String t
@@ -2605,16 +2605,22 @@
 Failure(
+final 
 boolean 
@@ -2734,16 +2734,22 @@
 RunTime(
+final 
 long run
@@ -2817,16 +2817,22 @@
 Message(
+final 
 String f
@@ -2993,16 +2993,22 @@
 uration(
+final 
 Configur
@@ -3178,16 +3178,22 @@
 stances(
+final 
 List%3CStr
@@ -3293,16 +3293,22 @@
 nstance(
+final 
 String s
@@ -3444,16 +3444,22 @@
 reCount(
+final 
 Long fai
@@ -3605,16 +3605,22 @@
 ionText(
+final 
 String a

change RunTestItem toString method for [RVF-141]