@Test public void test01Create_Get() { TestUtils.mmxApiHeaders.put("X-mmx-app-owner", TestUtils.appOwner); // Create User String payload = "{\n" + " \"username\": \"test01user\",\n" + " \"password\": \"pass\",\n" + " \"appId\": " + "\"" + TestUtils.appId + "\",\n" + " \"name\": \"test1 user\",\n" + " \"email\": \"[email protected]\",\n" + " \"isAdmin\" : true\n" + "}"; Response responsePost = given() .log() .all() .authentication() .preemptive() .basic(TestUtils.user, TestUtils.pass) .contentType(TestUtils.JSON) .headers(TestUtils.toHeaders(TestUtils.mmxApiHeaders)) .body(payload) .when() .post("/mmxadmin/rest/v1/user"); System.out.println(responsePost.asString()); responsePost.then().statusCode(201); // Get User by userName RestAssured.port = 5220; Response responseGet = given() .log() .all() .authentication() .preemptive() .basic(TestUtils.user, TestUtils.pass) .contentType(TestUtils.JSON) .headers(TestUtils.toHeaders(TestUtils.mmxApiHeaders)) .when() .queryParam("name", "test1 user") .get("/mmxmgmt/api/v1/users"); System.out.println(responseGet.asString()); responseGet .then() .statusCode(200) .assertThat() .body("results.any {it.username == 'test01user'}", is(true)) .assertThat() .body("results.any {it.name == 'test1 user'}", is(true)) .assertThat() .body("results.any {it.email == '*****@*****.**'}", is(true)); }
@Test public void test07Create_WithAmpersandInUserName() { TestUtils.mmxApiHeaders.put("X-mmx-app-owner", TestUtils.appOwner); String payload = "{\n" + " \"username\": \"amazing&user\",\n" + " \"password\": \"pass\",\n" + " \"appId\": " + "\"" + TestUtils.appId + "\",\n" + " \"name\": \"test1 user\",\n" + " \"email\": \"[email protected]\",\n" + " \"isAdmin\" : true\n" + "}"; Response responsePost = given() .log() .all() .authentication() .preemptive() .basic(TestUtils.user, TestUtils.pass) .contentType(TestUtils.JSON) .headers(TestUtils.toHeaders(TestUtils.mmxApiHeaders)) .body(payload) .when() .post("/mmxadmin/rest/v1/user"); responsePost .then() .statusCode(400) .body("code", equalTo(48)) .body("message", containsString(INVALID_CHAR_MESSAGE)); }
@Test(description = "classid为99999999", priority = 4) public void testErrclassid01() { Response response = TestConfig.getOrDeleteExecu("get", "/classes/9999999999/unteam_user?access_token=" + token); response.then().assertThat().statusCode(404); // body("status",equalTo(false)).body("message", equalTo("班次信息不存在")); }
@Test(description = "正常", priority = 1) public void test() { Response response = TestConfig.getOrDeleteExecu( "get", "/classes/" + classid + "/unteam_user?access_token=" + token); response .then() . // log().all(). assertThat() .statusCode(200) .body("status", equalTo(true)) . // body("message",equalTo("success")). body("data.curPage", equalTo(1)) /* * body("data.name", equalTo("响应式Web设计-单元得分")). * body("data.course.id",equalTo(1)). * body("data.course.name",equalTo("响应式Web设计")). * body("data.course.instructorList.id",Matchers.hasItem(1)). * body("data.course.instructorList.name",Matchers.hasItem("马鉴") * ) */ ; }
@Test(description = "quizzesID非法无效") public void testErrQuizzId02() { quizzesID = "-1"; Response response = TestConfig.postOrPutExecu( "put", "/quizzes/" + quizzesID + "/?access_token=" + accesstoken, jsonObject); response.then().assertThat().statusCode(404); }
@Test(description = "全部为空") public void testBody01() { quizzesID = "1682"; Response response = TestConfig.postOrPutExecu( "put", "/quizzes/" + quizzesID + "/?access_token=" + accesstoken, jsonObject); response.then().assertThat().statusCode(200).body("id", equalTo(quizzesID)); }
@Test(description = "token为空", priority = 3) public void testErrToken02() { Response response = TestConfig.getOrDeleteExecu("get", "/classes/" + classid + "/unteam_user?access_token="); response .then() .assertThat() .statusCode(401) .body("status", equalTo(false)) .body("message", equalTo("access_token不能为空")); }
@Test(description = "token为空") public void testErrToken02() { accesstoken = ""; Response response = TestConfig.postOrPutExecu( "put", "/quizzes/" + quizzesID + "/?access_token=" + accesstoken, jsonObject); response .then() .assertThat() .statusCode(400) .body("status", equalTo(false)) .body("message", equalTo("token不能为空")); }
@Test(description = "quizzesID不存在") public void testErrQuizzId01() { quizzesID = "9999"; Response response = TestConfig.postOrPutExecu( "put", "/quizzes/" + quizzesID + "/?access_token=" + accesstoken, jsonObject); response .then() .assertThat() .statusCode(200) .body("status", equalTo(false)) .body("message", equalTo("修改失败")); }
@Test public void testGetWorkflowPayloadShouldReturnSavedXmlPayload() throws IOException { Response response = given() .pathParam("bucketId", 1) .pathParam("workflowId", 1) .when() .get(WORKFLOW_RESOURCE + "?alt=xml"); Arrays.equals( ByteStreams.toByteArray(response.asInputStream()), workflowRepository.getMostRecentWorkflowRevision(1L, 1L).getXmlPayload()); response.then().assertThat().statusCode(HttpStatus.SC_OK).contentType("application/xml"); }
private Response postToReportUrl(ReportParameters params, String reportType, User user) { final String authToken = devHelper.login(user.username).token; final Response whenPostingToReportUrl = given() .contentType(ContentType.JSON) .accept(MEDIA_TYPE_EXCEL) .header(authorization(authToken)) .body(params) .when() .post(UrlSchema.REPORT, reportType); whenPostingToReportUrl .then() .assertThat() .statusCode(HttpStatus.OK.value()) .assertThat() .contentType(MEDIA_TYPE_EXCEL); return whenPostingToReportUrl; }
@Test public void testSaveAuthor() { // Create author with article AuthorDto authorDto = SampleData.createAuthorWithArticle(1); Response postResponse = RestAssured.given().contentType(ContentType.JSON).body(authorDto).when().post("/authors"); postResponse .then() .statusCode(200) .and() .assertThat() .body("id", notNullValue()) .body("articles", notNullValue()); // Get Author from response AuthorDto responseAuthor = postResponse.getBody().as(AuthorDto.class); if (CollectionUtils.isEmpty(responseAuthor.getArticles())) { Assert.fail("Author.articles should not be empty"); } }
@Test public void test01Create_WithLongName() { TestUtils.mmxApiHeaders.put("X-mmx-app-owner", TestUtils.appOwner); // Create User String payload = "{\n" + " \"username\": \"12345678901234567890123456789012345678901234567890123\",\n" + " \"password\": \"pass\",\n" + " \"appId\": " + "\"" + TestUtils.appId + "\",\n" + " \"name\": \"test1 user\",\n" + " \"email\": \"[email protected]\",\n" + " \"isAdmin\" : true\n" + "}"; Response responsePost = given() .log() .all() .authentication() .preemptive() .basic(TestUtils.user, TestUtils.pass) .contentType(TestUtils.JSON) .headers(TestUtils.toHeaders(TestUtils.mmxApiHeaders)) .body(payload) .when() .post("/mmxadmin/rest/v1/user"); System.out.println(responsePost.asString()); responsePost .then() .statusCode(400) .body("code", equalTo(48)) .body("message", containsString("Username must be 5 to 42 characters")); }
@Test public void testCreateStudentPhoneNumberOwner() throws NoSuchFieldException { if (Role.STUDENT.name().equals(this.role)) { PhoneNumber phoneNumber = new PhoneNumber(null, 1l, Boolean.FALSE, "(123) 12 234 5678"); Response response = given() .headers(getAuthHeaders()) .contentType("application/json") .body(phoneNumber) .post("/students/students/{ID}/phoneNumbers", getUserIdForRole(this.getRole())); response.then().assertThat().statusCode(200); int id = response.body().jsonPath().getInt("id"); given() .headers(getAdminAuthHeaders()) .delete( "/students/students/{STUDENTID}/phoneNumbers/{ID}", getUserIdForRole(this.getRole()), id); } }
@Test public void test08CreateDuplicateUser() { TestUtils.mmxApiHeaders.put("X-mmx-app-owner", TestUtils.appOwner); String userName = "******"; // Create User String payload = "{\n" + " \"username\": \"" + userName + "\",\n" + " \"password\": \"pass\",\n" + " \"appId\": " + "\"" + TestUtils.appId + "\",\n" + " \"name\": \"test08 user\",\n" + " \"email\": \"[email protected]\",\n" + " \"isAdmin\" : true\n" + "}"; Response responsePost = given() .log() .all() .authentication() .preemptive() .basic(TestUtils.user, TestUtils.pass) .contentType(TestUtils.JSON) .headers(TestUtils.toHeaders(TestUtils.mmxApiHeaders)) .body(payload) .when() .post("/mmxadmin/rest/v1/user"); responsePost.then().statusCode(201); /** try creating the same user again */ Response duplicatePost = given() .log() .all() .authentication() .preemptive() .basic(TestUtils.user, TestUtils.pass) .contentType(TestUtils.JSON) .headers(TestUtils.toHeaders(TestUtils.mmxApiHeaders)) .body(payload) .when() .post("/mmxadmin/rest/v1/user"); String errorMessage = String.format(DUPLICATE_USER, userName); duplicatePost .then() .statusCode(409) .body("code", equalTo(48)) .body("message", containsString(errorMessage)); // Delete Response responseDelete = given() .log() .all() .authentication() .preemptive() .basic(TestUtils.user, TestUtils.pass) .contentType(TestUtils.JSON) .headers(TestUtils.toHeaders(TestUtils.mmxApiHeaders)) .when() .delete("/mmxadmin/rest/v1/user/" + userName + "/app/" + TestUtils.appId); responseDelete.then().statusCode(200); }