/** * Expect that the response content conforms to one or more Hamcrest matchers. * * @param matcher The hamcrest matcher that must response content must match. * @return The builder */ public ResponseSpecBuilder expectBody(Matcher<?> matcher) { spec.body(matcher); return this; }
spec.body(path, arguments, matcher); return this;
spec.body(path, matcher); return this;
@Nonnull public static ResponseSpecification expectBody(@Nonnull String property, @Nonnull Matcher<?> bodyMatcher) { checkNotNull(property, "property"); checkNotNull(bodyMatcher, "bodyMatcher"); return RestAssured.expect().body(property, bodyMatcher); } }
private static ResponseSpecification expectAuthenticationConfig(String prefix, final AuthenticationConfig config) { Objects.requireNonNull(config, "config"); return RestAssured.expect() .body(prefix, notNullValue()) .body(prefix + "." + RestAuthenticationConfig.OAUTH, Matchers.is(config.isOAuthConfigured())) .body(prefix + "." + RestAuthenticationConfig.BASIC, Matchers.is(config.isBasicConfigured())) .body(prefix + "." + RestAuthenticationConfig.TRUSTED, Matchers.is(config.isTrustedConfigured())); } }
/** * @param applinkId expected applink ID * @return expectation that the Status result will be mapped to {@code applinkId} */ @Nonnull public static ResponseSpecification expectStatusWithApplink(@Nonnull String applinkId) { checkNotNull(applinkId, "applinkId"); return RestAssured.expect() .body(RestApplinkStatus.LINK, notNullValue()) .body(jsonPath(RestApplinkStatus.LINK, RestMinimalApplicationLink.ID), is(applinkId)); }
private static ResponseSpecification expectConfig(String prefix, OAuthConfig expectedConfig) { checkNotNull(expectedConfig, "expectedConfig"); return RestAssured.expect() .body(prefix, notNullValue()) .body(prefix + "." + RestOAuthConfig.ENABLED, Matchers.is(expectedConfig.isEnabled())) .body(prefix + "." + RestOAuthConfig.TWO_LO_ENABLED, Matchers.is(expectedConfig.isTwoLoEnabled())) .body(prefix + "." + RestOAuthConfig.TWO_LO_IMPERSONATION_ENABLED, Matchers.is(expectedConfig.isTwoLoImpersonationEnabled())); } }
@Nonnull public static ResponseSpecification expectNoError() { return RestAssured.expect().body(RestRemoteApplicationCapabilities.ERROR, nullValue()); } }
@Nonnull public static ResponseSpecification expectErrorDetails(@Nullable String path, @Nonnull Matcher<?> detailsMatcher) { checkNotNull(detailsMatcher, "detailsMatcher"); path = nullToEmpty(path); return RestAssured.expect() .body(path, notNullValue()) .body(jsonPath(path, RestApplinkError.DETAILS), detailsMatcher); } }
@Nonnull public static ResponseSpecification expectCapability(@Nonnull final ApplinksCapabilities capability) { Objects.requireNonNull(capability, "capability"); return RestAssured.expect().body(RestAuthenticationStatus.CAPABILITIES, Matchers.hasItem(capability.name())); }
@Nonnull public static ResponseSpecification expectAuthorisationUri(@Nonnull Matcher<?> authorisationUriMatcher) { checkNotNull(authorisationUriMatcher, "authorisationUriMatcher"); return RestAssured.expect() .body(jsonPath(RestApplinkStatus.ERROR, RestAuthorisationUriAwareApplinkError.AUTHORISATION_URI), authorisationUriMatcher); }
@Nonnull public static ResponseSpecification expectErrorType(@Nullable String path, @Nonnull ApplinkErrorType errorType) { checkNotNull(errorType, "errorType"); path = nullToEmpty(path); return RestAssured.expect() .body(path, notNullValue()) .body(jsonPath(path, RestApplinkError.TYPE), is(errorType.name())) .body(jsonPath(path, RestApplinkError.CATEGORY), is(errorType.getCategory().name())); }
@Override protected ResponseSpecification responseValidation(ResponseSpecification spec, Conference conference) { return spec. root("conference"). body("name", equalTo(conference.getName())). body("tagLine", equalTo(conference.getTagLine())). body("start", equalToXmlDate(conference.getDuration().getStart())). body("end", equalToXmlDate(conference.getDuration().getEnd())); }
@Test public void shouldProvideBookmarkLinkToResource() throws Exception { given(). contentType(TEST_MEDIA_TYPE). then(). contentType(TEST_MEDIA_TYPE). statusCode(Response.Status.OK.getStatusCode()). body("test.link.find {it.@rel == 'bookmark'}.size()", equalTo(1)). body("test.link.@href", equalTo(new URL(baseURL, "api/bookmark/test/200").toExternalForm())). when(). get(baseURL + "api/test/200"); }
@Test @InSequence(0) public void shouldNotBeAbleToLocateUserRoot() throws Exception { given(). then(). contentType(BASE_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("root"). body("link.find {it.@rel == 'user'}.size()", equalTo(0)). when(). get(new URL(base, "api/").toExternalForm()). body(); }
@Test @InSequence(0) public void shouldNotBeAbleToLocateAttachmentRoot() throws Exception { given(). then(). contentType(BASE_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("root"). body("link.find {it.@rel == 'attachment'}.size()", equalTo(0)). when(). get(new URL(base, "api/").toExternalForm()). body(); }
@Test @InSequence(2) public void shouldBeAbleToFindRelation() throws Exception { given(). then(). contentType(BASE_JSON_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). body("[0].id", equalTo(TARGET_ID)). when(). get(baseURL + "api/rel/{sourceObj}/{source}/{rel}/{targetObj}", "sourceobject", SOURCE_ID, type, "targetobject"); }
@Test @InSequence(6) public void shouldBeAbleToGetSessionsForAConference() throws Exception { assertNotNull("Previous step failed", uri_session); given(). then(). contentType(SESSION_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("collection"). body("session.size()", equalTo(1)). when(). get(uri_session); }
@Test public void testGetConnectors_badDefinition() throws Exception { given().expect() // .statusCode(400) // .log().ifValidationFails() // // TODO: check returned error .body(Matchers.containsString("definitionClass")) // .get(getVersionPrefix() + "/properties/{name}/connectors", DATA_SET_DEFINITION_NAME); }