Search in sources :

Example 11 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 isAJsonObjectWithTheSecondEmbedded.

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

Example 12 with Builder

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

the class JSONLDPageMessageMapperTest method testJSONLDPageMessageMapper.

@Test
public void testJSONLDPageMessageMapper() {
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    JsonObject jsonObject = MockPageWriter.write(httpHeaders, _pageMessageMapper);
    Builder builder = new Builder();
    Conditions conditions = builder.where("@context", is(aJsonArrayThat(contains(_theContext)))).where("@id", isALinkTo("localhost/p/name/id/root")).where("@type", containsTheTypes("Collection")).where("member", is(aJsonArrayThat(contains(_theMembers)))).where("numberOfItems", is(aJsonInt(equalTo(3)))).where("operation", is(aJsonArrayThat(_containsTheOperations))).where("totalItems", is(aJsonInt(equalTo(9)))).where("view", _isAJsonObjectWithTheView).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 13 with Builder

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

the class JSONLDTestUtil method aRootElementJsonObjectWithId.

/**
 * Returns a {@code Matcher} that checks if the field is a JSON object of a
 * {@code RootElement} that matches the provided ID.
 *
 * @param  id the ID of the {@code RootElement}
 * @param  addVocab whether the {@code @vocab} check must be added
 * @param  member whether this {@code RootElement} is added as a
 *         collection's member
 * @return the matcher
 */
public static Matcher<JsonElement> aRootElementJsonObjectWithId(String id, boolean addVocab, boolean member) {
    Builder builder = new Builder();
    List<Matcher<? super JsonElement>> theContext = new ArrayList<>();
    theContext.add(aJsonObjectWhere("embedded2", IS_A_TYPE_ID_JSON_OBJECT));
    theContext.add(aJsonObjectWhere("linked1", IS_A_TYPE_ID_JSON_OBJECT));
    theContext.add(aJsonObjectWhere("linked2", IS_A_TYPE_ID_JSON_OBJECT));
    theContext.add(aJsonObjectWhere("relatedCollection1", IS_A_TYPE_ID_JSON_OBJECT));
    theContext.add(aJsonObjectWhere("relatedCollection2", IS_A_TYPE_ID_JSON_OBJECT));
    if (addVocab) {
        theContext.add(aJsonObjectWhere("@vocab", is(aJsonString(equalTo("http://schema.org/")))));
        theContext.add(IS_A_LINK_TO_HYDRA_PROFILE);
    }
    Builder rootElementBuilder = builder.where("@context", is(aJsonArrayThat(contains(theContext)))).where("@id", isALinkTo("localhost/p/model/" + id)).where("@type", containsTheTypes("Type 1", "Type 2")).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(member)).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("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"));
    if (member) {
        return aJsonObjectWith(rootElementBuilder.build());
    }
    Conditions conditions = rootElementBuilder.where("operation", containsTheRootOperations()).build();
    return aJsonObjectWith(conditions);
}
Also used : Matcher(org.hamcrest.Matcher) JsonElement(com.google.gson.JsonElement) Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) ArrayList(java.util.ArrayList) 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