Search in sources :

Example 16 with Conditions

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

the class ProblemJSONErrorMessageMapperTest method testJSONLDErrorMessageMapper.

@Test
public void testJSONLDErrorMessageMapper() {
    APIError apiError = new APIError(new IllegalArgumentException(), "A title", "A description", "A type", 404);
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    String error = ErrorWriter.writeError(_errorMessageMapper, apiError, httpHeaders);
    Conditions.Builder builder = new Conditions.Builder();
    Conditions conditions = builder.where("detail", is(aJsonString(equalTo("A description")))).where("status", is(aJsonInt(equalTo(404)))).where("title", is(aJsonString(equalTo("A title")))).where("type", is(aJsonString(equalTo("A type")))).build();
    assertThat(error, is(aJsonObjectStringWith(conditions)));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) JsonMatchers.aJsonString(com.liferay.apio.architect.test.util.json.JsonMatchers.aJsonString) APIError(com.liferay.apio.architect.error.APIError) Conditions(com.liferay.apio.architect.test.util.json.Conditions) Test(org.junit.Test)

Example 17 with Conditions

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

the class JSONLDFormMessageMapperTest method testJSONLDFormMessageMapper.

@Test
public void testJSONLDFormMessageMapper() {
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    JsonObject jsonObject = MockFormWriter.write(httpHeaders, _formMessageMapper);
    Conditions.Builder builder = new Conditions.Builder();
    Conditions conditions = builder.where("@context", is(aJsonArrayThat(contains(_theContext)))).where("@id", isALinkTo("localhost/f/f/s")).where("@type", is(aJsonString(equalTo("Class")))).where("description", is(aJsonString(equalTo("description")))).where("supportedProperty", is(aJsonArrayThat(contains(_theProperties)))).where("title", is(aJsonString(equalTo("title")))).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)

Example 18 with Conditions

use of com.liferay.apio.architect.test.util.json.Conditions 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 19 with Conditions

use of com.liferay.apio.architect.test.util.json.Conditions 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 20 with Conditions

use of com.liferay.apio.architect.test.util.json.Conditions 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)

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