@Test public void dataverseCategory() { Response enableNonPublicSearch = enableSetting(SettingsServiceBean.Key.SearchApiNonPublicAllowed); assertEquals(200, enableNonPublicSearch.getStatusCode()); /** * Unfortunately, it appears that the ability to specify the category of a dataverse when * creating it is a GUI-only feature. It can't currently be done via the API, to our knowledge. * You also can't tell from the API which category was persisted but it always seems to be * "UNCATEGORIZED" */ TestDataverse dataverseToCreate = new TestDataverse(dv1, "dv1", Dataverse.DataverseType.ORGANIZATIONS_INSTITUTIONS); Response createDvResponse = createDataverse(dataverseToCreate, homer); assertEquals(201, createDvResponse.getStatusCode()); TestSearchQuery query = new TestSearchQuery("dv1"); Response searchResponse = search(query, homer); JsonPath jsonPath = JsonPath.from(searchResponse.body().asString()); String dv1Category = jsonPath.get("data.facets." + SearchFields.DATAVERSE_CATEGORY).toString(); String msg = "dv1Category: " + dv1Category; assertEquals("dv1Category: [null]", msg); Response disableNonPublicSearch = deleteSetting(SettingsServiceBean.Key.SearchApiNonPublicAllowed); assertEquals(200, disableNonPublicSearch.getStatusCode()); }
@Test public void sessionIMChatAccept13() throws JsonGenerationException, JsonMappingException, IOException { Setup.majorTest("Chat/IM", "isComposing functionality between users 3 and 4"); Setup.startTest("Send isComposing from User 3"); IsComposing isComposing = new IsComposing("active", new java.util.Date(), "text/plain", 60); ObjectMapper mapper = new ObjectMapper(); String jsonRequestData = "{\"isComposing\":" + mapper.writeValueAsString(isComposing) + "}"; System.out.println("Sending " + jsonRequestData); RestAssured.authentication = RestAssured.basic(Setup.TestUser3, Setup.applicationPassword); Response resp = RestAssured.given() .contentType("application/json") .body(jsonRequestData) .expect() .log() .ifError() .statusCode(204) .post(Setup.sendIMURL(Setup.TestUser3, Setup.TestUser4Contact, sessionID)); System.out.println("Response = " + resp.getStatusCode() + " / " + resp.asString()); Setup.endTest(); }
@Test public void sessionIMChatAccept2() { Setup.startTest("Checking IM notifications for user 3"); RestAssured.authentication = RestAssured.DEFAULT_AUTH; String url = (Setup.channelURL[3].split("username\\=")[0]) + "username="******"notificationList", Matchers.notNullValue()) .post(url); System.out.println( "Response = " + notifications3.getStatusCode() + " / " + notifications3.asString()); /* * {"notificationList":[{"messageStatusNotification": {"callbackData":"GSMA3","link": [{"rel":"ChatMessage","href":"http://api.oneapi-gw.gsma.com/chat/0.1/%2B15554000003/oneToOne/tel%3A%2B15554000004//messages/1352666437776-470267184"}], * "status":"Delivered","messageId":"1352666437776-470267184"}}, * {"messageStatusNotification": {"callbackData":"GSMA3","link": [{"rel":"ChatMessage","href":"http://api.oneapi-gw.gsma.com/chat/0.1/%2B15554000003/oneToOne/tel%3A%2B15554000004//messages/1352666437776-470267184"}], * "status":"Displayed","messageId":"1352666437776-470267184"}}, * {"chatEventNotification": {"callbackData":"GSMA3","link": [{"rel":"ChatSessionInformation","href":"http://api.oneapi-gw.gsma.com/chat/0.1/%2B15554000003/oneToOne/tel%3A%2B15554000004/373305033"}], * "eventType":"Accepted","sessionId":"373305033"}}]} */ JsonPath jsonData = notifications3.jsonPath(); sentMessageID = jsonData.getString("notificationList.messageStatusNotification[0].messageId"); System.out.println("Extracted messageId=" + sentMessageID); sendSessionURL = jsonData.getString("notificationList.chatEventNotification.link[0].href[0]"); System.out.println("Extracted sendSessionURL=" + sendSessionURL); sessionID = jsonData.getString("notificationList.chatEventNotification.sessionId[0]"); System.out.println("Extracted sessionId=" + sessionID); Setup.endTest(); }
@Test public final void whenResourcesAreRetrievedSorted_then200IsReceived() { final Response response = getAPI().findAllSortedAsResponse(SearchField.name.name(), Sort.Direction.ASC.name(), null); assertThat(response.getStatusCode(), is(200)); }
@Test public void sessionIMChatAccept5() { Setup.startTest("Checking IM notifications for user 4"); String url = (Setup.channelURL[4].split("username\\=")[0]) + "username="******"notificationList.messageNotification[0].senderAddress", Matchers.containsString(Setup.cleanPrefix(Setup.TestUser3Contact)), "notificationList.messageNotification[0].chatMessage.text", Matchers.equalTo("hello user4")) .post(url); System.out.println( "Response = " + notifications4.getStatusCode() + " / " + notifications4.asString()); /* * {"notificationList":[{"messageNotification": * {"callbackData":"GSMA3","link": * [{"rel":"MessageStatusReport","href":"http://api.oneapi-gw.gsma.com/chat/0.1/%2B15554000004/oneToOne/tel%3A%2B15554000003/-797939895/messages/1352475373833-1790113032/status"}], * "dateTime":"2012-11-09T15:36:13Z","chatMessage":{"text":"hello user4"},"sessionId":"-797939895","messageId":"1352475373833-1790113032", * "senderAddress":"tel:+15554000003"}}]} */ try { Thread.sleep(1000); } catch (InterruptedException e) { } Setup.endTest(); }
@Test public void sessionIMChatAccept18() throws JsonGenerationException, JsonMappingException, IOException { Setup.startTest("Checking that User 4 has received composing notification"); RestAssured.authentication = RestAssured.DEFAULT_AUTH; String url = (Setup.channelURL[4].split("username\\=")[0]) + "username="******"notificationList.messageNotification[0].isComposing.refresh", Matchers.equalTo(60), "notificationList.messageNotification[0].isComposing.status", Matchers.equalTo("idle"), "notificationList.messageNotification[0].sessionId", Matchers.equalTo(receiveSessionID), "notificationList.messageNotification[0].senderAddress", Matchers.containsString(Setup.cleanPrefix(Setup.TestUser3Contact))) .post(url); System.out.println("Response = " + response.getStatusCode() + " / " + response.asString()); Setup.endTest(); }
@Test public void adhocIMChat6() throws JsonGenerationException, JsonMappingException, IOException { Setup.startTest("Checking that User 1 has received a chat message"); receiveMessageStatusURL = INVALID; String url = (Setup.channelURL[1].split("username\\=")[0]) + "username="******"notificationList.messageNotification.chatMessage.text", Matchers.hasItem("how are you"), "notificationList.messageNotification.sessionId", Matchers.hasItem("adhoc"), "notificationList.messageNotification.messageId", Matchers.notNullValue(), "notificationList.messageNotification.senderAddress", Matchers.hasItem(Setup.TestUser2Contact), "notificationList.messageNotification.link", Matchers.notNullValue()) .post(url); System.out.println("Response = " + response.getStatusCode() + " / " + response.asString()); receiveMessageStatusURL = response.jsonPath().getString("notificationList.messageNotification[0].link[0].href"); System.out.println("message status URL = " + receiveMessageStatusURL); Setup.endTest(); }
@Test public void sessionIMChatAccept21() throws JsonGenerationException, JsonMappingException, IOException { Setup.startTest("Send invalid isComposing from User 4"); IsComposing isComposing = new IsComposing("rubbish", new java.util.Date(), "text/plain", 60); ObjectMapper mapper = new ObjectMapper(); String jsonRequestData = "{\"isComposing\":" + mapper.writeValueAsString(isComposing) + "}"; System.out.println("Sending " + jsonRequestData); RestAssured.authentication = RestAssured.basic(Setup.TestUser4, Setup.applicationPassword); Response resp = RestAssured.given() .contentType("application/json") .body(jsonRequestData) .expect() .log() .ifError() .statusCode(400) .post(Setup.sendIMURL(Setup.TestUser4, Setup.TestUser3Contact, receiveSessionID)); /* * 400 / {"requestError": {"serviceException": { * "messageId":"SVC002","variables": ["State is not valid. Received 'rubbish'"],"text":"Invalid input value for message. Part %0"}}} */ System.out.println("Response = " + resp.getStatusCode() + " / " + resp.asString()); Setup.endTest(); }
@Test public void sessionIMChatAccept23() throws JsonGenerationException, JsonMappingException, IOException { Setup.startTest("Checking that User 3 has received chat closed notification"); System.out.println("sessionID=" + sessionID); System.out.println("receiveSessionID=" + receiveSessionID); RestAssured.authentication = RestAssured.DEFAULT_AUTH; String url = (Setup.channelURL[3].split("username\\=")[0]) + "username="******"notificationList.chatEventNotification.eventType", Matchers.hasItem("SessionEnded"), "notificationList.chatEventNotification.sessionId", Matchers.hasItem(sessionID), "notificationList.chatEventNotification.link[0].rel", Matchers.hasItem("ChatSessionInformation")) .post(url); System.out.println("Response = " + response.getStatusCode() + " / " + response.asString()); Setup.endTest(); }
@Test public void sessionIMChatAccept1A() { Setup.startTest("Checking IM notifications for user 4"); String url = (Setup.channelURL[4].split("username\\=")[0]) + "username="******"notificationList.chatSessionInvitationNotification", Matchers.notNullValue(), "notificationList.messageNotification.dateTime", Matchers.notNullValue(), "notificationList.messageNotification.messageId", Matchers.notNullValue(), "notificationList.messageNotification.senderAddress[0]", Matchers.containsString(Setup.cleanPrefix(Setup.TestUser3Contact))) .post(url); System.out.println( "Response = " + notifications4.getStatusCode() + " / " + notifications4.asString()); JsonPath jsonData = notifications4.jsonPath(); receiveSessionURL = jsonData.getString("notificationList.chatSessionInvitationNotification[0].link[0].href"); System.out.println("Extracted receiveSessionURL=" + receiveSessionURL); receiveSessionID = jsonData.getString("notificationList.messageNotification.sessionId[0]"); System.out.println("Extracted receiveSessionID=" + receiveSessionID); receiveMessageID = jsonData.getString("notificationList.messageNotification.messageId[0]"); System.out.println("Extracted receiveMessageID=" + receiveMessageID); Setup.endTest(); }
@Test public void testDeleteStudentPhoneNumber() throws NoSuchFieldException { PhoneNumber phoneNumber = new PhoneNumber(null, 1l, Boolean.FALSE, "(123) 12 234 5678"); Response response = given() .headers(getAdminAuthHeaders()) .contentType("application/json") .body(phoneNumber) .post("/students/students/{STUDENTID}/phoneNumbers", TEST_STUDENT_ID); Long id = new Long(response.body().jsonPath().getInt("id")); response = given() .headers(getAuthHeaders()) .delete("/students/students/{STUDENTID}/phoneNumbers/{ID}", TEST_STUDENT_ID, id); assertOk(response, studentPermissions, StudentPermissions.DELETE_STUDENTPHONENUMBER, 204); if (response.getStatusCode() != 204) { given() .headers(getAdminAuthHeaders()) .delete("/students/students/{STUDENTID}/phoneNumbers/{ID}", TEST_STUDENT_ID, id); } }
private void subscribeToAddressBookNotifications(String userID, int i) { String test = "Subscribing User 1 to Address Book Notifications"; startTest(test); String clientCorrelator = Long.toString(System.currentTimeMillis()); String callback = callbackURL[i]; String requestData = requestDataClean(addressBookRequestData, clientCorrelator, callback); String url = replace(addressBookSubscriptionURL, apiVersion, userID); RestAssured.authentication = RestAssured.basic(userID, applicationPassword); Response response = RestAssured.given() .contentType("application/json") .body(requestData) .expect() .log() .ifError() .statusCode(201) .post(url); JsonPath jsonData = response.jsonPath(); subscriptionURL[i] = jsonData.getString("abChangesSubscription.resourceURL"); LOGGER.info("Response received = " + response.getStatusCode()); LOGGER.info("Body = " + response.asString()); endTest(test); }
@Test public void sessionIMChatAccept8() throws JsonGenerationException, JsonMappingException, IOException { Setup.startTest("Checking that User 3 has received a chat message"); receiveMessageStatusURL = INVALID; RestAssured.authentication = RestAssured.DEFAULT_AUTH; String url = (Setup.channelURL[3].split("username\\=")[0]) + "username="******"notificationList.messageNotification.chatMessage.text", Matchers.hasItem("I am good"), "notificationList.messageNotification.sessionId", Matchers.hasItem(sessionID), "notificationList.messageNotification.messageId", Matchers.notNullValue(), "notificationList.messageNotification.senderAddress", Matchers.hasItem(Setup.TestUser4Contact), "notificationList.messageNotification.link", Matchers.notNullValue()) .post(url); System.out.println("Response = " + response.getStatusCode() + " / " + response.asString()); receiveMessageStatusURL = response.jsonPath().getString("notificationList.messageNotification[0].link[0].href"); System.out.println("message status URL = " + receiveMessageStatusURL); try { Thread.sleep(1000); } catch (InterruptedException e) { } Setup.endTest(); }
@Test /* code */ public void whenResourceIsCreated_then201IsReceived() { // When final Response response = getApi().createAsResponse(createNewResource()); // Then assertThat(response.getStatusCode(), is(201)); }
@AfterClass public static void cleanup() { boolean enabled = true; if (!enabled) { return; } logger.info("Running cleanup..."); /** * We revoke roles here just in case an assertion failed because role assignments are currently * not deleted when you delete a user per https://github.com/IQSS/dataverse/issues/1929 * * <p>You can also delete the role assignments manually like this: * * <p>"DELETE FROM roleassignment WHERE assigneeidentifier='@ned';" */ Response revokeNedAdminOnRoot = revokeRole(dataverseToCreateDataset1In, nedAdminOnRootAssignment, homer.getApiToken()); // System.out.println(revokeNedAdminOnRoot.prettyPrint()); System.out.println( "cleanup - status code revoking admin on root from ned: " + revokeNedAdminOnRoot.getStatusCode()); if (!homerGivesNedPermissionAtRootTestDisabled) { Response deleteDataset1Response = deleteDataset(dataset1, homer.getApiToken()); assertEquals(204, deleteDataset1Response.getStatusCode()); } if (!homerGivesNedPermissionAtNewDvDisabled) { Response deleteDataset2Response = deleteDataset(dataset2, homer.getApiToken()); assertEquals(204, deleteDataset2Response.getStatusCode()); } Response deleteDv1Response = deleteDataverse(dv1, homer); assertEquals(200, deleteDv1Response.getStatusCode()); if (!homerGivesNedPermissionAtNewDvDisabled) { Response deleteDv2Response = deleteDataverse(dv2, homer); assertEquals(200, deleteDv2Response.getStatusCode()); } deleteUser(homer.getUsername()); deleteUser(ned.getUsername()); }
@Test public final void whenResourcesAreRetrievedWithNonNumericPageSize_then400IsReceived() { // When final Response response = get(getURI() + "?page=0" + "&size=" + randomAlphabetic(5)); // Then assertThat(response.getStatusCode(), is(400)); }
@Test public final void whenResourcesAreRetrievedByInvalidSorting_then400IsReceived() { // When final Response response = givenAuthenticated().get(getURI() + "?page=0&size=4&sortBy=invalid"); // Then assertThat(response.getStatusCode(), is(400)); }
@Test public final void whenResourcesAreRetrievedPaginated_then200IsReceived() { // When final Response response = getAPI().findAllPaginatedAsResponse(0, 1, null); // Then assertThat(response.getStatusCode(), is(200)); }
@Test /* code */ public void givenResourceDoesNotExist_whenResourceIsDeleted_then404IsReceived() { // When final Response response = getApi().deleteAsResponse(getUri() + randomNumeric(6)); // Then assertThat(response.getStatusCode(), is(404)); }
@Test /* code */ public void whenResourceIsDeletedByIncorrectNonNumericId_then400IsReceived() { // When final Response response = getApi().deleteAsResponse(getUri() + randomAlphabetic(6)); // Then assertThat(response.getStatusCode(), is(400)); }
@Test /* code */ public void whenResourceWithUnsupportedMediaTypeIsCreated_then415IsReceived() { // When final Response response = givenReadAuthenticated().contentType("unknown").post(getUri()); // Then assertThat(response.getStatusCode(), is(415)); }
@Test /* code */ public void whenResourceIsUpdatedWithNullId_then400IsReceived() { // When final Response response = getApi().updateAsResponse(createNewResource()); // Then assertThat(response.getStatusCode(), is(400)); }
@Test public final void whenResourcesAreRetrievedByPaginatedAndWithInvalidSorting_then400IsReceived() { // When final Response response = getAPI().findAllPaginatedAndSortedAsResponse(0, 4, "invalid", null, null); // Then assertThat(response.getStatusCode(), is(400)); }
public void testCors() { Response response = given().options("/rest/questionnaire/some-permalink"); assertThat(response.getStatusCode()).isEqualTo(Status.OK.getStatusCode()); assertThat(response.getHeader("Access-Control-Allow-Origin")).isEqualTo("*"); assertThat(response.getHeader("Access-Control-Allow-Methods")) .isEqualTo("POST, GET, UPDATE, DELETE, OPTIONS"); assertThat(response.getHeader("Access-Control-Allow-Headers")) .isEqualTo("content-type, x-http-method-override"); }
@Test // - note: may fail intermittently - TODO: investigate public final void whenPageOfResourcesIsRetrievedOutOfBounds_then404IsReceived() { // When final Response response = getAPI().findAllPaginatedAsResponse(Integer.parseInt(randomNumeric(5)), 1, null); // Then assertThat(response.getStatusCode(), is(404)); }
private static JsonObject createUser(String jsonStr) { JsonObjectBuilder createdUser = Json.createObjectBuilder(); Response response = createUserViaApi(jsonStr, getPassword(jsonStr)); // System.out.println(response.prettyPrint()); Assert.assertEquals(200, response.getStatusCode()); JsonPath jsonPath = JsonPath.from(response.body().asString()); createdUser.add(idKey, jsonPath.getInt("data.user." + idKey)); createdUser.add(usernameKey, jsonPath.get("data.user." + usernameKey).toString()); createdUser.add(apiTokenKey, jsonPath.get("data." + apiTokenKey).toString()); return createdUser.build(); }
@Test /* code */ public void whenResourceIsCreatedWithNonNullId_then409IsReceived() { final T resourceWithId = createNewResource(); resourceWithId.setId(5l); // When final Response response = getApi().createAsResponse(resourceWithId); // Then assertThat(response.getStatusCode(), is(409)); }
@Test /* code */ public void givenResourceExists_whenResourceIsUpdated_then200IsReceived() { // Given final T existingResource = getApi().create(createNewResource()); // When final Response response = getApi().updateAsResponse(existingResource); // Then assertThat(response.getStatusCode(), is(200)); }
@Test /* code */ public void givenResourceExists_whenResourceIsDeleted_then204IsReceived() { // Given final String uriForResourceCreation = getApi().createAsUri(createNewResource()); // When final Response response = getApi().deleteAsResponse(uriForResourceCreation); // Then assertThat(response.getStatusCode(), is(204)); }
public void readFile( String user, String password, String file, String contentType, String resource, int status) throws IOException { getMock("WEBHDFS") .expect() .method("GET") .pathInfo("/v1" + file) .queryParam("user.name", user) .queryParam("op", "OPEN") .respond() .status(HttpStatus.SC_TEMPORARY_REDIRECT) .header("Location", getRealUrl("DATANODE") + file + "?op=OPEN&user.name=" + user); if (status == HttpStatus.SC_OK) { getMock("DATANODE") .expect() .method("GET") .pathInfo(file) .queryParam("user.name", user) .queryParam("op", "OPEN") .respond() .status(status) .contentType(contentType) .content(getResourceBytes(resource)); } else { getMock("DATANODE") .expect() .method("GET") .pathInfo(file) .queryParam("user.name", user) .queryParam("op", "OPEN") .respond() .status(status); } Response response = given() // .log().all() .auth() .preemptive() .basic(user, password) .header("X-XSRF-Header", "jksdhfkhdsf") .queryParam("op", "OPEN") .expect() // .log().all() .statusCode(status) .when() .get(getUrl("WEBHDFS") + "/v1" + file + (isUseGateway() ? "" : "?user.name=" + user)); if (response.getStatusCode() == HttpStatus.SC_OK) { String actualContent = response.asString(); String expectedContent = getResourceString(resource, Charset.forName("UTF-8")); assertThat(actualContent, is(expectedContent)); } assertComplete(); }