Search in sources :

Example 26 with Conditions

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

the class HALTestUtil 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) {
    Conditions.Builder builder = new Conditions.Builder();
    Matcher<JsonElement> aNestedObjectMatcher = aJsonObjectWhere("nested3", aJsonObjectWhere("string1", is(aJsonString(equalTo("id 3")))));
    Conditions firstEmbeddedLinkConditions = builder.where("linked3", isALinkTo("localhost/p/third-inner-model/fifth")).where("bidirectionalModel3", isALinkTo("localhost/p/first-inner-model/" + id)).where("relatedCollection3", isALinkTo("localhost/p/model/" + id + "/models")).build();
    Conditions conditions = builder.where("number1", is(aJsonInt(equalTo(42)))).where("string1", is(aJsonString(equalTo(id)))).where("_links", aJsonObjectWith(firstEmbeddedLinkConditions)).where("_embedded", aNestedObjectMatcher).build();
    return aJsonObjectWith(conditions);
}
Also used : JsonElement(com.google.gson.JsonElement) Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 27 with Conditions

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

the class HALTestUtil 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() {
    Conditions.Builder builder = new Conditions.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 aJsonObjectWith(conditions);
}
Also used : Conditions(com.liferay.apio.architect.test.util.json.Conditions)

Example 28 with Conditions

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

the class IsJsonObjectStringMatcherTest method testValidEmptyJsonObjectValidates.

@Test
public void testValidEmptyJsonObjectValidates() {
    String json = "{}";
    Conditions conditions = _builder.build();
    assertThat(json, is(aJsonObjectStringWith(conditions)));
}
Also used : JsonMatchers.aJsonString(com.liferay.apio.architect.test.util.json.JsonMatchers.aJsonString) Conditions(com.liferay.apio.architect.test.util.json.Conditions) Test(org.junit.Test)

Example 29 with Conditions

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

the class IsJsonObjectStringMatcherTest method testInvalidJsonObjectFails.

@Test
public void testInvalidJsonObjectFails() {
    String json = "{";
    Conditions conditions = _builder.build();
    assertThat(json, is(not(aJsonObjectStringWith(conditions))));
}
Also used : JsonMatchers.aJsonString(com.liferay.apio.architect.test.util.json.JsonMatchers.aJsonString) Conditions(com.liferay.apio.architect.test.util.json.Conditions) Test(org.junit.Test)

Example 30 with Conditions

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

the class ErrorWriterTest method testWriteErrorCreatesCorrectJsonObject.

@Test
public void testWriteErrorCreatesCorrectJsonObject() {
    ErrorMessageMapper errorMessageMapper = new TestErrorMessageMapper();
    APIError apiError = new APIError(new IllegalArgumentException(), "A title", "A description", "A type", 404);
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    Mockito.when(httpHeaders.getHeaderString("start")).thenReturn("true");
    Mockito.when(httpHeaders.getHeaderString("end")).thenReturn("true");
    String error = ErrorWriter.writeError(errorMessageMapper, apiError, httpHeaders);
    Conditions.Builder builder = new Conditions.Builder();
    Conditions conditions = builder.where("description", is(aJsonString(equalTo("A description")))).where("title", is(aJsonString(equalTo("A title")))).where("type", is(aJsonString(equalTo("A type")))).where("status", is(aJsonInt(equalTo(404)))).where("start", is(aJsonBoolean(true))).where("end", is(aJsonBoolean(true))).withStrictModeDeactivated().build();
    assertThat(error, is(aJsonObjectStringWith(conditions)));
}
Also used : HttpHeaders(javax.ws.rs.core.HttpHeaders) JSONObjectBuilder(com.liferay.apio.architect.message.json.JSONObjectBuilder) ErrorMessageMapper(com.liferay.apio.architect.message.json.ErrorMessageMapper) 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)

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