package com.vxml.browser;

import java.io.IOException;
import java.net.URISyntaxException;
import java.util.Scanner;

import org.testng.AssertJUnit;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import com.vxml.browser.event.Event;
import com.vxml.core.VxmlException;
import com.vxml.core.browser.VxmlBrowser;
import com.vxml.tag.AbstractTag;

public class ForEachTagTest {

	private VxmlBrowser vxmlBrowser;
	private Scanner dtmfSource;

	@BeforeMethod
	public void init() {
		vxmlBrowser = new VxmlBrowser();
	}

	@BeforeClass
	@AfterMethod
	public void cleanUp() {
		if (dtmfSource != null) {
			dtmfSource.close();
		}
	}

	@Test
	public void testForEach() throws VxmlException, URISyntaxException, Event, IOException {
		// final String DTMF_INPUT = "1";
		final String[] FOR_LOOP_ITEMS = { "mango", "cotton candy", "apple pie", "cheesecake", "raspberry" };

		vxmlBrowser.setEntryPointUrl(VxmlBrowserWrapper.getFullUri("/forEach.vxml"));

		// dtmfSource = new Scanner(DTMF_INPUT);
		// dtmfSource.useDelimiter(",");
		// VxmlBrowser.getContext().setDtmfSource(dtmfSource);
		VxmlBrowserWrapper verifier = new VxmlBrowserWrapper(vxmlBrowser);
		verifier.start();
		AssertJUnit.assertEquals(verifier.nextOuput(), "TTS:Welcome to ABC Frozen Yogurt.");
		AssertJUnit.assertEquals(verifier.nextOuput(), "TTS:The current flavors of the week are");
		System.out.println(FOR_LOOP_ITEMS.length);
		for (int i = 0; i < FOR_LOOP_ITEMS.length; i++) {
			AssertJUnit.assertEquals(verifier.nextOuput(), FOR_LOOP_ITEMS[i]);
		}
		AssertJUnit.assertEquals(verifier.nextOuput(), "TTS:Thank you for calling ABC Frozen Yogurt. We hope you stop by soon.");
	}

}

@@ -710,16 +710,17 @@
 null) %7B%0A
+%0A
 %09%09%09dtmfS
@@ -841,19 +841,16 @@
 ion %7B%0A%09%09
-// 
 final St
@@ -907,17 +907,16 @@
 TEMS = %7B
- 
 %22mango%22,
@@ -970,17 +970,16 @@
 spberry%22
- 
 %7D;%0A%0A%09%09vx
@@ -1057,19 +1057,16 @@
 %22));%0A%0A%09%09
-// 
 dtmfSour
@@ -1097,19 +1097,16 @@
 PUT);%0A%09%09
-// 
 dtmfSour
@@ -1133,11 +1133,8 @@
 ;%0A%09%09
-// 
 Vxml
@@ -1454,53 +1454,8 @@
 %22);%0A
-%09%09System.out.println(FOR_LOOP_ITEMS.length);%0A
 %09%09fo
@@ -1493,16 +1493,17 @@
 S.length
+ 
 ; i++) %7B

For each test