// Import statement
   import java.io.*;

/**
 * The TestCookie class tests the methods contained in the Cookie class
 * including the ability to create a new cookie file, update a cookie file,
 * read a cookie file and delete a cookie file.
 * @auther
 * @version
 */
public class TestCookie{

	public static void main(String[] args) throws IOException{

		 System.out.println("Testing Cookie class");

		//Create a cookie object
		Cookie firstCookie = new Cookie();

		//Create a new cookie file
		System.out.println("Creating a new file: cookie1.txt");
		firstCookie.createCookie("cookie1.txt", "visitor:xyz@cse.unl.edu; date:02122004; searchkey:Java+book");

		//Verify cookie file was successfully created by printing contents of file
		System.out.println("Contents of cookie1.txt: " + firstCookie.readCookie("cookie1.txt"));

		//Delete cookie file
		firstCookie.deleteCookie("cookie1.txt");
		//Verify cookie from activity 1 is deleted by trying to read it
		System.out.println("Does cookie exist?");
		try{
			firstCookie.readCookie("cookie1.txt");
		}
		catch(IOException ex)
		{
			System.out.println("ERROR MESSAGE - activity 1: Exception thrown - file no longer exists");
		}

		System.out.println();
		//--------------------------------------------------
		//Uncomment the indicated lines when you complete Activity 2
		System.out.println("Now doing activity 2");
		System.out.println();

		//Activity 2 tests
		//Create another cookie object
		//**Uncomment next line
		//Cookie secondCookie = new Cookie();

		//attempt to read cookie before creating it
		//**Uncomment next two lines
		//System.out.println("Attempting to read a cookie that does not exist");
		//secondCookie.readCookie("cookie2.txt");

		//Create a new cookie file
		//**Uncomment next two lines
		//System.out.println("Creating a new file: cookie2.txt");
		//secondCookie.createCookie("cookie2.txt", "visitor:abc@foo.com; purchase:fiction+book");

		//Verify cookie file was successfully created by printing contents of file
		//**Uncomment next line
		//System.out.println("Contents of cookie2.txt: " + secondCookie.readCookie("cookie2.txt"));

		//Change cookie to be read only, then try to update it
		//**Uncomment next four lines
		//File cookieFile = new File("cookie2.txt");
		//cookieFile.setReadOnly();
		//System.out.println("made cookie file read-only");
		//secondCookie.modifyCookie("cookie2.txt", "visitor:meToo@foo.com; purchase:fiction+book");

	}
}
