Java Code Examples for com.jayway.restassured.response.Response#asString()
The following examples show how to use
com.jayway.restassured.response.Response#asString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DataSetAPITest.java From data-prep with Apache License 2.0 | 6 votes |
@Test public void shouldCopyDataset() throws Exception { // given final String originalId = testClient.createDataset("dataset/dataset.csv", "original"); // when final Response response = given() .param("name", "copy") // .when() // .expect() // .statusCode(200) // .log() // .ifError() // .post("/api/datasets/{id}/copy", originalId); // then assertThat(response.getStatusCode(), is(200)); String copyId = response.asString(); assertNotNull(dataSetMetadataRepository.get(copyId)); }
Example 2
Source File: DataSetAPITest.java From data-prep with Apache License 2.0 | 6 votes |
/** * DataSet deletion test case when the dataset is used by a preparation. */ @Test public void testDataSetDeleteWhenUsedByPreparation() throws Exception { // given final String dataSetId = testClient.createDataset("dataset/dataset.csv", "testDataset"); testClient.createPreparationFromDataset(dataSetId, "testPreparation", home.getId()); // when/then final Response response = when().delete("/api/datasets/" + dataSetId); // then final int statusCode = response.statusCode(); assertThat(statusCode, is(409)); final String responseAsString = response.asString(); final JsonPath json = from(responseAsString); assertThat(json.get("code"), is("TDP_API_DATASET_STILL_IN_USE")); }
Example 3
Source File: DataSetAPITest.java From data-prep with Apache License 2.0 | 6 votes |
@Test public void testDataSetFilter() throws Exception { // given final String dataSetId = testClient.createDataset("dataset/dataset.csv", "tagada"); final InputStream expected = PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_filter.json"); // when Response response = given() // .queryParam("metadata", "true") // .queryParam("columns", "false") // .queryParam("filter", "0001='John'") // .when() // .get("/api/datasets/{id}", dataSetId); // then response.then().contentType(ContentType.JSON); final String contentAsString = response.asString(); assertThat(contentAsString, sameJSONAsFile(expected)); }
Example 4
Source File: BasePreparationTest.java From data-prep with Apache License 2.0 | 6 votes |
/** * Create a preparation by calling the preparation API. * * @param preparationContent preparation content in json. * @param folderId the folder id where tp create the preparation (can be null / empty) * @return the preparation id. */ protected String createPreparationWithAPI(final String preparationContent, final String folderId) { final Response response = given() // .contentType(ContentType.JSON) // .body(preparationContent) // .queryParam("folderId", folderId) // .when() // .expect() .statusCode(200) .log() .ifError() // .post("/preparations"); assertThat(response.getStatusCode(), is(200)); return response.asString(); }
Example 5
Source File: DataSetServiceTest.java From data-prep with Apache License 2.0 | 6 votes |
@Test public void shouldCopy() throws Exception { // given String originalId = createCSVDataSet(this.getClass().getResourceAsStream(T_SHIRT_100_CSV), "original"); // when final Response response = given() // .queryParam("copyName", "copy") // .when()// .expect() .statusCode(200) .log() .ifError() // .post("/datasets/{id}/copy", originalId); // then assertEquals(200, response.getStatusCode()); final String copyId = response.asString(); final DataSetMetadata copy = dataSetMetadataRepository.get(copyId); assertNotNull(copy); assertEquals(9, copy.getRowMetadata().size()); }
Example 6
Source File: APIClientTest.java From data-prep with Apache License 2.0 | 6 votes |
public String createDataset(final InputStream resourceAsStream, MediaType contentType, final String name) throws IOException { assertNotNull(resourceAsStream); final String datasetContent = IOUtils.toString(resourceAsStream, UTF_8); final Response post = given() // .contentType(contentType.toString()) // .body(datasetContent) // .queryParam("name", name) // .when() // .post("/api/datasets"); final int statusCode = post.getStatusCode(); if (statusCode != 200) { LOGGER.error("Unable to create dataset (HTTP " + statusCode + "). Error: {}", post.asString()); } assertThat(statusCode, is(200)); final String dataSetId = post.asString(); assertNotNull(dataSetId); assertThat(dataSetId, not("")); return dataSetId; }
Example 7
Source File: ParametersTest.java From data-prep with Apache License 2.0 | 6 votes |
@Test public void testDynamicParams_should_return_textclustering_dynamic_params() throws Exception { // given final String datasetContent = IOUtils.toString(this.getClass().getResourceAsStream("../parameters/dataset.json"), UTF_8); final String expectedParameters = IOUtils.toString( this.getClass().getResourceAsStream("../parameters/expected_cluster_params_double_metaphone.json"), UTF_8); // when final Response post = given() // .contentType(JSON) // .body(datasetContent) // .when() // .post("/transform/suggest/textclustering/params?columnId=uglystate"); final String response = post.asString(); // then assertEquals(expectedParameters, response, false); }
Example 8
Source File: IT_restBase.java From movieapp-dialog with Apache License 2.0 | 6 votes |
/** *<ul> *<li><B>Info: </B>Ensure proper welcome response from initChat</li> *<li><B>Step: </B>Connect to Showcase Dialog app using initchat rest api call</li> *<li><B>Verify: </B>Validate that the welcome response JSON element welcomeMessage contains the proper response</li> *</ul> */ @Test public void initChatGreeting() { RestAPI api = RestAPI.getAPI(); String greeting = api.getJSONElem("/questions/" + COMMON, "GMessage"); Response response = RestAssured.given() .contentType(ContentType.JSON) .param("firstTime", "true") .get(RestAPI.initchat) .then() .statusCode(200) .extract() .response(); JsonPath jp = new JsonPath(response.asString()); //Validate that the client id is not empty Assert.assertTrue("ERROR: Return Response: " + jp.get(WDSRESPONSE).toString() + " does not contain: " + greeting, jp.get(WDSRESPONSE).toString().contains(greeting)); }
Example 9
Source File: IT_restBase.java From movieapp-dialog with Apache License 2.0 | 6 votes |
/** *<ul> *<li><B>Info: </B>Ensure that initChat records the conversationId in the rest response</li> *<li><B>Step: </B>Connect to Showcase Dialog app using initchat rest api call</li> *<li><B>Verify: </B>Validate that the rest response JSON element conversationId is not empty</li> *</ul> */ @Test public void initChatConversationId() { Response response = RestAssured.given() .contentType(ContentType.JSON) .param("firstTime", "true") .get(RestAPI.initchat) .then() .statusCode(200) .extract() .response(); JsonPath jp = new JsonPath(response.asString()); //Validate that the client id is not empty Assert.assertFalse("ERROR: Return clientId is empty", jp.get(CONVERSATIONID).toString().isEmpty()); }
Example 10
Source File: IT_restBase.java From movieapp-dialog with Apache License 2.0 | 6 votes |
/** *<ul> *<li><B>Info: </B>Ensure that initChat records the clientId in the rest response</li> *<li><B>Step: </B>Connect to Showcase Dialog app using initchat rest api call</li> *<li><B>Verify: </B>Validate that the rest response JSON element clientId is not empty</li> *</ul> */ @Test public void initChatClientId() { Response response = RestAssured.given() .contentType(ContentType.JSON) .param("firstTime", "true") .get(RestAPI.initchat) .then() .statusCode(200) .extract() .response(); JsonPath jp = new JsonPath(response.asString()); //Validate that the client id is not empty Assert.assertFalse("ERROR: Return clientId is empty", jp.get(CLIENTID).toString().isEmpty()); }
Example 11
Source File: ExportAPITest.java From data-prep with Apache License 2.0 | 6 votes |
@Test public void testExportCsvWithDefaultSeparator() throws Exception { // given final String datasetId = testClient.createDataset("export/export_dataset.csv", "testExport"); final String preparationId = testClient.createPreparationFromDataset(datasetId, "preparation", home.getId()); // when Response temp = testClient.exportPreparation(preparationId, "head"); final String export = temp.asString(); // then final InputStream expectedInput = this.getClass().getResourceAsStream("export/expected_export_default_separator.csv"); final String expectedExport = IOUtils.toString(expectedInput, UTF_8); assertEquals(expectedExport, export); }
Example 12
Source File: BaseQuestion.java From movieapp-dialog with Apache License 2.0 | 5 votes |
/** * Assign different clientId and conversationId * */ public void seperateConver(){ Response init = get(RestAPI.initchat); JsonPath jp = new JsonPath(init.asString()); this.setClientId(jp.get(SetupMethod.CLIENTID).toString()); this.setConversationId(jp.get(SetupMethod.CONVERSATIONID).toString()); }
Example 13
Source File: ProfileAttributesResourceTest.java From Knowage-Server with GNU Affero General Public License v3.0 | 5 votes |
@Test public void postTest() { ProfileAttribute test = buildAttribute(); Response response = given().contentType(ContentType.JSON).body(test).when().post("/attributes").then().statusCode(200) .body("attributeName", equalTo(test.getAttributeName())).extract().response(); try { JSONObject attr = new JSONObject(response.asString()); id = attr.getInt("attributeId"); } catch (JSONException e) { } }
Example 14
Source File: PreparationControllerTest.java From data-prep with Apache License 2.0 | 5 votes |
@Test public void shouldCopy() throws Exception { // given final Folder fromFolder = folderRepository.addFolder(home.getId(), "from"); final Folder toFolder = folderRepository.addFolder(home.getId(), "to"); final String originalId = clientTest.createPreparation(createTestPreparation("test_name", "1234"), fromFolder.getId()).getId(); // Change the author, to make it different from system user. repository.get(originalId, Preparation.class).setAuthor("tagada"); // when final Response response = given() // .queryParam("name", "the new preparation") // .queryParam("destination", toFolder.getId()) // .when() // .expect() .statusCode(200) .log() .ifError() // .post("/preparations/{id}/copy", originalId); final String copyId = response.asString(); // then assertThat(response.getStatusCode(), is(200)); assertThatPreparationIsFirstInsideFolder(copyId, toFolder.getId()); assertEquals("the new preparation", repository.get(copyId, Preparation.class).getName()); // Assert that the author is the system user, and not the original author of the prep: assertEquals(System.getProperty("user.name"), repository.get(copyId, Preparation.class).getAuthor()); // row metadata its nullity after copy caused https://jira.talendforge.org/browse/TDP-3379 assertNotNull(repository.get(copyId, Preparation.class).getRowMetadata()); }
Example 15
Source File: PreparationControllerTest.java From data-prep with Apache License 2.0 | 5 votes |
@Test public void shouldCopyWithDefaultParameters() throws Exception { // given final Folder folder = folderRepository.addFolder(home.getId(), "yet_another_folder"); final String originalId = clientTest.createPreparation(createTestPreparation("prep_1", "1234"), folder.getId()).getId(); final Folder toFolder = folderRepository.addFolder(home.getId(), "to"); // when final Response response = given() // .queryParam("destination", toFolder.getId()) // .when() // .expect() .statusCode(200) .log() .ifError() // .post("/preparations/{id}/copy", originalId); final String copyId = response.asString(); // then assertThat(response.getStatusCode(), is(200)); final Iterator<FolderEntry> iterator; try (Stream<FolderEntry> folderEntriesStream = folderRepository.entries(toFolder.getId(), PREPARATION)) { iterator = folderEntriesStream.iterator(); boolean found = false; while (iterator.hasNext()) { final FolderEntry entry = iterator.next(); if (entry.getContentId().equals(copyId)) { found = true; assertEquals("prep_1 copy", repository.get(entry.getContentId(), Preparation.class).getName()); } } assertTrue(found); } }
Example 16
Source File: PreparationClientTest.java From data-prep with Apache License 2.0 | 5 votes |
/** * Create a preparation by calling the preparation API. * * @param preparationContent preparation content in json. * @param folderId the folder id where tp create the preparation (can be null / empty) * @return the preparation id. */ public String createPreparationWithAPI(final String preparationContent, final String folderId) { final Response response = given() // .contentType(JSON) // .body(preparationContent) // .queryParam("folderId", folderId) // .when() // .post("/preparations"); assertThat(response.getStatusCode(), is(200)); return response.asString(); }
Example 17
Source File: PreparationAPITest.java From data-prep with Apache License 2.0 | 5 votes |
@Test public void shouldCopyPreparation() throws Exception { // given Folder destination = folderRepository.addFolder(home.getId(), "/destination"); Folder origin = folderRepository.addFolder(home.getId(), "/from"); final String preparationId = testClient.createPreparationFromFile("dataset/dataset.csv", "super preparation", origin.getId()); // when String newPreparationName = "NEW super preparation"; final Response response = given() // .queryParam("destination", destination.getId()) // .queryParam("newName", newPreparationName) // .when()// .expect() // .statusCode(200) // .log() // .ifError() // .post("api/preparations/{id}/copy", preparationId); // then assertEquals(200, response.getStatusCode()); String copyId = response.asString(); // check the folder entry final List<FolderEntry> entries = getEntries(destination.getId()); assertThat(entries.size(), greaterThan(0)); final FolderEntry entry = entries.get(0); assertEquals(entry.getContentId(), copyId); // check the name final Preparation actual = preparationRepository.get(copyId, Preparation.class); assertEquals(newPreparationName, actual.getName()); }
Example 18
Source File: OnnxMultipleOutputsTest.java From konduit-serving with Apache License 2.0 | 5 votes |
@Test public void runFaceDetector(TestContext testContext) throws Exception { File imageFile = Paths.get(new ClassPathResource(".").getFile().getAbsolutePath(), "inference/onnx/data/1.jpg").toFile(); if (!imageFile.exists()) { FileUtils.copyURLToFile(new URL("https://github.com/KonduitAI/konduit-serving-examples/raw/master/data/facedetector/1.jpg"), imageFile); } NativeImageLoader nativeImageLoader = new NativeImageLoader(240, 320); Image image = nativeImageLoader.asImageMatrix(imageFile); INDArray contents = image.getImage(); byte[] npyContents = Nd4j.toNpyByteArray(contents); File inputFile = temporary.newFile(); FileUtils.writeByteArrayToFile(inputFile, npyContents); Response response = given().port(port) .multiPart("input", inputFile) .body(npyContents) .post("nd4j/numpy") .andReturn(); assertEquals("Response failed", 200, response.getStatusCode()); JsonObject output = new JsonObject(response.asString()); assertTrue(output.containsKey("scores")); assertTrue(output.containsKey("boxes")); INDArray scores = ObjectMappers.fromJson(output.getJsonObject("scores").encode(), NDArrayOutput.class).getNdArray(); assertEquals(0.9539676, scores.getFloat(0), 1e-6); assertArrayEquals(new long[]{1, 8840}, scores.shape()); INDArray boxes = ObjectMappers.fromJson(output.getJsonObject("boxes").encode(), NDArrayOutput.class).getNdArray(); assertEquals(0.002913665, boxes.getFloat(0), 1e-6); assertArrayEquals(new long[]{1, 17680}, boxes.shape()); }
Example 19
Source File: DataSetAPITest.java From data-prep with Apache License 2.0 | 5 votes |
@Test public void testDataSetCreate() throws Exception { // given final String dataSetId = testClient.createDataset("dataset/dataset.csv", "tagada"); final InputStream expected = PreparationAPITest.class.getResourceAsStream("dataset/expected_dataset_with_metadata.json"); // when Response response = when().get("/api/datasets/{id}?metadata=true&columns=false", dataSetId); // then response.then().contentType(ContentType.JSON); final String contentAsString = response.asString(); assertThat(contentAsString, sameJSONAsFile(expected)); }
Example 20
Source File: MockTDPException.java From data-prep with Apache License 2.0 | 2 votes |
/** * Create a MockTDPException out of the given response. * * @param response the reponse to create the excepion from. */ public MockTDPException(Response response) { super(response.asString()); this.statusCode = response.getStatusCode(); }