use of com.liferay.apio.architect.test.util.json.Conditions in project com-liferay-apio-architect by liferay.
the class HALTestUtil method isAJsonObjectWithTheLinks.
/**
* Returns a {@code Matcher} that checks if the field is a JSON object
* containing the links of a {@code RootElement} that matches the provided
* ID.
*
* @param id the ID of the {@code RootElement}
* @return the matcher
*/
public static Matcher<JsonElement> isAJsonObjectWithTheLinks(String id) {
Conditions.Builder builder = new Conditions.Builder();
Conditions linkConditions = builder.where("binary1", isALinkTo("localhost/b/model/" + id + "/binary1")).where("binary2", isALinkTo("localhost/b/model/" + id + "/binary2")).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("relatedCollection1", isALinkTo("localhost/p/model/" + id + "/models")).where("relatedCollection2", isALinkTo("localhost/p/model/" + id + "/models")).where("self", isALinkTo("localhost/p/model/" + id)).build();
return is(aJsonObjectWith(linkConditions));
}
use of com.liferay.apio.architect.test.util.json.Conditions in project com-liferay-apio-architect by liferay.
the class HALTestUtil method isAJsonObjectWithTheFirstEmbedded.
/**
* Returns a {@code Matcher} that checks if the field is a JSON object of
* the first embedded model.
*
* @param id
* @return the matcher
*/
public static Matcher<JsonElement> isAJsonObjectWithTheFirstEmbedded(String id) {
Conditions.Builder builder = new Conditions.Builder();
Conditions firstEmbeddedLinkConditions = builder.where("binary", isALinkTo("localhost/b/first-inner-model/first/binary")).where("link", isALinkTo("www.liferay.com")).where("linked", isALinkTo("localhost/p/second-inner-model/second")).where("relatedCollection", isALinkTo("localhost/p/first-inner-model/first/models")).where("self", isALinkTo("localhost/p/first-inner-model/first")).build();
Matcher<JsonElement> isAJsonObjectWithTheSecondEmbedded = is(aJsonObjectWhere("embedded", isAJsonObjectWithTheSecondEmbedded()));
Conditions firstEmbeddedConditions = builder.where("_embedded", isAJsonObjectWithTheSecondEmbedded).where("_links", is(aJsonObjectWith(firstEmbeddedLinkConditions))).where("boolean", is(aJsonBoolean(true))).where("booleanList", isAJsonArrayContaining(true, false)).where("localizedString", is(aJsonString(equalTo("Translated")))).where("number", is(aJsonInt(equalTo(42)))).where("numberList", isAJsonArrayContaining(1, 2)).where("string", is(aJsonString(equalTo("A string")))).where("stringList", isAJsonArrayContaining("a", "b")).build();
Conditions conditions = builder.where("embedded1", is(aJsonObjectWith(firstEmbeddedConditions))).where("nested1", isAJsonObjectWithTheFirstNested()).where("nested2", isAJsonObjectWithTheSecondNested(id)).build();
return is(aJsonObjectWith(conditions));
}
use of com.liferay.apio.architect.test.util.json.Conditions in project com-liferay-apio-architect by liferay.
the class HALTestUtil 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() {
Conditions.Builder builder = new Conditions.Builder();
Conditions secondEmbeddedLinkConditions = builder.where("binary", isALinkTo("localhost/b/second-inner-model/first/binary")).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("relatedCollection", isALinkTo("localhost/p/second-inner-model/first/models")).where("self", isALinkTo("localhost/p/second-inner-model/first")).build();
Conditions secondEmbeddedConditions = builder.where("_links", is(aJsonObjectWith(secondEmbeddedLinkConditions))).where("boolean", is(aJsonBoolean(false))).where("booleanList", isAJsonArrayContaining(true)).where("number", is(aJsonInt(equalTo(2017)))).where("numberList", isAJsonArrayContaining(1)).where("string", is(aJsonString(equalTo("A string")))).where("stringList", isAJsonArrayContaining("a")).build();
return is(aJsonObjectWith(secondEmbeddedConditions));
}
use of com.liferay.apio.architect.test.util.json.Conditions in project com-liferay-apio-architect by liferay.
the class JSONLDErrorMessageMapperTest 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("@type", is(aJsonString(equalTo("A type")))).where("description", is(aJsonString(equalTo("A description")))).where("statusCode", is(aJsonInt(equalTo(404)))).where("title", is(aJsonString(equalTo("A title")))).build();
assertThat(error, is(aJsonObjectStringWith(conditions)));
}
use of com.liferay.apio.architect.test.util.json.Conditions in project com-liferay-apio-architect by liferay.
the class JSONLDTestUtil method isAJsonObjectWithTheFirstEmbedded.
/**
* Returns a {@code Matcher} that checks if the field is a JSON object of
* the first embedded model.
*
* @param member whether the {@code FirstEmbeddedModel} is added as a
* collection member
* @return the matcher
*/
public static Matcher<JsonElement> isAJsonObjectWithTheFirstEmbedded(boolean member) {
Builder builder = new Builder();
List<Matcher<? super JsonElement>> theContext = Arrays.asList(aJsonObjectWhere("linked", IS_A_TYPE_ID_JSON_OBJECT), aJsonObjectWhere("relatedCollection", IS_A_TYPE_ID_JSON_OBJECT));
Builder firstEmbeddedBuilder = builder.where("@context", is(aJsonArrayThat(contains(theContext)))).where("@id", isALinkTo("localhost/p/first-inner-model/first")).where("@type", containsTheTypes("Type")).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("string", is(aJsonString(equalTo("A string")))).where("stringList", isAJsonArrayContaining("a", "b"));
if (member) {
return aJsonObjectWith(firstEmbeddedBuilder.build());
}
Matcher<? super JsonElement> anOperation = builder.where("@id", is(aJsonString(equalTo("_:delete-operation")))).where("@type", is(aJsonString(equalTo("Operation")))).where("method", is(aJsonString(equalTo("DELETE")))).build();
Conditions conditions = firstEmbeddedBuilder.where("operation", is(aJsonArrayThat(contains(anOperation)))).build();
return aJsonObjectWith(conditions);
}
Aggregations