Search in sources :

Example 6 with Conditions

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

the class JSONLDTestUtil 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() {
    List<Matcher<? super JsonElement>> theContext = Arrays.asList(aJsonObjectWhere("embedded", IS_A_TYPE_ID_JSON_OBJECT), aJsonObjectWhere("linked", IS_A_TYPE_ID_JSON_OBJECT), aJsonObjectWhere("relatedCollection", IS_A_TYPE_ID_JSON_OBJECT));
    Conditions.Builder builder = new Conditions.Builder();
    Conditions secondEmbeddedConditions = builder.where("@context", is(aJsonArrayThat(contains(theContext)))).where("@id", isALinkTo("localhost/p/second-inner-model/first")).where("@type", containsTheTypes("Type")).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("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) Matcher(org.hamcrest.Matcher) JsonElement(com.google.gson.JsonElement) Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 7 with Conditions

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

the class JSONLDTestUtil method containsTheRootOperations.

/**
 * Returns a {@code Matcher} that checks if the field contains the {@code
 * RootModel} operations.
 *
 * @return the matcher
 */
public static Matcher<? extends JsonElement> containsTheRootOperations() {
    Builder builder = new Builder();
    Conditions firstOperationConditions = builder.where("@id", is(aJsonString(equalTo("_:delete-operation")))).where("@type", is(aJsonString(equalTo("Operation")))).where("method", is(aJsonString(equalTo("DELETE")))).build();
    Conditions secondOperationConditions = builder.where("@id", is(aJsonString(equalTo("_:update-operation")))).where("@type", is(aJsonString(equalTo("Operation")))).where("expects", is(aJsonString(equalTo("localhost/f/u/r")))).where("method", is(aJsonString(equalTo("PUT")))).build();
    List<Matcher<? super JsonElement>> theOperations = Arrays.asList(is(aJsonObjectWith(firstOperationConditions)), is(aJsonObjectWith(secondOperationConditions)));
    return is(aJsonArrayThat(contains(theOperations)));
}
Also used : Matcher(org.hamcrest.Matcher) JsonElement(com.google.gson.JsonElement) Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 8 with Conditions

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

the class JSONLDTestUtil 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("@type", containsTheTypes("Type 3")).where("number1", is(aJsonInt(equalTo(2017)))).where("string1", is(aJsonString(equalTo("id 1")))).where("string2", is(aJsonString(equalTo("string2")))).build();
    return 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 Conditions

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

the class JSONLDTestUtil 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) {
    List<Matcher<? super JsonElement>> theContext = Arrays.asList(aJsonObjectWhere("bidirectionalModel3", IS_A_TYPE_ID_JSON_OBJECT), aJsonObjectWhere("linked3", IS_A_TYPE_ID_JSON_OBJECT), aJsonObjectWhere("relatedCollection3", IS_A_TYPE_ID_JSON_OBJECT));
    Builder builder = new Builder();
    Conditions secondNestedConditions = builder.where("@context", is(aJsonArrayThat(contains(theContext)))).where("@type", containsTheTypes("Type 4")).where("bidirectionalModel3", isALinkTo("localhost/p/first-inner-model/" + id)).where("linked3", isALinkTo("localhost/p/third-inner-model/fifth")).where("nested3", isAJsonObjectWithTheThirdNested()).where("number1", is(aJsonInt(equalTo(42)))).where("relatedCollection3", isALinkTo("localhost/p/model/" + id + "/models")).where("string1", is(aJsonString(equalTo(id)))).build();
    return aJsonObjectWith(secondNestedConditions);
}
Also used : Matcher(org.hamcrest.Matcher) JsonElement(com.google.gson.JsonElement) Builder(com.liferay.apio.architect.test.util.json.Conditions.Builder) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 10 with Conditions

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

the class HALPageMessageMapperTest method testHALPageMessageMapper.

@Test
public void testHALPageMessageMapper() {
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    JsonObject jsonObject = MockPageWriter.write(httpHeaders, _pageMessageMapper);
    Conditions.Builder builder = new Conditions.Builder();
    Conditions conditions = builder.where("_embedded", _isAJsonObjectWithTheEmbedded).where("_links", _isAJsonObjectWithTheLinks).where("count", is(aJsonInt(equalTo(3)))).where("total", is(aJsonInt(equalTo(9)))).build();
    assertThat(jsonObject, is(aJsonObjectWith(conditions)));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) JsonObject(com.google.gson.JsonObject) Conditions(com.liferay.apio.architect.test.util.json.Conditions) Test(org.junit.Test)

Aggregations

Conditions (com.liferay.apio.architect.test.util.json.Conditions)30 Builder (com.liferay.apio.architect.test.util.json.Conditions.Builder)13 Test (org.junit.Test)13 JsonMatchers.aJsonString (com.liferay.apio.architect.test.util.json.JsonMatchers.aJsonString)8 HttpHeaders (javax.ws.rs.core.HttpHeaders)8 JsonElement (com.google.gson.JsonElement)7 JsonObject (com.google.gson.JsonObject)5 Matcher (org.hamcrest.Matcher)5 APIError (com.liferay.apio.architect.error.APIError)3 Description (org.hamcrest.Description)3 StringDescription (org.hamcrest.StringDescription)3 ErrorMessageMapper (com.liferay.apio.architect.message.json.ErrorMessageMapper)1 JSONObjectBuilder (com.liferay.apio.architect.message.json.JSONObjectBuilder)1 ArrayList (java.util.ArrayList)1