Search in sources :

Example 6 with Builder

use of com.liferay.apio.architect.test.util.json.Conditions.Builder in project com-liferay-apio-architect by liferay.

the class PlainJSONTestUtil method isAJsonObjectWithTheSecondNested.

/**
 * Returns a {@code Matcher} that checks if the field is a JSON object of
 * the second nested model.
 *
 * @return the matcher
 */
public static Matcher<JsonElement> isAJsonObjectWithTheSecondNested(String id) {
    Builder builder = new Builder();
    Conditions conditions = builder.where("bidirectionalModel3", isALinkTo("localhost/p/first-inner-model/" + id)).where("linked3", is(isALinkTo("localhost/p/third-inner-model/fifth"))).where("nested3", aJsonObjectWhere("string1", is(aJsonString(equalTo("id 3"))))).where("number1", is(aJsonInt(equalTo(42)))).where("relatedCollection3", is(isALinkTo("localhost/p/model/" + id + "/models"))).where("string1", is(aJsonString(equalTo(id)))).build();
    return is(aJsonObjectWith(conditions));
}
Also used : Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 7 with Builder

use of com.liferay.apio.architect.test.util.json.Conditions.Builder in project com-liferay-apio-architect by liferay.

the class PlainJSONPageMessageMapperTest method testPlainJSONPageMessageMapper.

@Test
public void testPlainJSONPageMessageMapper() {
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    JsonObject jsonObject = MockPageWriter.write(httpHeaders, _pageMessageMapper);
    Builder builder = new Builder();
    Conditions conditions = builder.where("collection", isALinkTo("localhost/p/name/id/root")).where("elements", is(aJsonArrayThat(_containsTheElements))).where("numberOfItems", is(aJsonInt(equalTo(3)))).where("pages", _isAJsonObjectWithThePages).where("self", isALinkTo("localhost/p/name/id/root?page=2&per_page=3")).where("totalNumberOfItems", is(aJsonInt(equalTo(9)))).build();
    assertThat(jsonObject, is(aJsonObjectWith(conditions)));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) JsonObject(com.google.gson.JsonObject) Conditions(com.liferay.apio.architect.test.util.json.Conditions) Test(org.junit.Test)

Example 8 with Builder

use of com.liferay.apio.architect.test.util.json.Conditions.Builder in project com-liferay-apio-architect by liferay.

the class PlainJSONTestUtil method aRootElementJsonObjectWithId.

/**
 * Returns a {@code Matcher} that checks if the field is the JSON Object of
 * a {@code RootElement} with the provided ID.
 *
 * @param  id the ID of the {@code RootElement}
 * @return the matcher
 */
public static Matcher<JsonElement> aRootElementJsonObjectWithId(String id) {
    Builder builder = new Builder();
    Conditions conditions = builder.where("binary1", isALinkTo("localhost/b/model/" + id + "/binary1")).where("binary2", isALinkTo("localhost/b/model/" + id + "/binary2")).where("boolean1", is(aJsonBoolean(true))).where("boolean2", is(aJsonBoolean(false))).where("booleanList1", isAJsonArrayContaining(true, true, false, false)).where("booleanList2", isAJsonArrayContaining(true, false, true, false)).where("date1", is(aJsonString(equalTo("2016-06-15T09:00Z")))).where("date2", is(aJsonString(equalTo("2017-04-03T18:36Z")))).where("embedded1", isAJsonObjectWithTheFirstEmbedded()).where("embedded2", isALinkTo("localhost/p/first-inner-model/second")).where("link1", isALinkTo("www.liferay.com")).where("link2", isALinkTo("community.liferay.com")).where("linked1", isALinkTo("localhost/p/first-inner-model/third")).where("linked2", isALinkTo("localhost/p/first-inner-model/fourth")).where("localizedString1", is(aJsonString(equalTo("Translated 1")))).where("localizedString2", is(aJsonString(equalTo("Translated 2")))).where("nested1", isAJsonObjectWithTheFirstNested()).where("nested2", isAJsonObjectWithTheSecondNested(id)).where("number1", is(aJsonInt(equalTo(2017)))).where("number2", is(aJsonInt(equalTo(42)))).where("numberList1", isAJsonArrayContaining(1, 2, 3, 4, 5)).where("numberList2", isAJsonArrayContaining(6, 7, 8, 9, 10)).where("relatedCollection1", isALinkTo("localhost/p/model/" + id + "/models")).where("relatedCollection2", isALinkTo("localhost/p/model/" + id + "/models")).where("self", isALinkTo("localhost/p/model/" + id)).where("string1", is(aJsonString(equalTo("Live long and prosper")))).where("string2", is(aJsonString(equalTo("Hypermedia")))).where("stringList1", isAJsonArrayContaining("a", "b", "c", "d", "e")).where("stringList2", isAJsonArrayContaining("f", "g", "h", "i", "j")).build();
    return is(aJsonObjectWith(conditions));
}
Also used : Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 9 with Builder

use of com.liferay.apio.architect.test.util.json.Conditions.Builder in project com-liferay-apio-architect by liferay.

the class PlainJSONTestUtil method isAJsonObjectWithTheFirstEmbedded.

/**
 * Returns a {@code Matcher} that checks if the field is a JSON object of
 * the first embedded model.
 *
 * @return the matcher
 */
public static Matcher<JsonElement> isAJsonObjectWithTheFirstEmbedded() {
    Conditions.Builder builder = new Conditions.Builder();
    Conditions firstEmbeddedConditions = builder.where("binary", isALinkTo("localhost/b/first-inner-model/first/binary")).where("boolean", is(aJsonBoolean(true))).where("booleanList", isAJsonArrayContaining(true, false)).where("embedded", isAJsonObjectWithTheSecondEmbedded()).where("link", isALinkTo("www.liferay.com")).where("linked", isALinkTo("localhost/p/second-inner-model/second")).where("localizedString", is(aJsonString(equalTo("Translated")))).where("number", is(aJsonInt(equalTo(42)))).where("numberList", isAJsonArrayContaining(1, 2)).where("relatedCollection", isALinkTo("localhost/p/first-inner-model/first/models")).where("self", isALinkTo("localhost/p/first-inner-model/first")).where("string", is(aJsonString(equalTo("A string")))).where("stringList", isAJsonArrayContaining("a", "b")).build();
    return is(aJsonObjectWith(firstEmbeddedConditions));
}
Also used : Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 10 with Builder

use of com.liferay.apio.architect.test.util.json.Conditions.Builder in project com-liferay-apio-architect by liferay.

the class PlainJSONTestUtil method isAJsonObjectWithTheFirstNested.

/**
 * Returns a {@code Matcher} that checks if the field is a JSON object of
 * the first nested model.
 *
 * @return the matcher
 */
public static Matcher<JsonElement> isAJsonObjectWithTheFirstNested() {
    Builder builder = new Builder();
    Conditions conditions = builder.where("number1", is(aJsonInt(equalTo(2017)))).where("string1", is(aJsonString(equalTo("id 1")))).where("string2", is(aJsonString(equalTo("string2")))).build();
    return is(aJsonObjectWith(conditions));
}
Also used : Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Aggregations

Conditions (com.liferay.apio.architect.test.util.json.Conditions)13 Builder (com.liferay.apio.architect.test.util.json.Conditions.Builder)13 JsonElement (com.google.gson.JsonElement)5 Matcher (org.hamcrest.Matcher)5 JsonObject (com.google.gson.JsonObject)2 HttpHeaders (javax.ws.rs.core.HttpHeaders)2 Test (org.junit.Test)2 ArrayList (java.util.ArrayList)1