Search in sources :

Example 1 with LONG_LIST

use of com.liferay.apio.architect.form.FieldType.LONG_LIST 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"));
}
Also used : DOUBLE_LIST(com.liferay.apio.architect.form.FieldType.DOUBLE_LIST) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) Date(java.util.Date) Matchers.emptyString(org.hamcrest.Matchers.emptyString) HashMap(java.util.HashMap) Function(java.util.function.Function) Builder(com.liferay.apio.architect.form.Form.Builder) ByteArrayInputStream(java.io.ByteArrayInputStream) Arrays.asList(java.util.Arrays.asList) Locale(java.util.Locale) DATE_LIST(com.liferay.apio.architect.form.FieldType.DATE_LIST) Map(java.util.Map) Is.is(org.hamcrest.core.Is.is) STRING(com.liferay.apio.architect.form.FieldType.STRING) BadRequestException(javax.ws.rs.BadRequestException) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) BOOLEAN(com.liferay.apio.architect.form.FieldType.BOOLEAN) IsMapContaining.hasEntry(org.hamcrest.collection.IsMapContaining.hasEntry) BinaryFile(com.liferay.apio.architect.file.BinaryFile) Try(com.liferay.apio.architect.functional.Try) FILE_LIST(com.liferay.apio.architect.form.FieldType.FILE_LIST) UTF_8(java.nio.charset.StandardCharsets.UTF_8) FILE(com.liferay.apio.architect.form.FieldType.FILE) Test(org.junit.Test) InputStreamReader(java.io.InputStreamReader) LONG(com.liferay.apio.architect.form.FieldType.LONG) IsCollectionWithSize.hasSize(org.hamcrest.collection.IsCollectionWithSize.hasSize) List(java.util.List) Language(com.liferay.apio.architect.language.Language) BOOLEAN_LIST(com.liferay.apio.architect.form.FieldType.BOOLEAN_LIST) Matchers.contains(org.hamcrest.Matchers.contains) STRING_LIST(com.liferay.apio.architect.form.FieldType.STRING_LIST) Optional(java.util.Optional) DOUBLE(com.liferay.apio.architect.form.FieldType.DOUBLE) BufferedReader(java.io.BufferedReader) DATE(com.liferay.apio.architect.form.FieldType.DATE) LONG_LIST(com.liferay.apio.architect.form.FieldType.LONG_LIST) Collections(java.util.Collections) Builder(com.liferay.apio.architect.form.Form.Builder) Matchers.emptyString(org.hamcrest.Matchers.emptyString) BinaryFile(com.liferay.apio.architect.file.BinaryFile) Date(java.util.Date) Language(com.liferay.apio.architect.language.Language) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

BinaryFile (com.liferay.apio.architect.file.BinaryFile)1 BOOLEAN (com.liferay.apio.architect.form.FieldType.BOOLEAN)1 BOOLEAN_LIST (com.liferay.apio.architect.form.FieldType.BOOLEAN_LIST)1 DATE (com.liferay.apio.architect.form.FieldType.DATE)1 DATE_LIST (com.liferay.apio.architect.form.FieldType.DATE_LIST)1 DOUBLE (com.liferay.apio.architect.form.FieldType.DOUBLE)1 DOUBLE_LIST (com.liferay.apio.architect.form.FieldType.DOUBLE_LIST)1 FILE (com.liferay.apio.architect.form.FieldType.FILE)1 FILE_LIST (com.liferay.apio.architect.form.FieldType.FILE_LIST)1 LONG (com.liferay.apio.architect.form.FieldType.LONG)1 LONG_LIST (com.liferay.apio.architect.form.FieldType.LONG_LIST)1 STRING (com.liferay.apio.architect.form.FieldType.STRING)1 STRING_LIST (com.liferay.apio.architect.form.FieldType.STRING_LIST)1 Builder (com.liferay.apio.architect.form.Form.Builder)1 Try (com.liferay.apio.architect.functional.Try)1 Language (com.liferay.apio.architect.language.Language)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1