@Nonnull public static ResponseSpecification expectNoError() { return RestAssured.expect().body(RestRemoteApplicationCapabilities.ERROR, nullValue()); } }
@Nonnull public static ResponseSpecification applicationVersion(@Nonnull Matcher<?> versionMatcher) { return RestAssured.expect().body(RestRemoteApplicationCapabilities.APPLICATION_VERSION, versionMatcher); }
@Nonnull public static ResponseSpecification expectBody(@Nonnull String property, @Nonnull Matcher<?> bodyMatcher) { checkNotNull(property, "property"); checkNotNull(bodyMatcher, "bodyMatcher"); return RestAssured.expect().body(property, bodyMatcher); } }
@Nonnull public static ResponseSpecification capabilities(@Nonnull Matcher<?> capabilitiesMatcher) { return RestAssured.expect().body(RestRemoteApplicationCapabilities.CAPABILITIES, capabilitiesMatcher); }
@Nonnull public static ResponseSpecification applinksVersion(@Nonnull Matcher<?> versionMatcher) { return RestAssured.expect().body(RestRemoteApplicationCapabilities.APPLINKS_VERSION, versionMatcher); }
/** * Expect {@code feature} to be in a state described by {@code status} (enabled/disabled). * * @param feature feature to examine in the response * @param status expected status * @return expectation to use while making request to the Applinks features resource */ @Nonnull public static ResponseSpecification expectFeatureStatus(@Nonnull ApplinksFeatures feature, boolean status) { return RestAssured.expect().body(checkNotNull(feature, "feature").name(), Matchers.is(status)); }
@Nonnull public static ResponseSpecification expectCapability(@Nonnull final ApplinksCapabilities capability) { Objects.requireNonNull(capability, "capability"); return RestAssured.expect().body(RestAuthenticationStatus.CAPABILITIES, Matchers.hasItem(capability.name())); }
/** * @return expectation that the Status result indicates a working applink */ @Nonnull public static ResponseSpecification expectStatusWorking() { return RestAssured.expect() .body(RestApplinkStatus.WORKING, is(true)) .body(RestApplinkStatus.ERROR, nullValue()); }
@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 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); } }
/** * @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)); }
/** * NOTE: expectations about the response status provided using this method <i>may</i> be overridden * by expectations provided by subsequently invoking {@link #specification(ResponseSpecification)} or any * variant of {@code expectStatus()}. * * @param status expected status * @return this builder instance */ @Nonnull public B expectStatus(@Nonnull Response.Status status) { specification(expect().statusCode(checkNotNull(status, "status").getStatusCode())); return self(); }
@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())); }
/** * NOTE: expectations about the response status provided using this method <i>may</i> be overridden * by expectations provided by subsequently invoking {@link #specification(ResponseSpecification)} or any * variant of {@link #expectStatus(Response.Status)}. * * @param statusMatcher matcher for the expected status * @return this builder instance */ @Nonnull public B expectStatus(@Nonnull Matcher<Response.Status> statusMatcher) { specification(expect().statusCode(withStatus(statusMatcher))); return self(); }
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())); } }
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())); } }
@Test public void testNotFound() { final ResponseBody response = expect(). statusCode(404). contentType("text/html"). given(). header("Accept", "text/html"). when(). get(ConfigurationService.RESOURCE_PATH + "/foo"). getBody(); //response.print(); final ResponseBody responseJson = expect(). statusCode(404). contentType("application/json"). given(). header("Accept", "application/json"). when(). get(ConfigurationService.RESOURCE_PATH + "/foo"). getBody(); responseJson.print(); Assert.assertEquals(404, responseJson.jsonPath().get("status")); Assert.assertEquals("Not Found", responseJson.jsonPath().get("reason")); }