use of com.liferay.apio.architect.form.Form.Builder in project com-liferay-apio-architect by liferay.
the class FormTest method testFormCreatesValidForm.
@Test
public void testFormCreatesValidForm() {
Builder<Map<String, Object>> builder = new Builder<>(asList("1", "2", "3"));
Form<Map<String, Object>> form = builder.title(__ -> "title").description(__ -> "description").constructor(HashMap::new).addOptionalBoolean("boolean1", (map, aBoolean) -> map.put("b1", aBoolean)).addOptionalBooleanList("booleanList", (map, list) -> map.put("bl1", list)).addOptionalDate("date1", (map, date) -> map.put("d1", date)).addOptionalDateList("dateList", (map, list) -> map.put("dl1", list)).addOptionalDouble("double1", (map, aDouble) -> map.put("do1", aDouble)).addOptionalDoubleList("doubleList", (map, list) -> map.put("dol1", list)).addOptionalFile("file1", (map, binaryFile) -> map.put("f1", binaryFile)).addOptionalFileList("fileList", (map, list) -> map.put("fl1", list)).addOptionalLong("long1", (map, aLong) -> map.put("l1", aLong)).addOptionalLongList("longList", (map, list) -> map.put("ll1", list)).addOptionalString("string1", (map, string) -> map.put("s1", string)).addOptionalStringList("stringList", (map, list) -> map.put("sl1", list)).addRequiredBoolean("boolean2", (map, aBoolean) -> map.put("b2", aBoolean)).addRequiredDate("date2", (map, date) -> map.put("d2", date)).addRequiredDouble("double2", (map, aDouble) -> map.put("do2", aDouble)).addRequiredFile("file2", (map, binaryFile) -> map.put("f2", binaryFile)).addRequiredLong("long2", (map, aLong) -> map.put("l2", aLong)).addRequiredString("string2", (map, string) -> map.put("s2", string)).addRequiredBooleanList("booleanList", (map, list) -> map.put("bl2", list)).addRequiredDateList("dateList", (map, list) -> map.put("dl2", list)).addRequiredDoubleList("doubleList", (map, list) -> map.put("dol2", list)).addRequiredFileList("fileList", (map, list) -> map.put("fl2", list)).addRequiredLongList("longList", (map, list) -> map.put("ll2", list)).addRequiredStringList("stringList", (map, list) -> map.put("sl2", list)).build();
assertThat(form.id, is("1/2/3"));
Language language = Locale::getDefault;
String title = form.getTitle(language);
String description = form.getDescription(language);
List<FormField> formFields = form.getFormFields();
assertThat(formFields, hasSize(24));
assertThat(formFields, contains(new FormField("boolean1", false, BOOLEAN), new FormField("booleanList", false, BOOLEAN_LIST), new FormField("date1", false, DATE), new FormField("dateList", false, DATE_LIST), new FormField("double1", false, DOUBLE), new FormField("doubleList", false, DOUBLE_LIST), new FormField("file1", false, FILE), new FormField("fileList", false, FILE_LIST), new FormField("long1", false, LONG), new FormField("longList", false, LONG_LIST), new FormField("string1", false, STRING), new FormField("stringList", false, STRING_LIST), new FormField("boolean2", true, BOOLEAN), new FormField("booleanList", true, BOOLEAN_LIST), new FormField("date2", true, DATE), new FormField("dateList", true, DATE_LIST), new FormField("double2", true, DOUBLE), new FormField("doubleList", true, DOUBLE_LIST), new FormField("file2", true, FILE), new FormField("fileList", true, FILE_LIST), new FormField("long2", true, LONG), new FormField("longList", true, LONG_LIST), new FormField("string2", true, STRING), new FormField("stringList", true, STRING_LIST)));
assertThat(title, is("title"));
assertThat(description, is("description"));
Map<String, Object> map = form.get(_body);
assertThat(map.size(), is(24));
assertThat(map, hasEntry(equalTo("b1"), equalTo(true)));
assertThat(map, hasEntry(equalTo("b2"), equalTo(false)));
assertThat(map, hasEntry(equalTo("d1"), equalTo(new Date(1465981200000L))));
assertThat(map, hasEntry(equalTo("d2"), equalTo(new Date(1491244560000L))));
assertThat(map, hasEntry(equalTo("l1"), equalTo(42L)));
assertThat(map, hasEntry(equalTo("l2"), equalTo(2017L)));
assertThat(map, hasEntry(equalTo("do1"), equalTo(3.5D)));
assertThat(map, hasEntry(equalTo("do2"), equalTo(25.2D)));
assertThat(map, hasEntry(equalTo("s1"), equalTo("Apio")));
assertThat(map, hasEntry(equalTo("s2"), equalTo("Hypermedia")));
BinaryFile binaryFile1 = (BinaryFile) map.get("f1");
assertThat(_readBinaryFile(binaryFile1), is("Input Stream 1"));
assertThat(binaryFile1.getMimeType(), is("mimetype1"));
BinaryFile binaryFile2 = (BinaryFile) map.get("f2");
assertThat(_readBinaryFile(binaryFile2), is("Input Stream 2"));
assertThat(binaryFile2.getMimeType(), is("mimetype2"));
}
Aggregations