0001: /*
0002: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
0003: * Distributed under the terms of the GNU Lesser General Public License, 2.1 or later
0004: * $Id: TestFormBuilderXhtml.java 3697 2007-03-16 16:59:32Z gbevin $
0005: */
0006: package com.uwyn.rife.site;
0007:
0008: import com.uwyn.rife.template.Template;
0009: import com.uwyn.rife.template.TemplateFactory;
0010: import com.uwyn.rife.tools.ExceptionUtils;
0011: import com.uwyn.rife.tools.StringUtils;
0012: import com.uwyn.rife.tools.exceptions.BeanUtilsException;
0013: import java.util.Collection;
0014: import java.util.HashMap;
0015: import java.util.Iterator;
0016: import java.util.ListResourceBundle;
0017: import java.util.Set;
0018: import junit.framework.TestCase;
0019:
0020: public class TestFormBuilderXhtml extends TestCase {
0021: public enum RadioInListEnum {
0022: a1, a3, a2
0023: };
0024:
0025: public enum CheckboxInListEnum {
0026: v1(1), v3(3), v2(2);
0027:
0028: private int mNumber;
0029:
0030: CheckboxInListEnum(int number) {
0031: mNumber = number;
0032: }
0033:
0034: public String toString() {
0035: return String.valueOf(mNumber);
0036: }
0037: };
0038:
0039: public enum SelectInListEnum {
0040: black, red, green, blue
0041: };
0042:
0043: public enum SelectInListEnum2 {
0044: black, red, blue
0045: };
0046:
0047: public enum SelectInListEnum3 {
0048: v1(1), v3(3), v5(5), v9(9);
0049:
0050: private int mNumber;
0051:
0052: SelectInListEnum3(int number) {
0053: mNumber = number;
0054: }
0055:
0056: public String toString() {
0057: return String.valueOf(mNumber);
0058: }
0059: };
0060:
0061: public TestFormBuilderXhtml(String name) {
0062: super (name);
0063: }
0064:
0065: public void testInstantiate() {
0066: FormBuilderXhtml builder = new FormBuilderXhtml();
0067: assertNotNull(builder);
0068: }
0069:
0070: public void testClone() {
0071: FormBuilderXhtml builder1 = new FormBuilderXhtml();
0072: FormBuilderXhtml builder2 = (FormBuilderXhtml) builder1.clone();
0073: assertNotNull(builder2);
0074: assertNotSame(builder1, builder2);
0075: }
0076:
0077: public void testGetValidationBuilder() {
0078: FormBuilderXhtml builder = new FormBuilderXhtml();
0079: assertNotNull(builder.getValidationBuilder());
0080: }
0081:
0082: public void testGenerateFieldInvalidArguments() {
0083: FormBuilderXhtml builder = new FormBuilderXhtml();
0084: assertEquals(0, builder.generateField(null,
0085: (ConstrainedProperty) null, null, null).size());
0086: assertEquals(0, builder.generateField(null, (String) null,
0087: null, null).size());
0088:
0089: Template template = TemplateFactory.ENGINEHTML
0090: .get("formbuilder_fields");
0091: String raw_content = template.getContent();
0092: assertNotNull(template);
0093: assertEquals(0, builder.generateField(template,
0094: (ConstrainedProperty) null, null, null).size());
0095: assertEquals(raw_content, template.getContent());
0096: assertEquals(0, builder.generateField(template, (String) null,
0097: null, null).size());
0098: assertEquals(raw_content, template.getContent());
0099: }
0100:
0101: public void testRemoveFieldInvalidArguments() {
0102: FormBuilderXhtml builder = new FormBuilderXhtml();
0103: builder.removeField(null, null, null);
0104:
0105: Template template = TemplateFactory.ENGINEHTML
0106: .get("formbuilder_fields");
0107: String raw_content = template.getContent();
0108: assertNotNull(template);
0109: builder.removeField(template, null, null);
0110: assertEquals(raw_content, template.getContent());
0111: builder.removeField(template, "", null);
0112: assertEquals(raw_content, template.getContent());
0113: }
0114:
0115: public void testGenerateFieldHiddenWithDefault() {
0116: FormBuilderXhtml builder = new FormBuilderXhtml();
0117: Collection<String> set_values;
0118:
0119: Template template = TemplateFactory.ENGINEHTML
0120: .get("formbuilder_fields");
0121:
0122: set_values = builder.generateField(template, "hidden", null,
0123: null);
0124: assertEquals(1, set_values.size());
0125: assertEquals("FORM:HIDDEN:hidden", set_values.iterator().next());
0126: assertEquals(
0127: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" />",
0128: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0129: template.removeValue(set_values.iterator().next());
0130: set_values.clear();
0131:
0132: set_values = builder.generateField(template,
0133: new ConstrainedProperty("hidden"), null, null);
0134: assertEquals(1, set_values.size());
0135: assertEquals("FORM:HIDDEN:hidden", set_values.iterator().next());
0136: assertEquals(
0137: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" />",
0138: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0139: template.removeValue(set_values.iterator().next());
0140: set_values.clear();
0141:
0142: set_values = builder.generateField(template,
0143: new ConstrainedProperty("hidden"), new String[] { null,
0144: "één" }, null);
0145: assertEquals(1, set_values.size());
0146: assertEquals("FORM:HIDDEN:hidden", set_values.iterator().next());
0147: assertEquals(
0148: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" />",
0149: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0150: template.removeValue(set_values.iterator().next());
0151: set_values.clear();
0152:
0153: set_values = builder.generateField(template,
0154: new ConstrainedProperty("hidden"),
0155: new String[] { "één" }, null);
0156: assertEquals(1, set_values.size());
0157: assertEquals("FORM:HIDDEN:hidden", set_values.iterator().next());
0158: assertEquals(
0159: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" value=\"één\" />",
0160: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0161: template.removeValue(set_values.iterator().next());
0162: set_values.clear();
0163:
0164: set_values = builder.generateField(template,
0165: new ConstrainedProperty("hidden").defaultValue("non&e")
0166: .maxLength(20), null, null);
0167: assertEquals(1, set_values.size());
0168: assertEquals("FORM:HIDDEN:hidden", set_values.iterator().next());
0169: assertEquals(
0170: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" value=\"non&e\" />",
0171: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0172: template.removeValue(set_values.iterator().next());
0173: set_values.clear();
0174:
0175: set_values = builder.generateField(template,
0176: new ConstrainedProperty("hidden").defaultValue("non&e")
0177: .maxLength(20), new String[] { "hé", "you" },
0178: null);
0179: assertEquals(1, set_values.size());
0180: assertEquals("FORM:HIDDEN:hidden", set_values.iterator().next());
0181: assertEquals(
0182: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" value=\"hé\" />",
0183: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0184: template.removeValue(set_values.iterator().next());
0185: set_values.clear();
0186:
0187: template.setValue("FORM:HIDDEN:hidden", "already set");
0188: set_values = builder.generateField(template,
0189: new ConstrainedProperty("hidden"), null, null);
0190: assertEquals(0, set_values.size());
0191: assertEquals("already set", StringUtils.splitToArray(template
0192: .getContent(), "\n")[52]);
0193: template.removeValue("FORM:HIDDEN:hidden");
0194: }
0195:
0196: public void testGenerateFieldHiddenWithoutDefault() {
0197: FormBuilderXhtml builder = new FormBuilderXhtml();
0198: Collection<String> set_values;
0199:
0200: Template template = TemplateFactory.ENGINEHTML
0201: .get("formbuilder_fields");
0202:
0203: set_values = builder.generateField(template, "anotherhidden",
0204: null, null);
0205: assertEquals(1, set_values.size());
0206: assertEquals("FORM:HIDDEN:anotherhidden", set_values.iterator()
0207: .next());
0208: assertEquals(
0209: "<input type=\"hidden\" name=\"anotherhidden\" />",
0210: StringUtils.splitToArray(template.getContent(), "\n")[53]);
0211: template.removeValue(set_values.iterator().next());
0212: set_values.clear();
0213:
0214: set_values = builder.generateField(template,
0215: new ConstrainedProperty("anotherhidden"), null, null);
0216: assertEquals(1, set_values.size());
0217: assertEquals("FORM:HIDDEN:anotherhidden", set_values.iterator()
0218: .next());
0219: assertEquals(
0220: "<input type=\"hidden\" name=\"anotherhidden\" />",
0221: StringUtils.splitToArray(template.getContent(), "\n")[53]);
0222: template.removeValue(set_values.iterator().next());
0223: set_values.clear();
0224:
0225: set_values = builder.generateField(template,
0226: new ConstrainedProperty("anotherhidden"),
0227: new String[] { "één" }, null);
0228: assertEquals(1, set_values.size());
0229: assertEquals("FORM:HIDDEN:anotherhidden", set_values.iterator()
0230: .next());
0231: assertEquals(
0232: "<input type=\"hidden\" name=\"anotherhidden\" value=\"één\" />",
0233: StringUtils.splitToArray(template.getContent(), "\n")[53]);
0234: template.removeValue(set_values.iterator().next());
0235: set_values.clear();
0236:
0237: set_values = builder.generateField(template,
0238: new ConstrainedProperty("anotherhidden").defaultValue(
0239: "non&e").maxLength(20), null, null);
0240: assertEquals(1, set_values.size());
0241: assertEquals("FORM:HIDDEN:anotherhidden", set_values.iterator()
0242: .next());
0243: assertEquals(
0244: "<input type=\"hidden\" name=\"anotherhidden\" value=\"non&e\" />",
0245: StringUtils.splitToArray(template.getContent(), "\n")[53]);
0246: template.removeValue(set_values.iterator().next());
0247: set_values.clear();
0248: }
0249:
0250: public void testGenerateFieldHiddenPrefix() {
0251: FormBuilderXhtml builder = new FormBuilderXhtml();
0252: Collection<String> set_values;
0253:
0254: Template template = TemplateFactory.ENGINEHTML
0255: .get("formbuilder_fields");
0256:
0257: set_values = builder.generateField(template, "hidden", null,
0258: "another");
0259: assertEquals(1, set_values.size());
0260: assertEquals("FORM:HIDDEN:anotherhidden", set_values.iterator()
0261: .next());
0262: assertEquals(
0263: "<input type=\"hidden\" name=\"anotherhidden\" />",
0264: StringUtils.splitToArray(template.getContent(), "\n")[53]);
0265: template.removeValue(set_values.iterator().next());
0266: set_values.clear();
0267:
0268: set_values = builder.generateField(template,
0269: new ConstrainedProperty("hidden"), null, "another");
0270: assertEquals(1, set_values.size());
0271: assertEquals("FORM:HIDDEN:anotherhidden", set_values.iterator()
0272: .next());
0273: assertEquals(
0274: "<input type=\"hidden\" name=\"anotherhidden\" />",
0275: StringUtils.splitToArray(template.getContent(), "\n")[53]);
0276: template.removeValue(set_values.iterator().next());
0277: set_values.clear();
0278:
0279: template.setValue("FORM:HIDDEN:anotherhidden", "already set");
0280: set_values = builder.generateField(template,
0281: new ConstrainedProperty("hidden"), null, "another");
0282: assertEquals(0, set_values.size());
0283: assertEquals("already set", StringUtils.splitToArray(template
0284: .getContent(), "\n")[53]);
0285: template.removeValue("FORM:HIDDEN:anotherhidden");
0286: }
0287:
0288: public void testGenerateFieldHiddenTemplateNameWithDefault() {
0289: FormBuilderXhtml builder = new FormBuilderXhtml();
0290: Collection<String> set_values;
0291:
0292: Template template = TemplateFactory.ENGINEHTML
0293: .get("formbuilder_fields_templatename");
0294:
0295: set_values = builder.replaceField(template,
0296: "templatenamehidden", "hidden", null, null);
0297: assertEquals(1, set_values.size());
0298: assertEquals("FORM:HIDDEN:templatenamehidden", set_values
0299: .iterator().next());
0300: assertEquals(
0301: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" />",
0302: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0303: template.removeValue(set_values.iterator().next());
0304: set_values.clear();
0305:
0306: set_values = builder.replaceField(template,
0307: "templatenamehidden",
0308: new ConstrainedProperty("hidden"), null, null);
0309: assertEquals(1, set_values.size());
0310: assertEquals("FORM:HIDDEN:templatenamehidden", set_values
0311: .iterator().next());
0312: assertEquals(
0313: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" />",
0314: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0315: template.removeValue(set_values.iterator().next());
0316: set_values.clear();
0317:
0318: set_values = builder.replaceField(template,
0319: "templatenamehidden",
0320: new ConstrainedProperty("hidden"), new String[] { null,
0321: "één" }, null);
0322: assertEquals(1, set_values.size());
0323: assertEquals("FORM:HIDDEN:templatenamehidden", set_values
0324: .iterator().next());
0325: assertEquals(
0326: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" />",
0327: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0328: template.removeValue(set_values.iterator().next());
0329: set_values.clear();
0330:
0331: set_values = builder.replaceField(template,
0332: "templatenamehidden",
0333: new ConstrainedProperty("hidden"),
0334: new String[] { "één" }, null);
0335: assertEquals(1, set_values.size());
0336: assertEquals("FORM:HIDDEN:templatenamehidden", set_values
0337: .iterator().next());
0338: assertEquals(
0339: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" value=\"één\" />",
0340: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0341: template.removeValue(set_values.iterator().next());
0342: set_values.clear();
0343:
0344: set_values = builder.replaceField(template,
0345: "templatenamehidden", new ConstrainedProperty("hidden")
0346: .defaultValue("non&e").maxLength(20), null,
0347: null);
0348: assertEquals(1, set_values.size());
0349: assertEquals("FORM:HIDDEN:templatenamehidden", set_values
0350: .iterator().next());
0351: assertEquals(
0352: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" value=\"non&e\" />",
0353: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0354: template.removeValue(set_values.iterator().next());
0355: set_values.clear();
0356:
0357: set_values = builder.replaceField(template,
0358: "templatenamehidden", new ConstrainedProperty("hidden")
0359: .defaultValue("non&e").maxLength(20),
0360: new String[] { "hé", "you" }, null);
0361: assertEquals(1, set_values.size());
0362: assertEquals("FORM:HIDDEN:templatenamehidden", set_values
0363: .iterator().next());
0364: assertEquals(
0365: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" value=\"hé\" />",
0366: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0367: template.removeValue(set_values.iterator().next());
0368: set_values.clear();
0369:
0370: template.setValue("FORM:HIDDEN:templatenamehidden",
0371: "already set");
0372: set_values = builder.replaceField(template,
0373: "templatenamehidden",
0374: new ConstrainedProperty("hidden"), null, null);
0375: assertEquals(1, set_values.size());
0376: assertEquals("FORM:HIDDEN:templatenamehidden", set_values
0377: .iterator().next());
0378: assertEquals(
0379: "<input type=\"hidden\" name=\"hidden\" id=\"thehiddenone\" />",
0380: StringUtils.splitToArray(template.getContent(), "\n")[52]);
0381: template.removeValue(set_values.iterator().next());
0382: set_values.clear();
0383: }
0384:
0385: public void testRemoveFieldHidden() {
0386: FormBuilderXhtml builder = new FormBuilderXhtml();
0387:
0388: Template template = TemplateFactory.ENGINEHTML
0389: .get("formbuilder_fields");
0390:
0391: String raw_content = template.getContent();
0392:
0393: builder.generateField(template, new ConstrainedProperty(
0394: "hidden").defaultValue("non&e").maxLength(20),
0395: new String[] { "hé", "you" }, null);
0396: assertFalse(raw_content.equals(template.getContent()));
0397: builder.removeField(template, "hidden", null);
0398: assertEquals(raw_content, template.getContent());
0399: }
0400:
0401: public void testRemoveFieldHiddenPrefix() {
0402: FormBuilderXhtml builder = new FormBuilderXhtml();
0403:
0404: Template template = TemplateFactory.ENGINEHTML
0405: .get("formbuilder_fields");
0406:
0407: String raw_content = template.getContent();
0408:
0409: builder.generateField(template, new ConstrainedProperty(
0410: "hidden").defaultValue("non&e").maxLength(20),
0411: new String[] { "hé", "you" }, "another");
0412: assertFalse(raw_content.equals(template.getContent()));
0413: builder.removeField(template, "hidden", "another");
0414: assertEquals(raw_content, template.getContent());
0415: }
0416:
0417: public void testRemoveFieldHiddenTemplateName() {
0418: FormBuilderXhtml builder = new FormBuilderXhtml();
0419:
0420: Template template = TemplateFactory.ENGINEHTML
0421: .get("formbuilder_fields_templatename");
0422:
0423: String raw_content = template.getContent();
0424:
0425: builder.replaceField(template, "templatenamehidden",
0426: new ConstrainedProperty("hidden").defaultValue("non&e")
0427: .maxLength(20), new String[] { "hé", "you" },
0428: null);
0429: assertFalse(raw_content.equals(template.getContent()));
0430: builder.removeField(template, "templatenamehidden");
0431: assertEquals(raw_content, template.getContent());
0432: }
0433:
0434: public void testGenerateFieldInputWithDefault() {
0435: FormBuilderXhtml builder = new FormBuilderXhtml();
0436: Collection<String> set_values;
0437: Iterator<String> set_values_it;
0438:
0439: Template template = TemplateFactory.ENGINEHTML
0440: .get("formbuilder_fields");
0441:
0442: set_values = builder.generateField(template, "login", null,
0443: null);
0444: set_values_it = set_values.iterator();
0445: assertEquals(2, set_values.size());
0446: assertEquals("FORM:INPUT:login", set_values_it.next());
0447: assertEquals("FORM:DISPLAY:login", set_values_it.next());
0448: assertEquals(
0449: "<input type=\"text\" name=\"login\" size=\"10\" />",
0450: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0451: assertEquals(
0452: "<div class=\"thedisplayedone\"></div>",
0453: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0454: set_values_it = set_values.iterator();
0455: template.removeValue(set_values_it.next());
0456: template.removeValue(set_values_it.next());
0457: set_values.clear();
0458:
0459: set_values = builder.generateField(template,
0460: new ConstrainedProperty("login"), null, null);
0461: set_values_it = set_values.iterator();
0462: assertEquals(2, set_values.size());
0463: assertEquals("FORM:INPUT:login", set_values_it.next());
0464: assertEquals("FORM:DISPLAY:login", set_values_it.next());
0465: assertEquals(
0466: "<input type=\"text\" name=\"login\" size=\"10\" />",
0467: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0468: assertEquals(
0469: "<div class=\"thedisplayedone\"></div>",
0470: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0471: set_values_it = set_values.iterator();
0472: template.removeValue(set_values_it.next());
0473: template.removeValue(set_values_it.next());
0474: set_values.clear();
0475:
0476: set_values = builder.generateField(template,
0477: new ConstrainedProperty("login"), new String[] { null,
0478: "één" }, null);
0479: set_values_it = set_values.iterator();
0480: assertEquals(2, set_values.size());
0481: assertEquals("FORM:INPUT:login", set_values_it.next());
0482: assertEquals("FORM:DISPLAY:login", set_values_it.next());
0483: assertEquals(
0484: "<input type=\"text\" name=\"login\" size=\"10\" />",
0485: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0486: assertEquals(
0487: "<div class=\"thedisplayedone\"></div><div class=\"thedisplayedone\">één</div>",
0488: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0489: set_values_it = set_values.iterator();
0490: template.removeValue(set_values_it.next());
0491: template.removeValue(set_values_it.next());
0492: set_values.clear();
0493:
0494: set_values = builder.generateField(template,
0495: new ConstrainedProperty("login"),
0496: new String[] { "één" }, null);
0497: set_values_it = set_values.iterator();
0498: assertEquals(2, set_values.size());
0499: assertEquals("FORM:INPUT:login", set_values_it.next());
0500: assertEquals("FORM:DISPLAY:login", set_values_it.next());
0501: assertEquals(
0502: "<input type=\"text\" name=\"login\" size=\"10\" value=\"één\" />",
0503: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0504: assertEquals(
0505: "<div class=\"thedisplayedone\">één</div>",
0506: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0507: set_values_it = set_values.iterator();
0508: template.removeValue(set_values_it.next());
0509: template.removeValue(set_values_it.next());
0510: set_values.clear();
0511:
0512: set_values = builder.generateField(template,
0513: new ConstrainedProperty("login").defaultValue("non&e")
0514: .maxLength(20), null, null);
0515: set_values_it = set_values.iterator();
0516: assertEquals(2, set_values.size());
0517: assertEquals("FORM:INPUT:login", set_values_it.next());
0518: assertEquals("FORM:DISPLAY:login", set_values_it.next());
0519: assertEquals(
0520: "<input type=\"text\" name=\"login\" size=\"10\" value=\"non&e\" maxlength=\"20\" />",
0521: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0522: assertEquals(
0523: "<div class=\"thedisplayedone\">non&e</div>",
0524: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0525: set_values_it = set_values.iterator();
0526: template.removeValue(set_values_it.next());
0527: template.removeValue(set_values_it.next());
0528: set_values.clear();
0529:
0530: set_values = builder.generateField(template,
0531: new ConstrainedProperty("login").defaultValue("non&e")
0532: .maxLength(20), new String[] { "hé", "you" },
0533: null);
0534: set_values_it = set_values.iterator();
0535: assertEquals(2, set_values.size());
0536: assertEquals("FORM:INPUT:login", set_values_it.next());
0537: assertEquals("FORM:DISPLAY:login", set_values_it.next());
0538: assertEquals(
0539: "<input type=\"text\" name=\"login\" size=\"10\" value=\"hé\" maxlength=\"20\" />",
0540: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0541: assertEquals(
0542: "<div class=\"thedisplayedone\">hé</div><div class=\"thedisplayedone\">you</div>",
0543: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0544: set_values_it = set_values.iterator();
0545: template.removeValue(set_values_it.next());
0546: template.removeValue(set_values_it.next());
0547: set_values.clear();
0548:
0549: template.setValue("FORM:INPUT:login", "already set");
0550: template.setValue("FORM:DISPLAY:login", "already set too");
0551: set_values = builder.generateField(template,
0552: new ConstrainedProperty("login"), null, null);
0553: assertEquals(0, set_values.size());
0554: assertEquals("already set", StringUtils.splitToArray(template
0555: .getContent(), "\n")[0]);
0556: assertEquals("already set too", StringUtils.splitToArray(
0557: template.getContent(), "\n")[54]);
0558: template.removeValue("FORM:INPUT:login");
0559: template.removeValue("FORM:DISPLAY:login");
0560: }
0561:
0562: public void testGenerateFieldInputWithoutDefault() {
0563: FormBuilderXhtml builder = new FormBuilderXhtml();
0564: Collection<String> set_values;
0565: Iterator<String> set_values_it;
0566:
0567: Template template = TemplateFactory.ENGINEHTML
0568: .get("formbuilder_fields");
0569:
0570: set_values = builder.generateField(template, "anotherlogin",
0571: null, null);
0572: set_values_it = set_values.iterator();
0573: assertEquals(2, set_values.size());
0574: assertEquals("FORM:INPUT:anotherlogin", set_values_it.next());
0575: assertEquals("FORM:DISPLAY:anotherlogin", set_values_it.next());
0576: assertEquals(
0577: "<input type=\"text\" name=\"anotherlogin\" />",
0578: StringUtils.splitToArray(template.getContent(), "\n")[1]);
0579: assertEquals("<div></div>", StringUtils.splitToArray(template
0580: .getContent(), "\n")[55]);
0581: set_values_it = set_values.iterator();
0582: template.removeValue(set_values_it.next());
0583: template.removeValue(set_values_it.next());
0584: set_values.clear();
0585:
0586: set_values = builder.generateField(template,
0587: new ConstrainedProperty("anotherlogin"), null, null);
0588: set_values_it = set_values.iterator();
0589: assertEquals(2, set_values.size());
0590: assertEquals("FORM:INPUT:anotherlogin", set_values_it.next());
0591: assertEquals("FORM:DISPLAY:anotherlogin", set_values_it.next());
0592: assertEquals(
0593: "<input type=\"text\" name=\"anotherlogin\" />",
0594: StringUtils.splitToArray(template.getContent(), "\n")[1]);
0595: assertEquals("<div></div>", StringUtils.splitToArray(template
0596: .getContent(), "\n")[55]);
0597: set_values_it = set_values.iterator();
0598: template.removeValue(set_values_it.next());
0599: template.removeValue(set_values_it.next());
0600: set_values.clear();
0601:
0602: set_values = builder.generateField(template,
0603: new ConstrainedProperty("anotherlogin"),
0604: new String[] { "één" }, null);
0605: set_values_it = set_values.iterator();
0606: assertEquals(2, set_values.size());
0607: assertEquals("FORM:INPUT:anotherlogin", set_values_it.next());
0608: assertEquals("FORM:DISPLAY:anotherlogin", set_values_it.next());
0609: assertEquals("FORM:INPUT:anotherlogin", set_values.iterator()
0610: .next());
0611: assertEquals(
0612: "<input type=\"text\" name=\"anotherlogin\" value=\"één\" />",
0613: StringUtils.splitToArray(template.getContent(), "\n")[1]);
0614: assertEquals("<div>één</div>", StringUtils
0615: .splitToArray(template.getContent(), "\n")[55]);
0616: set_values_it = set_values.iterator();
0617: template.removeValue(set_values_it.next());
0618: template.removeValue(set_values_it.next());
0619: set_values.clear();
0620:
0621: set_values = builder.generateField(template,
0622: new ConstrainedProperty("anotherlogin").defaultValue(
0623: "non&e").maxLength(20), null, null);
0624: set_values_it = set_values.iterator();
0625: assertEquals(2, set_values.size());
0626: assertEquals("FORM:INPUT:anotherlogin", set_values_it.next());
0627: assertEquals("FORM:DISPLAY:anotherlogin", set_values_it.next());
0628: assertEquals("FORM:INPUT:anotherlogin", set_values.iterator()
0629: .next());
0630: assertEquals(
0631: "<input type=\"text\" name=\"anotherlogin\" value=\"non&e\" maxlength=\"20\" />",
0632: StringUtils.splitToArray(template.getContent(), "\n")[1]);
0633: assertEquals("<div>non&e</div>", StringUtils.splitToArray(
0634: template.getContent(), "\n")[55]);
0635: set_values_it = set_values.iterator();
0636: template.removeValue(set_values_it.next());
0637: template.removeValue(set_values_it.next());
0638: set_values.clear();
0639: }
0640:
0641: public void testGenerateFieldInputPrefix() {
0642: FormBuilderXhtml builder = new FormBuilderXhtml();
0643: Collection<String> set_values;
0644: Iterator<String> set_values_it;
0645:
0646: Template template = TemplateFactory.ENGINEHTML
0647: .get("formbuilder_fields");
0648:
0649: set_values = builder.generateField(template, "login", null,
0650: "another");
0651: set_values_it = set_values.iterator();
0652: assertEquals(2, set_values.size());
0653: assertEquals("FORM:INPUT:anotherlogin", set_values_it.next());
0654: assertEquals("FORM:DISPLAY:anotherlogin", set_values_it.next());
0655: assertEquals(
0656: "<input type=\"text\" name=\"anotherlogin\" />",
0657: StringUtils.splitToArray(template.getContent(), "\n")[1]);
0658: assertEquals("<div></div>", StringUtils.splitToArray(template
0659: .getContent(), "\n")[55]);
0660: set_values_it = set_values.iterator();
0661: template.removeValue(set_values_it.next());
0662: template.removeValue(set_values_it.next());
0663: set_values.clear();
0664:
0665: set_values = builder.generateField(template,
0666: new ConstrainedProperty("login"), null, "another");
0667: set_values_it = set_values.iterator();
0668: assertEquals(2, set_values.size());
0669: assertEquals("FORM:INPUT:anotherlogin", set_values_it.next());
0670: assertEquals("FORM:DISPLAY:anotherlogin", set_values_it.next());
0671: assertEquals(
0672: "<input type=\"text\" name=\"anotherlogin\" />",
0673: StringUtils.splitToArray(template.getContent(), "\n")[1]);
0674: assertEquals("<div></div>", StringUtils.splitToArray(template
0675: .getContent(), "\n")[55]);
0676: set_values_it = set_values.iterator();
0677: template.removeValue(set_values_it.next());
0678: template.removeValue(set_values_it.next());
0679: set_values.clear();
0680:
0681: template.setValue("FORM:INPUT:anotherlogin", "already set");
0682: template.setValue("FORM:DISPLAY:anotherlogin",
0683: "already set too");
0684: set_values = builder.generateField(template,
0685: new ConstrainedProperty("login"), null, "another");
0686: assertEquals(0, set_values.size());
0687: assertEquals("already set", StringUtils.splitToArray(template
0688: .getContent(), "\n")[1]);
0689: assertEquals("already set too", StringUtils.splitToArray(
0690: template.getContent(), "\n")[55]);
0691: template.removeValue("FORM:INPUT:anotherlogin");
0692: template.removeValue("FORM:DISPLAY:anotherlogin");
0693: }
0694:
0695: public void testGenerateFieldInputWithDefaultTemplateName() {
0696: FormBuilderXhtml builder = new FormBuilderXhtml();
0697: Collection<String> set_values;
0698: Iterator<String> set_values_it;
0699:
0700: Template template = TemplateFactory.ENGINEHTML
0701: .get("formbuilder_fields_templatename");
0702:
0703: set_values = builder.replaceField(template,
0704: "templatenamelogin", "login", null, null);
0705: set_values_it = set_values.iterator();
0706: assertEquals(2, set_values.size());
0707: assertEquals("FORM:INPUT:templatenamelogin", set_values_it
0708: .next());
0709: assertEquals("FORM:DISPLAY:templatenamelogin", set_values_it
0710: .next());
0711: assertEquals(
0712: "<input type=\"text\" name=\"login\" size=\"10\" />",
0713: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0714: assertEquals(
0715: "<div class=\"thedisplayedone\"></div>",
0716: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0717: set_values_it = set_values.iterator();
0718: template.removeValue(set_values_it.next());
0719: template.removeValue(set_values_it.next());
0720: set_values.clear();
0721:
0722: set_values = builder.replaceField(template,
0723: "templatenamelogin", new ConstrainedProperty("login"),
0724: null, null);
0725: set_values_it = set_values.iterator();
0726: assertEquals(2, set_values.size());
0727: assertEquals("FORM:INPUT:templatenamelogin", set_values_it
0728: .next());
0729: assertEquals("FORM:DISPLAY:templatenamelogin", set_values_it
0730: .next());
0731: assertEquals(
0732: "<input type=\"text\" name=\"login\" size=\"10\" />",
0733: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0734: assertEquals(
0735: "<div class=\"thedisplayedone\"></div>",
0736: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0737: set_values_it = set_values.iterator();
0738: template.removeValue(set_values_it.next());
0739: template.removeValue(set_values_it.next());
0740: set_values.clear();
0741:
0742: set_values = builder.replaceField(template,
0743: "templatenamelogin", new ConstrainedProperty("login"),
0744: new String[] { null, "één" }, null);
0745: set_values_it = set_values.iterator();
0746: assertEquals(2, set_values.size());
0747: assertEquals("FORM:INPUT:templatenamelogin", set_values_it
0748: .next());
0749: assertEquals("FORM:DISPLAY:templatenamelogin", set_values_it
0750: .next());
0751: assertEquals(
0752: "<input type=\"text\" name=\"login\" size=\"10\" />",
0753: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0754: assertEquals(
0755: "<div class=\"thedisplayedone\"></div><div class=\"thedisplayedone\">één</div>",
0756: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0757: set_values_it = set_values.iterator();
0758: template.removeValue(set_values_it.next());
0759: template.removeValue(set_values_it.next());
0760: set_values.clear();
0761:
0762: set_values = builder.replaceField(template,
0763: "templatenamelogin", new ConstrainedProperty("login"),
0764: new String[] { "één" }, null);
0765: set_values_it = set_values.iterator();
0766: assertEquals(2, set_values.size());
0767: assertEquals("FORM:INPUT:templatenamelogin", set_values_it
0768: .next());
0769: assertEquals("FORM:DISPLAY:templatenamelogin", set_values_it
0770: .next());
0771: assertEquals(
0772: "<input type=\"text\" name=\"login\" size=\"10\" value=\"één\" />",
0773: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0774: assertEquals(
0775: "<div class=\"thedisplayedone\">één</div>",
0776: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0777: set_values_it = set_values.iterator();
0778: template.removeValue(set_values_it.next());
0779: template.removeValue(set_values_it.next());
0780: set_values.clear();
0781:
0782: set_values = builder.replaceField(template,
0783: "templatenamelogin", new ConstrainedProperty("login")
0784: .defaultValue("non&e").maxLength(20), null,
0785: null);
0786: set_values_it = set_values.iterator();
0787: assertEquals(2, set_values.size());
0788: assertEquals("FORM:INPUT:templatenamelogin", set_values_it
0789: .next());
0790: assertEquals("FORM:DISPLAY:templatenamelogin", set_values_it
0791: .next());
0792: assertEquals(
0793: "<input type=\"text\" name=\"login\" size=\"10\" value=\"non&e\" maxlength=\"20\" />",
0794: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0795: assertEquals(
0796: "<div class=\"thedisplayedone\">non&e</div>",
0797: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0798: set_values_it = set_values.iterator();
0799: template.removeValue(set_values_it.next());
0800: template.removeValue(set_values_it.next());
0801: set_values.clear();
0802:
0803: set_values = builder.replaceField(template,
0804: "templatenamelogin", new ConstrainedProperty("login")
0805: .defaultValue("non&e").maxLength(20),
0806: new String[] { "hé", "you" }, null);
0807: set_values_it = set_values.iterator();
0808: assertEquals(2, set_values.size());
0809: assertEquals("FORM:INPUT:templatenamelogin", set_values_it
0810: .next());
0811: assertEquals("FORM:DISPLAY:templatenamelogin", set_values_it
0812: .next());
0813: assertEquals(
0814: "<input type=\"text\" name=\"login\" size=\"10\" value=\"hé\" maxlength=\"20\" />",
0815: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0816: assertEquals(
0817: "<div class=\"thedisplayedone\">hé</div><div class=\"thedisplayedone\">you</div>",
0818: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0819: set_values_it = set_values.iterator();
0820: template.removeValue(set_values_it.next());
0821: template.removeValue(set_values_it.next());
0822: set_values.clear();
0823:
0824: template
0825: .setValue("FORM:INPUT:templatenamelogin", "already set");
0826: template.setValue("FORM:DISPLAY:templatenamelogin",
0827: "already set too");
0828: set_values = builder.replaceField(template,
0829: "templatenamelogin", new ConstrainedProperty("login"),
0830: null, null);
0831: set_values_it = set_values.iterator();
0832: assertEquals(2, set_values.size());
0833: assertEquals("FORM:INPUT:templatenamelogin", set_values_it
0834: .next());
0835: assertEquals("FORM:DISPLAY:templatenamelogin", set_values_it
0836: .next());
0837: assertEquals(
0838: "<input type=\"text\" name=\"login\" size=\"10\" />",
0839: StringUtils.splitToArray(template.getContent(), "\n")[0]);
0840: assertEquals(
0841: "<div class=\"thedisplayedone\"></div>",
0842: StringUtils.splitToArray(template.getContent(), "\n")[54]);
0843: set_values_it = set_values.iterator();
0844: template.removeValue(set_values_it.next());
0845: template.removeValue(set_values_it.next());
0846: set_values.clear();
0847: }
0848:
0849: public void testRemoveFieldInput() {
0850: FormBuilderXhtml builder = new FormBuilderXhtml();
0851:
0852: Template template = TemplateFactory.ENGINEHTML
0853: .get("formbuilder_fields");
0854:
0855: String raw_content = template.getContent();
0856:
0857: builder.generateField(template,
0858: new ConstrainedProperty("login").defaultValue("non&e")
0859: .maxLength(20), new String[] { "hé", "you" },
0860: null);
0861: assertFalse(raw_content.equals(template.getContent()));
0862: builder.removeField(template, "login", null);
0863: assertEquals(raw_content, template.getContent());
0864: }
0865:
0866: public void testRemoveFieldInputPrefix() {
0867: FormBuilderXhtml builder = new FormBuilderXhtml();
0868:
0869: Template template = TemplateFactory.ENGINEHTML
0870: .get("formbuilder_fields");
0871:
0872: String raw_content = template.getContent();
0873:
0874: builder.generateField(template,
0875: new ConstrainedProperty("login").defaultValue("non&e")
0876: .maxLength(20), new String[] { "hé", "you" },
0877: "another");
0878: assertFalse(raw_content.equals(template.getContent()));
0879: builder.removeField(template, "login", "another");
0880: assertEquals(raw_content, template.getContent());
0881: }
0882:
0883: public void testRemoveFieldInputTemplateName() {
0884: FormBuilderXhtml builder = new FormBuilderXhtml();
0885:
0886: Template template = TemplateFactory.ENGINEHTML
0887: .get("formbuilder_fields_templatename");
0888:
0889: String raw_content = template.getContent();
0890:
0891: builder.replaceField(template, "templatenamelogin",
0892: new ConstrainedProperty("login").defaultValue("non&e")
0893: .maxLength(20), new String[] { "hé", "you" },
0894: null);
0895: assertFalse(raw_content.equals(template.getContent()));
0896: builder.removeField(template, "templatenamelogin");
0897: assertEquals(raw_content, template.getContent());
0898: }
0899:
0900: public void testGenerateFieldSecretWithDefault() {
0901: FormBuilderXhtml builder = new FormBuilderXhtml();
0902: Collection<String> set_values;
0903:
0904: Template template = TemplateFactory.ENGINEHTML
0905: .get("formbuilder_fields");
0906:
0907: set_values = builder.generateField(template, "password", null,
0908: null);
0909: assertEquals(1, set_values.size());
0910: assertEquals("FORM:SECRET:password", set_values.iterator()
0911: .next());
0912: assertEquals(
0913: "<input type=\"password\" name=\"password\" size=\"10\" />",
0914: StringUtils.splitToArray(template.getContent(), "\n")[2]);
0915: template.removeValue(set_values.iterator().next());
0916: set_values.clear();
0917:
0918: set_values = builder.generateField(template,
0919: new ConstrainedProperty("password"), null, null);
0920: assertEquals(1, set_values.size());
0921: assertEquals("FORM:SECRET:password", set_values.iterator()
0922: .next());
0923: assertEquals(
0924: "<input type=\"password\" name=\"password\" size=\"10\" />",
0925: StringUtils.splitToArray(template.getContent(), "\n")[2]);
0926: template.removeValue(set_values.iterator().next());
0927: set_values.clear();
0928:
0929: set_values = builder.generateField(template,
0930: new ConstrainedProperty("password"), new String[] {
0931: null, "één" }, null);
0932: assertEquals(1, set_values.size());
0933: assertEquals("FORM:SECRET:password", set_values.iterator()
0934: .next());
0935: assertEquals(
0936: "<input type=\"password\" name=\"password\" size=\"10\" />",
0937: StringUtils.splitToArray(template.getContent(), "\n")[2]);
0938: template.removeValue(set_values.iterator().next());
0939: set_values.clear();
0940:
0941: set_values = builder.generateField(template,
0942: new ConstrainedProperty("password"),
0943: new String[] { "één" }, null);
0944: assertEquals(1, set_values.size());
0945: assertEquals("FORM:SECRET:password", set_values.iterator()
0946: .next());
0947: assertEquals(
0948: "<input type=\"password\" name=\"password\" size=\"10\" />",
0949: StringUtils.splitToArray(template.getContent(), "\n")[2]);
0950: template.removeValue(set_values.iterator().next());
0951: set_values.clear();
0952:
0953: set_values = builder.generateField(template,
0954: new ConstrainedProperty("password").defaultValue(
0955: "non&e").maxLength(20), null, null);
0956: assertEquals(1, set_values.size());
0957: assertEquals("FORM:SECRET:password", set_values.iterator()
0958: .next());
0959: assertEquals(
0960: "<input type=\"password\" name=\"password\" size=\"10\" maxlength=\"20\" />",
0961: StringUtils.splitToArray(template.getContent(), "\n")[2]);
0962: template.removeValue(set_values.iterator().next());
0963: set_values.clear();
0964:
0965: set_values = builder.generateField(template,
0966: new ConstrainedProperty("password").defaultValue(
0967: "non&e").maxLength(20), new String[] { "hé",
0968: "you" }, null);
0969: assertEquals(1, set_values.size());
0970: assertEquals("FORM:SECRET:password", set_values.iterator()
0971: .next());
0972: assertEquals(
0973: "<input type=\"password\" name=\"password\" size=\"10\" maxlength=\"20\" />",
0974: StringUtils.splitToArray(template.getContent(), "\n")[2]);
0975: template.removeValue(set_values.iterator().next());
0976: set_values.clear();
0977:
0978: template.setValue("FORM:SECRET:password", "already set");
0979: set_values = builder.generateField(template,
0980: new ConstrainedProperty("password"), null, null);
0981: assertEquals(0, set_values.size());
0982: assertEquals("already set", StringUtils.splitToArray(template
0983: .getContent(), "\n")[2]);
0984: template.removeValue("FORM:SECRET:password");
0985: }
0986:
0987: public void testGenerateFieldSecretWithoutDefault() {
0988: FormBuilderXhtml builder = new FormBuilderXhtml();
0989: Collection<String> set_values;
0990:
0991: Template template = TemplateFactory.ENGINEHTML
0992: .get("formbuilder_fields");
0993:
0994: set_values = builder.generateField(template, "anotherpassword",
0995: null, null);
0996: assertEquals(1, set_values.size());
0997: assertEquals("FORM:SECRET:anotherpassword", set_values
0998: .iterator().next());
0999: assertEquals(
1000: "<input type=\"password\" name=\"anotherpassword\" />",
1001: StringUtils.splitToArray(template.getContent(), "\n")[3]);
1002: template.removeValue(set_values.iterator().next());
1003: set_values.clear();
1004:
1005: set_values = builder.generateField(template,
1006: new ConstrainedProperty("anotherpassword"), null, null);
1007: assertEquals(1, set_values.size());
1008: assertEquals("FORM:SECRET:anotherpassword", set_values
1009: .iterator().next());
1010: assertEquals(
1011: "<input type=\"password\" name=\"anotherpassword\" />",
1012: StringUtils.splitToArray(template.getContent(), "\n")[3]);
1013: template.removeValue(set_values.iterator().next());
1014: set_values.clear();
1015:
1016: set_values = builder.generateField(template,
1017: new ConstrainedProperty("anotherpassword"),
1018: new String[] { "één" }, null);
1019: assertEquals(1, set_values.size());
1020: assertEquals("FORM:SECRET:anotherpassword", set_values
1021: .iterator().next());
1022: assertEquals(
1023: "<input type=\"password\" name=\"anotherpassword\" />",
1024: StringUtils.splitToArray(template.getContent(), "\n")[3]);
1025: template.removeValue(set_values.iterator().next());
1026: set_values.clear();
1027:
1028: set_values = builder.generateField(template,
1029: new ConstrainedProperty("anotherpassword")
1030: .defaultValue("non&e").maxLength(20), null,
1031: null);
1032: assertEquals(1, set_values.size());
1033: assertEquals("FORM:SECRET:anotherpassword", set_values
1034: .iterator().next());
1035: assertEquals(
1036: "<input type=\"password\" name=\"anotherpassword\" maxlength=\"20\" />",
1037: StringUtils.splitToArray(template.getContent(), "\n")[3]);
1038: template.removeValue(set_values.iterator().next());
1039: set_values.clear();
1040: }
1041:
1042: public void testGenerateFieldSecretPrefix() {
1043: FormBuilderXhtml builder = new FormBuilderXhtml();
1044: Collection<String> set_values;
1045:
1046: Template template = TemplateFactory.ENGINEHTML
1047: .get("formbuilder_fields");
1048:
1049: set_values = builder.generateField(template, "password", null,
1050: "another");
1051: assertEquals(1, set_values.size());
1052: assertEquals("FORM:SECRET:anotherpassword", set_values
1053: .iterator().next());
1054: assertEquals(
1055: "<input type=\"password\" name=\"anotherpassword\" />",
1056: StringUtils.splitToArray(template.getContent(), "\n")[3]);
1057: template.removeValue(set_values.iterator().next());
1058: set_values.clear();
1059:
1060: set_values = builder.generateField(template,
1061: new ConstrainedProperty("password"), null, "another");
1062: assertEquals(1, set_values.size());
1063: assertEquals("FORM:SECRET:anotherpassword", set_values
1064: .iterator().next());
1065: assertEquals(
1066: "<input type=\"password\" name=\"anotherpassword\" />",
1067: StringUtils.splitToArray(template.getContent(), "\n")[3]);
1068: template.removeValue(set_values.iterator().next());
1069: set_values.clear();
1070:
1071: template.setValue("FORM:SECRET:anotherpassword", "already set");
1072: set_values = builder.generateField(template,
1073: new ConstrainedProperty("password"), null, "another");
1074: assertEquals(0, set_values.size());
1075: assertEquals("already set", StringUtils.splitToArray(template
1076: .getContent(), "\n")[3]);
1077: template.removeValue("FORM:SECRET:anotherpassword");
1078: }
1079:
1080: public void testGenerateFieldSecretTemplateNameWithDefault() {
1081: FormBuilderXhtml builder = new FormBuilderXhtml();
1082: Collection<String> set_values;
1083:
1084: Template template = TemplateFactory.ENGINEHTML
1085: .get("formbuilder_fields_templatename");
1086:
1087: set_values = builder.replaceField(template,
1088: "templatenamepassword", "password", null, null);
1089: assertEquals(1, set_values.size());
1090: assertEquals("FORM:SECRET:templatenamepassword", set_values
1091: .iterator().next());
1092: assertEquals(
1093: "<input type=\"password\" name=\"password\" size=\"10\" />",
1094: StringUtils.splitToArray(template.getContent(), "\n")[2]);
1095: template.removeValue(set_values.iterator().next());
1096: set_values.clear();
1097:
1098: set_values = builder.replaceField(template,
1099: "templatenamepassword", new ConstrainedProperty(
1100: "password"), null, null);
1101: assertEquals(1, set_values.size());
1102: assertEquals("FORM:SECRET:templatenamepassword", set_values
1103: .iterator().next());
1104: assertEquals(
1105: "<input type=\"password\" name=\"password\" size=\"10\" />",
1106: StringUtils.splitToArray(template.getContent(), "\n")[2]);
1107: template.removeValue(set_values.iterator().next());
1108: set_values.clear();
1109:
1110: set_values = builder.replaceField(template,
1111: "templatenamepassword", new ConstrainedProperty(
1112: "password"), new String[] { null, "één" },
1113: null);
1114: assertEquals(1, set_values.size());
1115: assertEquals("FORM:SECRET:templatenamepassword", set_values
1116: .iterator().next());
1117: assertEquals(
1118: "<input type=\"password\" name=\"password\" size=\"10\" />",
1119: StringUtils.splitToArray(template.getContent(), "\n")[2]);
1120: template.removeValue(set_values.iterator().next());
1121: set_values.clear();
1122:
1123: set_values = builder.replaceField(template,
1124: "templatenamepassword", new ConstrainedProperty(
1125: "password"), new String[] { "één" }, null);
1126: assertEquals(1, set_values.size());
1127: assertEquals("FORM:SECRET:templatenamepassword", set_values
1128: .iterator().next());
1129: assertEquals(
1130: "<input type=\"password\" name=\"password\" size=\"10\" />",
1131: StringUtils.splitToArray(template.getContent(), "\n")[2]);
1132: template.removeValue(set_values.iterator().next());
1133: set_values.clear();
1134:
1135: set_values = builder.replaceField(template,
1136: "templatenamepassword",
1137: new ConstrainedProperty("password").defaultValue(
1138: "non&e").maxLength(20), null, null);
1139: assertEquals(1, set_values.size());
1140: assertEquals("FORM:SECRET:templatenamepassword", set_values
1141: .iterator().next());
1142: assertEquals(
1143: "<input type=\"password\" name=\"password\" size=\"10\" maxlength=\"20\" />",
1144: StringUtils.splitToArray(template.getContent(), "\n")[2]);
1145: template.removeValue(set_values.iterator().next());
1146: set_values.clear();
1147:
1148: set_values = builder.replaceField(template,
1149: "templatenamepassword",
1150: new ConstrainedProperty("password").defaultValue(
1151: "non&e").maxLength(20), new String[] { "hé",
1152: "you" }, null);
1153: assertEquals(1, set_values.size());
1154: assertEquals("FORM:SECRET:templatenamepassword", set_values
1155: .iterator().next());
1156: assertEquals(
1157: "<input type=\"password\" name=\"password\" size=\"10\" maxlength=\"20\" />",
1158: StringUtils.splitToArray(template.getContent(), "\n")[2]);
1159: template.removeValue(set_values.iterator().next());
1160: set_values.clear();
1161:
1162: template.setValue("FORM:SECRET:templatenamepassword",
1163: "already set");
1164: set_values = builder.replaceField(template,
1165: "templatenamepassword", new ConstrainedProperty(
1166: "password"), null, null);
1167: assertEquals(1, set_values.size());
1168: assertEquals("FORM:SECRET:templatenamepassword", set_values
1169: .iterator().next());
1170: assertEquals(
1171: "<input type=\"password\" name=\"password\" size=\"10\" />",
1172: StringUtils.splitToArray(template.getContent(), "\n")[2]);
1173: template.removeValue(set_values.iterator().next());
1174: set_values.clear();
1175: }
1176:
1177: public void testRemoveFieldSecret() {
1178: FormBuilderXhtml builder = new FormBuilderXhtml();
1179:
1180: Template template = TemplateFactory.ENGINEHTML
1181: .get("formbuilder_fields");
1182:
1183: String raw_content = template.getContent();
1184:
1185: builder.generateField(template, new ConstrainedProperty(
1186: "password").defaultValue("non&e").maxLength(20),
1187: new String[] { "hé", "you" }, null);
1188: assertFalse(raw_content.equals(template.getContent()));
1189: builder.removeField(template, "password", null);
1190: assertEquals(raw_content, template.getContent());
1191: }
1192:
1193: public void testRemoveFieldSecretPrefix() {
1194: FormBuilderXhtml builder = new FormBuilderXhtml();
1195:
1196: Template template = TemplateFactory.ENGINEHTML
1197: .get("formbuilder_fields");
1198:
1199: String raw_content = template.getContent();
1200:
1201: builder.generateField(template, new ConstrainedProperty(
1202: "password").defaultValue("non&e").maxLength(20),
1203: new String[] { "hé", "you" }, "another");
1204: assertFalse(raw_content.equals(template.getContent()));
1205: builder.removeField(template, "password", "another");
1206: assertEquals(raw_content, template.getContent());
1207: }
1208:
1209: public void testRemoveFieldSecretTemplateName() {
1210: FormBuilderXhtml builder = new FormBuilderXhtml();
1211:
1212: Template template = TemplateFactory.ENGINEHTML
1213: .get("formbuilder_fields_templatename");
1214:
1215: String raw_content = template.getContent();
1216:
1217: builder.replaceField(template, "templatenamepassword",
1218: new ConstrainedProperty("password").defaultValue(
1219: "non&e").maxLength(20), new String[] { "hé",
1220: "you" }, null);
1221: assertFalse(raw_content.equals(template.getContent()));
1222: builder.removeField(template, "templatenamepassword");
1223: assertEquals(raw_content, template.getContent());
1224: }
1225:
1226: public void testGenerateFieldTextareaWithDefault() {
1227: FormBuilderXhtml builder = new FormBuilderXhtml();
1228: Collection<String> set_values;
1229:
1230: Template template = TemplateFactory.ENGINEHTML
1231: .get("formbuilder_fields");
1232:
1233: set_values = builder.generateField(template, "comment", null,
1234: null);
1235: assertEquals(1, set_values.size());
1236: assertEquals("FORM:TEXTAREA:comment", set_values.iterator()
1237: .next());
1238: assertEquals(
1239: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"comment[!V 'FORM:VALUE'/]\"></textarea>",
1240: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1241: template.removeValue(set_values.iterator().next());
1242: set_values.clear();
1243:
1244: set_values = builder.generateField(template,
1245: new ConstrainedProperty("comment"), null, null);
1246: assertEquals(1, set_values.size());
1247: assertEquals("FORM:TEXTAREA:comment", set_values.iterator()
1248: .next());
1249: assertEquals(
1250: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"comment[!V 'FORM:VALUE'/]\"></textarea>",
1251: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1252: template.removeValue(set_values.iterator().next());
1253: set_values.clear();
1254:
1255: set_values = builder.generateField(template,
1256: new ConstrainedProperty("comment"), new String[] {
1257: null, "één" }, null);
1258: assertEquals(1, set_values.size());
1259: assertEquals("FORM:TEXTAREA:comment", set_values.iterator()
1260: .next());
1261: assertEquals(
1262: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"comment[!V 'FORM:VALUE'/]\"></textarea>",
1263: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1264: template.removeValue(set_values.iterator().next());
1265: set_values.clear();
1266:
1267: set_values = builder.generateField(template,
1268: new ConstrainedProperty("comment"),
1269: new String[] { "één" }, null);
1270: assertEquals(1, set_values.size());
1271: assertEquals("FORM:TEXTAREA:comment", set_values.iterator()
1272: .next());
1273: assertEquals(
1274: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"commentéén\">één</textarea>",
1275: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1276: template.removeValue(set_values.iterator().next());
1277: set_values.clear();
1278:
1279: set_values = builder.generateField(template,
1280: new ConstrainedProperty("comment")
1281: .defaultValue("non&e").maxLength(20), null,
1282: null);
1283: assertEquals(1, set_values.size());
1284: assertEquals("FORM:TEXTAREA:comment", set_values.iterator()
1285: .next());
1286: assertEquals(
1287: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"commentnon&e\">non&e</textarea>",
1288: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1289: template.removeValue(set_values.iterator().next());
1290: set_values.clear();
1291:
1292: set_values = builder.generateField(template,
1293: new ConstrainedProperty("comment")
1294: .defaultValue("non&e").maxLength(20),
1295: new String[] { "hé", "you" }, null);
1296: assertEquals(1, set_values.size());
1297: assertEquals("FORM:TEXTAREA:comment", set_values.iterator()
1298: .next());
1299: assertEquals(
1300: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"commenthé\">hé</textarea>",
1301: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1302: template.removeValue(set_values.iterator().next());
1303: set_values.clear();
1304:
1305: template.setValue("FORM:TEXTAREA:comment", "already set");
1306: set_values = builder.generateField(template,
1307: new ConstrainedProperty("comment"), null, null);
1308: assertEquals(0, set_values.size());
1309: assertEquals("already set", StringUtils.splitToArray(template
1310: .getContent(), "\n")[4]);
1311: template.removeValue("FORM:TEXTAREA:comment");
1312: }
1313:
1314: public void testGenerateFieldTextareaWithoutDefault() {
1315: FormBuilderXhtml builder = new FormBuilderXhtml();
1316: Collection<String> set_values;
1317:
1318: Template template = TemplateFactory.ENGINEHTML
1319: .get("formbuilder_fields");
1320:
1321: set_values = builder.generateField(template, "anothercomment",
1322: null, null);
1323: assertEquals(1, set_values.size());
1324: assertEquals("FORM:TEXTAREA:anothercomment", set_values
1325: .iterator().next());
1326: assertEquals(
1327: "<textarea name=\"anothercomment\"></textarea>",
1328: StringUtils.splitToArray(template.getContent(), "\n")[5]);
1329: template.removeValue(set_values.iterator().next());
1330: set_values.clear();
1331:
1332: set_values = builder.generateField(template,
1333: new ConstrainedProperty("anothercomment"), null, null);
1334: assertEquals(1, set_values.size());
1335: assertEquals("FORM:TEXTAREA:anothercomment", set_values
1336: .iterator().next());
1337: assertEquals(
1338: "<textarea name=\"anothercomment\"></textarea>",
1339: StringUtils.splitToArray(template.getContent(), "\n")[5]);
1340: template.removeValue(set_values.iterator().next());
1341: set_values.clear();
1342:
1343: set_values = builder.generateField(template,
1344: new ConstrainedProperty("anothercomment"),
1345: new String[] { "één" }, null);
1346: assertEquals(1, set_values.size());
1347: assertEquals("FORM:TEXTAREA:anothercomment", set_values
1348: .iterator().next());
1349: assertEquals(
1350: "<textarea name=\"anothercomment\">één</textarea>",
1351: StringUtils.splitToArray(template.getContent(), "\n")[5]);
1352: template.removeValue(set_values.iterator().next());
1353: set_values.clear();
1354:
1355: set_values = builder.generateField(template,
1356: new ConstrainedProperty("anothercomment").defaultValue(
1357: "non&e").maxLength(20), null, null);
1358: assertEquals(1, set_values.size());
1359: assertEquals("FORM:TEXTAREA:anothercomment", set_values
1360: .iterator().next());
1361: assertEquals(
1362: "<textarea name=\"anothercomment\">non&e</textarea>",
1363: StringUtils.splitToArray(template.getContent(), "\n")[5]);
1364: template.removeValue(set_values.iterator().next());
1365: set_values.clear();
1366: }
1367:
1368: public void testGenerateFieldTextareaPrefix() {
1369: FormBuilderXhtml builder = new FormBuilderXhtml();
1370: Collection<String> set_values;
1371:
1372: Template template = TemplateFactory.ENGINEHTML
1373: .get("formbuilder_fields");
1374:
1375: set_values = builder.generateField(template, "comment", null,
1376: "another");
1377: assertEquals(1, set_values.size());
1378: assertEquals("FORM:TEXTAREA:anothercomment", set_values
1379: .iterator().next());
1380: assertEquals(
1381: "<textarea name=\"anothercomment\"></textarea>",
1382: StringUtils.splitToArray(template.getContent(), "\n")[5]);
1383: template.removeValue(set_values.iterator().next());
1384: set_values.clear();
1385:
1386: set_values = builder.generateField(template,
1387: new ConstrainedProperty("comment"), null, "another");
1388: assertEquals(1, set_values.size());
1389: assertEquals("FORM:TEXTAREA:anothercomment", set_values
1390: .iterator().next());
1391: assertEquals(
1392: "<textarea name=\"anothercomment\"></textarea>",
1393: StringUtils.splitToArray(template.getContent(), "\n")[5]);
1394: template.removeValue(set_values.iterator().next());
1395: set_values.clear();
1396:
1397: template
1398: .setValue("FORM:TEXTAREA:anothercomment", "already set");
1399: set_values = builder.generateField(template,
1400: new ConstrainedProperty("comment"), null, "another");
1401: assertEquals(0, set_values.size());
1402: assertEquals("already set", StringUtils.splitToArray(template
1403: .getContent(), "\n")[5]);
1404: template.removeValue("FORM:TEXTAREA:anothercomment");
1405: }
1406:
1407: public void testGenerateFieldTextareaTemplateNameWithDefault() {
1408: FormBuilderXhtml builder = new FormBuilderXhtml();
1409: Collection<String> set_values;
1410:
1411: Template template = TemplateFactory.ENGINEHTML
1412: .get("formbuilder_fields_templatename");
1413:
1414: set_values = builder.replaceField(template,
1415: "templatenamecomment", "comment", null, null);
1416: assertEquals(1, set_values.size());
1417: assertEquals("FORM:TEXTAREA:templatenamecomment", set_values
1418: .iterator().next());
1419: assertEquals(
1420: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"comment[!V 'FORM:VALUE'/]\"></textarea>",
1421: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1422: template.removeValue(set_values.iterator().next());
1423: set_values.clear();
1424:
1425: set_values = builder.replaceField(template,
1426: "templatenamecomment", new ConstrainedProperty(
1427: "comment"), null, null);
1428: assertEquals(1, set_values.size());
1429: assertEquals("FORM:TEXTAREA:templatenamecomment", set_values
1430: .iterator().next());
1431: assertEquals(
1432: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"comment[!V 'FORM:VALUE'/]\"></textarea>",
1433: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1434: template.removeValue(set_values.iterator().next());
1435: set_values.clear();
1436:
1437: set_values = builder.replaceField(template,
1438: "templatenamecomment", new ConstrainedProperty(
1439: "comment"), new String[] { null, "één" },
1440: null);
1441: assertEquals(1, set_values.size());
1442: assertEquals("FORM:TEXTAREA:templatenamecomment", set_values
1443: .iterator().next());
1444: assertEquals(
1445: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"comment[!V 'FORM:VALUE'/]\"></textarea>",
1446: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1447: template.removeValue(set_values.iterator().next());
1448: set_values.clear();
1449:
1450: set_values = builder.replaceField(template,
1451: "templatenamecomment", new ConstrainedProperty(
1452: "comment"), new String[] { "één" }, null);
1453: assertEquals(1, set_values.size());
1454: assertEquals("FORM:TEXTAREA:templatenamecomment", set_values
1455: .iterator().next());
1456: assertEquals(
1457: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"commentéén\">één</textarea>",
1458: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1459: template.removeValue(set_values.iterator().next());
1460: set_values.clear();
1461:
1462: set_values = builder.replaceField(template,
1463: "templatenamecomment", new ConstrainedProperty(
1464: "comment").defaultValue("non&e").maxLength(20),
1465: null, null);
1466: assertEquals(1, set_values.size());
1467: assertEquals("FORM:TEXTAREA:templatenamecomment", set_values
1468: .iterator().next());
1469: assertEquals(
1470: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"commentnon&e\">non&e</textarea>",
1471: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1472: template.removeValue(set_values.iterator().next());
1473: set_values.clear();
1474:
1475: set_values = builder.replaceField(template,
1476: "templatenamecomment", new ConstrainedProperty(
1477: "comment").defaultValue("non&e").maxLength(20),
1478: new String[] { "hé", "you" }, null);
1479: assertEquals(1, set_values.size());
1480: assertEquals("FORM:TEXTAREA:templatenamecomment", set_values
1481: .iterator().next());
1482: assertEquals(
1483: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"commenthé\">hé</textarea>",
1484: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1485: template.removeValue(set_values.iterator().next());
1486: set_values.clear();
1487:
1488: template.setValue("FORM:TEXTAREA:templatenamecomment",
1489: "already set");
1490: set_values = builder.replaceField(template,
1491: "templatenamecomment", new ConstrainedProperty(
1492: "comment"), null, null);
1493: assertEquals(1, set_values.size());
1494: assertEquals("FORM:TEXTAREA:templatenamecomment", set_values
1495: .iterator().next());
1496: assertEquals(
1497: "<textarea name=\"comment\" cols=\"10\" rows=\"5\" id=\"comment[!V 'FORM:VALUE'/]\"></textarea>",
1498: StringUtils.splitToArray(template.getContent(), "\n")[4]);
1499: template.removeValue(set_values.iterator().next());
1500: set_values.clear();
1501: }
1502:
1503: public void testRemoveFieldTextarea() {
1504: FormBuilderXhtml builder = new FormBuilderXhtml();
1505:
1506: Template template = TemplateFactory.ENGINEHTML
1507: .get("formbuilder_fields");
1508:
1509: String raw_content = template.getContent();
1510:
1511: builder.generateField(template, new ConstrainedProperty(
1512: "comment").defaultValue("non&e").maxLength(20),
1513: new String[] { "hé", "you" }, null);
1514: assertFalse(raw_content.equals(template.getContent()));
1515: builder.removeField(template, "comment", null);
1516: assertEquals(raw_content, template.getContent());
1517: }
1518:
1519: public void testRemoveFieldTextareaPrefix() {
1520: FormBuilderXhtml builder = new FormBuilderXhtml();
1521:
1522: Template template = TemplateFactory.ENGINEHTML
1523: .get("formbuilder_fields");
1524:
1525: String raw_content = template.getContent();
1526:
1527: builder.generateField(template, new ConstrainedProperty(
1528: "comment").defaultValue("non&e").maxLength(20),
1529: new String[] { "hé", "you" }, "another");
1530: assertFalse(raw_content.equals(template.getContent()));
1531: builder.removeField(template, "comment", "another");
1532: assertEquals(raw_content, template.getContent());
1533: }
1534:
1535: public void testRemoveFieldTextareaTemplateName() {
1536: FormBuilderXhtml builder = new FormBuilderXhtml();
1537:
1538: Template template = TemplateFactory.ENGINEHTML
1539: .get("formbuilder_fields_templatename");
1540:
1541: String raw_content = template.getContent();
1542:
1543: builder.replaceField(template, "templatenamecomment",
1544: new ConstrainedProperty("comment")
1545: .defaultValue("non&e").maxLength(20),
1546: new String[] { "hé", "you" }, null);
1547: assertFalse(raw_content.equals(template.getContent()));
1548: builder.removeField(template, "templatenamecomment", null);
1549: assertEquals(raw_content, template.getContent());
1550: }
1551:
1552: public void testGenerateFieldRadioWithDefault() {
1553: FormBuilderXhtml builder = new FormBuilderXhtml();
1554: Collection<String> set_values;
1555: Iterator<String> set_values_it;
1556:
1557: Template template = TemplateFactory.ENGINEHTML
1558: .get("formbuilder_fields");
1559:
1560: set_values = builder.generateField(template, "question", null,
1561: null);
1562: set_values_it = set_values.iterator();
1563: assertEquals(2, set_values.size());
1564: assertEquals("FORM:RADIO:question", set_values_it.next());
1565: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1566: assertEquals(
1567: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"question[!V 'FORM:VALUE'/]\" />",
1568: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1569: assertEquals("<div></div>", StringUtils.splitToArray(template
1570: .getContent(), "\n")[56]);
1571: set_values_it = set_values.iterator();
1572: template.removeValue(set_values_it.next());
1573: template.removeValue(set_values_it.next());
1574: set_values.clear();
1575:
1576: set_values = builder.generateField(template,
1577: new ConstrainedProperty("question"), null, null);
1578: set_values_it = set_values.iterator();
1579: assertEquals(2, set_values.size());
1580: assertEquals("FORM:RADIO:question", set_values_it.next());
1581: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1582: assertEquals(
1583: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"question[!V 'FORM:VALUE'/]\" />",
1584: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1585: assertEquals("<div></div>", StringUtils.splitToArray(template
1586: .getContent(), "\n")[56]);
1587: set_values_it = set_values.iterator();
1588: template.removeValue(set_values_it.next());
1589: template.removeValue(set_values_it.next());
1590: set_values.clear();
1591:
1592: set_values = builder.generateField(template,
1593: new ConstrainedProperty("question").inList(null, "a1",
1594: null, "a3", "a2"), null, null);
1595: set_values_it = set_values.iterator();
1596: assertEquals(2, set_values.size());
1597: assertEquals("FORM:RADIO:question", set_values_it.next());
1598: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1599: assertEquals(
1600: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1601: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1602: assertEquals("<div></div>", StringUtils.splitToArray(template
1603: .getContent(), "\n")[56]);
1604: set_values_it = set_values.iterator();
1605: template.removeValue(set_values_it.next());
1606: template.removeValue(set_values_it.next());
1607: set_values.clear();
1608:
1609: set_values = builder.generateField(template,
1610: SelectInListEnum.class, new ConstrainedProperty(
1611: "question")
1612: .inList(null, "a1", null, "a3", "a2"), null,
1613: null);
1614: set_values_it = set_values.iterator();
1615: assertEquals(2, set_values.size());
1616: assertEquals("FORM:RADIO:question", set_values_it.next());
1617: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1618: assertEquals(
1619: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1620: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1621: assertEquals("<div></div>", StringUtils.splitToArray(template
1622: .getContent(), "\n")[56]);
1623: set_values_it = set_values.iterator();
1624: template.removeValue(set_values_it.next());
1625: template.removeValue(set_values_it.next());
1626: set_values.clear();
1627:
1628: set_values = builder.generateField(template,
1629: RadioInListEnum.class, "question", null, null);
1630: set_values_it = set_values.iterator();
1631: assertEquals(2, set_values.size());
1632: assertEquals("FORM:RADIO:question", set_values_it.next());
1633: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1634: assertEquals(
1635: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1636: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1637: assertEquals("<div></div>", StringUtils.splitToArray(template
1638: .getContent(), "\n")[56]);
1639: set_values_it = set_values.iterator();
1640: template.removeValue(set_values_it.next());
1641: template.removeValue(set_values_it.next());
1642: set_values.clear();
1643:
1644: set_values = builder.generateField(template,
1645: new ConstrainedProperty("question").inList(null, "a1",
1646: null, "a3", "a2").defaultValue("a2"),
1647: new String[] { null, "a1" }, null);
1648: set_values_it = set_values.iterator();
1649: assertEquals(2, set_values.size());
1650: assertEquals("FORM:RADIO:question", set_values_it.next());
1651: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1652: assertEquals(
1653: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />answer2",
1654: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1655: assertEquals(
1656: "<div>answer2</div><div>answer1</div>",
1657: StringUtils.splitToArray(template.getContent(), "\n")[56]);
1658: set_values_it = set_values.iterator();
1659: template.removeValue(set_values_it.next());
1660: template.removeValue(set_values_it.next());
1661: set_values.clear();
1662:
1663: set_values = builder.generateField(template,
1664: RadioInListEnum.class, new ConstrainedProperty(
1665: "question").defaultValue("a2"), new String[] {
1666: null, "a1" }, null);
1667: set_values_it = set_values.iterator();
1668: assertEquals(2, set_values.size());
1669: assertEquals("FORM:RADIO:question", set_values_it.next());
1670: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1671: assertEquals(
1672: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />answer2",
1673: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1674: assertEquals(
1675: "<div>answer2</div><div>answer1</div>",
1676: StringUtils.splitToArray(template.getContent(), "\n")[56]);
1677: set_values_it = set_values.iterator();
1678: template.removeValue(set_values_it.next());
1679: template.removeValue(set_values_it.next());
1680: set_values.clear();
1681:
1682: set_values = builder.generateField(template,
1683: new ConstrainedProperty("question").inList(null, "a1",
1684: null, "a3", "a2"), new String[] { "a1", "a2" },
1685: null);
1686: set_values_it = set_values.iterator();
1687: assertEquals(2, set_values.size());
1688: assertEquals("FORM:RADIO:question", set_values_it.next());
1689: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1690: assertEquals(
1691: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1692: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1693: assertEquals(
1694: "<div>answer1</div><div>answer2</div>",
1695: StringUtils.splitToArray(template.getContent(), "\n")[56]);
1696: set_values_it = set_values.iterator();
1697: template.removeValue(set_values_it.next());
1698: template.removeValue(set_values_it.next());
1699: set_values.clear();
1700:
1701: set_values = builder.generateField(template,
1702: RadioInListEnum.class, "question", new String[] { "a1",
1703: "a2" }, null);
1704: set_values_it = set_values.iterator();
1705: assertEquals(2, set_values.size());
1706: assertEquals("FORM:RADIO:question", set_values_it.next());
1707: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1708: assertEquals(
1709: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1710: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1711: assertEquals(
1712: "<div>answer1</div><div>answer2</div>",
1713: StringUtils.splitToArray(template.getContent(), "\n")[56]);
1714: set_values_it = set_values.iterator();
1715: template.removeValue(set_values_it.next());
1716: template.removeValue(set_values_it.next());
1717: set_values.clear();
1718:
1719: set_values = builder.generateField(template,
1720: new ConstrainedProperty("question").inList(null, "a1",
1721: null, "a3", "a2").defaultValue("a3"),
1722: new String[] { "a1", "a2" }, null);
1723: set_values_it = set_values.iterator();
1724: assertEquals(2, set_values.size());
1725: assertEquals("FORM:RADIO:question", set_values_it.next());
1726: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1727: assertEquals(
1728: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1729: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1730: assertEquals(
1731: "<div>answer1</div><div>answer2</div>",
1732: StringUtils.splitToArray(template.getContent(), "\n")[56]);
1733: set_values_it = set_values.iterator();
1734: template.removeValue(set_values_it.next());
1735: template.removeValue(set_values_it.next());
1736: set_values.clear();
1737:
1738: set_values = builder.generateField(template,
1739: RadioInListEnum.class, new ConstrainedProperty(
1740: "question").defaultValue("a3"), new String[] {
1741: "a1", "a2" }, null);
1742: set_values_it = set_values.iterator();
1743: assertEquals(2, set_values.size());
1744: assertEquals("FORM:RADIO:question", set_values_it.next());
1745: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1746: assertEquals(
1747: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1748: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1749: assertEquals(
1750: "<div>answer1</div><div>answer2</div>",
1751: StringUtils.splitToArray(template.getContent(), "\n")[56]);
1752: set_values_it = set_values.iterator();
1753: template.removeValue(set_values_it.next());
1754: template.removeValue(set_values_it.next());
1755: set_values.clear();
1756:
1757: set_values = builder.generateField(template,
1758: new ConstrainedProperty("question").inList(null, "a1",
1759: null, "a3", "a2"), new String[] { "a4" }, null);
1760: set_values_it = set_values.iterator();
1761: assertEquals(2, set_values.size());
1762: assertEquals("FORM:RADIO:question", set_values_it.next());
1763: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1764: assertEquals(
1765: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1766: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1767: assertEquals("<div>a4</div>", StringUtils.splitToArray(template
1768: .getContent(), "\n")[56]);
1769: set_values_it = set_values.iterator();
1770: template.removeValue(set_values_it.next());
1771: template.removeValue(set_values_it.next());
1772: set_values.clear();
1773:
1774: set_values = builder.generateField(template,
1775: RadioInListEnum.class, "question",
1776: new String[] { "a4" }, null);
1777: set_values_it = set_values.iterator();
1778: assertEquals(2, set_values.size());
1779: assertEquals("FORM:RADIO:question", set_values_it.next());
1780: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1781: assertEquals(
1782: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
1783: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1784: assertEquals("<div>a4</div>", StringUtils.splitToArray(template
1785: .getContent(), "\n")[56]);
1786: set_values_it = set_values.iterator();
1787: template.removeValue(set_values_it.next());
1788: template.removeValue(set_values_it.next());
1789: set_values.clear();
1790:
1791: template.setValue("FORM:RADIO:question", "already set");
1792: template.setValue("FORM:DISPLAY:question", "already set too");
1793: set_values = builder.generateField(template,
1794: new ConstrainedProperty("question"), null, null);
1795: assertEquals(0, set_values.size());
1796: assertEquals("already set", StringUtils.splitToArray(template
1797: .getContent(), "\n")[6]);
1798: assertEquals("already set too", StringUtils.splitToArray(
1799: template.getContent(), "\n")[56]);
1800: template.removeValue("FORM:RADIO:question");
1801: template.removeValue("FORM:DISPLAY:question");
1802: }
1803:
1804: public void testGenerateFieldRadioWithoutDefault() {
1805: FormBuilderXhtml builder = new FormBuilderXhtml();
1806: Collection<String> set_values;
1807:
1808: Template template = TemplateFactory.ENGINEHTML
1809: .get("formbuilder_fields");
1810:
1811: set_values = builder.generateField(template, "anotherquestion",
1812: null, null);
1813: assertEquals(1, set_values.size());
1814: assertEquals("FORM:RADIO:anotherquestion", set_values
1815: .iterator().next());
1816: assertEquals(
1817: "<input type=\"radio\" name=\"anotherquestion\" />",
1818: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1819: template.removeValue(set_values.iterator().next());
1820: set_values.clear();
1821:
1822: set_values = builder.generateField(template,
1823: new ConstrainedProperty("anotherquestion"), null, null);
1824: assertEquals(1, set_values.size());
1825: assertEquals("FORM:RADIO:anotherquestion", set_values
1826: .iterator().next());
1827: assertEquals(
1828: "<input type=\"radio\" name=\"anotherquestion\" />",
1829: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1830: template.removeValue(set_values.iterator().next());
1831: set_values.clear();
1832:
1833: set_values = builder.generateField(template,
1834: new ConstrainedProperty("anotherquestion").inList(null,
1835: "a1", null, "a3", "a2"), null, null);
1836: assertEquals(1, set_values.size());
1837: assertEquals("FORM:RADIO:anotherquestion", set_values
1838: .iterator().next());
1839: assertEquals(
1840: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1841: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1842: template.removeValue(set_values.iterator().next());
1843: set_values.clear();
1844:
1845: set_values = builder.generateField(template,
1846: RadioInListEnum.class, "anotherquestion", null, null);
1847: assertEquals(1, set_values.size());
1848: assertEquals("FORM:RADIO:anotherquestion", set_values
1849: .iterator().next());
1850: assertEquals(
1851: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1852: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1853: template.removeValue(set_values.iterator().next());
1854: set_values.clear();
1855:
1856: set_values = builder.generateField(template,
1857: new ConstrainedProperty("anotherquestion").inList(null,
1858: "a1", null, "a3", "a2").defaultValue("a3"),
1859: new String[] { "a1", "a2" }, null);
1860: assertEquals(1, set_values.size());
1861: assertEquals("FORM:RADIO:anotherquestion", set_values
1862: .iterator().next());
1863: assertEquals(
1864: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" checked=\"checked\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1865: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1866: template.removeValue(set_values.iterator().next());
1867: set_values.clear();
1868:
1869: set_values = builder.generateField(template,
1870: RadioInListEnum.class, new ConstrainedProperty(
1871: "anotherquestion").defaultValue("a3"),
1872: new String[] { "a1", "a2" }, null);
1873: assertEquals(1, set_values.size());
1874: assertEquals("FORM:RADIO:anotherquestion", set_values
1875: .iterator().next());
1876: assertEquals(
1877: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" checked=\"checked\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1878: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1879: template.removeValue(set_values.iterator().next());
1880: set_values.clear();
1881: }
1882:
1883: public void testGenerateFieldRadioPrefix() {
1884: FormBuilderXhtml builder = new FormBuilderXhtml();
1885: Collection<String> set_values;
1886:
1887: Template template = TemplateFactory.ENGINEHTML
1888: .get("formbuilder_fields");
1889:
1890: set_values = builder.generateField(template, "question", null,
1891: "another");
1892: assertEquals(1, set_values.size());
1893: assertEquals("FORM:RADIO:anotherquestion", set_values
1894: .iterator().next());
1895: assertEquals(
1896: "<input type=\"radio\" name=\"anotherquestion\" />",
1897: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1898: template.removeValue(set_values.iterator().next());
1899: set_values.clear();
1900:
1901: set_values = builder.generateField(template,
1902: new ConstrainedProperty("question"), null, "another");
1903: assertEquals(1, set_values.size());
1904: assertEquals("FORM:RADIO:anotherquestion", set_values
1905: .iterator().next());
1906: assertEquals(
1907: "<input type=\"radio\" name=\"anotherquestion\" />",
1908: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1909: template.removeValue(set_values.iterator().next());
1910: set_values.clear();
1911:
1912: set_values = builder.generateField(template,
1913: new ConstrainedProperty("question").inList(null, "a1",
1914: null, "a3", "a2"), null, "another");
1915: assertEquals(1, set_values.size());
1916: assertEquals("FORM:RADIO:anotherquestion", set_values
1917: .iterator().next());
1918: assertEquals(
1919: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1920: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1921: template.removeValue(set_values.iterator().next());
1922: set_values.clear();
1923:
1924: set_values = builder.generateField(template,
1925: RadioInListEnum.class, "question", null, "another");
1926: assertEquals(1, set_values.size());
1927: assertEquals("FORM:RADIO:anotherquestion", set_values
1928: .iterator().next());
1929: assertEquals(
1930: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1931: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1932: template.removeValue(set_values.iterator().next());
1933: set_values.clear();
1934:
1935: set_values = builder.generateField(template,
1936: new ConstrainedProperty("question").inList(null, "a1",
1937: null, "a3", "a2").defaultValue("a3"),
1938: new String[] { "a1", "a2" }, "another");
1939: assertEquals(1, set_values.size());
1940: assertEquals("FORM:RADIO:anotherquestion", set_values
1941: .iterator().next());
1942: assertEquals(
1943: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" checked=\"checked\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1944: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1945: template.removeValue(set_values.iterator().next());
1946: set_values.clear();
1947:
1948: set_values = builder.generateField(template,
1949: RadioInListEnum.class, new ConstrainedProperty(
1950: "question").defaultValue("a3"), new String[] {
1951: "a1", "a2" }, "another");
1952: assertEquals(1, set_values.size());
1953: assertEquals("FORM:RADIO:anotherquestion", set_values
1954: .iterator().next());
1955: assertEquals(
1956: "<input type=\"radio\" name=\"anotherquestion\" value=\"a1\" checked=\"checked\" />another answer 1<input type=\"radio\" name=\"anotherquestion\" value=\"a3\" />a3<input type=\"radio\" name=\"anotherquestion\" value=\"a2\" />another answer 2",
1957: StringUtils.splitToArray(template.getContent(), "\n")[10]);
1958: template.removeValue(set_values.iterator().next());
1959: set_values.clear();
1960:
1961: template.setValue("FORM:RADIO:anotherquestion", "already set");
1962: set_values = builder.generateField(template,
1963: new ConstrainedProperty("question"), null, "another");
1964: assertEquals(0, set_values.size());
1965: assertEquals("already set", StringUtils.splitToArray(template
1966: .getContent(), "\n")[10]);
1967: template.removeValue("FORM:RADIO:anotherquestion");
1968: }
1969:
1970: public void testGenerateFieldRadioDynamic() {
1971: FormBuilderXhtml builder = new FormBuilderXhtml();
1972: Collection<String> set_values;
1973: Iterator<String> set_values_it;
1974:
1975: Template template = TemplateFactory.ENGINEHTML
1976: .get("formbuilder_fields");
1977:
1978: template.addResourceBundle(new ListResourceBundle() {
1979: public Object[][] getContents() {
1980: return new Object[][] {
1981: { "question:a1", "dynamic first" },
1982: { "question:a2", "dynamic second" },
1983: { "question:a3", "dynamic third" } };
1984: }
1985: });
1986:
1987: set_values = builder.generateField(template,
1988: new ConstrainedProperty("question").inList("a1", "a3",
1989: "a2").defaultValue("a2"), null, null);
1990: set_values_it = set_values.iterator();
1991: assertEquals(2, set_values.size());
1992: assertEquals("FORM:RADIO:question", set_values_it.next());
1993: assertEquals("FORM:DISPLAY:question", set_values_it.next());
1994: assertEquals(
1995: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />dynamic third<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />dynamic second",
1996: StringUtils.splitToArray(template.getContent(), "\n")[6]);
1997: assertEquals("<div>dynamic second</div>", StringUtils
1998: .splitToArray(template.getContent(), "\n")[56]);
1999: set_values_it = set_values.iterator();
2000: template.removeValue(set_values_it.next());
2001: template.removeValue(set_values_it.next());
2002: set_values.clear();
2003:
2004: set_values = builder.generateField(template,
2005: RadioInListEnum.class, new ConstrainedProperty(
2006: "question").defaultValue("a2"), null, null);
2007: set_values_it = set_values.iterator();
2008: assertEquals(2, set_values.size());
2009: assertEquals("FORM:RADIO:question", set_values_it.next());
2010: assertEquals("FORM:DISPLAY:question", set_values_it.next());
2011: assertEquals(
2012: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />dynamic third<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />dynamic second",
2013: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2014: assertEquals("<div>dynamic second</div>", StringUtils
2015: .splitToArray(template.getContent(), "\n")[56]);
2016: set_values_it = set_values.iterator();
2017: template.removeValue(set_values_it.next());
2018: template.removeValue(set_values_it.next());
2019: set_values.clear();
2020:
2021: set_values = builder.generateField(template,
2022: new ConstrainedProperty("question").inList("a1", "a3",
2023: "a2").defaultValue("a2"), new String[] { "a1",
2024: "a2" }, null);
2025: set_values_it = set_values.iterator();
2026: assertEquals(2, set_values.size());
2027: assertEquals("FORM:RADIO:question", set_values_it.next());
2028: assertEquals("FORM:DISPLAY:question", set_values_it.next());
2029: assertEquals(
2030: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />dynamic third<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />dynamic second",
2031: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2032: assertEquals(
2033: "<div>dynamic first</div><div>dynamic second</div>",
2034: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2035: set_values_it = set_values.iterator();
2036: template.removeValue(set_values_it.next());
2037: template.removeValue(set_values_it.next());
2038: set_values.clear();
2039:
2040: set_values = builder.generateField(template,
2041: RadioInListEnum.class, new ConstrainedProperty(
2042: "question").defaultValue("a2"), new String[] {
2043: "a1", "a2" }, null);
2044: set_values_it = set_values.iterator();
2045: assertEquals(2, set_values.size());
2046: assertEquals("FORM:RADIO:question", set_values_it.next());
2047: assertEquals("FORM:DISPLAY:question", set_values_it.next());
2048: assertEquals(
2049: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />dynamic third<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />dynamic second",
2050: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2051: assertEquals(
2052: "<div>dynamic first</div><div>dynamic second</div>",
2053: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2054: set_values_it = set_values.iterator();
2055: template.removeValue(set_values_it.next());
2056: template.removeValue(set_values_it.next());
2057: set_values.clear();
2058:
2059: template.clear();
2060:
2061: template.addResourceBundle(new ListResourceBundle() {
2062: public Object[][] getContents() {
2063: return new Object[][] { { "question:a1",
2064: "dynamic first" }, };
2065: }
2066: });
2067:
2068: set_values = builder.generateField(template,
2069: new ConstrainedProperty("question").inList("a1", "a3",
2070: "a2").defaultValue("a2"), new String[] { "a1",
2071: "a2" }, null);
2072: set_values_it = set_values.iterator();
2073: assertEquals(2, set_values.size());
2074: assertEquals("FORM:RADIO:question", set_values_it.next());
2075: assertEquals("FORM:DISPLAY:question", set_values_it.next());
2076: assertEquals(
2077: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2078: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2079: assertEquals(
2080: "<div>dynamic first</div><div>answer2</div>",
2081: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2082: set_values_it = set_values.iterator();
2083: template.removeValue(set_values_it.next());
2084: template.removeValue(set_values_it.next());
2085: set_values.clear();
2086:
2087: set_values = builder.generateField(template,
2088: RadioInListEnum.class, new ConstrainedProperty(
2089: "question").defaultValue("a2"), new String[] {
2090: "a1", "a2" }, null);
2091: set_values_it = set_values.iterator();
2092: assertEquals(2, set_values.size());
2093: assertEquals("FORM:RADIO:question", set_values_it.next());
2094: assertEquals("FORM:DISPLAY:question", set_values_it.next());
2095: assertEquals(
2096: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2097: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2098: assertEquals(
2099: "<div>dynamic first</div><div>answer2</div>",
2100: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2101: set_values_it = set_values.iterator();
2102: template.removeValue(set_values_it.next());
2103: template.removeValue(set_values_it.next());
2104: set_values.clear();
2105:
2106: set_values = builder.generateField(template,
2107: new ConstrainedProperty("question").inList("a1", "a3",
2108: "a2").defaultValue("a2"),
2109: new String[] { "a2" }, null);
2110: set_values_it = set_values.iterator();
2111: assertEquals(2, set_values.size());
2112: assertEquals("FORM:RADIO:question", set_values_it.next());
2113: assertEquals("FORM:DISPLAY:question", set_values_it.next());
2114: assertEquals(
2115: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />answer2",
2116: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2117: assertEquals("<div>answer2</div>", StringUtils.splitToArray(
2118: template.getContent(), "\n")[56]);
2119: set_values_it = set_values.iterator();
2120: template.removeValue(set_values_it.next());
2121: template.removeValue(set_values_it.next());
2122: set_values.clear();
2123:
2124: set_values = builder.generateField(template,
2125: RadioInListEnum.class, new ConstrainedProperty(
2126: "question").defaultValue("a2"),
2127: new String[] { "a2" }, null);
2128: set_values_it = set_values.iterator();
2129: assertEquals(2, set_values.size());
2130: assertEquals("FORM:RADIO:question", set_values_it.next());
2131: assertEquals("FORM:DISPLAY:question", set_values_it.next());
2132: assertEquals(
2133: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />dynamic first<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />answer2",
2134: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2135: assertEquals("<div>answer2</div>", StringUtils.splitToArray(
2136: template.getContent(), "\n")[56]);
2137: set_values_it = set_values.iterator();
2138: template.removeValue(set_values_it.next());
2139: template.removeValue(set_values_it.next());
2140: set_values.clear();
2141: }
2142:
2143: public void testGenerateFieldRadioTemplateNameWithDefault() {
2144: FormBuilderXhtml builder = new FormBuilderXhtml();
2145: Collection<String> set_values;
2146: Iterator<String> set_values_it;
2147:
2148: Template template = TemplateFactory.ENGINEHTML
2149: .get("formbuilder_fields_templatename");
2150:
2151: set_values = builder.replaceField(template,
2152: "templatenamequestion", "question", null, null);
2153: set_values_it = set_values.iterator();
2154: assertEquals(2, set_values.size());
2155: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2156: .next());
2157: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2158: .next());
2159: assertEquals(
2160: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"question[!V 'FORM:VALUE'/]\" />",
2161: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2162: assertEquals("<div></div>", StringUtils.splitToArray(template
2163: .getContent(), "\n")[56]);
2164: set_values_it = set_values.iterator();
2165: template.removeValue(set_values_it.next());
2166: template.removeValue(set_values_it.next());
2167: set_values.clear();
2168:
2169: set_values = builder.replaceField(template,
2170: "templatenamequestion", new ConstrainedProperty(
2171: "question"), null, null);
2172: set_values_it = set_values.iterator();
2173: assertEquals(2, set_values.size());
2174: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2175: .next());
2176: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2177: .next());
2178: assertEquals(
2179: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"question[!V 'FORM:VALUE'/]\" />",
2180: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2181: assertEquals("<div></div>", StringUtils.splitToArray(template
2182: .getContent(), "\n")[56]);
2183: set_values_it = set_values.iterator();
2184: template.removeValue(set_values_it.next());
2185: template.removeValue(set_values_it.next());
2186: set_values.clear();
2187:
2188: set_values = builder.replaceField(template,
2189: "templatenamequestion", new ConstrainedProperty(
2190: "question")
2191: .inList(null, "a1", null, "a3", "a2"), null,
2192: null);
2193: set_values_it = set_values.iterator();
2194: assertEquals(2, set_values.size());
2195: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2196: .next());
2197: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2198: .next());
2199: assertEquals(
2200: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2201: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2202: assertEquals("<div></div>", StringUtils.splitToArray(template
2203: .getContent(), "\n")[56]);
2204: set_values_it = set_values.iterator();
2205: template.removeValue(set_values_it.next());
2206: template.removeValue(set_values_it.next());
2207: set_values.clear();
2208:
2209: set_values = builder.replaceField(template,
2210: "templatenamequestion", RadioInListEnum.class,
2211: "question", null, null);
2212: set_values_it = set_values.iterator();
2213: assertEquals(2, set_values.size());
2214: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2215: .next());
2216: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2217: .next());
2218: assertEquals(
2219: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2220: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2221: assertEquals("<div></div>", StringUtils.splitToArray(template
2222: .getContent(), "\n")[56]);
2223: set_values_it = set_values.iterator();
2224: template.removeValue(set_values_it.next());
2225: template.removeValue(set_values_it.next());
2226: set_values.clear();
2227:
2228: set_values = builder.replaceField(template,
2229: "templatenamequestion", new ConstrainedProperty(
2230: "question")
2231: .inList(null, "a1", null, "a3", "a2")
2232: .defaultValue("a2"),
2233: new String[] { null, "a1" }, null);
2234: set_values_it = set_values.iterator();
2235: assertEquals(2, set_values.size());
2236: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2237: .next());
2238: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2239: .next());
2240: assertEquals(
2241: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />answer2",
2242: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2243: assertEquals(
2244: "<div>answer2</div><div>answer1</div>",
2245: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2246: set_values_it = set_values.iterator();
2247: template.removeValue(set_values_it.next());
2248: template.removeValue(set_values_it.next());
2249: set_values.clear();
2250:
2251: set_values = builder.replaceField(template,
2252: "templatenamequestion", RadioInListEnum.class,
2253: new ConstrainedProperty("question").defaultValue("a2"),
2254: new String[] { null, "a1" }, null);
2255: set_values_it = set_values.iterator();
2256: assertEquals(2, set_values.size());
2257: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2258: .next());
2259: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2260: .next());
2261: assertEquals(
2262: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" checked=\"checked\" />answer2",
2263: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2264: assertEquals(
2265: "<div>answer2</div><div>answer1</div>",
2266: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2267: set_values_it = set_values.iterator();
2268: template.removeValue(set_values_it.next());
2269: template.removeValue(set_values_it.next());
2270: set_values.clear();
2271:
2272: set_values = builder.replaceField(template,
2273: "templatenamequestion", new ConstrainedProperty(
2274: "question")
2275: .inList(null, "a1", null, "a3", "a2"),
2276: new String[] { "a1", "a2" }, null);
2277: set_values_it = set_values.iterator();
2278: assertEquals(2, set_values.size());
2279: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2280: .next());
2281: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2282: .next());
2283: assertEquals(
2284: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2285: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2286: assertEquals(
2287: "<div>answer1</div><div>answer2</div>",
2288: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2289: set_values_it = set_values.iterator();
2290: template.removeValue(set_values_it.next());
2291: template.removeValue(set_values_it.next());
2292: set_values.clear();
2293:
2294: set_values = builder.replaceField(template,
2295: "templatenamequestion", RadioInListEnum.class,
2296: "question", new String[] { "a1", "a2" }, null);
2297: set_values_it = set_values.iterator();
2298: assertEquals(2, set_values.size());
2299: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2300: .next());
2301: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2302: .next());
2303: assertEquals(
2304: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2305: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2306: assertEquals(
2307: "<div>answer1</div><div>answer2</div>",
2308: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2309: set_values_it = set_values.iterator();
2310: template.removeValue(set_values_it.next());
2311: template.removeValue(set_values_it.next());
2312: set_values.clear();
2313:
2314: set_values = builder.replaceField(template,
2315: "templatenamequestion", new ConstrainedProperty(
2316: "question")
2317: .inList(null, "a1", null, "a3", "a2")
2318: .defaultValue("a3"),
2319: new String[] { "a1", "a2" }, null);
2320: set_values_it = set_values.iterator();
2321: assertEquals(2, set_values.size());
2322: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2323: .next());
2324: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2325: .next());
2326: assertEquals(
2327: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2328: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2329: assertEquals(
2330: "<div>answer1</div><div>answer2</div>",
2331: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2332: set_values_it = set_values.iterator();
2333: template.removeValue(set_values_it.next());
2334: template.removeValue(set_values_it.next());
2335: set_values.clear();
2336:
2337: set_values = builder.replaceField(template,
2338: "templatenamequestion", RadioInListEnum.class,
2339: new ConstrainedProperty("question").defaultValue("a3"),
2340: new String[] { "a1", "a2" }, null);
2341: set_values_it = set_values.iterator();
2342: assertEquals(2, set_values.size());
2343: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2344: .next());
2345: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2346: .next());
2347: assertEquals(
2348: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" checked=\"checked\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2349: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2350: assertEquals(
2351: "<div>answer1</div><div>answer2</div>",
2352: StringUtils.splitToArray(template.getContent(), "\n")[56]);
2353: set_values_it = set_values.iterator();
2354: template.removeValue(set_values_it.next());
2355: template.removeValue(set_values_it.next());
2356: set_values.clear();
2357:
2358: set_values = builder.replaceField(template,
2359: "templatenamequestion", new ConstrainedProperty(
2360: "question")
2361: .inList(null, "a1", null, "a3", "a2"),
2362: new String[] { "a4" }, null);
2363: set_values_it = set_values.iterator();
2364: assertEquals(2, set_values.size());
2365: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2366: .next());
2367: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2368: .next());
2369: assertEquals(
2370: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2371: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2372: assertEquals("<div>a4</div>", StringUtils.splitToArray(template
2373: .getContent(), "\n")[56]);
2374: set_values_it = set_values.iterator();
2375: template.removeValue(set_values_it.next());
2376: template.removeValue(set_values_it.next());
2377: set_values.clear();
2378:
2379: set_values = builder.replaceField(template,
2380: "templatenamequestion", RadioInListEnum.class,
2381: "question", new String[] { "a4" }, null);
2382: set_values_it = set_values.iterator();
2383: assertEquals(2, set_values.size());
2384: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2385: .next());
2386: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2387: .next());
2388: assertEquals(
2389: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona1\" value=\"a1\" />answer1<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona3\" value=\"a3\" />a3<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"questiona2\" value=\"a2\" />answer2",
2390: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2391: assertEquals("<div>a4</div>", StringUtils.splitToArray(template
2392: .getContent(), "\n")[56]);
2393: set_values_it = set_values.iterator();
2394: template.removeValue(set_values_it.next());
2395: template.removeValue(set_values_it.next());
2396: set_values.clear();
2397:
2398: template.setValue("FORM:RADIO:templatenamequestion",
2399: "already set");
2400: template.setValue("FORM:DISPLAY:templatenamequestion",
2401: "already set too");
2402: set_values = builder.replaceField(template,
2403: "templatenamequestion", "question", null, null);
2404: set_values_it = set_values.iterator();
2405: assertEquals(2, set_values.size());
2406: assertEquals("FORM:RADIO:templatenamequestion", set_values_it
2407: .next());
2408: assertEquals("FORM:DISPLAY:templatenamequestion", set_values_it
2409: .next());
2410: assertEquals(
2411: "<input type=\"radio\" name=\"question\" alt=\"sometext\" id=\"question[!V 'FORM:VALUE'/]\" />",
2412: StringUtils.splitToArray(template.getContent(), "\n")[6]);
2413: assertEquals("<div></div>", StringUtils.splitToArray(template
2414: .getContent(), "\n")[56]);
2415: set_values_it = set_values.iterator();
2416: template.removeValue(set_values_it.next());
2417: template.removeValue(set_values_it.next());
2418: set_values.clear();
2419: }
2420:
2421: public void testGenerateFieldRadioCustomWithDefault() {
2422: FormBuilderXhtml builder = new FormBuilderXhtml();
2423: Collection<String> set_values;
2424:
2425: Template template = TemplateFactory.ENGINEHTML
2426: .get("formbuilder_fields");
2427:
2428: set_values = builder.generateField(template, "customquestion",
2429: null, null);
2430: assertEquals(1, set_values.size());
2431: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2432: .next());
2433: assertEquals(
2434: "<input type=\"radio\" name=\"customquestion\" alt=\"customtext\" />",
2435: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2436: template.removeValue(set_values.iterator().next());
2437: set_values.clear();
2438:
2439: set_values = builder.generateField(template,
2440: new ConstrainedProperty("customquestion"), null, null);
2441: assertEquals(1, set_values.size());
2442: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2443: .next());
2444: assertEquals(
2445: "<input type=\"radio\" name=\"customquestion\" alt=\"customtext\" />",
2446: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2447: template.removeValue(set_values.iterator().next());
2448: set_values.clear();
2449:
2450: set_values = builder.generateField(template,
2451: new ConstrainedProperty("customquestion").inList(null,
2452: "a1", null, "a3", "a2"), null, null);
2453: assertEquals(1, set_values.size());
2454: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2455: .next());
2456: assertEquals(
2457: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2458: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2459: template.removeValue(set_values.iterator().next());
2460: set_values.clear();
2461:
2462: set_values = builder.generateField(template,
2463: new ConstrainedProperty("customquestion").inList(null,
2464: "a1", null, "a3", "a2"), null, null);
2465: assertEquals(1, set_values.size());
2466: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2467: .next());
2468: assertEquals(
2469: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2470: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2471: template.removeValue(set_values.iterator().next());
2472: set_values.clear();
2473:
2474: set_values = builder.generateField(template,
2475: RadioInListEnum.class, new ConstrainedProperty(
2476: "customquestion").defaultValue("a2"),
2477: new String[] { null, "a1" }, null);
2478: assertEquals(1, set_values.size());
2479: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2480: .next());
2481: assertEquals(
2482: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" checked=\"checked\" />",
2483: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2484: template.removeValue(set_values.iterator().next());
2485: set_values.clear();
2486:
2487: set_values = builder.generateField(template,
2488: new ConstrainedProperty("customquestion").inList(null,
2489: "a1", null, "a3", "a2"), new String[] { "a1",
2490: "a2" }, null);
2491: assertEquals(1, set_values.size());
2492: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2493: .next());
2494: assertEquals(
2495: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2496: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2497: template.removeValue(set_values.iterator().next());
2498: set_values.clear();
2499:
2500: set_values = builder.generateField(template,
2501: RadioInListEnum.class, "customquestion", new String[] {
2502: "a1", "a2" }, null);
2503: assertEquals(1, set_values.size());
2504: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2505: .next());
2506: assertEquals(
2507: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2508: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2509: template.removeValue(set_values.iterator().next());
2510: set_values.clear();
2511:
2512: set_values = builder.generateField(template,
2513: new ConstrainedProperty("customquestion").inList(null,
2514: "a1", null, "a3", "a2").defaultValue("a3"),
2515: new String[] { "a1", "a2" }, null);
2516: assertEquals(1, set_values.size());
2517: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2518: .next());
2519: assertEquals(
2520: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2521: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2522: template.removeValue(set_values.iterator().next());
2523: set_values.clear();
2524:
2525: set_values = builder.generateField(template,
2526: RadioInListEnum.class, new ConstrainedProperty(
2527: "customquestion").defaultValue("a3"),
2528: new String[] { "a1", "a2" }, null);
2529: assertEquals(1, set_values.size());
2530: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2531: .next());
2532: assertEquals(
2533: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2534: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2535: template.removeValue(set_values.iterator().next());
2536: set_values.clear();
2537:
2538: set_values = builder.generateField(template,
2539: new ConstrainedProperty("customquestion").inList(null,
2540: "a1", null, "a3", "a2"), new String[] { "a4" },
2541: null);
2542: assertEquals(1, set_values.size());
2543: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2544: .next());
2545: assertEquals(
2546: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2547: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2548: template.removeValue(set_values.iterator().next());
2549: set_values.clear();
2550:
2551: set_values = builder.generateField(template,
2552: RadioInListEnum.class, "customquestion",
2553: new String[] { "a4" }, null);
2554: assertEquals(1, set_values.size());
2555: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2556: .next());
2557: assertEquals(
2558: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />custom answer 2 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2559: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2560: template.removeValue(set_values.iterator().next());
2561: set_values.clear();
2562:
2563: template.setValue("FORM:RADIO:customquestion", "already set");
2564: set_values = builder.generateField(template,
2565: new ConstrainedProperty("customquestion"), null, null);
2566: assertEquals(0, set_values.size());
2567: assertEquals("already set", StringUtils.splitToArray(template
2568: .getContent(), "\n")[14]);
2569: template.removeValue("FORM:RADIO:customquestion");
2570: }
2571:
2572: public void testGenerateFieldRadioCustomWithoutDefault() {
2573: FormBuilderXhtml builder = new FormBuilderXhtml();
2574: Collection<String> set_values;
2575:
2576: Template template = TemplateFactory.ENGINEHTML
2577: .get("formbuilder_fields");
2578:
2579: set_values = builder.generateField(template,
2580: "anothercustomquestion", null, null);
2581: assertEquals(1, set_values.size());
2582: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2583: .iterator().next());
2584: assertEquals(
2585: "<input type=\"radio\" name=\"anothercustomquestion\" />",
2586: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2587: template.removeValue(set_values.iterator().next());
2588: set_values.clear();
2589:
2590: set_values = builder.generateField(template,
2591: new ConstrainedProperty("anothercustomquestion"), null,
2592: null);
2593: assertEquals(1, set_values.size());
2594: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2595: .iterator().next());
2596: assertEquals(
2597: "<input type=\"radio\" name=\"anothercustomquestion\" />",
2598: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2599: template.removeValue(set_values.iterator().next());
2600: set_values.clear();
2601:
2602: set_values = builder.generateField(template,
2603: new ConstrainedProperty("anothercustomquestion")
2604: .inList(null, "a1", null, "a3", "a2"), null,
2605: null);
2606: assertEquals(1, set_values.size());
2607: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2608: .iterator().next());
2609: assertEquals(
2610: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2611: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2612: template.removeValue(set_values.iterator().next());
2613: set_values.clear();
2614:
2615: set_values = builder.generateField(template,
2616: RadioInListEnum.class, "anothercustomquestion", null,
2617: null);
2618: assertEquals(1, set_values.size());
2619: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2620: .iterator().next());
2621: assertEquals(
2622: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2623: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2624: template.removeValue(set_values.iterator().next());
2625: set_values.clear();
2626:
2627: set_values = builder.generateField(template,
2628: new ConstrainedProperty("anothercustomquestion")
2629: .inList(null, "a1", null, "a3", "a2")
2630: .defaultValue("a2"),
2631: new String[] { null, "a1" }, null);
2632: assertEquals(1, set_values.size());
2633: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2634: .iterator().next());
2635: assertEquals(
2636: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" checked=\"checked\" />",
2637: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2638: template.removeValue(set_values.iterator().next());
2639: set_values.clear();
2640:
2641: set_values = builder.generateField(template,
2642: RadioInListEnum.class, new ConstrainedProperty(
2643: "anothercustomquestion").defaultValue("a2"),
2644: new String[] { null, "a1" }, null);
2645: assertEquals(1, set_values.size());
2646: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2647: .iterator().next());
2648: assertEquals(
2649: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" checked=\"checked\" />",
2650: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2651: template.removeValue(set_values.iterator().next());
2652: set_values.clear();
2653:
2654: set_values = builder.generateField(template,
2655: new ConstrainedProperty("anothercustomquestion")
2656: .inList(null, "a1", null, "a3", "a2"),
2657: new String[] { "a1", "a2" }, null);
2658: assertEquals(1, set_values.size());
2659: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2660: .iterator().next());
2661: assertEquals(
2662: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2663: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2664: template.removeValue(set_values.iterator().next());
2665: set_values.clear();
2666:
2667: set_values = builder.generateField(template,
2668: RadioInListEnum.class, "anothercustomquestion",
2669: new String[] { "a1", "a2" }, null);
2670: assertEquals(1, set_values.size());
2671: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2672: .iterator().next());
2673: assertEquals(
2674: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2675: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2676: template.removeValue(set_values.iterator().next());
2677: set_values.clear();
2678:
2679: set_values = builder.generateField(template,
2680: new ConstrainedProperty("anothercustomquestion")
2681: .inList(null, "a1", null, "a3", "a2")
2682: .defaultValue("a3"),
2683: new String[] { "a1", "a2" }, null);
2684: assertEquals(1, set_values.size());
2685: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2686: .iterator().next());
2687: assertEquals(
2688: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2689: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2690: template.removeValue(set_values.iterator().next());
2691: set_values.clear();
2692:
2693: set_values = builder.generateField(template,
2694: RadioInListEnum.class, new ConstrainedProperty(
2695: "anothercustomquestion").defaultValue("a3"),
2696: new String[] { "a1", "a2" }, null);
2697: assertEquals(1, set_values.size());
2698: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2699: .iterator().next());
2700: assertEquals(
2701: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2702: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2703: template.removeValue(set_values.iterator().next());
2704: set_values.clear();
2705:
2706: set_values = builder.generateField(template,
2707: new ConstrainedProperty("anothercustomquestion")
2708: .inList(null, "a1", null, "a3", "a2"),
2709: new String[] { "a4" }, null);
2710: assertEquals(1, set_values.size());
2711: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2712: .iterator().next());
2713: assertEquals(
2714: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2715: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2716: template.removeValue(set_values.iterator().next());
2717: set_values.clear();
2718:
2719: set_values = builder.generateField(template,
2720: RadioInListEnum.class, "anothercustomquestion",
2721: new String[] { "a4" }, null);
2722: assertEquals(1, set_values.size());
2723: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2724: .iterator().next());
2725: assertEquals(
2726: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2727: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2728: template.removeValue(set_values.iterator().next());
2729: set_values.clear();
2730:
2731: template.setValue("FORM:RADIO:anothercustomquestion",
2732: "already set");
2733: set_values = builder.generateField(template,
2734: new ConstrainedProperty("anothercustomquestion"), null,
2735: null);
2736: assertEquals(0, set_values.size());
2737: assertEquals("already set", StringUtils.splitToArray(template
2738: .getContent(), "\n")[19]);
2739: template.removeValue("FORM:RADIO:anothercustomquestion");
2740: }
2741:
2742: public void testGenerateFieldRadioCustomPrefix() {
2743: FormBuilderXhtml builder = new FormBuilderXhtml();
2744: Collection<String> set_values;
2745:
2746: Template template = TemplateFactory.ENGINEHTML
2747: .get("formbuilder_fields");
2748:
2749: set_values = builder.generateField(template,
2750: new ConstrainedProperty("customquestion").inList(null,
2751: "a1", null, "a3", "a2"), null, "another");
2752: assertEquals(1, set_values.size());
2753: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2754: .iterator().next());
2755: assertEquals(
2756: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2757: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2758: template.removeValue(set_values.iterator().next());
2759: set_values.clear();
2760:
2761: set_values = builder.generateField(template,
2762: RadioInListEnum.class, "customquestion", null,
2763: "another");
2764: assertEquals(1, set_values.size());
2765: assertEquals("FORM:RADIO:anothercustomquestion", set_values
2766: .iterator().next());
2767: assertEquals(
2768: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2769: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2770: template.removeValue(set_values.iterator().next());
2771: set_values.clear();
2772:
2773: template.setValue("FORM:RADIO:anothercustomquestion",
2774: "already set");
2775: set_values = builder.generateField(template,
2776: new ConstrainedProperty("customquestion"), null,
2777: "another");
2778: assertEquals(0, set_values.size());
2779: assertEquals("already set", StringUtils.splitToArray(template
2780: .getContent(), "\n")[19]);
2781: template.removeValue("FORM:RADIO:anothercustomquestion");
2782: }
2783:
2784: public void testGenerateFieldRadioCustomDynamic() {
2785: FormBuilderXhtml builder = new FormBuilderXhtml();
2786: Collection<String> set_values;
2787:
2788: Template template = TemplateFactory.ENGINEHTML
2789: .get("formbuilder_fields");
2790:
2791: template.addResourceBundle(new ListResourceBundle() {
2792: public Object[][] getContents() {
2793: return new Object[][] {
2794: { "customquestion:a1", "dynamic first" },
2795: { "customquestion:a2", "dynamic second" },
2796: { "customquestion:a3", "dynamic third" } };
2797: }
2798: });
2799:
2800: set_values = builder.generateField(template,
2801: new ConstrainedProperty("customquestion").inList("a1",
2802: "a3", "a2").defaultValue("a2"), null, null);
2803: assertEquals(1, set_values.size());
2804: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2805: .next());
2806: assertEquals(
2807: "dynamic first : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" />dynamic third : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />dynamic second : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" checked=\"checked\" />",
2808: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2809: template.removeValue(set_values.iterator().next());
2810: set_values.clear();
2811:
2812: set_values = builder.generateField(template,
2813: RadioInListEnum.class, new ConstrainedProperty(
2814: "customquestion").defaultValue("a2"), null,
2815: null);
2816: assertEquals(1, set_values.size());
2817: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2818: .next());
2819: assertEquals(
2820: "dynamic first : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" />dynamic third : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />dynamic second : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" checked=\"checked\" />",
2821: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2822: template.removeValue(set_values.iterator().next());
2823: set_values.clear();
2824:
2825: set_values = builder.generateField(template,
2826: new ConstrainedProperty("customquestion").inList("a1",
2827: "a3", "a2").defaultValue("a2"), new String[] {
2828: "a1", "a3" }, null);
2829: assertEquals(1, set_values.size());
2830: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2831: .next());
2832: assertEquals(
2833: "dynamic first : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />dynamic third : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />dynamic second : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2834: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2835: template.removeValue(set_values.iterator().next());
2836: set_values.clear();
2837:
2838: set_values = builder.generateField(template,
2839: RadioInListEnum.class, new ConstrainedProperty(
2840: "customquestion").defaultValue("a2"),
2841: new String[] { "a1", "a3" }, null);
2842: assertEquals(1, set_values.size());
2843: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2844: .next());
2845: assertEquals(
2846: "dynamic first : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />dynamic third : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />dynamic second : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2847: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2848: template.removeValue(set_values.iterator().next());
2849: set_values.clear();
2850:
2851: template.clear();
2852:
2853: template.addResourceBundle(new ListResourceBundle() {
2854: public Object[][] getContents() {
2855: return new Object[][] { { "customquestion:a2",
2856: "dynamic second" }, };
2857: }
2858: });
2859:
2860: set_values = builder.generateField(template,
2861: new ConstrainedProperty("customquestion").inList("a1",
2862: "a3", "a2").defaultValue("a2"), new String[] {
2863: "a1", "a3" }, null);
2864: assertEquals(1, set_values.size());
2865: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2866: .next());
2867: assertEquals(
2868: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />dynamic second : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2869: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2870: template.removeValue(set_values.iterator().next());
2871: set_values.clear();
2872:
2873: set_values = builder.generateField(template,
2874: RadioInListEnum.class, new ConstrainedProperty(
2875: "customquestion").defaultValue("a2"),
2876: new String[] { "a1", "a3" }, null);
2877: assertEquals(1, set_values.size());
2878: assertEquals("FORM:RADIO:customquestion", set_values.iterator()
2879: .next());
2880: assertEquals(
2881: "custom answer 1 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a1\" checked=\"checked\" />a3 : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a3\" />dynamic second : <input type=\"radio\" name=\"customquestion\" alt=\"customtext\" value=\"a2\" />",
2882: StringUtils.splitToArray(template.getContent(), "\n")[14]);
2883: template.removeValue(set_values.iterator().next());
2884: set_values.clear();
2885: }
2886:
2887: public void testGenerateFieldRadioCustomTemplateNameWithoutDefault() {
2888: FormBuilderXhtml builder = new FormBuilderXhtml();
2889: Collection<String> set_values;
2890:
2891: Template template = TemplateFactory.ENGINEHTML
2892: .get("formbuilder_fields_templatename");
2893:
2894: set_values = builder.replaceField(template,
2895: "templatenameanothercustomquestion",
2896: "anothercustomquestion", null, null);
2897: assertEquals(1, set_values.size());
2898: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2899: set_values.iterator().next());
2900: assertEquals(
2901: "<input type=\"radio\" name=\"anothercustomquestion\" />",
2902: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2903: template.removeValue(set_values.iterator().next());
2904: set_values.clear();
2905:
2906: set_values = builder.replaceField(template,
2907: "templatenameanothercustomquestion",
2908: new ConstrainedProperty("anothercustomquestion"), null,
2909: null);
2910: assertEquals(1, set_values.size());
2911: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2912: set_values.iterator().next());
2913: assertEquals(
2914: "<input type=\"radio\" name=\"anothercustomquestion\" />",
2915: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2916: template.removeValue(set_values.iterator().next());
2917: set_values.clear();
2918:
2919: set_values = builder.replaceField(template,
2920: "templatenameanothercustomquestion",
2921: new ConstrainedProperty("anothercustomquestion")
2922: .inList(null, "a1", null, "a3", "a2"), null,
2923: null);
2924: assertEquals(1, set_values.size());
2925: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2926: set_values.iterator().next());
2927: assertEquals(
2928: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2929: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2930: template.removeValue(set_values.iterator().next());
2931: set_values.clear();
2932:
2933: set_values = builder.replaceField(template,
2934: "templatenameanothercustomquestion",
2935: RadioInListEnum.class, "anothercustomquestion", null,
2936: null);
2937: assertEquals(1, set_values.size());
2938: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2939: set_values.iterator().next());
2940: assertEquals(
2941: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2942: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2943: template.removeValue(set_values.iterator().next());
2944: set_values.clear();
2945:
2946: set_values = builder.replaceField(template,
2947: "templatenameanothercustomquestion",
2948: new ConstrainedProperty("anothercustomquestion")
2949: .inList(null, "a1", null, "a3", "a2")
2950: .defaultValue("a2"),
2951: new String[] { null, "a1" }, null);
2952: assertEquals(1, set_values.size());
2953: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2954: set_values.iterator().next());
2955: assertEquals(
2956: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" checked=\"checked\" />",
2957: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2958: template.removeValue(set_values.iterator().next());
2959: set_values.clear();
2960:
2961: set_values = builder.replaceField(template,
2962: "templatenameanothercustomquestion",
2963: RadioInListEnum.class, new ConstrainedProperty(
2964: "anothercustomquestion").defaultValue("a2"),
2965: new String[] { null, "a1" }, null);
2966: assertEquals(1, set_values.size());
2967: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2968: set_values.iterator().next());
2969: assertEquals(
2970: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" checked=\"checked\" />",
2971: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2972: template.removeValue(set_values.iterator().next());
2973: set_values.clear();
2974:
2975: set_values = builder.replaceField(template,
2976: "templatenameanothercustomquestion",
2977: new ConstrainedProperty("anothercustomquestion")
2978: .inList(null, "a1", null, "a3", "a2"),
2979: new String[] { "a1", "a2" }, null);
2980: assertEquals(1, set_values.size());
2981: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2982: set_values.iterator().next());
2983: assertEquals(
2984: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2985: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2986: template.removeValue(set_values.iterator().next());
2987: set_values.clear();
2988:
2989: set_values = builder.replaceField(template,
2990: "templatenameanothercustomquestion",
2991: RadioInListEnum.class, "anothercustomquestion",
2992: new String[] { "a1", "a2" }, null);
2993: assertEquals(1, set_values.size());
2994: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
2995: set_values.iterator().next());
2996: assertEquals(
2997: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
2998: StringUtils.splitToArray(template.getContent(), "\n")[19]);
2999: template.removeValue(set_values.iterator().next());
3000: set_values.clear();
3001:
3002: set_values = builder.replaceField(template,
3003: "templatenameanothercustomquestion",
3004: new ConstrainedProperty("anothercustomquestion")
3005: .inList(null, "a1", null, "a3", "a2")
3006: .defaultValue("a3"),
3007: new String[] { "a1", "a2" }, null);
3008: assertEquals(1, set_values.size());
3009: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
3010: set_values.iterator().next());
3011: assertEquals(
3012: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
3013: StringUtils.splitToArray(template.getContent(), "\n")[19]);
3014: template.removeValue(set_values.iterator().next());
3015: set_values.clear();
3016:
3017: set_values = builder.replaceField(template,
3018: "templatenameanothercustomquestion",
3019: RadioInListEnum.class, new ConstrainedProperty(
3020: "anothercustomquestion").defaultValue("a3"),
3021: new String[] { "a1", "a2" }, null);
3022: assertEquals(1, set_values.size());
3023: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
3024: set_values.iterator().next());
3025: assertEquals(
3026: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" checked=\"checked\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
3027: StringUtils.splitToArray(template.getContent(), "\n")[19]);
3028: template.removeValue(set_values.iterator().next());
3029: set_values.clear();
3030:
3031: set_values = builder.replaceField(template,
3032: "templatenameanothercustomquestion",
3033: new ConstrainedProperty("anothercustomquestion")
3034: .inList(null, "a1", null, "a3", "a2"),
3035: new String[] { "a4" }, null);
3036: assertEquals(1, set_values.size());
3037: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
3038: set_values.iterator().next());
3039: assertEquals(
3040: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
3041: StringUtils.splitToArray(template.getContent(), "\n")[19]);
3042: template.removeValue(set_values.iterator().next());
3043: set_values.clear();
3044:
3045: set_values = builder.replaceField(template,
3046: "templatenameanothercustomquestion",
3047: RadioInListEnum.class, "anothercustomquestion",
3048: new String[] { "a4" }, null);
3049: assertEquals(1, set_values.size());
3050: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
3051: set_values.iterator().next());
3052: assertEquals(
3053: "anothercustomquestion-a1:anothercustom answer 1 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a1\" />anothercustomquestion-a3:a3 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a3\" />anothercustomquestion-a2:anothercustom answer 2 : <input type=\"radio\" name=\"anothercustomquestion\" value=\"a2\" />",
3054: StringUtils.splitToArray(template.getContent(), "\n")[19]);
3055: template.removeValue(set_values.iterator().next());
3056: set_values.clear();
3057:
3058: template.setValue(
3059: "FORM:RADIO:templatenameanothercustomquestion",
3060: "already set");
3061: set_values = builder.replaceField(template,
3062: "templatenameanothercustomquestion",
3063: new ConstrainedProperty("anothercustomquestion"), null,
3064: null);
3065: assertEquals(1, set_values.size());
3066: assertEquals("FORM:RADIO:templatenameanothercustomquestion",
3067: set_values.iterator().next());
3068: assertEquals(
3069: "<input type=\"radio\" name=\"anothercustomquestion\" />",
3070: StringUtils.splitToArray(template.getContent(), "\n")[19]);
3071: template.removeValue(set_values.iterator().next());
3072: set_values.clear();
3073: }
3074:
3075: public void testGenerateFieldRadioEmptyCustomWithDefault() {
3076: FormBuilderXhtml builder = new FormBuilderXhtml();
3077: Collection<String> set_values;
3078:
3079: Template template = TemplateFactory.ENGINEHTML
3080: .get("formbuilder_fields_emptycustom");
3081:
3082: set_values = builder.generateField(template,
3083: "emptycustomquestion", null, null);
3084: assertEquals(1, set_values.size());
3085: assertEquals("FORM:RADIO:emptycustomquestion", set_values
3086: .iterator().next());
3087: assertEquals(
3088: "<input type=\"radio\" name=\"emptycustomquestion\" alt=\"emptycustomtext\" />",
3089: StringUtils.splitToArray(template.getContent(), "\n")[0]);
3090: template.removeValue(set_values.iterator().next());
3091: set_values.clear();
3092:
3093: set_values = builder.generateField(template,
3094: new ConstrainedProperty("emptycustomquestion"), null,
3095: null);
3096: assertEquals(1, set_values.size());
3097: assertEquals("FORM:RADIO:emptycustomquestion", set_values
3098: .iterator().next());
3099: assertEquals(
3100: "<input type=\"radio\" name=\"emptycustomquestion\" alt=\"emptycustomtext\" />",
3101: StringUtils.splitToArray(template.getContent(), "\n")[0]);
3102: template.removeValue(set_values.iterator().next());
3103: set_values.clear();
3104:
3105: set_values = builder.generateField(template,
3106: new ConstrainedProperty("emptycustomquestion").inList(
3107: null, "a1", null, "a3", "a2"), null, null);
3108: assertEquals(1, set_values.size());
3109: assertEquals("FORM:RADIO:emptycustomquestion", set_values
3110: .iterator().next());
3111: assertEquals(" - - - ", StringUtils.splitToArray(template
3112: .getContent(), "\n")[0]);
3113: template.removeValue(set_values.iterator().next());
3114: set_values.clear();
3115:
3116: set_values = builder.generateField(template,
3117: RadioInListEnum.class, "emptycustomquestion", null,
3118: null);
3119: assertEquals(1, set_values.size());
3120: assertEquals("FORM:RADIO:emptycustomquestion", set_values
3121: .iterator().next());
3122: assertEquals(" - - - ", StringUtils.splitToArray(template
3123: .getContent(), "\n")[0]);
3124: template.removeValue(set_values.iterator().next());
3125: set_values.clear();
3126:
3127: template.setValue("FORM:RADIO:emptycustomquestion",
3128: "already set");
3129: set_values = builder.generateField(template,
3130: new ConstrainedProperty("emptycustomquestion"), null,
3131: null);
3132: assertEquals(0, set_values.size());
3133: assertEquals("already set", StringUtils.splitToArray(template
3134: .getContent(), "\n")[0]);
3135: template.removeValue("FORM:RADIO:emptycustomquestion");
3136: }
3137:
3138: public void testGenerateFieldRadioEmptyCustomWithoutDefault() {
3139: FormBuilderXhtml builder = new FormBuilderXhtml();
3140: Collection<String> set_values;
3141:
3142: Template template = TemplateFactory.ENGINEHTML
3143: .get("formbuilder_fields_emptycustom");
3144:
3145: set_values = builder.generateField(template,
3146: "anotheremptycustomquestion", null, null);
3147: assertEquals(1, set_values.size());
3148: assertEquals("FORM:RADIO:anotheremptycustomquestion",
3149: set_values.iterator().next());
3150: assertEquals(
3151: "<input type=\"radio\" name=\"anotheremptycustomquestion\" />",
3152: StringUtils.splitToArray(template.getContent(), "\n")[2]);
3153: template.removeValue(set_values.iterator().next());
3154: set_values.clear();
3155:
3156: set_values = builder.generateField(template,
3157: new ConstrainedProperty("anotheremptycustomquestion"),
3158: null, null);
3159: assertEquals(1, set_values.size());
3160: assertEquals("FORM:RADIO:anotheremptycustomquestion",
3161: set_values.iterator().next());
3162: assertEquals(
3163: "<input type=\"radio\" name=\"anotheremptycustomquestion\" />",
3164: StringUtils.splitToArray(template.getContent(), "\n")[2]);
3165: template.removeValue(set_values.iterator().next());
3166: set_values.clear();
3167:
3168: set_values = builder.generateField(template,
3169: new ConstrainedProperty("anotheremptycustomquestion")
3170: .inList(null, "a1", null, "a3", "a2"), null,
3171: null);
3172: assertEquals(1, set_values.size());
3173: assertEquals("FORM:RADIO:anotheremptycustomquestion",
3174: set_values.iterator().next());
3175: assertEquals(" - - - ", StringUtils.splitToArray(template
3176: .getContent(), "\n")[2]);
3177: template.removeValue(set_values.iterator().next());
3178: set_values.clear();
3179:
3180: set_values = builder.generateField(template,
3181: RadioInListEnum.class, "anotheremptycustomquestion",
3182: null, null);
3183: assertEquals(1, set_values.size());
3184: assertEquals("FORM:RADIO:anotheremptycustomquestion",
3185: set_values.iterator().next());
3186: assertEquals(" - - - ", StringUtils.splitToArray(template
3187: .getContent(), "\n")[2]);
3188: template.removeValue(set_values.iterator().next());
3189: set_values.clear();
3190:
3191: template.setValue("FORM:RADIO:anotheremptycustomquestion",
3192: "already set");
3193: set_values = builder.generateField(template,
3194: new ConstrainedProperty("anotheremptycustomquestion"),
3195: null, null);
3196: assertEquals(0, set_values.size());
3197: assertEquals("already set", StringUtils.splitToArray(template
3198: .getContent(), "\n")[2]);
3199: template.removeValue("FORM:RADIO:anotheremptycustomquestion");
3200: }
3201:
3202: public void testGenerateFieldRadioEmptyCustomPrefix() {
3203: FormBuilderXhtml builder = new FormBuilderXhtml();
3204: Collection<String> set_values;
3205:
3206: Template template = TemplateFactory.ENGINEHTML
3207: .get("formbuilder_fields_emptycustom");
3208:
3209: set_values = builder.generateField(template,
3210: "emptycustomquestion", null, "another");
3211: assertEquals(1, set_values.size());
3212: assertEquals("FORM:RADIO:anotheremptycustomquestion",
3213: set_values.iterator().next());
3214: assertEquals(
3215: "<input type=\"radio\" name=\"anotheremptycustomquestion\" />",
3216: StringUtils.splitToArray(template.getContent(), "\n")[2]);
3217: template.removeValue(set_values.iterator().next());
3218: set_values.clear();
3219:
3220: set_values = builder.generateField(template,
3221: new ConstrainedProperty("emptycustomquestion").inList(
3222: null, "a1", null, "a3", "a2"), null, "another");
3223: assertEquals(1, set_values.size());
3224: assertEquals("FORM:RADIO:anotheremptycustomquestion",
3225: set_values.iterator().next());
3226: assertEquals(" - - - ", StringUtils.splitToArray(template
3227: .getContent(), "\n")[2]);
3228: template.removeValue(set_values.iterator().next());
3229: set_values.clear();
3230:
3231: set_values = builder.generateField(template,
3232: RadioInListEnum.class, "emptycustomquestion", null,
3233: "another");
3234: assertEquals(1, set_values.size());
3235: assertEquals("FORM:RADIO:anotheremptycustomquestion",
3236: set_values.iterator().next());
3237: assertEquals(" - - - ", StringUtils.splitToArray(template
3238: .getContent(), "\n")[2]);
3239: template.removeValue(set_values.iterator().next());
3240: set_values.clear();
3241:
3242: template.setValue("FORM:RADIO:anotheremptycustomquestion",
3243: "already set");
3244: set_values = builder.generateField(template,
3245: new ConstrainedProperty("emptycustomquestion"), null,
3246: "another");
3247: assertEquals(0, set_values.size());
3248: assertEquals("already set", StringUtils.splitToArray(template
3249: .getContent(), "\n")[2]);
3250: template.removeValue("FORM:RADIO:anotheremptycustomquestion");
3251: }
3252:
3253: public void testRemoveFieldRadio() {
3254: FormBuilderXhtml builder = new FormBuilderXhtml();
3255:
3256: Template template = TemplateFactory.ENGINEHTML
3257: .get("formbuilder_fields");
3258:
3259: String raw_content = template.getContent();
3260:
3261: builder.generateField(template, new ConstrainedProperty(
3262: "question").inList(null, "a1", null, "a3", "a2"),
3263: new String[] { "a4" }, null);
3264: assertFalse(raw_content.equals(template.getContent()));
3265: builder.removeField(template, "question", null);
3266: assertEquals(raw_content, template.getContent());
3267:
3268: builder.generateField(template, RadioInListEnum.class,
3269: "question", new String[] { "a4" }, null);
3270: assertFalse(raw_content.equals(template.getContent()));
3271: builder.removeField(template, "question", null);
3272: assertEquals(raw_content, template.getContent());
3273: }
3274:
3275: public void testRemoveFieldRadioTemplateName() {
3276: FormBuilderXhtml builder = new FormBuilderXhtml();
3277:
3278: Template template = TemplateFactory.ENGINEHTML
3279: .get("formbuilder_fields_templatename");
3280:
3281: String raw_content = template.getContent();
3282:
3283: builder.replaceField(template, "templatenamequestion",
3284: new ConstrainedProperty("question").inList(null, "a1",
3285: null, "a3", "a2"), new String[] { "a4" }, null);
3286: assertFalse(raw_content.equals(template.getContent()));
3287: builder.removeField(template, "templatenamequestion");
3288: assertEquals(raw_content, template.getContent());
3289:
3290: builder.replaceField(template, "templatenamequestion",
3291: RadioInListEnum.class, "question",
3292: new String[] { "a4" }, null);
3293: assertFalse(raw_content.equals(template.getContent()));
3294: builder.removeField(template, "templatenamequestion");
3295: assertEquals(raw_content, template.getContent());
3296: }
3297:
3298: public void testRemoveFieldRadioPrefix() {
3299: FormBuilderXhtml builder = new FormBuilderXhtml();
3300:
3301: Template template = TemplateFactory.ENGINEHTML
3302: .get("formbuilder_fields");
3303:
3304: String raw_content = template.getContent();
3305:
3306: builder.generateField(template, new ConstrainedProperty(
3307: "question").inList(null, "a1", null, "a3", "a2"),
3308: new String[] { "a4" }, "another");
3309: assertFalse(raw_content.equals(template.getContent()));
3310: builder.removeField(template, "question", "another");
3311: assertEquals(raw_content, template.getContent());
3312:
3313: builder.generateField(template, RadioInListEnum.class,
3314: "question", new String[] { "a4" }, "another");
3315: assertFalse(raw_content.equals(template.getContent()));
3316: builder.removeField(template, "question", "another");
3317: assertEquals(raw_content, template.getContent());
3318: }
3319:
3320: public void testGenerateFieldCheckboxWithDefault() {
3321: FormBuilderXhtml builder = new FormBuilderXhtml();
3322: Collection<String> set_values;
3323:
3324: Template template = TemplateFactory.ENGINEHTML
3325: .get("formbuilder_fields");
3326:
3327: set_values = builder.generateField(template, "options", null,
3328: null);
3329: assertEquals(1, set_values.size());
3330: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3331: .next());
3332: assertEquals(
3333: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" />",
3334: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3335: template.removeValue(set_values.iterator().next());
3336: set_values.clear();
3337:
3338: set_values = builder.generateField(template,
3339: new ConstrainedProperty("options"), null, null);
3340: assertEquals(1, set_values.size());
3341: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3342: .next());
3343: assertEquals(
3344: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" />",
3345: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3346: template.removeValue(set_values.iterator().next());
3347: set_values.clear();
3348:
3349: set_values = builder.generateField(template,
3350: new ConstrainedProperty("options").inList(null, "1",
3351: null, "3", "2"), null, null);
3352: assertEquals(1, set_values.size());
3353: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3354: .next());
3355: assertEquals(
3356: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3357: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3358: template.removeValue(set_values.iterator().next());
3359: set_values.clear();
3360:
3361: set_values = builder.generateField(template,
3362: RadioInListEnum.class, new ConstrainedProperty(
3363: "options").inList(null, "1", null, "3", "2"),
3364: null, null);
3365: assertEquals(1, set_values.size());
3366: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3367: .next());
3368: assertEquals(
3369: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3370: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3371: template.removeValue(set_values.iterator().next());
3372: set_values.clear();
3373:
3374: set_values = builder.generateField(template,
3375: CheckboxInListEnum.class, "options", null, null);
3376: assertEquals(1, set_values.size());
3377: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3378: .next());
3379: assertEquals(
3380: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3381: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3382: template.removeValue(set_values.iterator().next());
3383: set_values.clear();
3384:
3385: set_values = builder.generateField(template,
3386: new ConstrainedProperty("options").inList(null, "1",
3387: null, "3", "2").defaultValue("2"),
3388: new String[] { null, "1" }, null);
3389: assertEquals(1, set_values.size());
3390: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3391: .next());
3392: assertEquals(
3393: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3394: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3395: template.removeValue(set_values.iterator().next());
3396: set_values.clear();
3397:
3398: set_values = builder.generateField(template,
3399: CheckboxInListEnum.class, new ConstrainedProperty(
3400: "options").defaultValue("2"), new String[] {
3401: null, "1" }, null);
3402: assertEquals(1, set_values.size());
3403: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3404: .next());
3405: assertEquals(
3406: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3407: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3408: template.removeValue(set_values.iterator().next());
3409: set_values.clear();
3410:
3411: set_values = builder.generateField(template,
3412: new ConstrainedProperty("options").inList(null, "1",
3413: null, "3", "2"), new String[] { "1", "2" },
3414: null);
3415: assertEquals(1, set_values.size());
3416: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3417: .next());
3418: assertEquals(
3419: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3420: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3421: template.removeValue(set_values.iterator().next());
3422: set_values.clear();
3423:
3424: set_values = builder.generateField(template,
3425: CheckboxInListEnum.class, "options", new String[] {
3426: "1", "2" }, null);
3427: assertEquals(1, set_values.size());
3428: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3429: .next());
3430: assertEquals(
3431: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3432: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3433: template.removeValue(set_values.iterator().next());
3434: set_values.clear();
3435:
3436: set_values = builder.generateField(template,
3437: new ConstrainedProperty("options").inList(null, "1",
3438: null, "3", "2").defaultValue("3"),
3439: new String[] { "1", "2" }, null);
3440: assertEquals(1, set_values.size());
3441: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3442: .next());
3443: assertEquals(
3444: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3445: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3446: template.removeValue(set_values.iterator().next());
3447: set_values.clear();
3448:
3449: set_values = builder.generateField(template,
3450: CheckboxInListEnum.class, new ConstrainedProperty(
3451: "options").defaultValue("3"), new String[] {
3452: "1", "2" }, null);
3453: assertEquals(1, set_values.size());
3454: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3455: .next());
3456: assertEquals(
3457: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3458: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3459: template.removeValue(set_values.iterator().next());
3460: set_values.clear();
3461:
3462: set_values = builder.generateField(template,
3463: new ConstrainedProperty("options").inList(null, "1",
3464: null, "3", "2"), new String[] { "a4" }, null);
3465: assertEquals(1, set_values.size());
3466: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3467: .next());
3468: assertEquals(
3469: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3470: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3471: template.removeValue(set_values.iterator().next());
3472: set_values.clear();
3473:
3474: set_values = builder.generateField(template,
3475: CheckboxInListEnum.class, "options",
3476: new String[] { "a4" }, null);
3477: assertEquals(1, set_values.size());
3478: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
3479: .next());
3480: assertEquals(
3481: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3482: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3483: template.removeValue(set_values.iterator().next());
3484: set_values.clear();
3485:
3486: template.setValue("FORM:CHECKBOX:options", "already set");
3487: set_values = builder.generateField(template,
3488: new ConstrainedProperty("options"), null, null);
3489: assertEquals(0, set_values.size());
3490: assertEquals("already set", StringUtils.splitToArray(template
3491: .getContent(), "\n")[24]);
3492: template.removeValue("FORM:CHECKBOX:options");
3493: }
3494:
3495: public void testGenerateFieldCheckboxWithoutDefault() {
3496: FormBuilderXhtml builder = new FormBuilderXhtml();
3497: Collection<String> set_values;
3498: Iterator<String> set_values_it;
3499:
3500: Template template = TemplateFactory.ENGINEHTML
3501: .get("formbuilder_fields");
3502:
3503: set_values = builder.generateField(template, "otheroptions",
3504: null, null);
3505: set_values_it = set_values.iterator();
3506: assertEquals(2, set_values.size());
3507: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3508: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3509: assertEquals(
3510: "<input type=\"checkbox\" name=\"otheroptions\" />",
3511: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3512: assertEquals(
3513: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3514: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3515: set_values_it = set_values.iterator();
3516: template.removeValue(set_values_it.next());
3517: template.removeValue(set_values_it.next());
3518: set_values.clear();
3519:
3520: set_values = builder.generateField(template,
3521: new ConstrainedProperty("otheroptions"), null, null);
3522: set_values_it = set_values.iterator();
3523: assertEquals(2, set_values.size());
3524: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3525: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3526: assertEquals(
3527: "<input type=\"checkbox\" name=\"otheroptions\" />",
3528: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3529: assertEquals(
3530: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3531: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3532: set_values_it = set_values.iterator();
3533: template.removeValue(set_values_it.next());
3534: template.removeValue(set_values_it.next());
3535: set_values.clear();
3536:
3537: set_values = builder.generateField(template,
3538: new ConstrainedProperty("otheroptions").inList(null,
3539: "1", null, "3", "2"), null, null);
3540: set_values_it = set_values.iterator();
3541: assertEquals(2, set_values.size());
3542: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3543: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3544: assertEquals(
3545: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" />other option 2",
3546: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3547: assertEquals(
3548: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3549: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3550: set_values_it = set_values.iterator();
3551: template.removeValue(set_values_it.next());
3552: template.removeValue(set_values_it.next());
3553: set_values.clear();
3554:
3555: set_values = builder.generateField(template,
3556: CheckboxInListEnum.class, "otheroptions", null, null);
3557: set_values_it = set_values.iterator();
3558: assertEquals(2, set_values.size());
3559: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3560: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3561: assertEquals(
3562: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" />other option 2",
3563: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3564: assertEquals(
3565: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3566: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3567: set_values_it = set_values.iterator();
3568: template.removeValue(set_values_it.next());
3569: template.removeValue(set_values_it.next());
3570: set_values.clear();
3571:
3572: set_values = builder.generateField(template,
3573: new ConstrainedProperty("otheroptions").inList(null,
3574: "1", null, "3", "2").defaultValue("3"),
3575: new String[] { "1", "2" }, null);
3576: set_values_it = set_values.iterator();
3577: assertEquals(2, set_values.size());
3578: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3579: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3580: assertEquals(
3581: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" checked=\"checked\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" checked=\"checked\" />other option 2",
3582: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3583: assertEquals(
3584: "<div id=\"otheroptions1\">other option 1</div><div id=\"otheroptions2\">other option 2</div>",
3585: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3586: set_values_it = set_values.iterator();
3587: template.removeValue(set_values_it.next());
3588: template.removeValue(set_values_it.next());
3589: set_values.clear();
3590:
3591: set_values = builder.generateField(template,
3592: CheckboxInListEnum.class, new ConstrainedProperty(
3593: "otheroptions").defaultValue("3"),
3594: new String[] { "1", "2" }, null);
3595: set_values_it = set_values.iterator();
3596: assertEquals(2, set_values.size());
3597: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3598: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3599: assertEquals(
3600: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" checked=\"checked\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" checked=\"checked\" />other option 2",
3601: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3602: assertEquals(
3603: "<div id=\"otheroptions1\">other option 1</div><div id=\"otheroptions2\">other option 2</div>",
3604: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3605: set_values_it = set_values.iterator();
3606: template.removeValue(set_values_it.next());
3607: template.removeValue(set_values_it.next());
3608: set_values.clear();
3609: }
3610:
3611: public void testGenerateFieldCheckboxPrefix() {
3612: FormBuilderXhtml builder = new FormBuilderXhtml();
3613: Collection<String> set_values;
3614: Iterator<String> set_values_it;
3615:
3616: Template template = TemplateFactory.ENGINEHTML
3617: .get("formbuilder_fields");
3618:
3619: set_values = builder.generateField(template, "options", null,
3620: "other");
3621: set_values_it = set_values.iterator();
3622: assertEquals(2, set_values.size());
3623: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3624: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3625: assertEquals("FORM:CHECKBOX:otheroptions", set_values
3626: .iterator().next());
3627: assertEquals(
3628: "<input type=\"checkbox\" name=\"otheroptions\" />",
3629: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3630: assertEquals(
3631: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3632: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3633: set_values_it = set_values.iterator();
3634: template.removeValue(set_values_it.next());
3635: template.removeValue(set_values_it.next());
3636: set_values.clear();
3637:
3638: set_values = builder.generateField(template,
3639: new ConstrainedProperty("options"), null, "other");
3640: set_values_it = set_values.iterator();
3641: assertEquals(2, set_values.size());
3642: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3643: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3644: assertEquals(
3645: "<input type=\"checkbox\" name=\"otheroptions\" />",
3646: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3647: assertEquals(
3648: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3649: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3650: set_values_it = set_values.iterator();
3651: template.removeValue(set_values_it.next());
3652: template.removeValue(set_values_it.next());
3653: set_values.clear();
3654:
3655: set_values = builder.generateField(template,
3656: new ConstrainedProperty("options").inList(null, "1",
3657: null, "3", "2"), null, "other");
3658: set_values_it = set_values.iterator();
3659: assertEquals(2, set_values.size());
3660: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3661: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3662: assertEquals(
3663: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" />other option 2",
3664: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3665: assertEquals(
3666: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3667: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3668: set_values_it = set_values.iterator();
3669: template.removeValue(set_values_it.next());
3670: template.removeValue(set_values_it.next());
3671: set_values.clear();
3672:
3673: set_values = builder.generateField(template,
3674: CheckboxInListEnum.class, "options", null, "other");
3675: set_values_it = set_values.iterator();
3676: assertEquals(2, set_values.size());
3677: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3678: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3679: assertEquals(
3680: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" />other option 2",
3681: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3682: assertEquals(
3683: "<div id=\"otheroptions[!V 'FORM:VALUE'/]\"></div>",
3684: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3685: set_values_it = set_values.iterator();
3686: template.removeValue(set_values_it.next());
3687: template.removeValue(set_values_it.next());
3688: set_values.clear();
3689:
3690: set_values = builder.generateField(template,
3691: new ConstrainedProperty("options").inList(null, "1",
3692: null, "3", "2").defaultValue("3"),
3693: new String[] { "1", "2" }, "other");
3694: set_values_it = set_values.iterator();
3695: assertEquals(2, set_values.size());
3696: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3697: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3698: assertEquals(
3699: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" checked=\"checked\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" checked=\"checked\" />other option 2",
3700: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3701: assertEquals(
3702: "<div id=\"otheroptions1\">other option 1</div><div id=\"otheroptions2\">other option 2</div>",
3703: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3704: set_values_it = set_values.iterator();
3705: template.removeValue(set_values_it.next());
3706: template.removeValue(set_values_it.next());
3707: set_values.clear();
3708:
3709: set_values = builder.generateField(template,
3710: CheckboxInListEnum.class, new ConstrainedProperty(
3711: "options").defaultValue("3"), new String[] {
3712: "1", "2" }, "other");
3713: set_values_it = set_values.iterator();
3714: assertEquals(2, set_values.size());
3715: assertEquals("FORM:CHECKBOX:otheroptions", set_values_it.next());
3716: assertEquals("FORM:DISPLAY:otheroptions", set_values_it.next());
3717: assertEquals(
3718: "<input type=\"checkbox\" name=\"otheroptions\" value=\"1\" checked=\"checked\" />other option 1<input type=\"checkbox\" name=\"otheroptions\" value=\"3\" />3<input type=\"checkbox\" name=\"otheroptions\" value=\"2\" checked=\"checked\" />other option 2",
3719: StringUtils.splitToArray(template.getContent(), "\n")[28]);
3720: assertEquals(
3721: "<div id=\"otheroptions1\">other option 1</div><div id=\"otheroptions2\">other option 2</div>",
3722: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3723: set_values_it = set_values.iterator();
3724: template.removeValue(set_values_it.next());
3725: template.removeValue(set_values_it.next());
3726: set_values.clear();
3727:
3728: template.setValue("FORM:CHECKBOX:otheroptions", "already set");
3729: template.setValue("FORM:DISPLAY:otheroptions",
3730: "already set too");
3731: set_values = builder.generateField(template,
3732: new ConstrainedProperty("options"), null, "other");
3733: assertEquals(0, set_values.size());
3734: assertEquals("already set", StringUtils.splitToArray(template
3735: .getContent(), "\n")[28]);
3736: assertEquals("already set too", StringUtils.splitToArray(
3737: template.getContent(), "\n")[57]);
3738: template.removeValue("FORM:DISPLAY:otheroptions");
3739: template.removeValue("FORM:CHECKBOX:otheroptions");
3740: }
3741:
3742: public void testGenerateFieldCheckboxTemplateNameWithDefault() {
3743: FormBuilderXhtml builder = new FormBuilderXhtml();
3744: Collection<String> set_values;
3745:
3746: Template template = TemplateFactory.ENGINEHTML
3747: .get("formbuilder_fields_templatename");
3748:
3749: set_values = builder.replaceField(template,
3750: "templatenameoptions", "options", null, null);
3751: assertEquals(2, set_values.size());
3752: Iterator set_values_it = set_values.iterator();
3753: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3754: .next());
3755: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3756: .next());
3757: assertEquals(
3758: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" />",
3759: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3760: assertEquals(
3761: "<div id=\"options[!V 'FORM:VALUE'/]\"></div>",
3762: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3763: template.removeValue(set_values.iterator().next());
3764: set_values.clear();
3765:
3766: set_values = builder.replaceField(template,
3767: "templatenameoptions", new ConstrainedProperty(
3768: "options"), null, null);
3769: assertEquals(2, set_values.size());
3770: set_values_it = set_values.iterator();
3771: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3772: .next());
3773: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3774: .next());
3775: assertEquals(
3776: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" />",
3777: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3778: assertEquals(
3779: "<div id=\"options[!V 'FORM:VALUE'/]\"></div>",
3780: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3781: template.removeValue(set_values.iterator().next());
3782: set_values.clear();
3783:
3784: set_values = builder.replaceField(template,
3785: "templatenameoptions", new ConstrainedProperty(
3786: "options").inList(null, "1", null, "3", "2"),
3787: null, null);
3788: assertEquals(2, set_values.size());
3789: set_values_it = set_values.iterator();
3790: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3791: .next());
3792: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3793: .next());
3794: assertEquals(
3795: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3796: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3797: assertEquals(
3798: "<div id=\"options[!V 'FORM:VALUE'/]\"></div>",
3799: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3800: template.removeValue(set_values.iterator().next());
3801: set_values.clear();
3802:
3803: set_values = builder.replaceField(template,
3804: "templatenameoptions", CheckboxInListEnum.class,
3805: "options", null, null);
3806: assertEquals(2, set_values.size());
3807: set_values_it = set_values.iterator();
3808: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3809: .next());
3810: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3811: .next());
3812: assertEquals(
3813: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3814: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3815: assertEquals(
3816: "<div id=\"options[!V 'FORM:VALUE'/]\"></div>",
3817: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3818: template.removeValue(set_values.iterator().next());
3819: set_values.clear();
3820:
3821: set_values = builder.replaceField(template,
3822: "templatenameoptions", new ConstrainedProperty(
3823: "options").inList(null, "1", null, "3", "2")
3824: .defaultValue("2"), new String[] { null, "1" },
3825: null);
3826: assertEquals(2, set_values.size());
3827: set_values_it = set_values.iterator();
3828: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3829: .next());
3830: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3831: .next());
3832: assertEquals(
3833: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3834: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3835: assertEquals(
3836: "<div id=\"options2\">option2</div><div id=\"options1\">option1</div>",
3837: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3838: template.removeValue(set_values.iterator().next());
3839: set_values.clear();
3840:
3841: set_values = builder.replaceField(template,
3842: "templatenameoptions", CheckboxInListEnum.class,
3843: new ConstrainedProperty("options").defaultValue("2"),
3844: new String[] { null, "1" }, null);
3845: assertEquals(2, set_values.size());
3846: set_values_it = set_values.iterator();
3847: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3848: .next());
3849: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3850: .next());
3851: assertEquals(
3852: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3853: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3854: assertEquals(
3855: "<div id=\"options2\">option2</div><div id=\"options1\">option1</div>",
3856: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3857: template.removeValue(set_values.iterator().next());
3858: set_values.clear();
3859:
3860: set_values = builder.replaceField(template,
3861: "templatenameoptions", new ConstrainedProperty(
3862: "options").inList(null, "1", null, "3", "2"),
3863: new String[] { "1", "2" }, null);
3864: assertEquals(2, set_values.size());
3865: set_values_it = set_values.iterator();
3866: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3867: .next());
3868: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3869: .next());
3870: assertEquals(
3871: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3872: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3873: assertEquals(
3874: "<div id=\"options1\">option1</div><div id=\"options2\">option2</div>",
3875: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3876: template.removeValue(set_values.iterator().next());
3877: set_values.clear();
3878:
3879: set_values = builder.replaceField(template,
3880: "templatenameoptions", CheckboxInListEnum.class,
3881: "options", new String[] { "1", "2" }, null);
3882: assertEquals(2, set_values.size());
3883: set_values_it = set_values.iterator();
3884: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3885: .next());
3886: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3887: .next());
3888: assertEquals(
3889: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3890: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3891: assertEquals(
3892: "<div id=\"options1\">option1</div><div id=\"options2\">option2</div>",
3893: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3894: template.removeValue(set_values.iterator().next());
3895: set_values.clear();
3896:
3897: set_values = builder.replaceField(template,
3898: "templatenameoptions", new ConstrainedProperty(
3899: "options").inList(null, "1", null, "3", "2")
3900: .defaultValue("3"), new String[] { "1", "2" },
3901: null);
3902: assertEquals(2, set_values.size());
3903: set_values_it = set_values.iterator();
3904: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3905: .next());
3906: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3907: .next());
3908: assertEquals(
3909: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3910: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3911: assertEquals(
3912: "<div id=\"options1\">option1</div><div id=\"options2\">option2</div>",
3913: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3914: template.removeValue(set_values.iterator().next());
3915: set_values.clear();
3916:
3917: set_values = builder.replaceField(template,
3918: "templatenameoptions", CheckboxInListEnum.class,
3919: new ConstrainedProperty("options").defaultValue("3"),
3920: new String[] { "1", "2" }, null);
3921: assertEquals(2, set_values.size());
3922: set_values_it = set_values.iterator();
3923: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3924: .next());
3925: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3926: .next());
3927: assertEquals(
3928: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />option2",
3929: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3930: assertEquals(
3931: "<div id=\"options1\">option1</div><div id=\"options2\">option2</div>",
3932: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3933: template.removeValue(set_values.iterator().next());
3934: set_values.clear();
3935:
3936: set_values = builder.replaceField(template,
3937: "templatenameoptions", new ConstrainedProperty(
3938: "options").inList(null, "1", null, "3", "2"),
3939: new String[] { "a4" }, null);
3940: assertEquals(2, set_values.size());
3941: set_values_it = set_values.iterator();
3942: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3943: .next());
3944: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3945: .next());
3946: assertEquals(
3947: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3948: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3949: assertEquals("<div id=\"optionsa4\">a4</div>", StringUtils
3950: .splitToArray(template.getContent(), "\n")[57]);
3951: template.removeValue(set_values.iterator().next());
3952: set_values.clear();
3953:
3954: set_values = builder.replaceField(template,
3955: "templatenameoptions", CheckboxInListEnum.class,
3956: "options", new String[] { "a4" }, null);
3957: assertEquals(2, set_values.size());
3958: set_values_it = set_values.iterator();
3959: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3960: .next());
3961: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3962: .next());
3963: assertEquals(
3964: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />option2",
3965: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3966: assertEquals("<div id=\"optionsa4\">a4</div>", StringUtils
3967: .splitToArray(template.getContent(), "\n")[57]);
3968: template.removeValue(set_values.iterator().next());
3969: set_values.clear();
3970:
3971: template.setValue("FORM:CHECKBOX:templatenameoptions",
3972: "already set");
3973: set_values = builder.replaceField(template,
3974: "templatenameoptions", new ConstrainedProperty(
3975: "options"), null, null);
3976: assertEquals(2, set_values.size());
3977: set_values_it = set_values.iterator();
3978: assertEquals("FORM:CHECKBOX:templatenameoptions", set_values_it
3979: .next());
3980: assertEquals("FORM:DISPLAY:templatenameoptions", set_values_it
3981: .next());
3982: assertEquals(
3983: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" />",
3984: StringUtils.splitToArray(template.getContent(), "\n")[24]);
3985: assertEquals(
3986: "<div id=\"options[!V 'FORM:VALUE'/]\"></div>",
3987: StringUtils.splitToArray(template.getContent(), "\n")[57]);
3988: template.removeValue(set_values.iterator().next());
3989: set_values.clear();
3990: }
3991:
3992: public void testGenerateFieldCheckboxDynamic() {
3993: FormBuilderXhtml builder = new FormBuilderXhtml();
3994: Collection<String> set_values;
3995:
3996: Template template = TemplateFactory.ENGINEHTML
3997: .get("formbuilder_fields");
3998:
3999: template.addResourceBundle(new ListResourceBundle() {
4000: public Object[][] getContents() {
4001: return new Object[][] {
4002: { "options:1", "dynamic first" },
4003: { "options:2", "dynamic second" },
4004: { "options:3", "dynamic third" } };
4005: }
4006: });
4007:
4008: set_values = builder.generateField(template,
4009: new ConstrainedProperty("options")
4010: .inList("1", "3", "2").defaultValue("2"), null,
4011: null);
4012: assertEquals(1, set_values.size());
4013: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
4014: .next());
4015: assertEquals(
4016: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />dynamic first<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />dynamic third<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />dynamic second",
4017: StringUtils.splitToArray(template.getContent(), "\n")[24]);
4018: template.removeValue(set_values.iterator().next());
4019: set_values.clear();
4020:
4021: set_values = builder.generateField(template,
4022: CheckboxInListEnum.class, new ConstrainedProperty(
4023: "options").defaultValue("2"), null, null);
4024: assertEquals(1, set_values.size());
4025: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
4026: .next());
4027: assertEquals(
4028: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />dynamic first<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />dynamic third<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />dynamic second",
4029: StringUtils.splitToArray(template.getContent(), "\n")[24]);
4030: template.removeValue(set_values.iterator().next());
4031: set_values.clear();
4032:
4033: set_values = builder.generateField(template,
4034: new ConstrainedProperty("options")
4035: .inList("1", "3", "2").defaultValue("2"),
4036: new String[] { "3", "1" }, null);
4037: assertEquals(1, set_values.size());
4038: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
4039: .next());
4040: assertEquals(
4041: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />dynamic first<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" checked=\"checked\" />dynamic third<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />dynamic second",
4042: StringUtils.splitToArray(template.getContent(), "\n")[24]);
4043: template.removeValue(set_values.iterator().next());
4044: set_values.clear();
4045:
4046: set_values = builder.generateField(template,
4047: CheckboxInListEnum.class, new ConstrainedProperty(
4048: "options").defaultValue("2"), new String[] {
4049: "3", "1" }, null);
4050: assertEquals(1, set_values.size());
4051: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
4052: .next());
4053: assertEquals(
4054: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" checked=\"checked\" />dynamic first<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" checked=\"checked\" />dynamic third<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" />dynamic second",
4055: StringUtils.splitToArray(template.getContent(), "\n")[24]);
4056: template.removeValue(set_values.iterator().next());
4057: set_values.clear();
4058:
4059: template.clear();
4060:
4061: template.addResourceBundle(new ListResourceBundle() {
4062: public Object[][] getContents() {
4063: return new Object[][] { { "options:2", "dynamic second" }, };
4064: }
4065: });
4066:
4067: set_values = builder.generateField(template,
4068: new ConstrainedProperty("options")
4069: .inList("1", "3", "2").defaultValue("2"), null,
4070: null);
4071: assertEquals(1, set_values.size());
4072: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
4073: .next());
4074: assertEquals(
4075: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />dynamic second",
4076: StringUtils.splitToArray(template.getContent(), "\n")[24]);
4077: template.removeValue(set_values.iterator().next());
4078: set_values.clear();
4079:
4080: set_values = builder.generateField(template,
4081: CheckboxInListEnum.class, new ConstrainedProperty(
4082: "options").defaultValue("2"), null, null);
4083: assertEquals(1, set_values.size());
4084: assertEquals("FORM:CHECKBOX:options", set_values.iterator()
4085: .next());
4086: assertEquals(
4087: "<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"1\" />option1<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"3\" />3<input type=\"checkbox\" name=\"options\" alt=\"someblurp\" value=\"2\" checked=\"checked\" />dynamic second",
4088: StringUtils.splitToArray(template.getContent(), "\n")[24]);
4089: template.removeValue(set_values.iterator().next());
4090: set_values.clear();
4091: }
4092:
4093: public void testGenerateFieldCheckboxCustomWithDefault() {
4094: FormBuilderXhtml builder = new FormBuilderXhtml();
4095: Collection<String> set_values;
4096:
4097: Template template = TemplateFactory.ENGINEHTML
4098: .get("formbuilder_fields");
4099:
4100: set_values = builder.generateField(template, "customoptions",
4101: null, null);
4102: assertEquals(1, set_values.size());
4103: assertEquals("FORM:CHECKBOX:customoptions", set_values
4104: .iterator().next());
4105: assertEquals(
4106: "<input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" />",
4107: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4108: template.removeValue(set_values.iterator().next());
4109: set_values.clear();
4110:
4111: set_values = builder.generateField(template,
4112: new ConstrainedProperty("customoptions"), null, null);
4113: assertEquals(1, set_values.size());
4114: assertEquals("FORM:CHECKBOX:customoptions", set_values
4115: .iterator().next());
4116: assertEquals(
4117: "<input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" />",
4118: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4119: template.removeValue(set_values.iterator().next());
4120: set_values.clear();
4121:
4122: set_values = builder.generateField(template,
4123: new ConstrainedProperty("customoptions").inList(null,
4124: "1", null, "3", "2"), null, null);
4125: assertEquals(1, set_values.size());
4126: assertEquals("FORM:CHECKBOX:customoptions", set_values
4127: .iterator().next());
4128: assertEquals(
4129: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4130: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4131: template.removeValue(set_values.iterator().next());
4132: set_values.clear();
4133:
4134: set_values = builder.generateField(template,
4135: CheckboxInListEnum.class, "customoptions", null, null);
4136: assertEquals(1, set_values.size());
4137: assertEquals("FORM:CHECKBOX:customoptions", set_values
4138: .iterator().next());
4139: assertEquals(
4140: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4141: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4142: template.removeValue(set_values.iterator().next());
4143: set_values.clear();
4144:
4145: set_values = builder.generateField(template,
4146: new ConstrainedProperty("customoptions").inList(null,
4147: "1", null, "3", "2").defaultValue("2"),
4148: new String[] { null, "1" }, null);
4149: assertEquals(1, set_values.size());
4150: assertEquals("FORM:CHECKBOX:customoptions", set_values
4151: .iterator().next());
4152: assertEquals(
4153: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4154: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4155: template.removeValue(set_values.iterator().next());
4156: set_values.clear();
4157:
4158: set_values = builder.generateField(template,
4159: CheckboxInListEnum.class, new ConstrainedProperty(
4160: "customoptions").defaultValue("2"),
4161: new String[] { null, "1" }, null);
4162: assertEquals(1, set_values.size());
4163: assertEquals("FORM:CHECKBOX:customoptions", set_values
4164: .iterator().next());
4165: assertEquals(
4166: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4167: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4168: template.removeValue(set_values.iterator().next());
4169: set_values.clear();
4170:
4171: set_values = builder.generateField(template,
4172: new ConstrainedProperty("customoptions").inList(null,
4173: "1", null, "3", "2"),
4174: new String[] { "1", "2" }, null);
4175: assertEquals(1, set_values.size());
4176: assertEquals("FORM:CHECKBOX:customoptions", set_values
4177: .iterator().next());
4178: assertEquals(
4179: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" checked=\"checked\" />",
4180: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4181: template.removeValue(set_values.iterator().next());
4182: set_values.clear();
4183:
4184: set_values = builder.generateField(template,
4185: CheckboxInListEnum.class, "customoptions",
4186: new String[] { "1", "2" }, null);
4187: assertEquals(1, set_values.size());
4188: assertEquals("FORM:CHECKBOX:customoptions", set_values
4189: .iterator().next());
4190: assertEquals(
4191: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" checked=\"checked\" />",
4192: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4193: template.removeValue(set_values.iterator().next());
4194: set_values.clear();
4195:
4196: set_values = builder.generateField(template,
4197: new ConstrainedProperty("customoptions").inList(null,
4198: "1", null, "3", "2").defaultValue("3"),
4199: new String[] { "1", "2" }, null);
4200: assertEquals(1, set_values.size());
4201: assertEquals("FORM:CHECKBOX:customoptions", set_values
4202: .iterator().next());
4203: assertEquals(
4204: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" checked=\"checked\" />",
4205: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4206: template.removeValue(set_values.iterator().next());
4207: set_values.clear();
4208:
4209: set_values = builder.generateField(template,
4210: CheckboxInListEnum.class, new ConstrainedProperty(
4211: "customoptions").defaultValue("3"),
4212: new String[] { "1", "2" }, null);
4213: assertEquals(1, set_values.size());
4214: assertEquals("FORM:CHECKBOX:customoptions", set_values
4215: .iterator().next());
4216: assertEquals(
4217: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" checked=\"checked\" />",
4218: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4219: template.removeValue(set_values.iterator().next());
4220: set_values.clear();
4221:
4222: set_values = builder.generateField(template,
4223: new ConstrainedProperty("customoptions").inList(null,
4224: "1", null, "3", "2"), new String[] { "a4" },
4225: null);
4226: assertEquals(1, set_values.size());
4227: assertEquals("FORM:CHECKBOX:customoptions", set_values
4228: .iterator().next());
4229: assertEquals(
4230: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4231: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4232: template.removeValue(set_values.iterator().next());
4233: set_values.clear();
4234:
4235: set_values = builder.generateField(template,
4236: CheckboxInListEnum.class, "customoptions",
4237: new String[] { "a4" }, null);
4238: assertEquals(1, set_values.size());
4239: assertEquals("FORM:CHECKBOX:customoptions", set_values
4240: .iterator().next());
4241: assertEquals(
4242: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />custom option 2 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4243: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4244: template.removeValue(set_values.iterator().next());
4245: set_values.clear();
4246:
4247: template.setValue("FORM:CHECKBOX:customoptions", "already set");
4248: set_values = builder.generateField(template,
4249: new ConstrainedProperty("customoptions"), null, null);
4250: assertEquals(0, set_values.size());
4251: assertEquals("already set", StringUtils.splitToArray(template
4252: .getContent(), "\n")[32]);
4253: template.removeValue("FORM:CHECKBOX:customoptions");
4254: }
4255:
4256: public void testGenerateFieldCheckboxCustomWithoutDefault() {
4257: FormBuilderXhtml builder = new FormBuilderXhtml();
4258: Collection<String> set_values;
4259:
4260: Template template = TemplateFactory.ENGINEHTML
4261: .get("formbuilder_fields");
4262:
4263: set_values = builder.generateField(template,
4264: "othercustomoptions", null, null);
4265: assertEquals(1, set_values.size());
4266: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4267: .iterator().next());
4268: assertEquals(
4269: "<input type=\"checkbox\" name=\"othercustomoptions\" />",
4270: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4271: template.removeValue(set_values.iterator().next());
4272: set_values.clear();
4273:
4274: set_values = builder.generateField(template,
4275: new ConstrainedProperty("othercustomoptions"), null,
4276: null);
4277: assertEquals(1, set_values.size());
4278: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4279: .iterator().next());
4280: assertEquals(
4281: "<input type=\"checkbox\" name=\"othercustomoptions\" />",
4282: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4283: template.removeValue(set_values.iterator().next());
4284: set_values.clear();
4285:
4286: set_values = builder.generateField(template,
4287: new ConstrainedProperty("othercustomoptions").inList(
4288: null, "1", null, "3", "2"), null, null);
4289: assertEquals(1, set_values.size());
4290: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4291: .iterator().next());
4292: assertEquals(
4293: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4294: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4295: template.removeValue(set_values.iterator().next());
4296: set_values.clear();
4297:
4298: set_values = builder.generateField(template,
4299: CheckboxInListEnum.class, "othercustomoptions", null,
4300: null);
4301: assertEquals(1, set_values.size());
4302: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4303: .iterator().next());
4304: assertEquals(
4305: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4306: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4307: template.removeValue(set_values.iterator().next());
4308: set_values.clear();
4309:
4310: set_values = builder.generateField(template,
4311: new ConstrainedProperty("othercustomoptions").inList(
4312: null, "1", null, "3", "2").defaultValue("2"),
4313: new String[] { null, "1" }, null);
4314: assertEquals(1, set_values.size());
4315: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4316: .iterator().next());
4317: assertEquals(
4318: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4319: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4320: template.removeValue(set_values.iterator().next());
4321: set_values.clear();
4322:
4323: set_values = builder.generateField(template,
4324: CheckboxInListEnum.class, new ConstrainedProperty(
4325: "othercustomoptions").defaultValue("2"),
4326: new String[] { null, "1" }, null);
4327: assertEquals(1, set_values.size());
4328: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4329: .iterator().next());
4330: assertEquals(
4331: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4332: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4333: template.removeValue(set_values.iterator().next());
4334: set_values.clear();
4335:
4336: set_values = builder.generateField(template,
4337: new ConstrainedProperty("othercustomoptions").inList(
4338: null, "1", null, "3", "2"), new String[] { "1",
4339: "2" }, null);
4340: assertEquals(1, set_values.size());
4341: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4342: .iterator().next());
4343: assertEquals(
4344: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4345: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4346: template.removeValue(set_values.iterator().next());
4347: set_values.clear();
4348:
4349: set_values = builder.generateField(template,
4350: CheckboxInListEnum.class, "othercustomoptions",
4351: new String[] { "1", "2" }, null);
4352: assertEquals(1, set_values.size());
4353: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4354: .iterator().next());
4355: assertEquals(
4356: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4357: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4358: template.removeValue(set_values.iterator().next());
4359: set_values.clear();
4360:
4361: set_values = builder.generateField(template,
4362: new ConstrainedProperty("othercustomoptions").inList(
4363: null, "1", null, "3", "2").defaultValue("3"),
4364: new String[] { "1", "2" }, null);
4365: assertEquals(1, set_values.size());
4366: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4367: .iterator().next());
4368: assertEquals(
4369: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4370: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4371: template.removeValue(set_values.iterator().next());
4372: set_values.clear();
4373:
4374: set_values = builder.generateField(template,
4375: CheckboxInListEnum.class, new ConstrainedProperty(
4376: "othercustomoptions").defaultValue("3"),
4377: new String[] { "1", "2" }, null);
4378: assertEquals(1, set_values.size());
4379: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4380: .iterator().next());
4381: assertEquals(
4382: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4383: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4384: template.removeValue(set_values.iterator().next());
4385: set_values.clear();
4386:
4387: set_values = builder.generateField(template,
4388: new ConstrainedProperty("othercustomoptions").inList(
4389: null, "1", null, "3", "2"),
4390: new String[] { "a4" }, null);
4391: assertEquals(1, set_values.size());
4392: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4393: .iterator().next());
4394: assertEquals(
4395: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4396: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4397: template.removeValue(set_values.iterator().next());
4398: set_values.clear();
4399:
4400: set_values = builder.generateField(template,
4401: CheckboxInListEnum.class, "othercustomoptions",
4402: new String[] { "a4" }, null);
4403: assertEquals(1, set_values.size());
4404: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4405: .iterator().next());
4406: assertEquals(
4407: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4408: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4409: template.removeValue(set_values.iterator().next());
4410: set_values.clear();
4411:
4412: template.setValue("FORM:CHECKBOX:othercustomoptions",
4413: "already set");
4414: set_values = builder.generateField(template,
4415: new ConstrainedProperty("othercustomoptions"), null,
4416: null);
4417: assertEquals(0, set_values.size());
4418: assertEquals("already set", StringUtils.splitToArray(template
4419: .getContent(), "\n")[37]);
4420: template.removeValue("FORM:CHECKBOX:othercustomoptions");
4421: }
4422:
4423: public void testGenerateFieldCheckboxTemplatNameCustomWithoutDefault() {
4424: FormBuilderXhtml builder = new FormBuilderXhtml();
4425: Collection<String> set_values;
4426:
4427: Template template = TemplateFactory.ENGINEHTML
4428: .get("formbuilder_fields_templatename");
4429:
4430: set_values = builder.replaceField(template,
4431: "templatenameothercustomoptions", "othercustomoptions",
4432: null, null);
4433: assertEquals(1, set_values.size());
4434: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4435: set_values.iterator().next());
4436: assertEquals(
4437: "<input type=\"checkbox\" name=\"othercustomoptions\" />",
4438: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4439: template.removeValue(set_values.iterator().next());
4440: set_values.clear();
4441:
4442: set_values = builder.replaceField(template,
4443: "templatenameothercustomoptions",
4444: new ConstrainedProperty("othercustomoptions"), null,
4445: null);
4446: assertEquals(1, set_values.size());
4447: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4448: set_values.iterator().next());
4449: assertEquals(
4450: "<input type=\"checkbox\" name=\"othercustomoptions\" />",
4451: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4452: template.removeValue(set_values.iterator().next());
4453: set_values.clear();
4454:
4455: set_values = builder.replaceField(template,
4456: "templatenameothercustomoptions",
4457: new ConstrainedProperty("othercustomoptions").inList(
4458: null, "1", null, "3", "2"), null, null);
4459: assertEquals(1, set_values.size());
4460: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4461: set_values.iterator().next());
4462: assertEquals(
4463: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4464: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4465: template.removeValue(set_values.iterator().next());
4466: set_values.clear();
4467:
4468: set_values = builder.replaceField(template,
4469: "templatenameothercustomoptions",
4470: CheckboxInListEnum.class, "othercustomoptions", null,
4471: null);
4472: assertEquals(1, set_values.size());
4473: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4474: set_values.iterator().next());
4475: assertEquals(
4476: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4477: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4478: template.removeValue(set_values.iterator().next());
4479: set_values.clear();
4480:
4481: set_values = builder.replaceField(template,
4482: "templatenameothercustomoptions",
4483: new ConstrainedProperty("othercustomoptions").inList(
4484: null, "1", null, "3", "2").defaultValue("2"),
4485: new String[] { null, "1" }, null);
4486: assertEquals(1, set_values.size());
4487: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4488: set_values.iterator().next());
4489: assertEquals(
4490: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4491: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4492: template.removeValue(set_values.iterator().next());
4493: set_values.clear();
4494:
4495: set_values = builder.replaceField(template,
4496: "templatenameothercustomoptions",
4497: CheckboxInListEnum.class, new ConstrainedProperty(
4498: "othercustomoptions").defaultValue("2"),
4499: new String[] { null, "1" }, null);
4500: assertEquals(1, set_values.size());
4501: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4502: set_values.iterator().next());
4503: assertEquals(
4504: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4505: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4506: template.removeValue(set_values.iterator().next());
4507: set_values.clear();
4508:
4509: set_values = builder.replaceField(template,
4510: "templatenameothercustomoptions",
4511: new ConstrainedProperty("othercustomoptions").inList(
4512: null, "1", null, "3", "2"), new String[] { "1",
4513: "2" }, null);
4514: assertEquals(1, set_values.size());
4515: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4516: set_values.iterator().next());
4517: assertEquals(
4518: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4519: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4520: template.removeValue(set_values.iterator().next());
4521: set_values.clear();
4522:
4523: set_values = builder.replaceField(template,
4524: "templatenameothercustomoptions",
4525: CheckboxInListEnum.class, "othercustomoptions",
4526: new String[] { "1", "2" }, null);
4527: assertEquals(1, set_values.size());
4528: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4529: set_values.iterator().next());
4530: assertEquals(
4531: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4532: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4533: template.removeValue(set_values.iterator().next());
4534: set_values.clear();
4535:
4536: set_values = builder.replaceField(template,
4537: "templatenameothercustomoptions",
4538: new ConstrainedProperty("othercustomoptions").inList(
4539: null, "1", null, "3", "2").defaultValue("3"),
4540: new String[] { "1", "2" }, null);
4541: assertEquals(1, set_values.size());
4542: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4543: set_values.iterator().next());
4544: assertEquals(
4545: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4546: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4547: template.removeValue(set_values.iterator().next());
4548: set_values.clear();
4549:
4550: set_values = builder.replaceField(template,
4551: "templatenameothercustomoptions",
4552: CheckboxInListEnum.class, new ConstrainedProperty(
4553: "othercustomoptions").defaultValue("3"),
4554: new String[] { "1", "2" }, null);
4555: assertEquals(1, set_values.size());
4556: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4557: set_values.iterator().next());
4558: assertEquals(
4559: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" checked=\"checked\" />",
4560: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4561: template.removeValue(set_values.iterator().next());
4562: set_values.clear();
4563:
4564: set_values = builder.replaceField(template,
4565: "templatenameothercustomoptions",
4566: new ConstrainedProperty("othercustomoptions").inList(
4567: null, "1", null, "3", "2"),
4568: new String[] { "a4" }, null);
4569: assertEquals(1, set_values.size());
4570: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4571: set_values.iterator().next());
4572: assertEquals(
4573: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4574: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4575: template.removeValue(set_values.iterator().next());
4576: set_values.clear();
4577:
4578: set_values = builder.replaceField(template,
4579: "templatenameothercustomoptions",
4580: CheckboxInListEnum.class, "othercustomoptions",
4581: new String[] { "a4" }, null);
4582: assertEquals(1, set_values.size());
4583: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4584: set_values.iterator().next());
4585: assertEquals(
4586: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4587: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4588: template.removeValue(set_values.iterator().next());
4589: set_values.clear();
4590:
4591: template.setValue(
4592: "FORM:CHECKBOX:templatenameothercustomoptions",
4593: "already set");
4594: set_values = builder.replaceField(template,
4595: "templatenameothercustomoptions",
4596: new ConstrainedProperty("othercustomoptions"), null,
4597: null);
4598: assertEquals(1, set_values.size());
4599: assertEquals("FORM:CHECKBOX:templatenameothercustomoptions",
4600: set_values.iterator().next());
4601: assertEquals(
4602: "<input type=\"checkbox\" name=\"othercustomoptions\" />",
4603: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4604: template.removeValue(set_values.iterator().next());
4605: set_values.clear();
4606: }
4607:
4608: public void testGenerateFieldCheckboxCustomPrefix() {
4609: FormBuilderXhtml builder = new FormBuilderXhtml();
4610: Collection<String> set_values;
4611:
4612: Template template = TemplateFactory.ENGINEHTML
4613: .get("formbuilder_fields");
4614:
4615: set_values = builder.generateField(template,
4616: new ConstrainedProperty("customoptions").inList(null,
4617: "1", null, "3", "2"), null, "other");
4618: assertEquals(1, set_values.size());
4619: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4620: .iterator().next());
4621: assertEquals(
4622: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4623: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4624: template.removeValue(set_values.iterator().next());
4625: set_values.clear();
4626:
4627: set_values = builder.generateField(template,
4628: CheckboxInListEnum.class, "customoptions", null,
4629: "other");
4630: assertEquals(1, set_values.size());
4631: assertEquals("FORM:CHECKBOX:othercustomoptions", set_values
4632: .iterator().next());
4633: assertEquals(
4634: "othercustom option 1 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"1\" />3 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"3\" />othercustom option 2 : <input type=\"checkbox\" name=\"othercustomoptions\" value=\"2\" />",
4635: StringUtils.splitToArray(template.getContent(), "\n")[37]);
4636: template.removeValue(set_values.iterator().next());
4637: set_values.clear();
4638:
4639: template.setValue("FORM:CHECKBOX:othercustomoptions",
4640: "already set");
4641: set_values = builder
4642: .generateField(template, new ConstrainedProperty(
4643: "customoptions"), null, "other");
4644: assertEquals(0, set_values.size());
4645: assertEquals("already set", StringUtils.splitToArray(template
4646: .getContent(), "\n")[37]);
4647: template.removeValue("FORM:CHECKBOX:othercustomoptions");
4648: }
4649:
4650: public void testGenerateFieldCheckboxCustomDynamic() {
4651: FormBuilderXhtml builder = new FormBuilderXhtml();
4652: Collection<String> set_values;
4653:
4654: Template template = TemplateFactory.ENGINEHTML
4655: .get("formbuilder_fields");
4656:
4657: template.addResourceBundle(new ListResourceBundle() {
4658: public Object[][] getContents() {
4659: return new Object[][] {
4660: { "customoptions:1", "dynamic first" },
4661: { "customoptions:2", "dynamic second" },
4662: { "customoptions:3", "dynamic third" } };
4663: }
4664: });
4665:
4666: set_values = builder.generateField(template,
4667: new ConstrainedProperty("customoptions").inList("1",
4668: "3", "2").defaultValue("2"), null, null);
4669: assertEquals(1, set_values.size());
4670: assertEquals("FORM:CHECKBOX:customoptions", set_values
4671: .iterator().next());
4672: assertEquals(
4673: "dynamic first : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" />dynamic third : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />dynamic second : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" checked=\"checked\" />",
4674: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4675: template.removeValue(set_values.iterator().next());
4676: set_values.clear();
4677:
4678: set_values = builder.generateField(template,
4679: CheckboxInListEnum.class, new ConstrainedProperty(
4680: "customoptions").defaultValue("2"), null, null);
4681: assertEquals(1, set_values.size());
4682: assertEquals("FORM:CHECKBOX:customoptions", set_values
4683: .iterator().next());
4684: assertEquals(
4685: "dynamic first : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" />dynamic third : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />dynamic second : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" checked=\"checked\" />",
4686: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4687: template.removeValue(set_values.iterator().next());
4688: set_values.clear();
4689:
4690: set_values = builder.generateField(template,
4691: new ConstrainedProperty("customoptions").inList("1",
4692: "3", "2").defaultValue("2"),
4693: new String[] { "1" }, null);
4694: assertEquals(1, set_values.size());
4695: assertEquals("FORM:CHECKBOX:customoptions", set_values
4696: .iterator().next());
4697: assertEquals(
4698: "dynamic first : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />dynamic third : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />dynamic second : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4699: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4700: template.removeValue(set_values.iterator().next());
4701: set_values.clear();
4702:
4703: set_values = builder.generateField(template,
4704: CheckboxInListEnum.class, new ConstrainedProperty(
4705: "customoptions").defaultValue("2"),
4706: new String[] { "1" }, null);
4707: assertEquals(1, set_values.size());
4708: assertEquals("FORM:CHECKBOX:customoptions", set_values
4709: .iterator().next());
4710: assertEquals(
4711: "dynamic first : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />dynamic third : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />dynamic second : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4712: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4713: template.removeValue(set_values.iterator().next());
4714: set_values.clear();
4715:
4716: template.clear();
4717:
4718: template.addResourceBundle(new ListResourceBundle() {
4719: public Object[][] getContents() {
4720: return new Object[][] { { "customoptions:2",
4721: "dynamic second" }, };
4722: }
4723: });
4724:
4725: set_values = builder.generateField(template,
4726: new ConstrainedProperty("customoptions").inList("1",
4727: "3", "2").defaultValue("2"),
4728: new String[] { "1" }, null);
4729: assertEquals(1, set_values.size());
4730: assertEquals("FORM:CHECKBOX:customoptions", set_values
4731: .iterator().next());
4732: assertEquals(
4733: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />dynamic second : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4734: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4735: template.removeValue(set_values.iterator().next());
4736: set_values.clear();
4737:
4738: set_values = builder.generateField(template,
4739: CheckboxInListEnum.class, new ConstrainedProperty(
4740: "customoptions").defaultValue("2"),
4741: new String[] { "1" }, null);
4742: assertEquals(1, set_values.size());
4743: assertEquals("FORM:CHECKBOX:customoptions", set_values
4744: .iterator().next());
4745: assertEquals(
4746: "custom option 1 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"1\" checked=\"checked\" />3 : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"3\" />dynamic second : <input type=\"checkbox\" name=\"customoptions\" alt=\"customblurp\" value=\"2\" />",
4747: StringUtils.splitToArray(template.getContent(), "\n")[32]);
4748: template.removeValue(set_values.iterator().next());
4749: set_values.clear();
4750: }
4751:
4752: public void testGenerateFieldCheckboxEmptyCustomWithDefault() {
4753: FormBuilderXhtml builder = new FormBuilderXhtml();
4754: Collection<String> set_values;
4755:
4756: Template template = TemplateFactory.ENGINEHTML
4757: .get("formbuilder_fields_emptycustom");
4758:
4759: set_values = builder.generateField(template,
4760: "emptycustomoptions", null, null);
4761: assertEquals(1, set_values.size());
4762: assertEquals("FORM:CHECKBOX:emptycustomoptions", set_values
4763: .iterator().next());
4764: assertEquals(
4765: "<input type=\"checkbox\" name=\"emptycustomoptions\" alt=\"emptycustomblurp\" />",
4766: StringUtils.splitToArray(template.getContent(), "\n")[4]);
4767: template.removeValue(set_values.iterator().next());
4768: set_values.clear();
4769:
4770: set_values = builder.generateField(template,
4771: new ConstrainedProperty("emptycustomoptions"), null,
4772: null);
4773: assertEquals(1, set_values.size());
4774: assertEquals("FORM:CHECKBOX:emptycustomoptions", set_values
4775: .iterator().next());
4776: assertEquals(
4777: "<input type=\"checkbox\" name=\"emptycustomoptions\" alt=\"emptycustomblurp\" />",
4778: StringUtils.splitToArray(template.getContent(), "\n")[4]);
4779: template.removeValue(set_values.iterator().next());
4780: set_values.clear();
4781:
4782: set_values = builder.generateField(template,
4783: new ConstrainedProperty("emptycustomoptions").inList(
4784: null, "1", null, "3", "2"), null, null);
4785: assertEquals(1, set_values.size());
4786: assertEquals("FORM:CHECKBOX:emptycustomoptions", set_values
4787: .iterator().next());
4788: assertEquals(" - - - ", StringUtils.splitToArray(template
4789: .getContent(), "\n")[4]);
4790: template.removeValue(set_values.iterator().next());
4791: set_values.clear();
4792:
4793: set_values = builder.generateField(template,
4794: CheckboxInListEnum.class, "emptycustomoptions", null,
4795: null);
4796: assertEquals(1, set_values.size());
4797: assertEquals("FORM:CHECKBOX:emptycustomoptions", set_values
4798: .iterator().next());
4799: assertEquals(" - - - ", StringUtils.splitToArray(template
4800: .getContent(), "\n")[4]);
4801: template.removeValue(set_values.iterator().next());
4802: set_values.clear();
4803:
4804: template.setValue("FORM:CHECKBOX:emptycustomoptions",
4805: "already set");
4806: set_values = builder.generateField(template,
4807: new ConstrainedProperty("emptycustomoptions"), null,
4808: null);
4809: assertEquals(0, set_values.size());
4810: assertEquals("already set", StringUtils.splitToArray(template
4811: .getContent(), "\n")[4]);
4812: template.removeValue("FORM:CHECKBOX:emptycustomoptions");
4813: }
4814:
4815: public void testGenerateFieldCheckboxEmptyCustomWithoutDefault() {
4816: FormBuilderXhtml builder = new FormBuilderXhtml();
4817: Collection<String> set_values;
4818:
4819: Template template = TemplateFactory.ENGINEHTML
4820: .get("formbuilder_fields_emptycustom");
4821:
4822: set_values = builder.generateField(template,
4823: "otheremptycustomoptions", null, null);
4824: assertEquals(1, set_values.size());
4825: assertEquals("FORM:CHECKBOX:otheremptycustomoptions",
4826: set_values.iterator().next());
4827: assertEquals(
4828: "<input type=\"checkbox\" name=\"otheremptycustomoptions\" />",
4829: StringUtils.splitToArray(template.getContent(), "\n")[6]);
4830: template.removeValue(set_values.iterator().next());
4831: set_values.clear();
4832:
4833: set_values = builder.generateField(template,
4834: new ConstrainedProperty("otheremptycustomoptions"),
4835: null, null);
4836: assertEquals(1, set_values.size());
4837: assertEquals("FORM:CHECKBOX:otheremptycustomoptions",
4838: set_values.iterator().next());
4839: assertEquals(
4840: "<input type=\"checkbox\" name=\"otheremptycustomoptions\" />",
4841: StringUtils.splitToArray(template.getContent(), "\n")[6]);
4842: template.removeValue(set_values.iterator().next());
4843: set_values.clear();
4844:
4845: set_values = builder.generateField(template,
4846: new ConstrainedProperty("otheremptycustomoptions")
4847: .inList(null, "1", null, "3", "2"), null, null);
4848: assertEquals(1, set_values.size());
4849: assertEquals("FORM:CHECKBOX:otheremptycustomoptions",
4850: set_values.iterator().next());
4851: assertEquals(" - - - ", StringUtils.splitToArray(template
4852: .getContent(), "\n")[6]);
4853: template.removeValue(set_values.iterator().next());
4854: set_values.clear();
4855:
4856: set_values = builder.generateField(template,
4857: CheckboxInListEnum.class, "otheremptycustomoptions",
4858: null, null);
4859: assertEquals(1, set_values.size());
4860: assertEquals("FORM:CHECKBOX:otheremptycustomoptions",
4861: set_values.iterator().next());
4862: assertEquals(" - - - ", StringUtils.splitToArray(template
4863: .getContent(), "\n")[6]);
4864: template.removeValue(set_values.iterator().next());
4865: set_values.clear();
4866:
4867: template.setValue("FORM:CHECKBOX:otheremptycustomoptions",
4868: "already set");
4869: set_values = builder.generateField(template,
4870: new ConstrainedProperty("otheremptycustomoptions"),
4871: null, null);
4872: assertEquals(0, set_values.size());
4873: assertEquals("already set", StringUtils.splitToArray(template
4874: .getContent(), "\n")[6]);
4875: template.removeValue("FORM:CHECKBOX:otheremptycustomoptions");
4876: }
4877:
4878: public void testGenerateFieldCheckboxEmptyCustomPrefix() {
4879: FormBuilderXhtml builder = new FormBuilderXhtml();
4880: Collection<String> set_values;
4881:
4882: Template template = TemplateFactory.ENGINEHTML
4883: .get("formbuilder_fields_emptycustom");
4884:
4885: set_values = builder.generateField(template,
4886: "emptycustomoptions", null, "other");
4887: assertEquals(1, set_values.size());
4888: assertEquals("FORM:CHECKBOX:otheremptycustomoptions",
4889: set_values.iterator().next());
4890: assertEquals(
4891: "<input type=\"checkbox\" name=\"otheremptycustomoptions\" />",
4892: StringUtils.splitToArray(template.getContent(), "\n")[6]);
4893: template.removeValue(set_values.iterator().next());
4894: set_values.clear();
4895:
4896: set_values = builder.generateField(template,
4897: new ConstrainedProperty("emptycustomoptions").inList(
4898: null, "1", null, "3", "2"), null, "other");
4899: assertEquals(1, set_values.size());
4900: assertEquals("FORM:CHECKBOX:otheremptycustomoptions",
4901: set_values.iterator().next());
4902: assertEquals(" - - - ", StringUtils.splitToArray(template
4903: .getContent(), "\n")[6]);
4904: template.removeValue(set_values.iterator().next());
4905: set_values.clear();
4906:
4907: set_values = builder.generateField(template,
4908: CheckboxInListEnum.class, "emptycustomoptions", null,
4909: "other");
4910: assertEquals(1, set_values.size());
4911: assertEquals("FORM:CHECKBOX:otheremptycustomoptions",
4912: set_values.iterator().next());
4913: assertEquals(" - - - ", StringUtils.splitToArray(template
4914: .getContent(), "\n")[6]);
4915: template.removeValue(set_values.iterator().next());
4916: set_values.clear();
4917:
4918: template.setValue("FORM:CHECKBOX:otheremptycustomoptions",
4919: "already set");
4920: set_values = builder.generateField(template,
4921: new ConstrainedProperty("emptycustomoptions"), null,
4922: "other");
4923: assertEquals(0, set_values.size());
4924: assertEquals("already set", StringUtils.splitToArray(template
4925: .getContent(), "\n")[6]);
4926: template.removeValue("FORM:CHECKBOX:otheremptycustomoptions");
4927: }
4928:
4929: public void testGenerateFieldCheckboxBooleanWithDefault() {
4930: FormBuilderXhtml builder = new FormBuilderXhtml();
4931: Collection<String> set_values;
4932:
4933: Template template = TemplateFactory.ENGINEHTML
4934: .get("formbuilder_fields");
4935:
4936: set_values = builder.generateField(template, "invoice", null,
4937: null);
4938: assertEquals(1, set_values.size());
4939: assertEquals("FORM:CHECKBOX:invoice", set_values.iterator()
4940: .next());
4941: assertEquals(
4942: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
4943: StringUtils.splitToArray(template.getContent(), "\n")[42]);
4944: template.removeValue(set_values.iterator().next());
4945: set_values.clear();
4946:
4947: set_values = builder.generateField(template,
4948: new ConstrainedProperty("invoice"), null, null);
4949: assertEquals(1, set_values.size());
4950: assertEquals("FORM:CHECKBOX:invoice", set_values.iterator()
4951: .next());
4952: assertEquals(
4953: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
4954: StringUtils.splitToArray(template.getContent(), "\n")[42]);
4955: template.removeValue(set_values.iterator().next());
4956: set_values.clear();
4957:
4958: set_values = builder.generateField(template,
4959: new ConstrainedProperty("invoice").defaultValue(true),
4960: null, null);
4961: assertEquals(1, set_values.size());
4962: assertEquals("FORM:CHECKBOX:invoice", set_values.iterator()
4963: .next());
4964: assertEquals(
4965: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" checked=\"checked\" />I want an invoice",
4966: StringUtils.splitToArray(template.getContent(), "\n")[42]);
4967: template.removeValue(set_values.iterator().next());
4968: set_values.clear();
4969:
4970: set_values = builder.generateField(template,
4971: new ConstrainedProperty("invoice")
4972: .defaultValue("false"),
4973: new String[] { "true" }, null);
4974: assertEquals(1, set_values.size());
4975: assertEquals("FORM:CHECKBOX:invoice", set_values.iterator()
4976: .next());
4977: assertEquals(
4978: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" checked=\"checked\" />I want an invoice",
4979: StringUtils.splitToArray(template.getContent(), "\n")[42]);
4980: template.removeValue(set_values.iterator().next());
4981: set_values.clear();
4982:
4983: set_values = builder
4984: .generateField(template, new ConstrainedProperty(
4985: "invoice").defaultValue("flam"), null, null);
4986: assertEquals(1, set_values.size());
4987: assertEquals("FORM:CHECKBOX:invoice", set_values.iterator()
4988: .next());
4989: assertEquals(
4990: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
4991: StringUtils.splitToArray(template.getContent(), "\n")[42]);
4992: template.removeValue(set_values.iterator().next());
4993: set_values.clear();
4994:
4995: set_values = builder.generateField(template,
4996: new ConstrainedProperty("invoice")
4997: .defaultValue("false"),
4998: new String[] { "flum" }, null);
4999: assertEquals(1, set_values.size());
5000: assertEquals("FORM:CHECKBOX:invoice", set_values.iterator()
5001: .next());
5002: assertEquals(
5003: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
5004: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5005: template.removeValue(set_values.iterator().next());
5006: set_values.clear();
5007:
5008: template.setValue("FORM:CHECKBOX:invoice", "set : ");
5009: set_values = builder.generateField(template,
5010: new ConstrainedProperty("invoice"), null, null);
5011: assertEquals(0, set_values.size());
5012: assertEquals("set : I want an invoice", StringUtils
5013: .splitToArray(template.getContent(), "\n")[42]);
5014: template.removeValue("FORM:CHECKBOX:invoice");
5015: }
5016:
5017: public void testGenerateFieldCheckboxBooleanWithoutDefault() {
5018: FormBuilderXhtml builder = new FormBuilderXhtml();
5019: Collection<String> set_values;
5020:
5021: Template template = TemplateFactory.ENGINEHTML
5022: .get("formbuilder_fields");
5023:
5024: set_values = builder.generateField(template, "onemoreinvoice",
5025: null, null);
5026: assertEquals(1, set_values.size());
5027: assertEquals("FORM:CHECKBOX:onemoreinvoice", set_values
5028: .iterator().next());
5029: assertEquals(
5030: "<input type=\"checkbox\" name=\"onemoreinvoice\" />I want one more invoice",
5031: StringUtils.splitToArray(template.getContent(), "\n")[43]);
5032: template.removeValue(set_values.iterator().next());
5033: set_values.clear();
5034:
5035: set_values = builder.generateField(template,
5036: new ConstrainedProperty("onemoreinvoice"), null, null);
5037: assertEquals(1, set_values.size());
5038: assertEquals("FORM:CHECKBOX:onemoreinvoice", set_values
5039: .iterator().next());
5040: assertEquals(
5041: "<input type=\"checkbox\" name=\"onemoreinvoice\" />I want one more invoice",
5042: StringUtils.splitToArray(template.getContent(), "\n")[43]);
5043: template.removeValue(set_values.iterator().next());
5044: set_values.clear();
5045:
5046: set_values = builder.generateField(template,
5047: new ConstrainedProperty("onemoreinvoice")
5048: .defaultValue("false"),
5049: new String[] { "true" }, null);
5050: assertEquals(1, set_values.size());
5051: assertEquals("FORM:CHECKBOX:onemoreinvoice", set_values
5052: .iterator().next());
5053: assertEquals(
5054: "<input type=\"checkbox\" name=\"onemoreinvoice\" checked=\"checked\" />I want one more invoice",
5055: StringUtils.splitToArray(template.getContent(), "\n")[43]);
5056: template.removeValue(set_values.iterator().next());
5057: set_values.clear();
5058:
5059: template.setValue("FORM:CHECKBOX:onemoreinvoice", "set : ");
5060: set_values = builder.generateField(template,
5061: new ConstrainedProperty("onemoreinvoice"), null, null);
5062: assertEquals(0, set_values.size());
5063: assertEquals("set : I want one more invoice", StringUtils
5064: .splitToArray(template.getContent(), "\n")[43]);
5065: template.removeValue("FORM:CHECKBOX:onemoreinvoice");
5066: }
5067:
5068: public void testGenerateFieldCheckboxTemplateNameBooleanWithDefault() {
5069: FormBuilderXhtml builder = new FormBuilderXhtml();
5070: Collection<String> set_values;
5071:
5072: Template template = TemplateFactory.ENGINEHTML
5073: .get("formbuilder_fields_templatename");
5074:
5075: set_values = builder.replaceField(template,
5076: "templatenameinvoice", "invoice", null, null);
5077: assertEquals(1, set_values.size());
5078: assertEquals("FORM:CHECKBOX:templatenameinvoice", set_values
5079: .iterator().next());
5080: assertEquals(
5081: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
5082: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5083: template.removeValue(set_values.iterator().next());
5084: set_values.clear();
5085:
5086: set_values = builder.replaceField(template,
5087: "templatenameinvoice", new ConstrainedProperty(
5088: "invoice"), null, null);
5089: assertEquals(1, set_values.size());
5090: assertEquals("FORM:CHECKBOX:templatenameinvoice", set_values
5091: .iterator().next());
5092: assertEquals(
5093: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
5094: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5095: template.removeValue(set_values.iterator().next());
5096: set_values.clear();
5097:
5098: set_values = builder.replaceField(template,
5099: "templatenameinvoice", new ConstrainedProperty(
5100: "invoice").defaultValue(true), null, null);
5101: assertEquals(1, set_values.size());
5102: assertEquals("FORM:CHECKBOX:templatenameinvoice", set_values
5103: .iterator().next());
5104: assertEquals(
5105: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" checked=\"checked\" />I want an invoice",
5106: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5107: template.removeValue(set_values.iterator().next());
5108: set_values.clear();
5109:
5110: set_values = builder.replaceField(template,
5111: "templatenameinvoice", new ConstrainedProperty(
5112: "invoice").defaultValue("false"),
5113: new String[] { "true" }, null);
5114: assertEquals(1, set_values.size());
5115: assertEquals("FORM:CHECKBOX:templatenameinvoice", set_values
5116: .iterator().next());
5117: assertEquals(
5118: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" checked=\"checked\" />I want an invoice",
5119: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5120: template.removeValue(set_values.iterator().next());
5121: set_values.clear();
5122:
5123: set_values = builder.replaceField(template,
5124: "templatenameinvoice", new ConstrainedProperty(
5125: "invoice").defaultValue("flam"), null, null);
5126: assertEquals(1, set_values.size());
5127: assertEquals("FORM:CHECKBOX:templatenameinvoice", set_values
5128: .iterator().next());
5129: assertEquals(
5130: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
5131: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5132: template.removeValue(set_values.iterator().next());
5133: set_values.clear();
5134:
5135: set_values = builder.replaceField(template,
5136: "templatenameinvoice", new ConstrainedProperty(
5137: "invoice").defaultValue("false"),
5138: new String[] { "flum" }, null);
5139: assertEquals(1, set_values.size());
5140: assertEquals("FORM:CHECKBOX:templatenameinvoice", set_values
5141: .iterator().next());
5142: assertEquals(
5143: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
5144: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5145: template.removeValue(set_values.iterator().next());
5146: set_values.clear();
5147:
5148: template
5149: .setValue("FORM:CHECKBOX:templatenameinvoice", "set : ");
5150: set_values = builder.replaceField(template,
5151: "templatenameinvoice", new ConstrainedProperty(
5152: "invoice"), null, null);
5153: assertEquals(1, set_values.size());
5154: assertEquals("FORM:CHECKBOX:templatenameinvoice", set_values
5155: .iterator().next());
5156: assertEquals(
5157: "<input type=\"checkbox\" name=\"invoice\" alt=\"atext\" />I want an invoice",
5158: StringUtils.splitToArray(template.getContent(), "\n")[42]);
5159: template.removeValue(set_values.iterator().next());
5160: set_values.clear();
5161: }
5162:
5163: public void testGenerateFieldCheckboxBooleanPrefix() {
5164: FormBuilderXhtml builder = new FormBuilderXhtml();
5165: Collection<String> set_values;
5166:
5167: Template template = TemplateFactory.ENGINEHTML
5168: .get("formbuilder_fields");
5169:
5170: set_values = builder.generateField(template, "invoice", null,
5171: "onemore");
5172: assertEquals(1, set_values.size());
5173: assertEquals("FORM:CHECKBOX:onemoreinvoice", set_values
5174: .iterator().next());
5175: assertEquals(
5176: "<input type=\"checkbox\" name=\"onemoreinvoice\" />I want one more invoice",
5177: StringUtils.splitToArray(template.getContent(), "\n")[43]);
5178: template.removeValue(set_values.iterator().next());
5179: set_values.clear();
5180:
5181: set_values = builder.generateField(template,
5182: new ConstrainedProperty("invoice"), null, "onemore");
5183: assertEquals(1, set_values.size());
5184: assertEquals("FORM:CHECKBOX:onemoreinvoice", set_values
5185: .iterator().next());
5186: assertEquals(
5187: "<input type=\"checkbox\" name=\"onemoreinvoice\" />I want one more invoice",
5188: StringUtils.splitToArray(template.getContent(), "\n")[43]);
5189: template.removeValue(set_values.iterator().next());
5190: set_values.clear();
5191:
5192: set_values = builder.generateField(template,
5193: new ConstrainedProperty("invoice")
5194: .defaultValue("false"),
5195: new String[] { "true" }, "onemore");
5196: assertEquals(1, set_values.size());
5197: assertEquals("FORM:CHECKBOX:onemoreinvoice", set_values
5198: .iterator().next());
5199: assertEquals(
5200: "<input type=\"checkbox\" name=\"onemoreinvoice\" checked=\"checked\" />I want one more invoice",
5201: StringUtils.splitToArray(template.getContent(), "\n")[43]);
5202: template.removeValue(set_values.iterator().next());
5203: set_values.clear();
5204:
5205: template.setValue("FORM:CHECKBOX:onemoreinvoice", "set : ");
5206: set_values = builder.generateField(template,
5207: new ConstrainedProperty("invoice"), null, "onemore");
5208: assertEquals(0, set_values.size());
5209: assertEquals("set : I want one more invoice", StringUtils
5210: .splitToArray(template.getContent(), "\n")[43]);
5211: template.removeValue("FORM:CHECKBOX:onemoreinvoice");
5212: }
5213:
5214: public void testRemoveFieldCheckbox() {
5215: FormBuilderXhtml builder = new FormBuilderXhtml();
5216:
5217: Template template = TemplateFactory.ENGINEHTML
5218: .get("formbuilder_fields");
5219:
5220: String raw_content = template.getContent();
5221:
5222: builder.generateField(template, new ConstrainedProperty(
5223: "options").inList(null, "1", null, "3", "2"),
5224: new String[] { "a4" }, null);
5225: assertFalse(raw_content.equals(template.getContent()));
5226: builder.removeField(template, "options", null);
5227: assertEquals(raw_content, template.getContent());
5228:
5229: builder.generateField(template, CheckboxInListEnum.class,
5230: "options", new String[] { "a4" }, null);
5231: assertFalse(raw_content.equals(template.getContent()));
5232: builder.removeField(template, "options", null);
5233: assertEquals(raw_content, template.getContent());
5234: }
5235:
5236: public void testRemoveFieldCheckboxTemplateName() {
5237: FormBuilderXhtml builder = new FormBuilderXhtml();
5238:
5239: Template template = TemplateFactory.ENGINEHTML
5240: .get("formbuilder_fields_templatename");
5241:
5242: String raw_content = template.getContent();
5243:
5244: builder.replaceField(template, "templatenameoptions",
5245: new ConstrainedProperty("options").inList(null, "1",
5246: null, "3", "2"), new String[] { "a4" }, null);
5247: assertFalse(raw_content.equals(template.getContent()));
5248: builder.removeField(template, "templatenameoptions");
5249: assertEquals(raw_content, template.getContent());
5250:
5251: builder.replaceField(template, "templatenameoptions",
5252: CheckboxInListEnum.class, "options",
5253: new String[] { "a4" }, null);
5254: assertFalse(raw_content.equals(template.getContent()));
5255: builder.removeField(template, "templatenameoptions");
5256: assertEquals(raw_content, template.getContent());
5257: }
5258:
5259: public void testRemoveFieldCheckboxPrefix() {
5260: FormBuilderXhtml builder = new FormBuilderXhtml();
5261:
5262: Template template = TemplateFactory.ENGINEHTML
5263: .get("formbuilder_fields");
5264:
5265: String raw_content = template.getContent();
5266:
5267: builder.generateField(template, new ConstrainedProperty(
5268: "options").inList(null, "1", null, "3", "2"),
5269: new String[] { "a4" }, "other");
5270: assertFalse(raw_content.equals(template.getContent()));
5271: builder.removeField(template, "options", "other");
5272: assertEquals(raw_content, template.getContent());
5273:
5274: builder.generateField(template, CheckboxInListEnum.class,
5275: "options", new String[] { "a4" }, "other");
5276: assertFalse(raw_content.equals(template.getContent()));
5277: builder.removeField(template, "options", "other");
5278: assertEquals(raw_content, template.getContent());
5279: }
5280:
5281: public void testGenerateFieldSelectWithDefault() {
5282: FormBuilderXhtml builder = new FormBuilderXhtml();
5283: Collection<String> set_values;
5284: Iterator<String> set_values_it;
5285:
5286: Template template = TemplateFactory.ENGINEHTML
5287: .get("formbuilder_fields");
5288:
5289: set_values = builder.generateField(template, "colors", null,
5290: null);
5291: set_values_it = set_values.iterator();
5292: assertEquals(2, set_values.size());
5293: assertEquals("FORM:SELECT:colors", set_values_it.next());
5294: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5295: assertEquals("<select name=\"colors\"></select>", StringUtils
5296: .splitToArray(template.getContent(), "\n")[44]);
5297: assertEquals("<div></div>", StringUtils.splitToArray(template
5298: .getContent(), "\n")[58]);
5299: set_values_it = set_values.iterator();
5300: template.removeValue(set_values_it.next());
5301: template.removeValue(set_values_it.next());
5302: set_values.clear();
5303:
5304: set_values = builder.generateField(template,
5305: new ConstrainedProperty("colors"), null, null);
5306: set_values_it = set_values.iterator();
5307: assertEquals(2, set_values.size());
5308: assertEquals("FORM:SELECT:colors", set_values_it.next());
5309: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5310: assertEquals("<select name=\"colors\"></select>", StringUtils
5311: .splitToArray(template.getContent(), "\n")[44]);
5312: assertEquals("<div></div>", StringUtils.splitToArray(template
5313: .getContent(), "\n")[58]);
5314: set_values_it = set_values.iterator();
5315: template.removeValue(set_values_it.next());
5316: template.removeValue(set_values_it.next());
5317: set_values.clear();
5318:
5319: set_values = builder.generateField(template,
5320: RadioInListEnum.class,
5321: new ConstrainedProperty("colors").inList("black",
5322: "red", null, "green", "blue"), null, null);
5323: set_values_it = set_values.iterator();
5324: assertEquals(2, set_values.size());
5325: assertEquals("FORM:SELECT:colors", set_values_it.next());
5326: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5327: assertEquals(
5328: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5329: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5330: assertEquals("<div></div>", StringUtils.splitToArray(template
5331: .getContent(), "\n")[58]);
5332: set_values_it = set_values.iterator();
5333: template.removeValue(set_values_it.next());
5334: template.removeValue(set_values_it.next());
5335: set_values.clear();
5336:
5337: set_values = builder.generateField(template,
5338: new ConstrainedProperty("colors").inList("black",
5339: "red", null, "green", "blue"), null, null);
5340: set_values_it = set_values.iterator();
5341: assertEquals(2, set_values.size());
5342: assertEquals("FORM:SELECT:colors", set_values_it.next());
5343: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5344: assertEquals(
5345: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5346: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5347: assertEquals("<div></div>", StringUtils.splitToArray(template
5348: .getContent(), "\n")[58]);
5349: set_values_it = set_values.iterator();
5350: template.removeValue(set_values_it.next());
5351: template.removeValue(set_values_it.next());
5352: set_values.clear();
5353:
5354: set_values = builder.generateField(template,
5355: SelectInListEnum.class, "colors", null, null);
5356: set_values_it = set_values.iterator();
5357: assertEquals(2, set_values.size());
5358: assertEquals("FORM:SELECT:colors", set_values_it.next());
5359: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5360: assertEquals(
5361: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5362: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5363: assertEquals("<div></div>", StringUtils.splitToArray(template
5364: .getContent(), "\n")[58]);
5365: set_values_it = set_values.iterator();
5366: template.removeValue(set_values_it.next());
5367: template.removeValue(set_values_it.next());
5368: set_values.clear();
5369:
5370: set_values = builder.generateField(template,
5371: new ConstrainedProperty("colors").inList("black",
5372: "red", null, "green", "blue").defaultValue(
5373: "green"), null, null);
5374: set_values_it = set_values.iterator();
5375: assertEquals(2, set_values.size());
5376: assertEquals("FORM:SELECT:colors", set_values_it.next());
5377: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5378: assertEquals(
5379: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\" selected=\"selected\">green spots</option><option value=\"blue\">blue spots</option></select>",
5380: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5381: assertEquals("<div>green spots</div>", StringUtils
5382: .splitToArray(template.getContent(), "\n")[58]);
5383: set_values_it = set_values.iterator();
5384: template.removeValue(set_values_it.next());
5385: template.removeValue(set_values_it.next());
5386: set_values.clear();
5387:
5388: set_values = builder.generateField(template,
5389: SelectInListEnum.class, new ConstrainedProperty(
5390: "colors").defaultValue("green"), null, null);
5391: set_values_it = set_values.iterator();
5392: assertEquals(2, set_values.size());
5393: assertEquals("FORM:SELECT:colors", set_values_it.next());
5394: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5395: assertEquals(
5396: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\" selected=\"selected\">green spots</option><option value=\"blue\">blue spots</option></select>",
5397: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5398: assertEquals("<div>green spots</div>", StringUtils
5399: .splitToArray(template.getContent(), "\n")[58]);
5400: set_values_it = set_values.iterator();
5401: template.removeValue(set_values_it.next());
5402: template.removeValue(set_values_it.next());
5403: set_values.clear();
5404:
5405: set_values = builder.generateField(template,
5406: new ConstrainedProperty("colors").inList("black",
5407: "red", null, "green", "blue").defaultValue(
5408: "green"), new String[] { null, "red" }, null);
5409: set_values_it = set_values.iterator();
5410: assertEquals(2, set_values.size());
5411: assertEquals("FORM:SELECT:colors", set_values_it.next());
5412: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5413: assertEquals(
5414: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5415: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5416: assertEquals(
5417: "<div>green spots</div><div>red spots</div>",
5418: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5419: set_values_it = set_values.iterator();
5420: template.removeValue(set_values_it.next());
5421: template.removeValue(set_values_it.next());
5422: set_values.clear();
5423:
5424: set_values = builder.generateField(template,
5425: SelectInListEnum.class, new ConstrainedProperty(
5426: "colors").defaultValue("green"), new String[] {
5427: null, "red" }, null);
5428: set_values_it = set_values.iterator();
5429: assertEquals(2, set_values.size());
5430: assertEquals("FORM:SELECT:colors", set_values_it.next());
5431: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5432: assertEquals(
5433: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5434: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5435: assertEquals(
5436: "<div>green spots</div><div>red spots</div>",
5437: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5438: set_values_it = set_values.iterator();
5439: template.removeValue(set_values_it.next());
5440: template.removeValue(set_values_it.next());
5441: set_values.clear();
5442:
5443: set_values = builder.generateField(template,
5444: new ConstrainedProperty("colors").inList("black",
5445: "red", null, "green", "blue"), new String[] {
5446: "red", "blue" }, null);
5447: set_values_it = set_values.iterator();
5448: assertEquals(2, set_values.size());
5449: assertEquals("FORM:SELECT:colors", set_values_it.next());
5450: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5451: assertEquals(
5452: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\" selected=\"selected\">blue spots</option></select>",
5453: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5454: assertEquals(
5455: "<div>red spots</div><div>blue spots</div>",
5456: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5457: set_values_it = set_values.iterator();
5458: template.removeValue(set_values_it.next());
5459: template.removeValue(set_values_it.next());
5460: set_values.clear();
5461:
5462: set_values = builder.generateField(template,
5463: SelectInListEnum.class, "colors", new String[] { "red",
5464: "blue" }, null);
5465: set_values_it = set_values.iterator();
5466: assertEquals(2, set_values.size());
5467: assertEquals("FORM:SELECT:colors", set_values_it.next());
5468: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5469: assertEquals(
5470: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\" selected=\"selected\">blue spots</option></select>",
5471: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5472: assertEquals(
5473: "<div>red spots</div><div>blue spots</div>",
5474: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5475: set_values_it = set_values.iterator();
5476: template.removeValue(set_values_it.next());
5477: template.removeValue(set_values_it.next());
5478: set_values.clear();
5479:
5480: set_values = builder
5481: .generateField(template, new ConstrainedProperty(
5482: "colors").inList("black", "red", null, "green",
5483: "blue").defaultValue("green"), new String[] {
5484: "black", "red" }, null);
5485: set_values_it = set_values.iterator();
5486: assertEquals(2, set_values.size());
5487: assertEquals("FORM:SELECT:colors", set_values_it.next());
5488: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5489: assertEquals(
5490: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5491: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5492: assertEquals(
5493: "<div>black</div><div>red spots</div>",
5494: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5495: set_values_it = set_values.iterator();
5496: template.removeValue(set_values_it.next());
5497: template.removeValue(set_values_it.next());
5498: set_values.clear();
5499:
5500: set_values = builder.generateField(template,
5501: SelectInListEnum.class, new ConstrainedProperty(
5502: "colors").defaultValue("green"), new String[] {
5503: "black", "red" }, null);
5504: set_values_it = set_values.iterator();
5505: assertEquals(2, set_values.size());
5506: assertEquals("FORM:SELECT:colors", set_values_it.next());
5507: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5508: assertEquals(
5509: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5510: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5511: assertEquals(
5512: "<div>black</div><div>red spots</div>",
5513: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5514: set_values_it = set_values.iterator();
5515: template.removeValue(set_values_it.next());
5516: template.removeValue(set_values_it.next());
5517: set_values.clear();
5518:
5519: set_values = builder.generateField(template,
5520: new ConstrainedProperty("colors").inList("black",
5521: "red", null, "green", "blue"),
5522: new String[] { "orange" }, null);
5523: set_values_it = set_values.iterator();
5524: assertEquals(2, set_values.size());
5525: assertEquals("FORM:SELECT:colors", set_values_it.next());
5526: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5527: assertEquals(
5528: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5529: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5530: assertEquals("<div>orange</div>", StringUtils.splitToArray(
5531: template.getContent(), "\n")[58]);
5532: set_values_it = set_values.iterator();
5533: template.removeValue(set_values_it.next());
5534: template.removeValue(set_values_it.next());
5535: set_values.clear();
5536:
5537: set_values = builder.generateField(template,
5538: SelectInListEnum.class, "colors",
5539: new String[] { "orange" }, null);
5540: set_values_it = set_values.iterator();
5541: assertEquals(2, set_values.size());
5542: assertEquals("FORM:SELECT:colors", set_values_it.next());
5543: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5544: assertEquals(
5545: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5546: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5547: assertEquals("<div>orange</div>", StringUtils.splitToArray(
5548: template.getContent(), "\n")[58]);
5549: set_values_it = set_values.iterator();
5550: template.removeValue(set_values_it.next());
5551: template.removeValue(set_values_it.next());
5552: set_values.clear();
5553:
5554: template.setValue("FORM:SELECT:colors", "already set");
5555: template.setValue("FORM:DISPLAY:colors", "already set too");
5556: set_values = builder.generateField(template,
5557: new ConstrainedProperty("colors"), null, null);
5558: assertEquals(0, set_values.size());
5559: assertEquals("already set", StringUtils.splitToArray(template
5560: .getContent(), "\n")[44]);
5561: assertEquals("already set too", StringUtils.splitToArray(
5562: template.getContent(), "\n")[58]);
5563: template.removeValue("FORM:SELECT:colors");
5564: template.removeValue("FORM:DISPLAY:colors");
5565: }
5566:
5567: public void testGenerateFieldSelectWithoutDefault() {
5568: FormBuilderXhtml builder = new FormBuilderXhtml();
5569: Collection<String> set_values;
5570:
5571: Template template = TemplateFactory.ENGINEHTML
5572: .get("formbuilder_fields");
5573:
5574: set_values = builder.generateField(template, "morecolors",
5575: null, null);
5576: assertEquals(1, set_values.size());
5577: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
5578: .next());
5579: assertEquals(
5580: "<select name=\"morecolors\"></select>",
5581: StringUtils.splitToArray(template.getContent(), "\n")[48]);
5582: template.removeValue(set_values.iterator().next());
5583: set_values.clear();
5584:
5585: set_values = builder.generateField(template,
5586: new ConstrainedProperty("morecolors"), null, null);
5587: assertEquals(1, set_values.size());
5588: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
5589: .next());
5590: assertEquals(
5591: "<select name=\"morecolors\"></select>",
5592: StringUtils.splitToArray(template.getContent(), "\n")[48]);
5593: template.removeValue(set_values.iterator().next());
5594: set_values.clear();
5595:
5596: set_values = builder.generateField(template,
5597: new ConstrainedProperty("morecolors").inList("black",
5598: "red", null, "green", "blue"), null, null);
5599: assertEquals(1, set_values.size());
5600: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
5601: .next());
5602: assertEquals(
5603: "<select name=\"morecolors\"><option value=\"black\">black</option><option value=\"red\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
5604: StringUtils.splitToArray(template.getContent(), "\n")[48]);
5605: template.removeValue(set_values.iterator().next());
5606: set_values.clear();
5607:
5608: set_values = builder.generateField(template,
5609: SelectInListEnum.class, "morecolors", null, null);
5610: assertEquals(1, set_values.size());
5611: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
5612: .next());
5613: assertEquals(
5614: "<select name=\"morecolors\"><option value=\"black\">black</option><option value=\"red\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
5615: StringUtils.splitToArray(template.getContent(), "\n")[48]);
5616: template.removeValue(set_values.iterator().next());
5617: set_values.clear();
5618:
5619: set_values = builder
5620: .generateField(template, new ConstrainedProperty(
5621: "morecolors").inList("black", "red", null,
5622: "green", "blue").defaultValue("green"),
5623: new String[] { "black", "red" }, null);
5624: assertEquals(1, set_values.size());
5625: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
5626: .next());
5627: assertEquals(
5628: "<select name=\"morecolors\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
5629: StringUtils.splitToArray(template.getContent(), "\n")[48]);
5630: template.removeValue(set_values.iterator().next());
5631: set_values.clear();
5632:
5633: set_values = builder.generateField(template,
5634: SelectInListEnum.class, new ConstrainedProperty(
5635: "morecolors").defaultValue("green"),
5636: new String[] { "black", "red" }, null);
5637: assertEquals(1, set_values.size());
5638: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
5639: .next());
5640: assertEquals(
5641: "<select name=\"morecolors\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
5642: StringUtils.splitToArray(template.getContent(), "\n")[48]);
5643: template.removeValue(set_values.iterator().next());
5644: set_values.clear();
5645:
5646: template.setValue("FORM:SELECT:morecolors", "already set");
5647: set_values = builder.generateField(template,
5648: new ConstrainedProperty("morecolors"), null, null);
5649: assertEquals(0, set_values.size());
5650: assertEquals("already set", StringUtils.splitToArray(template
5651: .getContent(), "\n")[48]);
5652: template.removeValue("FORM:SELECT:morecolors");
5653: }
5654:
5655: public void testGenerateFieldSelectTemplateNameWithDefault() {
5656: FormBuilderXhtml builder = new FormBuilderXhtml();
5657: Collection<String> set_values;
5658: Iterator<String> set_values_it;
5659:
5660: Template template = TemplateFactory.ENGINEHTML
5661: .get("formbuilder_fields_templatename");
5662:
5663: set_values = builder.replaceField(template,
5664: "templatenamecolors", "colors", null, null);
5665: set_values_it = set_values.iterator();
5666: assertEquals(2, set_values.size());
5667: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5668: .next());
5669: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5670: .next());
5671: assertEquals("<select name=\"colors\"></select>", StringUtils
5672: .splitToArray(template.getContent(), "\n")[44]);
5673: assertEquals("<div></div>", StringUtils.splitToArray(template
5674: .getContent(), "\n")[58]);
5675: set_values_it = set_values.iterator();
5676: template.removeValue(set_values_it.next());
5677: template.removeValue(set_values_it.next());
5678: set_values.clear();
5679:
5680: set_values = builder.replaceField(template,
5681: "templatenamecolors",
5682: new ConstrainedProperty("colors"), null, null);
5683: set_values_it = set_values.iterator();
5684: assertEquals(2, set_values.size());
5685: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5686: .next());
5687: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5688: .next());
5689: assertEquals("<select name=\"colors\"></select>", StringUtils
5690: .splitToArray(template.getContent(), "\n")[44]);
5691: assertEquals("<div></div>", StringUtils.splitToArray(template
5692: .getContent(), "\n")[58]);
5693: set_values_it = set_values.iterator();
5694: template.removeValue(set_values_it.next());
5695: template.removeValue(set_values_it.next());
5696: set_values.clear();
5697:
5698: set_values = builder.replaceField(template,
5699: "templatenamecolors", new ConstrainedProperty("colors")
5700: .inList("black", "red", null, "green", "blue"),
5701: null, null);
5702: set_values_it = set_values.iterator();
5703: assertEquals(2, set_values.size());
5704: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5705: .next());
5706: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5707: .next());
5708: assertEquals(
5709: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5710: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5711: assertEquals("<div></div>", StringUtils.splitToArray(template
5712: .getContent(), "\n")[58]);
5713: set_values_it = set_values.iterator();
5714: template.removeValue(set_values_it.next());
5715: template.removeValue(set_values_it.next());
5716: set_values.clear();
5717:
5718: set_values = builder.replaceField(template,
5719: "templatenamecolors", SelectInListEnum.class, "colors",
5720: null, null);
5721: set_values_it = set_values.iterator();
5722: assertEquals(2, set_values.size());
5723: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5724: .next());
5725: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5726: .next());
5727: assertEquals(
5728: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5729: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5730: assertEquals("<div></div>", StringUtils.splitToArray(template
5731: .getContent(), "\n")[58]);
5732: set_values_it = set_values.iterator();
5733: template.removeValue(set_values_it.next());
5734: template.removeValue(set_values_it.next());
5735: set_values.clear();
5736:
5737: set_values = builder.replaceField(template,
5738: "templatenamecolors", new ConstrainedProperty("colors")
5739: .inList("black", "red", null, "green", "blue")
5740: .defaultValue("green"), null, null);
5741: set_values_it = set_values.iterator();
5742: assertEquals(2, set_values.size());
5743: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5744: .next());
5745: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5746: .next());
5747: assertEquals(
5748: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\" selected=\"selected\">green spots</option><option value=\"blue\">blue spots</option></select>",
5749: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5750: assertEquals("<div>green spots</div>", StringUtils
5751: .splitToArray(template.getContent(), "\n")[58]);
5752: set_values_it = set_values.iterator();
5753: template.removeValue(set_values_it.next());
5754: template.removeValue(set_values_it.next());
5755: set_values.clear();
5756:
5757: set_values = builder
5758: .replaceField(template, "templatenamecolors",
5759: SelectInListEnum.class,
5760: new ConstrainedProperty("colors")
5761: .defaultValue("green"), null, null);
5762: set_values_it = set_values.iterator();
5763: assertEquals(2, set_values.size());
5764: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5765: .next());
5766: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5767: .next());
5768: assertEquals(
5769: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\" selected=\"selected\">green spots</option><option value=\"blue\">blue spots</option></select>",
5770: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5771: assertEquals("<div>green spots</div>", StringUtils
5772: .splitToArray(template.getContent(), "\n")[58]);
5773: set_values_it = set_values.iterator();
5774: template.removeValue(set_values_it.next());
5775: template.removeValue(set_values_it.next());
5776: set_values.clear();
5777:
5778: set_values = builder.replaceField(template,
5779: "templatenamecolors", new ConstrainedProperty("colors")
5780: .inList("black", "red", null, "green", "blue")
5781: .defaultValue("green"), new String[] { null,
5782: "red" }, null);
5783: set_values_it = set_values.iterator();
5784: assertEquals(2, set_values.size());
5785: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5786: .next());
5787: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5788: .next());
5789: assertEquals(
5790: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5791: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5792: assertEquals(
5793: "<div>green spots</div><div>red spots</div>",
5794: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5795: set_values_it = set_values.iterator();
5796: template.removeValue(set_values_it.next());
5797: template.removeValue(set_values_it.next());
5798: set_values.clear();
5799:
5800: set_values = builder
5801: .replaceField(template, "templatenamecolors",
5802: SelectInListEnum.class,
5803: new ConstrainedProperty("colors")
5804: .defaultValue("green"), new String[] {
5805: null, "red" }, null);
5806: set_values_it = set_values.iterator();
5807: assertEquals(2, set_values.size());
5808: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5809: .next());
5810: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5811: .next());
5812: assertEquals(
5813: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5814: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5815: assertEquals(
5816: "<div>green spots</div><div>red spots</div>",
5817: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5818: set_values_it = set_values.iterator();
5819: template.removeValue(set_values_it.next());
5820: template.removeValue(set_values_it.next());
5821: set_values.clear();
5822:
5823: set_values = builder.replaceField(template,
5824: "templatenamecolors", new ConstrainedProperty("colors")
5825: .inList("black", "red", null, "green", "blue"),
5826: new String[] { "red", "blue" }, null);
5827: set_values_it = set_values.iterator();
5828: assertEquals(2, set_values.size());
5829: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5830: .next());
5831: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5832: .next());
5833: assertEquals(
5834: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\" selected=\"selected\">blue spots</option></select>",
5835: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5836: assertEquals(
5837: "<div>red spots</div><div>blue spots</div>",
5838: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5839: set_values_it = set_values.iterator();
5840: template.removeValue(set_values_it.next());
5841: template.removeValue(set_values_it.next());
5842: set_values.clear();
5843:
5844: set_values = builder.replaceField(template,
5845: "templatenamecolors", SelectInListEnum.class, "colors",
5846: new String[] { "red", "blue" }, null);
5847: set_values_it = set_values.iterator();
5848: assertEquals(2, set_values.size());
5849: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5850: .next());
5851: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5852: .next());
5853: assertEquals(
5854: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\" selected=\"selected\">blue spots</option></select>",
5855: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5856: assertEquals(
5857: "<div>red spots</div><div>blue spots</div>",
5858: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5859: set_values_it = set_values.iterator();
5860: template.removeValue(set_values_it.next());
5861: template.removeValue(set_values_it.next());
5862: set_values.clear();
5863:
5864: set_values = builder.replaceField(template,
5865: "templatenamecolors", new ConstrainedProperty("colors")
5866: .inList("black", "red", null, "green", "blue")
5867: .defaultValue("green"), new String[] { "black",
5868: "red" }, null);
5869: set_values_it = set_values.iterator();
5870: assertEquals(2, set_values.size());
5871: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5872: .next());
5873: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5874: .next());
5875: assertEquals(
5876: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5877: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5878: assertEquals(
5879: "<div>black</div><div>red spots</div>",
5880: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5881: set_values_it = set_values.iterator();
5882: template.removeValue(set_values_it.next());
5883: template.removeValue(set_values_it.next());
5884: set_values.clear();
5885:
5886: set_values = builder
5887: .replaceField(template, "templatenamecolors",
5888: SelectInListEnum.class,
5889: new ConstrainedProperty("colors")
5890: .defaultValue("green"), new String[] {
5891: "black", "red" }, null);
5892: set_values_it = set_values.iterator();
5893: assertEquals(2, set_values.size());
5894: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5895: .next());
5896: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5897: .next());
5898: assertEquals(
5899: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5900: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5901: assertEquals(
5902: "<div>black</div><div>red spots</div>",
5903: StringUtils.splitToArray(template.getContent(), "\n")[58]);
5904: set_values_it = set_values.iterator();
5905: template.removeValue(set_values_it.next());
5906: template.removeValue(set_values_it.next());
5907: set_values.clear();
5908:
5909: set_values = builder.replaceField(template,
5910: "templatenamecolors", new ConstrainedProperty("colors")
5911: .inList("black", "red", null, "green", "blue"),
5912: new String[] { "orange" }, null);
5913: set_values_it = set_values.iterator();
5914: assertEquals(2, set_values.size());
5915: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5916: .next());
5917: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5918: .next());
5919: assertEquals(
5920: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5921: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5922: assertEquals("<div>orange</div>", StringUtils.splitToArray(
5923: template.getContent(), "\n")[58]);
5924: set_values_it = set_values.iterator();
5925: template.removeValue(set_values_it.next());
5926: template.removeValue(set_values_it.next());
5927: set_values.clear();
5928:
5929: set_values = builder.replaceField(template,
5930: "templatenamecolors", SelectInListEnum.class, "colors",
5931: new String[] { "orange" }, null);
5932: set_values_it = set_values.iterator();
5933: assertEquals(2, set_values.size());
5934: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5935: .next());
5936: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5937: .next());
5938: assertEquals(
5939: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"green\">green spots</option><option value=\"blue\">blue spots</option></select>",
5940: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5941: assertEquals("<div>orange</div>", StringUtils.splitToArray(
5942: template.getContent(), "\n")[58]);
5943: set_values_it = set_values.iterator();
5944: template.removeValue(set_values_it.next());
5945: template.removeValue(set_values_it.next());
5946: set_values.clear();
5947:
5948: template.setValue("FORM:SELECT:templatenamecolors",
5949: "already set");
5950: template.setValue("FORM:DISPLAY:templatenamecolors",
5951: "already set too");
5952: set_values = builder.replaceField(template,
5953: "templatenamecolors",
5954: new ConstrainedProperty("colors"), null, null);
5955: set_values_it = set_values.iterator();
5956: assertEquals(2, set_values.size());
5957: assertEquals("FORM:SELECT:templatenamecolors", set_values_it
5958: .next());
5959: assertEquals("FORM:DISPLAY:templatenamecolors", set_values_it
5960: .next());
5961: assertEquals("<select name=\"colors\"></select>", StringUtils
5962: .splitToArray(template.getContent(), "\n")[44]);
5963: assertEquals("<div></div>", StringUtils.splitToArray(template
5964: .getContent(), "\n")[58]);
5965: set_values_it = set_values.iterator();
5966: template.removeValue(set_values_it.next());
5967: template.removeValue(set_values_it.next());
5968: set_values.clear();
5969: }
5970:
5971: public void testGenerateFieldSelectWithOutOfListDefault() {
5972: FormBuilderXhtml builder = new FormBuilderXhtml();
5973: Collection<String> set_values;
5974: Iterator<String> set_values_it;
5975:
5976: Template template = TemplateFactory.ENGINEHTML
5977: .get("formbuilder_fields");
5978:
5979: set_values = builder.generateField(template,
5980: new ConstrainedProperty("colors").inList("black",
5981: "red", null, "blue").defaultValue("green"),
5982: null, null);
5983: set_values_it = set_values.iterator();
5984: assertEquals(2, set_values.size());
5985: assertEquals("FORM:SELECT:colors", set_values_it.next());
5986: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
5987: assertEquals(
5988: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"green\" selected=\"selected\">green spots</option><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"blue\">blue spots</option></select>",
5989: StringUtils.splitToArray(template.getContent(), "\n")[44]);
5990: assertEquals("<div>green spots</div>", StringUtils
5991: .splitToArray(template.getContent(), "\n")[58]);
5992: set_values_it = set_values.iterator();
5993: template.removeValue(set_values_it.next());
5994: template.removeValue(set_values_it.next());
5995: set_values.clear();
5996:
5997: set_values = builder.generateField(template,
5998: SelectInListEnum2.class, new ConstrainedProperty(
5999: "colors").defaultValue("green"), null, null);
6000: set_values_it = set_values.iterator();
6001: assertEquals(2, set_values.size());
6002: assertEquals("FORM:SELECT:colors", set_values_it.next());
6003: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6004: assertEquals(
6005: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"green\" selected=\"selected\">green spots</option><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"blue\">blue spots</option></select>",
6006: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6007: assertEquals("<div>green spots</div>", StringUtils
6008: .splitToArray(template.getContent(), "\n")[58]);
6009: set_values_it = set_values.iterator();
6010: template.removeValue(set_values_it.next());
6011: template.removeValue(set_values_it.next());
6012: set_values.clear();
6013:
6014: set_values = builder.generateField(template,
6015: new ConstrainedProperty("colors").inList("black",
6016: "red", null, "blue").defaultValue("green"),
6017: new String[] { null, "red" }, null);
6018: set_values_it = set_values.iterator();
6019: assertEquals(2, set_values.size());
6020: assertEquals("FORM:SELECT:colors", set_values_it.next());
6021: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6022: assertEquals(
6023: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"green\">green spots</option><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"blue\">blue spots</option></select>",
6024: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6025: assertEquals(
6026: "<div>green spots</div><div>red spots</div>",
6027: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6028: set_values_it = set_values.iterator();
6029: template.removeValue(set_values_it.next());
6030: template.removeValue(set_values_it.next());
6031: set_values.clear();
6032:
6033: set_values = builder.generateField(template,
6034: SelectInListEnum2.class, new ConstrainedProperty(
6035: "colors").defaultValue("green"), new String[] {
6036: null, "red" }, null);
6037: set_values_it = set_values.iterator();
6038: assertEquals(2, set_values.size());
6039: assertEquals("FORM:SELECT:colors", set_values_it.next());
6040: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6041: assertEquals(
6042: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"green\">green spots</option><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"blue\">blue spots</option></select>",
6043: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6044: assertEquals(
6045: "<div>green spots</div><div>red spots</div>",
6046: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6047: set_values_it = set_values.iterator();
6048: template.removeValue(set_values_it.next());
6049: template.removeValue(set_values_it.next());
6050: set_values.clear();
6051:
6052: set_values = builder.generateField(template,
6053: new ConstrainedProperty("colors").inList("black",
6054: "red", null, "blue"), new String[] { "red",
6055: "blue" }, null);
6056: set_values_it = set_values.iterator();
6057: assertEquals(2, set_values.size());
6058: assertEquals("FORM:SELECT:colors", set_values_it.next());
6059: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6060: assertEquals(
6061: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"blue\" selected=\"selected\">blue spots</option></select>",
6062: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6063: assertEquals(
6064: "<div>red spots</div><div>blue spots</div>",
6065: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6066: set_values_it = set_values.iterator();
6067: template.removeValue(set_values_it.next());
6068: template.removeValue(set_values_it.next());
6069: set_values.clear();
6070:
6071: set_values = builder.generateField(template,
6072: SelectInListEnum2.class, "colors", new String[] {
6073: "red", "blue" }, null);
6074: set_values_it = set_values.iterator();
6075: assertEquals(2, set_values.size());
6076: assertEquals("FORM:SELECT:colors", set_values_it.next());
6077: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6078: assertEquals(
6079: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"blue\" selected=\"selected\">blue spots</option></select>",
6080: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6081: assertEquals(
6082: "<div>red spots</div><div>blue spots</div>",
6083: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6084: set_values_it = set_values.iterator();
6085: template.removeValue(set_values_it.next());
6086: template.removeValue(set_values_it.next());
6087: set_values.clear();
6088:
6089: set_values = builder.generateField(template,
6090: new ConstrainedProperty("colors").inList("black",
6091: "red", null, "blue").defaultValue("green"),
6092: new String[] { "black", "red" }, null);
6093: set_values_it = set_values.iterator();
6094: assertEquals(2, set_values.size());
6095: assertEquals("FORM:SELECT:colors", set_values_it.next());
6096: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6097: assertEquals(
6098: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"green\">green spots</option><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"blue\">blue spots</option></select>",
6099: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6100: assertEquals(
6101: "<div>black</div><div>red spots</div>",
6102: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6103: set_values_it = set_values.iterator();
6104: template.removeValue(set_values_it.next());
6105: template.removeValue(set_values_it.next());
6106: set_values.clear();
6107:
6108: set_values = builder.generateField(template,
6109: SelectInListEnum2.class, new ConstrainedProperty(
6110: "colors").defaultValue("green"), new String[] {
6111: "black", "red" }, null);
6112: set_values_it = set_values.iterator();
6113: assertEquals(2, set_values.size());
6114: assertEquals("FORM:SELECT:colors", set_values_it.next());
6115: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6116: assertEquals(
6117: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"green\">green spots</option><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">red spots</option><option value=\"blue\">blue spots</option></select>",
6118: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6119: assertEquals(
6120: "<div>black</div><div>red spots</div>",
6121: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6122: set_values_it = set_values.iterator();
6123: template.removeValue(set_values_it.next());
6124: template.removeValue(set_values_it.next());
6125: set_values.clear();
6126:
6127: set_values = builder.generateField(template,
6128: new ConstrainedProperty("colors").inList("black",
6129: "red", null, "blue"),
6130: new String[] { "orange" }, null);
6131: set_values_it = set_values.iterator();
6132: assertEquals(2, set_values.size());
6133: assertEquals("FORM:SELECT:colors", set_values_it.next());
6134: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6135: assertEquals(
6136: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"blue\">blue spots</option></select>",
6137: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6138: assertEquals("<div>orange</div>", StringUtils.splitToArray(
6139: template.getContent(), "\n")[58]);
6140: set_values_it = set_values.iterator();
6141: template.removeValue(set_values_it.next());
6142: template.removeValue(set_values_it.next());
6143: set_values.clear();
6144:
6145: set_values = builder.generateField(template,
6146: SelectInListEnum2.class, "colors",
6147: new String[] { "orange" }, null);
6148: set_values_it = set_values.iterator();
6149: assertEquals(2, set_values.size());
6150: assertEquals("FORM:SELECT:colors", set_values_it.next());
6151: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6152: assertEquals(
6153: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\">red spots</option><option value=\"blue\">blue spots</option></select>",
6154: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6155: assertEquals("<div>orange</div>", StringUtils.splitToArray(
6156: template.getContent(), "\n")[58]);
6157: set_values_it = set_values.iterator();
6158: template.removeValue(set_values_it.next());
6159: template.removeValue(set_values_it.next());
6160: set_values.clear();
6161: }
6162:
6163: public void testGenerateFieldSelectPrefix() {
6164: FormBuilderXhtml builder = new FormBuilderXhtml();
6165: Collection<String> set_values;
6166:
6167: Template template = TemplateFactory.ENGINEHTML
6168: .get("formbuilder_fields");
6169:
6170: set_values = builder.generateField(template, "colors", null,
6171: "more");
6172: assertEquals(1, set_values.size());
6173: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
6174: .next());
6175: assertEquals(
6176: "<select name=\"morecolors\"></select>",
6177: StringUtils.splitToArray(template.getContent(), "\n")[48]);
6178: template.removeValue(set_values.iterator().next());
6179: set_values.clear();
6180:
6181: set_values = builder.generateField(template,
6182: new ConstrainedProperty("colors"), null, "more");
6183: assertEquals(1, set_values.size());
6184: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
6185: .next());
6186: assertEquals(
6187: "<select name=\"morecolors\"></select>",
6188: StringUtils.splitToArray(template.getContent(), "\n")[48]);
6189: template.removeValue(set_values.iterator().next());
6190: set_values.clear();
6191:
6192: set_values = builder.generateField(template,
6193: new ConstrainedProperty("colors").inList("black",
6194: "red", null, "green", "blue"), null, "more");
6195: assertEquals(1, set_values.size());
6196: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
6197: .next());
6198: assertEquals(
6199: "<select name=\"morecolors\"><option value=\"black\">black</option><option value=\"red\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
6200: StringUtils.splitToArray(template.getContent(), "\n")[48]);
6201: template.removeValue(set_values.iterator().next());
6202: set_values.clear();
6203:
6204: set_values = builder.generateField(template,
6205: SelectInListEnum.class, "colors", null, "more");
6206: assertEquals(1, set_values.size());
6207: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
6208: .next());
6209: assertEquals(
6210: "<select name=\"morecolors\"><option value=\"black\">black</option><option value=\"red\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
6211: StringUtils.splitToArray(template.getContent(), "\n")[48]);
6212: template.removeValue(set_values.iterator().next());
6213: set_values.clear();
6214:
6215: set_values = builder.generateField(template,
6216: new ConstrainedProperty("colors").inList("black",
6217: "red", null, "green", "blue").defaultValue(
6218: "green"), new String[] { "black", "red" },
6219: "more");
6220: assertEquals(1, set_values.size());
6221: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
6222: .next());
6223: assertEquals(
6224: "<select name=\"morecolors\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
6225: StringUtils.splitToArray(template.getContent(), "\n")[48]);
6226: template.removeValue(set_values.iterator().next());
6227: set_values.clear();
6228:
6229: set_values = builder.generateField(template,
6230: SelectInListEnum.class, new ConstrainedProperty(
6231: "colors").defaultValue("green"), new String[] {
6232: "black", "red" }, "more");
6233: assertEquals(1, set_values.size());
6234: assertEquals("FORM:SELECT:morecolors", set_values.iterator()
6235: .next());
6236: assertEquals(
6237: "<select name=\"morecolors\"><option value=\"black\" selected=\"selected\">black</option><option value=\"red\" selected=\"selected\">more red spots</option><option value=\"green\">more green spots</option><option value=\"blue\">more blue spots</option></select>",
6238: StringUtils.splitToArray(template.getContent(), "\n")[48]);
6239: template.removeValue(set_values.iterator().next());
6240: set_values.clear();
6241:
6242: template.setValue("FORM:SELECT:morecolors", "already set");
6243: set_values = builder.generateField(template,
6244: new ConstrainedProperty("colors"), null, "more");
6245: assertEquals(0, set_values.size());
6246: assertEquals("already set", StringUtils.splitToArray(template
6247: .getContent(), "\n")[48]);
6248: template.removeValue("FORM:SELECT:morecolors");
6249: }
6250:
6251: public void testGenerateFieldSelectDynamic() {
6252: FormBuilderXhtml builder = new FormBuilderXhtml();
6253: Collection<String> set_values;
6254: Iterator<String> set_values_it;
6255:
6256: Template template = TemplateFactory.ENGINEHTML
6257: .get("formbuilder_fields");
6258:
6259: template.addResourceBundle(new ListResourceBundle() {
6260: public Object[][] getContents() {
6261: return new Object[][] { { "colors:1", "one" },
6262: { "colors:3", "three" },
6263: { "colors:5", "five" }, { "colors:9", "nine" }, };
6264: }
6265: });
6266:
6267: set_values = builder.generateField(template,
6268: new ConstrainedProperty("colors").inList("1", "3", "5",
6269: "9").defaultValue("5"), null, null);
6270: set_values_it = set_values.iterator();
6271: assertEquals(2, set_values.size());
6272: assertEquals("FORM:SELECT:colors", set_values_it.next());
6273: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6274: assertEquals(
6275: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"1\">one</option><option value=\"3\">three</option><option value=\"5\" selected=\"selected\">five</option><option value=\"9\">nine</option></select>",
6276: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6277: assertEquals("<div>five</div>", StringUtils.splitToArray(
6278: template.getContent(), "\n")[58]);
6279: set_values_it = set_values.iterator();
6280: template.removeValue(set_values_it.next());
6281: template.removeValue(set_values_it.next());
6282: set_values.clear();
6283:
6284: set_values = builder.generateField(template,
6285: SelectInListEnum3.class, new ConstrainedProperty(
6286: "colors").defaultValue("5"), null, null);
6287: set_values_it = set_values.iterator();
6288: assertEquals(2, set_values.size());
6289: assertEquals("FORM:SELECT:colors", set_values_it.next());
6290: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6291: assertEquals(
6292: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"1\">one</option><option value=\"3\">three</option><option value=\"5\" selected=\"selected\">five</option><option value=\"9\">nine</option></select>",
6293: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6294: assertEquals("<div>five</div>", StringUtils.splitToArray(
6295: template.getContent(), "\n")[58]);
6296: set_values_it = set_values.iterator();
6297: template.removeValue(set_values_it.next());
6298: template.removeValue(set_values_it.next());
6299: set_values.clear();
6300:
6301: set_values = builder.generateField(template,
6302: new ConstrainedProperty("colors").inList("1", "3", "5",
6303: "9").defaultValue("5"),
6304: new String[] { "3", "9" }, null);
6305: set_values_it = set_values.iterator();
6306: assertEquals(2, set_values.size());
6307: assertEquals("FORM:SELECT:colors", set_values_it.next());
6308: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6309: assertEquals(
6310: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"1\">one</option><option value=\"3\" selected=\"selected\">three</option><option value=\"5\">five</option><option value=\"9\" selected=\"selected\">nine</option></select>",
6311: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6312: assertEquals("<div>three</div><div>nine</div>", StringUtils
6313: .splitToArray(template.getContent(), "\n")[58]);
6314: set_values_it = set_values.iterator();
6315: template.removeValue(set_values_it.next());
6316: template.removeValue(set_values_it.next());
6317: set_values.clear();
6318:
6319: set_values = builder.generateField(template,
6320: SelectInListEnum3.class, new ConstrainedProperty(
6321: "colors").defaultValue("5"), new String[] {
6322: "3", "9" }, null);
6323: set_values_it = set_values.iterator();
6324: assertEquals(2, set_values.size());
6325: assertEquals("FORM:SELECT:colors", set_values_it.next());
6326: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6327: assertEquals(
6328: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"1\">one</option><option value=\"3\" selected=\"selected\">three</option><option value=\"5\">five</option><option value=\"9\" selected=\"selected\">nine</option></select>",
6329: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6330: assertEquals("<div>three</div><div>nine</div>", StringUtils
6331: .splitToArray(template.getContent(), "\n")[58]);
6332: set_values_it = set_values.iterator();
6333: template.removeValue(set_values_it.next());
6334: template.removeValue(set_values_it.next());
6335: set_values.clear();
6336:
6337: template.clear();
6338:
6339: template.addResourceBundle(new ListResourceBundle() {
6340: public Object[][] getContents() {
6341: return new Object[][] {
6342: { "colors:blue", "blue waves" },
6343: { "colors:red", "red waves" } };
6344: }
6345: });
6346:
6347: set_values = builder.generateField(template,
6348: new ConstrainedProperty("colors").inList("black",
6349: "red", null, "green", "blue").defaultValue(
6350: "green"), new String[] { null, "red" }, null);
6351: set_values_it = set_values.iterator();
6352: assertEquals(2, set_values.size());
6353: assertEquals("FORM:SELECT:colors", set_values_it.next());
6354: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6355: assertEquals(
6356: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red waves</option><option value=\"green\">green spots</option><option value=\"blue\">blue waves</option></select>",
6357: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6358: assertEquals(
6359: "<div>green spots</div><div>red waves</div>",
6360: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6361: set_values_it = set_values.iterator();
6362: template.removeValue(set_values_it.next());
6363: template.removeValue(set_values_it.next());
6364: set_values.clear();
6365:
6366: set_values = builder.generateField(template,
6367: SelectInListEnum.class, new ConstrainedProperty(
6368: "colors").defaultValue("green"), new String[] {
6369: null, "red" }, null);
6370: set_values_it = set_values.iterator();
6371: assertEquals(2, set_values.size());
6372: assertEquals("FORM:SELECT:colors", set_values_it.next());
6373: assertEquals("FORM:DISPLAY:colors", set_values_it.next());
6374: assertEquals(
6375: "<select name=\"colors\" size=\"3\" multiple=\"multiple\"><option value=\"black\">black</option><option value=\"red\" selected=\"selected\">red waves</option><option value=\"green\">green spots</option><option value=\"blue\">blue waves</option></select>",
6376: StringUtils.splitToArray(template.getContent(), "\n")[44]);
6377: assertEquals(
6378: "<div>green spots</div><div>red waves</div>",
6379: StringUtils.splitToArray(template.getContent(), "\n")[58]);
6380: set_values_it = set_values.iterator();
6381: template.removeValue(set_values_it.next());
6382: template.removeValue(set_values_it.next());
6383: set_values.clear();
6384: }
6385:
6386: public void testRemoveFieldSelect() {
6387: FormBuilderXhtml builder = new FormBuilderXhtml();
6388:
6389: Template template = TemplateFactory.ENGINEHTML
6390: .get("formbuilder_fields");
6391:
6392: String raw_content = template.getContent();
6393:
6394: builder.generateField(template,
6395: new ConstrainedProperty("colors").inList("black",
6396: "red", null, "green", "blue"),
6397: new String[] { "orange" }, null);
6398: assertFalse(raw_content.equals(template.getContent()));
6399: builder.removeField(template, "colors", null);
6400: assertEquals(raw_content, template.getContent());
6401:
6402: builder.generateField(template, SelectInListEnum.class,
6403: "colors", new String[] { "orange" }, null);
6404: assertFalse(raw_content.equals(template.getContent()));
6405: builder.removeField(template, "colors", null);
6406: assertEquals(raw_content, template.getContent());
6407: }
6408:
6409: public void testRemoveFieldSelectRTemplateName() {
6410: FormBuilderXhtml builder = new FormBuilderXhtml();
6411:
6412: Template template = TemplateFactory.ENGINEHTML
6413: .get("formbuilder_fields_templatename");
6414:
6415: String raw_content = template.getContent();
6416:
6417: builder.generateField(template, new ConstrainedProperty(
6418: "templatenamecolors").inList("black", "red", null,
6419: "green", "blue"), new String[] { "orange" }, null);
6420: assertFalse(raw_content.equals(template.getContent()));
6421: builder.removeField(template, "templatenamecolors");
6422: assertEquals(raw_content, template.getContent());
6423:
6424: builder.generateField(template, SelectInListEnum.class,
6425: "templatenamecolors", new String[] { "orange" }, null);
6426: assertFalse(raw_content.equals(template.getContent()));
6427: builder.removeField(template, "templatenamecolors");
6428: assertEquals(raw_content, template.getContent());
6429: }
6430:
6431: public void testRemoveFieldSelectPrefix() {
6432: FormBuilderXhtml builder = new FormBuilderXhtml();
6433:
6434: Template template = TemplateFactory.ENGINEHTML
6435: .get("formbuilder_fields");
6436:
6437: String raw_content = template.getContent();
6438:
6439: builder.generateField(template,
6440: new ConstrainedProperty("colors").inList("black",
6441: "red", null, "green", "blue"),
6442: new String[] { "orange" }, "more");
6443: assertFalse(raw_content.equals(template.getContent()));
6444: builder.removeField(template, "colors", "more");
6445: assertEquals(raw_content, template.getContent());
6446:
6447: builder.generateField(template, SelectInListEnum.class,
6448: "colors", new String[] { "orange" }, "more");
6449: assertFalse(raw_content.equals(template.getContent()));
6450: builder.removeField(template, "colors", "more");
6451: assertEquals(raw_content, template.getContent());
6452: }
6453:
6454: public void testGenerateFormClassInvalidArguments() {
6455: try {
6456: FormBuilderXhtml builder = new FormBuilderXhtml();
6457: assertEquals(0, builder
6458: .generateForm(null, null, null, null).size());
6459:
6460: Template template = TemplateFactory.ENGINEHTML
6461: .get("formbuilder_fields");
6462: String raw_content = template.getContent();
6463: assertNotNull(template);
6464: assertEquals(0, builder.generateForm(template, null, null,
6465: null).size());
6466: assertEquals(raw_content, template.getContent());
6467: } catch (BeanUtilsException e) {
6468: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6469: }
6470: }
6471:
6472: public void testGenerateFormBeanInvalidArguments() {
6473: try {
6474: FormBuilderXhtml builder = new FormBuilderXhtml();
6475: assertEquals(0, builder.generateForm(null, (Object) null,
6476: null, null).size());
6477: assertEquals(0, builder.generateForm(null, new Object(),
6478: null, null).size());
6479:
6480: Template template = TemplateFactory.ENGINEHTML
6481: .get("formbuilder_fields");
6482: String raw_content = template.getContent();
6483: assertNotNull(template);
6484: assertEquals(0, builder.generateForm(template,
6485: (Object) null, null, null).size());
6486: assertEquals(0, builder.generateForm(template,
6487: (Class) null, null, null).size());
6488: assertEquals(raw_content, template.getContent());
6489:
6490: try {
6491: builder.generateForm(template, (Object) Object.class,
6492: null, null);
6493: fail();
6494: } catch (IllegalArgumentException e) {
6495: assertTrue(true);
6496: }
6497: } catch (BeanUtilsException e) {
6498: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6499: }
6500: }
6501:
6502: public void testGenerateFormBeanNotInstantiatable() {
6503: FormBuilderXhtml builder = new FormBuilderXhtml();
6504:
6505: Template template = TemplateFactory.ENGINEHTML
6506: .get("formbuilder_fields");
6507:
6508: try {
6509: builder.generateForm(template, PrivateBeanImpl.class, null,
6510: null);
6511: assertEquals(TemplateFactory.ENGINEHTML.get(
6512: "formbuilder_fields_out_regular_empty")
6513: .getContent(), template.getContent());
6514: } catch (BeanUtilsException e) {
6515: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6516: }
6517: }
6518:
6519: public void testRemoveFormInvalidArguments() {
6520: try {
6521: FormBuilderXhtml builder = new FormBuilderXhtml();
6522: builder.removeForm(null, null, null);
6523:
6524: Template template = TemplateFactory.ENGINEHTML
6525: .get("formbuilder_fields");
6526: String raw_content = template.getContent();
6527: assertNotNull(template);
6528: builder.removeForm(template, null, null);
6529: assertEquals(raw_content, template.getContent());
6530: } catch (BeanUtilsException e) {
6531: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6532: }
6533: }
6534:
6535: public void testRemoveFormBeanNotInstantiatable() {
6536: FormBuilderXhtml builder = new FormBuilderXhtml();
6537:
6538: Template template = TemplateFactory.ENGINEHTML
6539: .get("formbuilder_fields");
6540:
6541: String raw_content = template.getContent();
6542:
6543: try {
6544: builder.generateForm(template, RegularBeanImpl.class, null,
6545: null);
6546: assertFalse(raw_content.equals(template.getContent()));
6547: builder.removeForm(template, PrivateBeanImpl.class, null);
6548: assertEquals(raw_content, template.getContent());
6549: } catch (BeanUtilsException e) {
6550: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6551: }
6552: }
6553:
6554: private static class PrivateBeanImpl extends RegularBeanImpl {
6555: private PrivateBeanImpl() {
6556: }
6557: }
6558:
6559: public void testGenerateFormConstrainedEmpty() {
6560: FormBuilderXhtml builder = new FormBuilderXhtml();
6561:
6562: Template template = TemplateFactory.ENGINEHTML
6563: .get("formbuilder_fields");
6564:
6565: try {
6566: builder.generateForm(template, ConstrainedBeanImpl.class,
6567: null, null);
6568: assertEquals(TemplateFactory.ENGINEHTML.get(
6569: "formbuilder_fields_out_constrained_empty")
6570: .getContent(), template.getContent());
6571: } catch (BeanUtilsException e) {
6572: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6573: }
6574: }
6575:
6576: public void testRemoveFormConstrainedEmpty() {
6577: FormBuilderXhtml builder = new FormBuilderXhtml();
6578:
6579: Template template = TemplateFactory.ENGINEHTML
6580: .get("formbuilder_fields");
6581:
6582: String raw_content = template.getContent();
6583:
6584: try {
6585: builder.generateForm(template, ConstrainedBeanImpl.class,
6586: null, null);
6587: assertFalse(raw_content.equals(template.getContent()));
6588: builder.removeForm(template, ConstrainedBeanImpl.class,
6589: null);
6590: assertEquals(raw_content, template.getContent());
6591: } catch (BeanUtilsException e) {
6592: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6593: }
6594: }
6595:
6596: public void testGenerateFormConstrainedExternalValues() {
6597: FormBuilderXhtml builder = new FormBuilderXhtml();
6598:
6599: Template template = TemplateFactory.ENGINEHTML
6600: .get("formbuilder_fields");
6601:
6602: HashMap<String, String[]> values = new HashMap<String, String[]>();
6603: values.put("hidden", new String[] { "canyouseeme" });
6604: values.put("anotherhidden", new String[] { "I can't see you" });
6605: values.put("login", new String[] { "ikke" });
6606: values.put("anotherlogin", new String[] { "jullie" });
6607: values.put("password", new String[] { "secret" });
6608: values.put("anotherpassword", new String[] { "real secret" });
6609: values.put("comment", new String[] { "één comment" });
6610: values.put("anothercomment", new String[] { "this comment" });
6611: values.put("question", new String[] { "a2" });
6612: values.put("anotherquestion", new String[] { "a3" });
6613: values.put("customquestion", new String[] { "a1" });
6614: values.put("anothercustomquestion", new String[] { "a2" });
6615: values.put("options", new String[] { "2" });
6616: values.put("otheroptions", new String[] { "2", "0" });
6617: values.put("customoptions", new String[] { "1" });
6618: values.put("othercustomoptions", new String[] { "2" });
6619: values.put("invoice", new String[] { "1" });
6620: values.put("onemoreinvoice", new String[] { "0" });
6621: values.put("colors", new String[] { "red", "green" });
6622: values.put("morecolors", new String[] { "black" });
6623: values.put("yourcolors", new String[] { "brown" });
6624: try {
6625: builder.generateForm(template, ConstrainedBeanImpl.class,
6626: values, null);
6627: assertEquals(TemplateFactory.ENGINEHTML.get(
6628: "formbuilder_fields_out_constrained_values")
6629: .getContent(), template.getContent());
6630: } catch (BeanUtilsException e) {
6631: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6632: }
6633: }
6634:
6635: public void testGenerateFormConstrainedBeanValues() {
6636: FormBuilderXhtml builder = new FormBuilderXhtml();
6637:
6638: Template template = TemplateFactory.ENGINEHTML
6639: .get("formbuilder_fields");
6640:
6641: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
6642: bean.setHidden("canyouseeme");
6643: bean.setAnotherhidden("I can't see you");
6644: bean.setLogin("ikke");
6645: bean.setAnotherlogin("jullie");
6646: bean.setPassword("secret");
6647: bean.setAnotherpassword("real secret");
6648: bean.setComment("één comment");
6649: bean.setAnothercomment("this comment");
6650: bean.setQuestion(ConstrainedBeanImpl.Question.a2);
6651: bean.setAnotherquestion("a3");
6652: bean.setCustomquestion("a1");
6653: bean.setAnothercustomquestion("a2");
6654: bean.setOptions(new int[] { 2 });
6655: bean.setOtheroptions(new int[] { 2, 0 });
6656: bean.setCustomoptions(new int[] { 1 });
6657: bean.setOthercustomoptions(new int[] { 2 });
6658: bean.setInvoice(true);
6659: bean.setOnemoreinvoice(false);
6660: bean.setColors(new String[] { "red", "green" });
6661: bean.setMorecolors(new String[] { "black" });
6662: bean.setYourcolors(new String[] { "brown" });
6663: try {
6664: builder.generateForm(template, bean, null, null);
6665: assertEquals(TemplateFactory.ENGINEHTML.get(
6666: "formbuilder_fields_out_constrained_values")
6667: .getContent(), template.getContent());
6668: } catch (BeanUtilsException e) {
6669: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6670: }
6671: }
6672:
6673: public void testGenerateFormConstrainedBeanValuesInvalid() {
6674: FormBuilderXhtml builder = new FormBuilderXhtml();
6675:
6676: Template template = TemplateFactory.ENGINEHTML
6677: .get("formbuilder_fields");
6678:
6679: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
6680:
6681: bean.addValidationError(new ValidationError.INCOMPLETE("that"));
6682: Set<ValidationError> errors = bean.getValidationErrors();
6683:
6684: bean.setLogin("1234567");
6685: bean.setAnotherlogin(null);
6686: bean.setPassword(null);
6687: bean.setAnotherpassword("123456789abcd");
6688: bean.setComment(null);
6689: bean.setAnothercomment(null);
6690: bean.setQuestion(null);
6691: bean.setAnotherquestion("a5");
6692: bean.setCustomquestion(null);
6693: bean.setAnothercustomquestion("a6");
6694: bean.setOptions(new int[] { 1 });
6695: bean.setOtheroptions(null);
6696: bean.setCustomoptions(new int[] { 1, 0 });
6697: bean.setOthercustomoptions(new int[] { 4 });
6698: bean.setInvoice(false);
6699: bean.setOnemoreinvoice(true);
6700: bean.setColors(new String[] { "red", "green", "black" });
6701: bean.setMorecolors(null);
6702: bean.setYourcolors(new String[] { "white" });
6703: try {
6704: builder.generateForm(template, bean, null, null);
6705: assertEquals(TemplateFactory.ENGINEHTML.get(
6706: "formbuilder_fields_out_constrained_invalid")
6707: .getContent(), template.getContent());
6708: } catch (BeanUtilsException e) {
6709: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6710: }
6711:
6712: assertSame(errors, bean.getValidationErrors());
6713: }
6714:
6715: public void testGenerateFormConstrainedEmptyPrefix() {
6716: FormBuilderXhtml builder = new FormBuilderXhtml();
6717:
6718: Template template = TemplateFactory.ENGINEHTML
6719: .get("formbuilder_form_prefix");
6720: try {
6721: builder.generateForm(template, ConstrainedBeanImpl.class,
6722: null, "prefix_");
6723: assertEquals(TemplateFactory.ENGINEHTML.get(
6724: "formbuilder_form_prefix_out_constrained_empty")
6725: .getContent(), template.getContent());
6726: } catch (BeanUtilsException e) {
6727: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6728: }
6729: }
6730:
6731: public void testGenerateFormConstrainedExternalValuesPrefix() {
6732: FormBuilderXhtml builder = new FormBuilderXhtml();
6733:
6734: Template template = TemplateFactory.ENGINEHTML
6735: .get("formbuilder_form_prefix");
6736:
6737: HashMap<String, String[]> values = new HashMap<String, String[]>();
6738: values.put("prefix_hidden", new String[] { "canyouseeme" });
6739: values.put("prefix_login", new String[] { "ikke" });
6740: values.put("prefix_password", new String[] { "secret" });
6741: values.put("prefix_comment", new String[] { "één comment" });
6742: values.put("prefix_question", new String[] { "a2" });
6743: values.put("prefix_options", new String[] { "2" });
6744: values.put("prefix_invoice", new String[] { "1" });
6745: values.put("prefix_colors", new String[] { "red", "green" });
6746: values.put("prefix_yourcolors", new String[] { "brown",
6747: "orange" });
6748: try {
6749: builder.generateForm(template, ConstrainedBeanImpl.class,
6750: values, "prefix_");
6751: assertEquals(TemplateFactory.ENGINEHTML.get(
6752: "formbuilder_form_prefix_out_constrained_values")
6753: .getContent(), template.getContent());
6754: } catch (BeanUtilsException e) {
6755: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6756: }
6757: }
6758:
6759: public void testGenerateFormConstrainedBeanValuesPrefix() {
6760: FormBuilderXhtml builder = new FormBuilderXhtml();
6761:
6762: Template template = TemplateFactory.ENGINEHTML
6763: .get("formbuilder_form_prefix");
6764:
6765: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
6766: bean.setHidden("canyouseeme");
6767: bean.setLogin("ikke");
6768: bean.setPassword("secret");
6769: bean.setComment("één comment");
6770: bean.setQuestion(ConstrainedBeanImpl.Question.a2);
6771: bean.setOptions(new int[] { 2 });
6772: bean.setInvoice(true);
6773: bean.setColors(new String[] { "red", "green" });
6774: bean.setYourcolors(new String[] { "orange", "brown" });
6775: try {
6776: builder.generateForm(template, bean, null, "prefix_");
6777: assertEquals(TemplateFactory.ENGINEHTML.get(
6778: "formbuilder_form_prefix_out_constrained_values")
6779: .getContent(), template.getContent());
6780: } catch (BeanUtilsException e) {
6781: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6782: }
6783: }
6784:
6785: public void testRemoveFormConstrainedBeanValuesPrefix() {
6786: FormBuilderXhtml builder = new FormBuilderXhtml();
6787:
6788: Template template = TemplateFactory.ENGINEHTML
6789: .get("formbuilder_form_prefix");
6790:
6791: String raw_content = template.getContent();
6792:
6793: ConstrainedBeanImpl bean = new ConstrainedBeanImpl();
6794: bean.setHidden("canyouseeme");
6795: bean.setLogin("ikke");
6796: bean.setPassword("secret");
6797: bean.setComment("één comment");
6798: bean.setQuestion(ConstrainedBeanImpl.Question.a2);
6799: bean.setOptions(new int[] { 2 });
6800: bean.setInvoice(true);
6801: bean.setColors(new String[] { "red", "green" });
6802: bean.setYourcolors(new String[] { "orange", "brown" });
6803: try {
6804: builder.generateForm(template, bean, null, "prefix_");
6805: assertEquals(TemplateFactory.ENGINEHTML.get(
6806: "formbuilder_form_prefix_out_constrained_values")
6807: .getContent(), template.getContent());
6808: assertFalse(raw_content.equals(template.getContent()));
6809: builder.removeForm(template, RegularBeanImpl.class,
6810: "prefix_");
6811: assertEquals(raw_content, template.getContent());
6812: } catch (BeanUtilsException e) {
6813: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6814: }
6815: }
6816:
6817: public void testRemoveFormConstrainedValues() {
6818: FormBuilderXhtml builder = new FormBuilderXhtml();
6819:
6820: Template template = TemplateFactory.ENGINEHTML
6821: .get("formbuilder_fields");
6822:
6823: String raw_content = template.getContent();
6824:
6825: HashMap<String, String[]> values = new HashMap<String, String[]>();
6826: values.put("hidden", new String[] { "canyouseeme" });
6827: values.put("anotherhidden", new String[] { "I can't see you" });
6828: values.put("login", new String[] { "ikke" });
6829: values.put("anotherlogin", new String[] { "jullie" });
6830: values.put("password", new String[] { "secret" });
6831: values.put("anotherpassword", new String[] { "real secret" });
6832: values.put("comment", new String[] { "één comment" });
6833: values.put("anothercomment", new String[] { "this comment" });
6834: values.put("question", new String[] { "a2" });
6835: values.put("anotherquestion", new String[] { "a3" });
6836: values.put("customquestion", new String[] { "a1" });
6837: values.put("anothercustomquestion", new String[] { "a2" });
6838: values.put("options", new String[] { "2" });
6839: values.put("otheroptions", new String[] { "2", "0" });
6840: values.put("customoptions", new String[] { "1" });
6841: values.put("othercustomoptions", new String[] { "2" });
6842: values.put("invoice", new String[] { "1" });
6843: values.put("onemoreinvoice", new String[] { "0" });
6844: values.put("colors", new String[] { "red", "green" });
6845: values.put("morecolors", new String[] { "black" });
6846: try {
6847: builder.generateForm(template, ConstrainedBeanImpl.class,
6848: values, null);
6849: assertFalse(raw_content.equals(template.getContent()));
6850: builder.removeForm(template, ConstrainedBeanImpl.class,
6851: null);
6852: assertEquals(raw_content, template.getContent());
6853: } catch (BeanUtilsException e) {
6854: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6855: }
6856: }
6857:
6858: public void testGenerateFormRegularEmpty() {
6859: FormBuilderXhtml builder = new FormBuilderXhtml();
6860:
6861: Template template = TemplateFactory.ENGINEHTML
6862: .get("formbuilder_fields");
6863:
6864: try {
6865: builder.generateForm(template, RegularBeanImpl.class, null,
6866: null);
6867: assertEquals(TemplateFactory.ENGINEHTML.get(
6868: "formbuilder_fields_out_regular_empty")
6869: .getContent(), template.getContent());
6870: } catch (BeanUtilsException e) {
6871: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6872: }
6873: }
6874:
6875: public void testRemoveFormRegularEmpty() {
6876: FormBuilderXhtml builder = new FormBuilderXhtml();
6877:
6878: Template template = TemplateFactory.ENGINEHTML
6879: .get("formbuilder_fields");
6880:
6881: String raw_content = template.getContent();
6882:
6883: try {
6884: builder.generateForm(template, RegularBeanImpl.class, null,
6885: null);
6886: assertFalse(raw_content.equals(template.getContent()));
6887: builder.removeForm(template, RegularBeanImpl.class, null);
6888: assertEquals(raw_content, template.getContent());
6889: } catch (BeanUtilsException e) {
6890: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6891: }
6892: }
6893:
6894: public void testGenerateFormRegularExternalValues() {
6895: FormBuilderXhtml builder = new FormBuilderXhtml();
6896:
6897: Template template = TemplateFactory.ENGINEHTML
6898: .get("formbuilder_fields");
6899:
6900: HashMap<String, String[]> values = new HashMap<String, String[]>();
6901: values.put("hidden", new String[] { "canyouseeme" });
6902: values.put("anotherhidden", new String[] { "I can't see you" });
6903: values.put("login", new String[] { "ikke" });
6904: values.put("anotherlogin", new String[] { "jullie" });
6905: values.put("password", new String[] { "secret" });
6906: values.put("anotherpassword", new String[] { "real secret" });
6907: values.put("comment", new String[] { "één comment" });
6908: values.put("anothercomment", new String[] { "this comment" });
6909: values.put("question", new String[] { "a2" });
6910: values.put("anotherquestion", new String[] { "a3" });
6911: values.put("customquestion", new String[] { "a1" });
6912: values.put("anothercustomquestion", new String[] { "a2" });
6913: values.put("options", new String[] { "2" });
6914: values.put("otheroptions", new String[] { "2", "0" });
6915: values.put("customoptions", new String[] { "1" });
6916: values.put("othercustomoptions", new String[] { "2" });
6917: values.put("invoice", new String[] { "1" });
6918: values.put("onemoreinvoice", new String[] { "0" });
6919: values.put("colors", new String[] { "red", "green" });
6920: values.put("morecolors", new String[] { "black" });
6921: values.put("yourcolors", new String[] { "brown" });
6922: try {
6923: builder.generateForm(template, RegularBeanImpl.class,
6924: values, null);
6925: assertEquals(TemplateFactory.ENGINEHTML.get(
6926: "formbuilder_fields_out_regular_values")
6927: .getContent(), template.getContent());
6928: } catch (BeanUtilsException e) {
6929: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6930: }
6931: }
6932:
6933: public void testGenerateFormRegularBeanValues() {
6934: FormBuilderXhtml builder = new FormBuilderXhtml();
6935:
6936: Template template = TemplateFactory.ENGINEHTML
6937: .get("formbuilder_fields");
6938:
6939: RegularBeanImpl bean = new RegularBeanImpl();
6940: bean.setHidden("canyouseeme");
6941: bean.setAnotherhidden("I can't see you");
6942: bean.setLogin("ikke");
6943: bean.setAnotherlogin("jullie");
6944: bean.setPassword("secret");
6945: bean.setAnotherpassword("real secret");
6946: bean.setComment("één comment");
6947: bean.setAnothercomment("this comment");
6948: bean.setQuestion("a2");
6949: bean.setAnotherquestion("a3");
6950: bean.setCustomquestion("a1");
6951: bean.setAnothercustomquestion("a2");
6952: bean.setOptions(new int[] { 2 });
6953: bean.setOtheroptions(new int[] { 2, 0 });
6954: bean.setCustomoptions(new int[] { 1 });
6955: bean.setOthercustomoptions(new int[] { 2 });
6956: bean.setInvoice(true);
6957: bean.setOnemoreinvoice(false);
6958: bean
6959: .setColors(new RegularBeanImpl.Color[] {
6960: RegularBeanImpl.Color.red,
6961: RegularBeanImpl.Color.green });
6962: bean.setMorecolors(new String[] { "black" });
6963: bean.setYourcolors(new String[] { "brown" });
6964: try {
6965: builder.generateForm(template, bean, null, null);
6966: assertEquals(TemplateFactory.ENGINEHTML.get(
6967: "formbuilder_fields_out_regular_values")
6968: .getContent(), template.getContent());
6969: } catch (BeanUtilsException e) {
6970: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6971: }
6972: }
6973:
6974: public void testGenerateFormRegularEmptyPrefix() {
6975: FormBuilderXhtml builder = new FormBuilderXhtml();
6976:
6977: Template template = TemplateFactory.ENGINEHTML
6978: .get("formbuilder_form_prefix");
6979: try {
6980: builder.generateForm(template, RegularBeanImpl.class, null,
6981: "prefix_");
6982: assertEquals(TemplateFactory.ENGINEHTML.get(
6983: "formbuilder_form_prefix_out_regular_empty")
6984: .getContent(), template.getContent());
6985: } catch (BeanUtilsException e) {
6986: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
6987: }
6988: }
6989:
6990: public void testGenerateFormRegularExternalValuesPrefix() {
6991: FormBuilderXhtml builder = new FormBuilderXhtml();
6992:
6993: Template template = TemplateFactory.ENGINEHTML
6994: .get("formbuilder_form_prefix");
6995:
6996: HashMap<String, String[]> values = new HashMap<String, String[]>();
6997: values.put("prefix_hidden", new String[] { "canyouseeme" });
6998: values.put("prefix_login", new String[] { "ikke" });
6999: values.put("prefix_password", new String[] { "secret" });
7000: values.put("prefix_comment", new String[] { "één comment" });
7001: values.put("prefix_question", new String[] { "a2" });
7002: values.put("prefix_options", new String[] { "2" });
7003: values.put("prefix_invoice", new String[] { "1" });
7004: values.put("prefix_colors", new String[] { "red", "green" });
7005: values.put("prefix_yourcolors", new String[] { "brown" });
7006: try {
7007: builder.generateForm(template, RegularBeanImpl.class,
7008: values, "prefix_");
7009: assertEquals(TemplateFactory.ENGINEHTML.get(
7010: "formbuilder_form_prefix_out_regular_values")
7011: .getContent(), template.getContent());
7012: } catch (BeanUtilsException e) {
7013: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
7014: }
7015: }
7016:
7017: public void testGenerateFormRegularBeanValuesPrefix() {
7018: FormBuilderXhtml builder = new FormBuilderXhtml();
7019:
7020: Template template = TemplateFactory.ENGINEHTML
7021: .get("formbuilder_form_prefix");
7022:
7023: RegularBeanImpl bean = new RegularBeanImpl();
7024: bean.setHidden("canyouseeme");
7025: bean.setLogin("ikke");
7026: bean.setPassword("secret");
7027: bean.setComment("één comment");
7028: bean.setQuestion("a2");
7029: bean.setOptions(new int[] { 2 });
7030: bean.setInvoice(true);
7031: bean
7032: .setColors(new RegularBeanImpl.Color[] {
7033: RegularBeanImpl.Color.red,
7034: RegularBeanImpl.Color.green });
7035: bean.setYourcolors(new String[] { "brown" });
7036: try {
7037: builder.generateForm(template, bean, null, "prefix_");
7038: assertEquals(TemplateFactory.ENGINEHTML.get(
7039: "formbuilder_form_prefix_out_regular_values")
7040: .getContent(), template.getContent());
7041: } catch (BeanUtilsException e) {
7042: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
7043: }
7044: }
7045:
7046: public void testRemoveFormRegularBeanValuesPrefix() {
7047: FormBuilderXhtml builder = new FormBuilderXhtml();
7048:
7049: Template template = TemplateFactory.ENGINEHTML
7050: .get("formbuilder_form_prefix");
7051:
7052: String raw_content = template.getContent();
7053:
7054: RegularBeanImpl bean = new RegularBeanImpl();
7055: bean.setHidden("canyouseeme");
7056: bean.setLogin("ikke");
7057: bean.setPassword("secret");
7058: bean.setComment("één comment");
7059: bean.setQuestion("a2");
7060: bean.setOptions(new int[] { 2 });
7061: bean.setInvoice(true);
7062: bean
7063: .setColors(new RegularBeanImpl.Color[] {
7064: RegularBeanImpl.Color.red,
7065: RegularBeanImpl.Color.green });
7066: bean.setYourcolors(new String[] { "brown" });
7067: try {
7068: builder.generateForm(template, bean, null, "prefix_");
7069: assertEquals(TemplateFactory.ENGINEHTML.get(
7070: "formbuilder_form_prefix_out_regular_values")
7071: .getContent(), template.getContent());
7072: assertFalse(raw_content.equals(template.getContent()));
7073: builder.removeForm(template, RegularBeanImpl.class,
7074: "prefix_");
7075: assertEquals(raw_content, template.getContent());
7076: } catch (BeanUtilsException e) {
7077: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
7078: }
7079: }
7080:
7081: public void testRemoveFormRegularValues() {
7082: FormBuilderXhtml builder = new FormBuilderXhtml();
7083:
7084: Template template = TemplateFactory.ENGINEHTML
7085: .get("formbuilder_fields");
7086:
7087: String raw_content = template.getContent();
7088:
7089: HashMap<String, String[]> values = new HashMap<String, String[]>();
7090: values.put("hidden", new String[] { "canyouseeme" });
7091: values.put("anotherhidden", new String[] { "I can't see you" });
7092: values.put("login", new String[] { "ikke" });
7093: values.put("anotherlogin", new String[] { "jullie" });
7094: values.put("password", new String[] { "secret" });
7095: values.put("anotherpassword", new String[] { "real secret" });
7096: values.put("comment", new String[] { "één comment" });
7097: values.put("anothercomment", new String[] { "this comment" });
7098: values.put("question", new String[] { "a2" });
7099: values.put("anotherquestion", new String[] { "a3" });
7100: values.put("customquestion", new String[] { "a1" });
7101: values.put("anothercustomquestion", new String[] { "a2" });
7102: values.put("options", new String[] { "2" });
7103: values.put("otheroptions", new String[] { "2", "0" });
7104: values.put("customoptions", new String[] { "1" });
7105: values.put("othercustomoptions", new String[] { "2" });
7106: values.put("invoice", new String[] { "1" });
7107: values.put("onemoreinvoice", new String[] { "0" });
7108: values.put("colors", new String[] { "red", "green" });
7109: values.put("morecolors", new String[] { "black" });
7110: try {
7111: builder.generateForm(template, RegularBeanImpl.class,
7112: values, null);
7113: assertFalse(raw_content.equals(template.getContent()));
7114: builder.removeForm(template, RegularBeanImpl.class, null);
7115: assertEquals(raw_content, template.getContent());
7116: } catch (BeanUtilsException e) {
7117: assertTrue(ExceptionUtils.getExceptionStackTrace(e), false);
7118: }
7119: }
7120:
7121: public void testSelectParameterInvalidArguments() {
7122: FormBuilderXhtml builder = new FormBuilderXhtml();
7123: assertEquals(0, builder.selectParameter(null, null, null)
7124: .size());
7125:
7126: Template template = TemplateFactory.ENGINEHTML
7127: .get("formbuilder_parameters");
7128: String raw_content = template.getContent();
7129: assertNotNull(template);
7130: assertEquals(0, builder.selectParameter(template, null, null)
7131: .size());
7132: assertEquals(raw_content, template.getContent());
7133: assertEquals(0, builder.selectParameter(template, "", null)
7134: .size());
7135: assertEquals(raw_content, template.getContent());
7136: assertEquals(0, builder.selectParameter(template, "name", null)
7137: .size());
7138: assertEquals(raw_content, template.getContent());
7139: assertEquals(0, builder.selectParameter(template, "name",
7140: new String[0]).size());
7141: assertEquals(raw_content, template.getContent());
7142: }
7143:
7144: public void testSelectParameterChecked() {
7145: FormBuilderXhtml builder = new FormBuilderXhtml();
7146: Template template = TemplateFactory.ENGINEHTML
7147: .get("formbuilder_parameters");
7148: assertEquals(0, builder.selectParameter(template,
7149: "wantsupdates", new String[] { "false", null }).size());
7150: Collection<String> set_values = builder.selectParameter(
7151: template, "wantsupdates", new String[] { "true" });
7152: assertEquals(1, set_values.size());
7153: assertEquals("wantsupdates:CHECKED", set_values.iterator()
7154: .next());
7155: assertEquals("wantsupdates checked=\"checked\"\n" + "orange\n"
7156: + "blue\n" + "red\n" + "lastname\n" + "lastname\n",
7157: template.getContent());
7158: }
7159:
7160: public void testSelectParameterCheckedValues() {
7161: FormBuilderXhtml builder = new FormBuilderXhtml();
7162: Template template = TemplateFactory.ENGINEHTML
7163: .get("formbuilder_parameters");
7164: assertEquals(0, builder.selectParameter(template, "colors",
7165: new String[] { "green" }).size());
7166: Collection<String> set_values = builder.selectParameter(
7167: template, "colors", new String[] { "orange", "red",
7168: null, "black" });
7169: assertEquals(2, set_values.size());
7170: Iterator<String> it = set_values.iterator();
7171: assertEquals("colors:orange:CHECKED", it.next());
7172: assertEquals("colors:red:CHECKED", it.next());
7173: assertEquals("wantsupdates\n" + "orange checked=\"checked\"\n"
7174: + "blue\n" + "red checked=\"checked\"\n" + "lastname\n"
7175: + "lastname\n", template.getContent());
7176: }
7177:
7178: public void testSelectParameterSelectedValues() {
7179: FormBuilderXhtml builder = new FormBuilderXhtml();
7180: Template template = TemplateFactory.ENGINEHTML
7181: .get("formbuilder_parameters");
7182: assertEquals(0, builder.selectParameter(template, "lastname",
7183: new String[] { "Smith" }).size());
7184: Collection<String> set_values = builder.selectParameter(
7185: template, "lastname", new String[] { "Smith", null,
7186: "Mafessoni" });
7187: assertEquals(1, set_values.size());
7188: Iterator<String> it = set_values.iterator();
7189: assertEquals("lastname:Mafessoni:SELECTED", it.next());
7190: assertEquals("wantsupdates\n" + "orange\n" + "blue\n" + "red\n"
7191: + "lastname\n" + "lastname selected=\"selected\"\n",
7192: template.getContent());
7193: }
7194:
7195: public void testUnselectParameterInvalidArguments() {
7196: FormBuilderXhtml builder = new FormBuilderXhtml();
7197: builder.unselectParameter(null, null, null);
7198:
7199: Template template = TemplateFactory.ENGINEHTML
7200: .get("formbuilder_parameters");
7201: template.setValue("wantsupdates:CHECKED", "1");
7202: template.setValue("colors:orange:CHECKED", "1");
7203: template.setValue("colors:blue:CHECKED", "1");
7204: template.setValue("colors:red:CHECKED", "1");
7205: template.setValue("lastname:Bevin:SELECTED", "1");
7206: template.setValue("lastname:Mafessoni:SELECTED", "1");
7207:
7208: String raw_content = template.getContent();
7209: assertEquals("wantsupdates1\n" + "orange1\n" + "blue1\n"
7210: + "red1\n" + "lastname1\n" + "lastname1\n", raw_content);
7211:
7212: assertNotNull(template);
7213: builder.unselectParameter(template, null, null);
7214: assertEquals(raw_content, template.getContent());
7215: builder.unselectParameter(template, "", null);
7216: assertEquals(raw_content, template.getContent());
7217: builder.unselectParameter(template, "name", null);
7218: assertEquals(raw_content, template.getContent());
7219: builder.unselectParameter(template, "name", new String[0]);
7220: assertEquals(raw_content, template.getContent());
7221: }
7222:
7223: public void testUnselectParameterChecked() {
7224: FormBuilderXhtml builder = new FormBuilderXhtml();
7225: builder.unselectParameter(null, null, null);
7226:
7227: Template template = TemplateFactory.ENGINEHTML
7228: .get("formbuilder_parameters");
7229: template.setValue("wantsupdates:CHECKED", "1");
7230: template.setValue("colors:orange:CHECKED", "1");
7231: template.setValue("colors:blue:CHECKED", "1");
7232: template.setValue("colors:red:CHECKED", "1");
7233: template.setValue("lastname:Bevin:SELECTED", "1");
7234: template.setValue("lastname:Mafessoni:SELECTED", "1");
7235:
7236: String raw_content = template.getContent();
7237: assertEquals("wantsupdates1\n" + "orange1\n" + "blue1\n"
7238: + "red1\n" + "lastname1\n" + "lastname1\n", raw_content);
7239:
7240: builder.unselectParameter(template, "wantsupdates",
7241: new String[] { "false", null });
7242: builder.unselectParameter(template, "wantsupdates",
7243: new String[] { "true" });
7244: assertEquals("wantsupdates\n" + "orange1\n" + "blue1\n"
7245: + "red1\n" + "lastname1\n" + "lastname1\n", template
7246: .getContent());
7247: }
7248:
7249: public void testUnselectParameterCheckedValues() {
7250: FormBuilderXhtml builder = new FormBuilderXhtml();
7251: builder.unselectParameter(null, null, null);
7252:
7253: Template template = TemplateFactory.ENGINEHTML
7254: .get("formbuilder_parameters");
7255: template.setValue("wantsupdates:CHECKED", "1");
7256: template.setValue("colors:orange:CHECKED", "1");
7257: template.setValue("colors:blue:CHECKED", "1");
7258: template.setValue("colors:red:CHECKED", "1");
7259: template.setValue("lastname:Bevin:SELECTED", "1");
7260: template.setValue("lastname:Mafessoni:SELECTED", "1");
7261:
7262: String raw_content = template.getContent();
7263: assertEquals("wantsupdates1\n" + "orange1\n" + "blue1\n"
7264: + "red1\n" + "lastname1\n" + "lastname1\n", raw_content);
7265:
7266: builder.unselectParameter(template, "colors",
7267: new String[] { "green" });
7268: builder.unselectParameter(template, "colors", new String[] {
7269: "orange", "red", null, "black" });
7270: assertEquals("wantsupdates1\n" + "orange\n" + "blue1\n"
7271: + "red\n" + "lastname1\n" + "lastname1\n", template
7272: .getContent());
7273: }
7274:
7275: public void testUnselectParameterSelectedValues() {
7276: FormBuilderXhtml builder = new FormBuilderXhtml();
7277: builder.unselectParameter(null, null, null);
7278:
7279: Template template = TemplateFactory.ENGINEHTML
7280: .get("formbuilder_parameters");
7281: template.setValue("wantsupdates:CHECKED", "1");
7282: template.setValue("colors:orange:CHECKED", "1");
7283: template.setValue("colors:blue:CHECKED", "1");
7284: template.setValue("colors:red:CHECKED", "1");
7285: template.setValue("lastname:Bevin:SELECTED", "1");
7286: template.setValue("lastname:Mafessoni:SELECTED", "1");
7287:
7288: String raw_content = template.getContent();
7289: assertEquals("wantsupdates1\n" + "orange1\n" + "blue1\n"
7290: + "red1\n" + "lastname1\n" + "lastname1\n", raw_content);
7291:
7292: builder.unselectParameter(template, "lastname",
7293: new String[] { "Smith" });
7294: builder.unselectParameter(template, "lastname", new String[] {
7295: "Smith", null, "Mafessoni" });
7296: assertEquals("wantsupdates1\n" + "orange1\n" + "blue1\n"
7297: + "red1\n" + "lastname1\n" + "lastname\n", template
7298: .getContent());
7299: }
7300: }
|