package com.enactor.pos;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;

import com.enactor.core.automation.AUT.AutomationException;

public class PosTestResultDataManager {
	
	private static final String PATH = "/target/";
	private static final String FILE_NAME = "testResultData.log";

	public static void write(String text) throws AutomationException {
		
		String workingDir = System.getProperty("user.dir");		
	    File file = new File(workingDir + "/" + PATH + FILE_NAME);
	    try{
	    	if (!file.exists()) {
	    		file.createNewFile();
	    	}	    		    
	        FileWriter fw = new FileWriter(file.getAbsoluteFile());
	        BufferedWriter bw = new BufferedWriter(fw);
	        bw.write(text);
	        bw.close();
	    }
	    catch (IOException e){
	        throw new AutomationException(e.toString());
	    }
		
	}
	
	public static void write(Map<String, String> table) throws AutomationException {		
		String workingDir = System.getProperty("user.dir");
		File file = new File(workingDir + "/" + PATH + FILE_NAME);
		try {
			if (!file.exists()) {
				file.createNewFile();
			}
			FileWriter fw = new FileWriter(file.getAbsoluteFile());
			BufferedWriter bw = new BufferedWriter(fw);
			for(String key : table.keySet()) {
				bw.write(key +"="+ table.get(key) + "\n");
				System.out.println(key +"="+ table.get(key));
			}
			bw.close();
		} catch (IOException e) {
			throw new AutomationException(e.toString());
		}
	}

}
