use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.
the class FormEndpointTest method testValidNestedCreatorFormMethodReturnsSuccess.
@Test
public void testValidNestedCreatorFormMethodReturnsSuccess() {
FormEndpoint formEndpoint = new FormEndpoint(__ -> Optional.empty(), __ -> Optional.empty(), (name, nestedName) -> Optional.of(_nestedCollectionRoutes()));
Try<Form> nestedCreatorFormTry = formEndpoint.nestedCreatorForm("", "");
assertThat(nestedCreatorFormTry, is(aSuccessTry()));
Form form = nestedCreatorFormTry.getUnchecked();
assertThat(form.id, is("c/name/nestedName"));
}
use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.
the class FormEndpointTest method testValidUpdaterFormMethodReturnsSuccess.
@Test
public void testValidUpdaterFormMethodReturnsSuccess() {
FormEndpoint formEndpoint = new FormEndpoint(__ -> Optional.empty(), __ -> Optional.of(_itemRoutes()), (name, nestedName) -> Optional.empty());
Try<Form> updaterFormTry = formEndpoint.updaterForm("");
assertThat(updaterFormTry, is(aSuccessTry()));
Form form = updaterFormTry.getUnchecked();
assertThat(form.id, is("u/name"));
}
use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.
the class FormMessageBodyWriter method writeTo.
@Override
public void writeTo(Success<Form> success, Class<?> aClass, Type type, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream outputStream) throws IOException, WebApplicationException {
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream, StandardCharsets.UTF_8);
PrintWriter printWriter = new PrintWriter(outputStreamWriter, true);
Form form = success.getValue();
Optional<FormMessageMapper> optional = _formMessageMapperManager.getFormMessageMapperOptional(_request);
FormMessageMapper formMessageMapper = optional.orElseThrow(NotSupportedException::new);
RequestInfo requestInfo = RequestInfo.create(builder -> builder.httpHeaders(_httpHeaders).httpServletRequest(_httpServletRequest).serverURL(_providerManager.provideMandatory(_httpServletRequest, ServerURL.class)).embedded(_providerManager.provideOptional(_httpServletRequest, Embedded.class).orElse(__ -> false)).fields(_providerManager.provideOptional(_httpServletRequest, Fields.class).orElse(__ -> string -> true)).language(_providerManager.provideOptional(_httpServletRequest, Language.class).orElse(Locale::getDefault)).build());
FormWriter formWriter = FormWriter.create(builder -> builder.form(form).formMessageMapper(formMessageMapper).requestInfo(requestInfo).build());
httpHeaders.put(CONTENT_TYPE, Collections.singletonList(formMessageMapper.getMediaType()));
printWriter.println(formWriter.write());
printWriter.close();
}
use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.
the class FormConditionsTest method testInvokingDescribesToUpdatesDescription.
@Test
public void testInvokingDescribesToUpdatesDescription() {
Builder<Map<String, Object>> builder = new Builder<>();
FormConditions formConditions = builder.whereBoolean("boolean", isReturnedIn(map -> map.get("boolean"))).whereString("string", isReturnedIn(map -> map.get("string"))).build();
Description description = new StringDescription();
formConditions.describeTo(description);
StringBuilder stringBuilder = new StringBuilder();
String expected = stringBuilder.append("a Form...\n\t...that should have a non empty title\n\t...that ").append("should have a non empty description\n\t...that should return ").append("something that is <true>\n\t...that should return something that ").append("is \"String\"\n").toString();
assertThat(description.toString(), is(expected));
}
use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.
the class FormConditionsTest method testFormWithInvalidTitleUpdatesDescription.
@Test
public void testFormWithInvalidTitleUpdatesDescription() {
Form.Builder<Map<String, Object>> builder = Form.Builder.empty();
Form<Map<String, Object>> form = builder.title(__ -> "").description(__ -> "description").constructor(HashMap::new).build();
Builder<Map<String, Object>> formConditionsBuilder = new Builder<>();
FormConditions<Map<String, Object>> formConditions = formConditionsBuilder.whereString("string", isReturnedIn(map -> null)).build();
Description description = new StringDescription();
formConditions.describeMismatch(form, description);
String expected = "was a Form...\n\t...whose title was (null or an empty string)" + "\n\t...that should have returned something that is " + "\"String\" instead of null\n";
assertThat(description.toString(), is(expected));
}
Aggregations