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);
}
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);
}
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)));
}
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))));
}
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)));
}
Aggregations