package test;

import java.util.HashMap;
import java.util.Map;

import junit.framework.TestCase;

import com.akjava.lib.common.form.FormFieldData;
import com.akjava.lib.common.form.FormFieldDataDto;
import com.akjava.lib.common.form.FormFieldDataDto.FormFieldToInputEditTagFunction;
import com.akjava.lib.common.tag.LabelAndValue;
import com.akjava.lib.common.tag.Tag;

public class FormFieldToInputTemplateTest extends TestCase{

	public void testText1(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_TEXT_SHORT);
		data.setName("Text");
		data.setKey("text");
		
		
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		
		assertEquals("<input type=\"text\" name=\"text\" value=\"${value_text}\"/>", tag.toString());
	}
	
	public void testId1(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_ID);
		data.setName("Id");
		data.setKey("id");
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		assertEquals("<input type=\"text\" name=\"id\" value=\"${value_id}\"/>", tag.toString());
	}
	
	public void testTextLong1(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_TEXT_LONG);
		data.setName("TextLong");
		data.setKey("text_long");
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		assertEquals("<textarea name=\"text_long\">${value_text_long}</textarea>", tag.toString());
	}
	
	public void testCheck1(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_CHECK);
		data.setName("Check");
		data.setKey("check");
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		
		assertEquals("<input type=\"checkbox\" name=\"check\" checked=\"${checked_check}\"/>", tag.toString());
	}
	
	public void testSelect1(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_SELECT_SINGLE);
		data.setName("Single");
		data.setKey("single");
		
		data.getOptionValues().add(new LabelAndValue("test1"));
		data.getOptionValues().add(new LabelAndValue("test2"));
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		
		assertEquals("<select name=\"single\">\n<option selected=\"${selected_single0}\">test1</option>\n<option selected=\"${selected_single1}\">test2</option></select>", tag.toString());
	}
	
	public void testSelect2(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_SELECT_SINGLE);
		data.setName("Single");
		data.setKey("single");
		
		data.getOptionValues().add(new LabelAndValue("test1","0"));
		data.getOptionValues().add(new LabelAndValue("test2","1"));
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		assertEquals("<select name=\"single\">\n<option value=\"0\" selected=\"${selected_single0}\">test1</option>\n<option value=\"1\" selected=\"${selected_single1}\">test2</option></select>", tag.toString());
	}
	public void testSelectMulti1(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_SELECT_MULTI);
		data.setName("Multi");
		data.setKey("multi");
		
		data.getOptionValues().add(new LabelAndValue("test1"));
		data.getOptionValues().add(new LabelAndValue("test2"));
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		
		assertEquals("<select name=\"multi\" multiple=\"multiple\">\n<option selected=\"${selected_multi0}\">test1</option>\n<option selected=\"${selected_multi1}\">test2</option></select>", tag.toString());
	}
	
	public void testSelectMulti2(){
		FormFieldData data=new FormFieldData();
		data.setType(FormFieldData.TYPE_SELECT_MULTI);
		data.setName("Multi");
		data.setKey("multi");
		
		data.getOptionValues().add(new LabelAndValue("test1"));
		data.getOptionValues().add(new LabelAndValue("test2"));
		
		Tag tag=FormFieldDataDto.getFormFieldToInputTemplateTagFunction().apply(data);
		
		assertEquals("<select name=\"multi\" multiple=\"multiple\">\n<option selected=\"${selected_multi0}\">test1</option>\n<option selected=\"${selected_multi1}\">test2</option></select>", tag.toString());
	}
}

@@ -1829,18 +1829,8 @@
 k%5C%22 
-checked=%5C%22
 $%7Bch
@@ -1841,18 +1841,16 @@
 d_check%7D
-%5C%22
 /%3E%22, tag
@@ -2305,35 +2305,24 @@
 %22%3E%5Cn%3Coption 
-selected=%5C%22
 $%7Bselected_s
@@ -2320,34 +2320,32 @@
 elected_single0%7D
-%5C%22
 %3Etest1%3C/option%3E%5C
@@ -2349,35 +2349,24 @@
 n%3E%5Cn%3Coption 
-selected=%5C%22
 $%7Bselected_s
@@ -2364,34 +2364,32 @@
 elected_single1%7D
-%5C%22
 %3Etest2%3C/option%3E%3C
@@ -2878,27 +2878,16 @@
 e=%5C%220%5C%22 
-selected=%5C%22
 $%7Bselect
@@ -2897,18 +2897,16 @@
 single0%7D
-%5C%22
 %3Etest1%3C/
@@ -2934,27 +2934,16 @@
 e=%5C%221%5C%22 
-selected=%5C%22
 $%7Bselect
@@ -2953,18 +2953,16 @@
 single1%7D
-%5C%22
 %3Etest2%3C/
@@ -3459,35 +3459,24 @@
 %22%3E%5Cn%3Coption 
-selected=%5C%22
 $%7Bselected_m
@@ -3473,34 +3473,32 @@
 selected_multi0%7D
-%5C%22
 %3Etest1%3C/option%3E%5C
@@ -3502,35 +3502,24 @@
 n%3E%5Cn%3Coption 
-selected=%5C%22
 $%7Bselected_m
@@ -3516,34 +3516,32 @@
 selected_multi1%7D
-%5C%22
 %3Etest2%3C/option%3E%3C
@@ -4033,35 +4033,24 @@
 %22%3E%5Cn%3Coption 
-selected=%5C%22
 $%7Bselected_m
@@ -4055,18 +4055,16 @@
 _multi0%7D
-%5C%22
 %3Etest1%3C/
@@ -4084,19 +4084,8 @@
 ion 
-selected=%5C%22
 $%7Bse
@@ -4098,18 +4098,16 @@
 _multi1%7D
-%5C%22
 %3Etest2%3C/

test fixed and passed all