Search in sources :

Example 11 with Form

use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.

the class FormEndpointTest method testValidCreatorFormMethodReturnsSuccess.

@Test
public void testValidCreatorFormMethodReturnsSuccess() {
    FormEndpoint formEndpoint = new FormEndpoint(__ -> Optional.of(_collectionRoutes()), __ -> Optional.empty(), (name, nestedName) -> Optional.empty());
    Try<Form> creatorFormTry = formEndpoint.creatorForm("");
    assertThat(creatorFormTry, is(aSuccessTry()));
    Form form = creatorFormTry.getUnchecked();
    assertThat(form.id, is("c/name"));
}
Also used : Form(com.liferay.apio.architect.form.Form) Test(org.junit.Test)

Example 12 with Form

use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.

the class FormConditionsTest method testInvokingMatchesUpdatedDescription.

@Test
public void testInvokingMatchesUpdatedDescription() {
    Builder<Map<String, Object>> builder = new Builder<>();
    FormConditions formConditions = builder.whereBoolean("boolean", isReturnedIn(__ -> null)).whereString("string", isReturnedIn(__ -> null)).build();
    Description description = new StringDescription();
    Form.Builder<Map<String, Object>> formBuilder = Form.Builder.empty();
    Form<Map<String, Object>> form = formBuilder.title(__ -> "title").description(__ -> "description").constructor(HashMap::new).build();
    boolean matchesElement = formConditions.matches(form);
    formConditions.describeMismatch(form, description);
    String expected = "was a Form...\n\t...that should have returned something that is " + "<true> instead of null\n\t...that should have returned " + "something that is \"String\" instead of null\n";
    assertThat(matchesElement, is(false));
    assertThat(description.toString(), is(expected));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) Map(java.util.Map) FormMatchers.isReturnedIn(com.liferay.apio.architect.test.util.form.FormMatchers.isReturnedIn) Is.is(org.hamcrest.core.Is.is) Form(com.liferay.apio.architect.form.Form) Builder(com.liferay.apio.architect.test.util.form.FormConditions.Builder) HashMap(java.util.HashMap) Test(org.junit.Test) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) Form(com.liferay.apio.architect.form.Form) Builder(com.liferay.apio.architect.test.util.form.FormConditions.Builder) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 13 with Form

use of com.liferay.apio.architect.form.Form in project com-liferay-apio-architect by liferay.

the class FormConditionsTest method testFormWithInvalidFieldsUpdatesDescription.

@Test
public void testFormWithInvalidFieldsUpdatesDescription() {
    Form.Builder<Map<String, Object>> builder = Form.Builder.empty();
    Form<Map<String, Object>> form = builder.title(__ -> "title").description(__ -> "description").constructor(HashMap::new).build();
    Builder<Map<String, Object>> formConditionsBuilder = new Builder<>();
    FormConditions<Map<String, Object>> formConditions = formConditionsBuilder.whereDouble("double", isReturnedIn(map -> null)).build();
    Description description = new StringDescription();
    formConditions.describeMismatch(form, description);
    String expected = "was a Form...\n\t...that should have returned something that is " + "<21.2> instead of null\n";
    assertThat(description.toString(), is(expected));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) Map(java.util.Map) FormMatchers.isReturnedIn(com.liferay.apio.architect.test.util.form.FormMatchers.isReturnedIn) Is.is(org.hamcrest.core.Is.is) Form(com.liferay.apio.architect.form.Form) Builder(com.liferay.apio.architect.test.util.form.FormConditions.Builder) HashMap(java.util.HashMap) Test(org.junit.Test) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) Form(com.liferay.apio.architect.form.Form) StringDescription(org.hamcrest.StringDescription) Builder(com.liferay.apio.architect.test.util.form.FormConditions.Builder) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Aggregations

Form (com.liferay.apio.architect.form.Form)13 Map (java.util.Map)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)6 Description (org.hamcrest.Description)6 Builder (com.liferay.apio.architect.test.util.form.FormConditions.Builder)5 FormMatchers.isReturnedIn (com.liferay.apio.architect.test.util.form.FormMatchers.isReturnedIn)5 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)5 StringDescription (org.hamcrest.StringDescription)5 Is.is (org.hamcrest.core.Is.is)5 Optional (java.util.Optional)4 JSONObjectBuilder (com.liferay.apio.architect.message.json.JSONObjectBuilder)3 Operation (com.liferay.apio.architect.operation.Operation)3 RequestInfo (com.liferay.apio.architect.request.RequestInfo)3 WriterUtil.getFieldsWriter (com.liferay.apio.architect.writer.util.WriterUtil.getFieldsWriter)3 Collections (java.util.Collections)3 List (java.util.List)3 Function (java.util.function.Function)3 JsonObject (com.google.gson.JsonObject)2 Try (com.liferay.apio.architect.functional.Try)2