Search in sources :

Example 11 with Conditions

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

the class JSONLDDocumentationMessageMapperTest method testJSONLDDocumentationMessageMapper.

@Test
public void testJSONLDDocumentationMessageMapper() {
    HttpHeaders httpHeaders = Mockito.mock(HttpHeaders.class);
    JsonObject jsonObject = MockDocumentationWriter.write(httpHeaders, _documentationMessageMapper);
    Conditions.Builder builder = new Conditions.Builder();
    Conditions conditions = builder.where("@context", IS_A_LINK_TO_HYDRA_PROFILE).where("@id", is(aJsonString(equalTo("http://api.example.com/doc/")))).where("@type", is(aJsonString(equalTo("ApiDocumentation")))).where("description", is(aJsonString(equalTo("Description")))).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 12 with Conditions

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

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

the class IsJsonObjectStringMatcherTest method testInvalidJsonObjectWithMultiConditionUpdatesDescription.

@Test
public void testInvalidJsonObjectWithMultiConditionUpdatesDescription() {
    Conditions conditions = _builder.where("apio", is(aJsonString(equalTo("Live long and prosper")))).where("geek", is(aJsonBoolean(true))).build();
    Matcher<String> stringMatcher = aJsonObjectStringWith(conditions);
    Description description = new StringDescription();
    stringMatcher.describeMismatch("{}", description);
    String expected = "was a JSON object {\n  apio: was null\n  geek: was null\n}";
    assertThat(description.toString(), is(expected));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) 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 14 with Conditions

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

the class IsJsonObjectStringMatcherTest method testIsJsonMatcherUpdatesDescription.

@Test
public void testIsJsonMatcherUpdatesDescription() {
    Conditions conditions = _builder.build();
    Matcher<String> stringMatcher = aJsonObjectStringWith(conditions);
    Description description = new StringDescription();
    stringMatcher.describeTo(description);
    assertThat(description.toString(), is("a JSON object where {\n}"));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) 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 15 with Conditions

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

the class IsJsonObjectStringMatcherTest method testInvalidJsonObjectUpdatesValidDescription.

@Test
public void testInvalidJsonObjectUpdatesValidDescription() {
    Conditions conditions = _builder.build();
    Matcher<String> stringMatcher = aJsonObjectStringWith(conditions);
    Description description = new StringDescription();
    stringMatcher.describeMismatch("{", description);
    assertThat(description.toString(), is("was not a JSON object"));
}
Also used : Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) StringDescription(org.hamcrest.StringDescription) JsonMatchers.aJsonString(com.liferay.apio.architect.test.util.json.JsonMatchers.aJsonString) 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