/** * Set the response content type to be <code>contentType</code>. * <p>Note that this will affect the way the response is decoded. * E,g. if you can't use JSON/XML matching (see e.g. {@link #expectBody(String, org.hamcrest.Matcher)}) if you specify a * content-type of "text/plain". If you don't specify the response content type REST Assured will automatically try to * figure out which content type to use.</p> * * @param contentType The content type of the response. * @return The builder */ public ResponseSpecBuilder expectContentType(ContentType contentType) { spec.contentType(contentType); return this; }
/** * Set the response content type to be <code>contentType</code>. * <p>Note that this will affect the way the response is decoded. * E,g. if you can't use JSON/XML matching (see e.g. {@link #expectBody(String, org.hamcrest.Matcher)}) if you specify a * content-type of "text/plain". If you don't specify the response content type REST Assured will automatically try to * figure out which content type to use.</p> * * @param contentType The content type of the response. * @return The builder */ public ResponseSpecBuilder expectContentType(String contentType) { spec.contentType(contentType); return this; }
/** * Specify the expected response content type. * * @param contentType The content type * @deprecated Use {@link com.jayway.restassured.builder.ResponseSpecBuilder#expectContentType(com.jayway.restassured.http.ContentType)} and assign it to {@link #responseSpecification} instead. */ @Deprecated public static void responseContentType(ContentType contentType) { responseSpecification = (responseSpecification == null ? new ResponseSpecBuilder().build() : responseSpecification).contentType(contentType); }
/** * Specify the expected response content type. * * @param contentType The content type * @deprecated Use {@link com.jayway.restassured.builder.ResponseSpecBuilder#expectContentType(com.jayway.restassured.http.ContentType)} and assign it to {@link #responseSpecification} instead. */ @Deprecated public static void responseContentType(String contentType) { responseSpecification = (responseSpecification == null ? new ResponseSpecBuilder().build() : responseSpecification).contentType(contentType); }
@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 public void shouldAssambleRootResourcesXML() throws Exception { given(). then(). contentType(ROOT_XML_MEDIA_TYPE). body("root.link[0].@rel", equalTo("test")). body("root.link[0].@href", equalTo(new URL(baseURL, "api/test").toExternalForm())). when(). get(baseURL + "api/"); }
@Test public void shouldAssambleRootResourcesJSON() throws Exception { given(). then(). contentType(ROOT_JSON_MEDIA_TYPE). body("link[0].rel", equalTo("test")). body("link[0].href", equalTo(new URL(baseURL, "api/test").toExternalForm())). when(). get(baseURL + "api/"); }
@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(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(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(7) public void shouldBeAbleToGetSession() throws Exception { assertNotNull("Previous step failed", uri_sessionInstance); given(). then(). contentType(SESSION_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("session"). body("link.find {it.@rel == 'bookmark'}.size()", equalTo(1)). body("link.find {it.@rel == 'self'}.size()", equalTo(1)). body("link.find {it.@rel == 'parent'}.size()", equalTo(1)). when(). get(uri_sessionInstance); }
@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 @InSequence(2) public void shouldBeAbleToGetUser() throws Exception { assertNotNull("Previous step failed", uri_userInstance); given(). then(). contentType(USER_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). when(). get(uri_userInstance); }
@Test @InSequence(4) public void verifyUpdatedAttachment() throws Exception { assertNotNull("Previous step failed", uri_attachmentInstance); AttachmentType conf = getUpdateAttachment(); given(). then(). contentType(ATTACHMENT_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("attachment"). body("title", equalTo(conf.getTitle())). body("mimeType", equalTo(conf.getMimeType())). when(). get(uri_attachmentInstance); }
@Test @InSequence(9) public void verifyUpdatedSession() throws Exception { assertNotNull("Previous step failed", uri_sessionInstance); SessionType session = getUpdateSession(); given(). then(). contentType(SESSION_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). root("session"). body("title", equalTo(session.getTitle())). body("outline", equalTo(session.getOutline())). when(). get(uri_sessionInstance); }
private final Query queryResource(URL contextURL, String path) throws IOException { Response response= given(). accept(TEXT_TURTLE). baseUri(contextURL.toString()). expect(). statusCode(OK). contentType(TEXT_TURTLE). when(). get(path); return QueryResponseHelper.getQuery(contextURL, path, response.asString()); }
@Test public void testGetIcon_svgImageTypeFound() throws Exception { given().expect() // .statusCode(200).log().ifError() // .body(Matchers.containsString("</svg>")) // .contentType(IMAGE_SVG_VALUE) // .get(getVersionPrefix() + "/properties/{name}/icon/{type}", DATA_SET_DEFINITION_NAME, DefinitionImageType.SVG_ICON); }
@Test @InSequence(2) public void shouldBeAbleToGetAttachment() throws Exception { assertNotNull("Previous step failed", uri_attachmentInstance); given(). then(). contentType(ATTACHMENT_MEDIA_TYPE). statusCode(Status.OK.getStatusCode()). when(). get(uri_attachmentInstance). body(). path("attachment.link.find {it.@rel == 'session'}.@href"); }
@Override public void perform() { responseValidation( given(). then(). contentType(getTypedMediaType()) , domain). when(). get(createRootURL() + "/{id}", domain.getId()). body(); } }).inspect(new SetupRepository<DOMAIN>(getDomainClass(), domain));
@Test public void testGetIcon_pngImageTypeFound() throws Exception { given().expect() // .contentType(IMAGE_PNG_VALUE) // .body(Matchers.startsWith("\uFFFDPNG")) // Magic header for PNG files. .statusCode(200).log().ifError() // .get(getVersionPrefix() + "/properties/{name}/icon/{type}", DATA_STORE_DEFINITION_NAME, DefinitionImageType.PALETTE_ICON_32X32); }