package org.bench4q.recorder;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;

import org.bench4q.recorder.httpcapture.Param;
import org.junit.Test;

public class Test_ParamParser {
	private String testcase = " _nacc=yeah ;_nvid=525d29a534e918cbf04ea7159706a93d;_nvtm=0;_nvsf=0;_nvfi=1;_nlag=zh-cn;_nlmf=1389570024;_nres=1440x900;_nscd=32-bit;_nstm=0;";

	private List<String> expectedNFField = new ArrayList<String>() {
		private static final long serialVersionUID = 1L;
		{
			add("_nacc=yeah");
			add("_nvid=525d29a534e918cbf04ea7159706a93d");
			add("_nvtm=0");
			add("_nvsf=0");
			add("_nvfi=1");
			add("_nlag=zh-cn");
			add("_nlmf=1389570024");
			add("_nres=1440x900");
			add("_nscd=32-bit");
			add("_nstm=0");
		}
	};

	private List<Param> expectedParams = new ArrayList<Param>() {
		private static final long serialVersionUID = 1L;
		{
			add(Param.createParam("_nacc", "yeah"));
			add(Param.createParam("_nvid", "525d29a534e918cbf04ea7159706a93d"));
			add(Param.createParam("_nvtm", "0"));
		}
	};

	@Test
	public void testParseParam() {
		List<String> result = Param.ParamParser.getNVField(testcase);
		assertEquals(10, result.size());
		for (int i = 0; i < result.size(); i++) {
			assertEquals(result.get(i), expectedNFField.get(i));
			System.out.println(result.get(i));
		}
	}

	@Test
	public void testParse() {
		List<Param> result = Param.ParamParser.parse(testcase);
		assertEquals(10, result.size());
		for (int i = 0; i < 3; i++) {
			assertEquals(result.get(i).name, expectedParams.get(i).name);
			assertEquals(result.get(i).value, expectedParams.get(i).value);
		}
	}
}
