Esempio n. 1
0
 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
  public void b_shouldListMoreThanOneMailInBox() {

    for (int i = 0; i < 2; i++) {
      enviaEmailSimples();
    }

    final String json =
        given()
            .contentType(ContentType.JSON)
            .accept(ContentType.JSON)
            .pathParam("nNumber", myMessageProvider.getnNumber())
            .expect()
            .statusCode(OK)
            .log()
            .ifError()
            .when()
            .get(SHOW_ALL)
            .asString();

    JsonPath jp = new JsonPath(json);
    final Collection<?> inbox = jp.get("");

    assertThat(inbox.size(), greaterThan(1));
  }
Esempio n. 3
0
  @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());
  }
Esempio n. 4
0
  @Test
  public void shouldSendToRequestedPlayersOnly() throws UnsupportedEncodingException {
    sender.scheduleUpdate(updateRequestFor("vasya"));

    sender.sendUpdates(
        screenFor("petya", "petyaboard").addScreenFor("vasya", 123, "vasyaboard").asMap());

    JsonPath jsonPath = from(response.getContentAsString());
    assertNull("Should contain only requested user screens", jsonPath.get("petyaboard"));
  }
  @Test
  public void unsubscribeUnsubscribedUserFromAddressBookSubscriptions() {
    String userID = user3;
    TestUtils.startNotificationChannel(
        userThree,
        notificationChannelURL,
        apiVersion,
        validLongPoll,
        applicationUsername,
        applicationPassword);
    // subscribeToAddressBookNotifications(userID, i);

    String test = "Unsubscribe User 1 from Address Book Subscriptions";
    startTest(test);

    String url = replace(addressBookSubscriptionURL, apiVersion, userID);
    url = url + "/" + userID;

    RestAssured.authentication = RestAssured.basic(userID, applicationPassword);

    Response response =
        RestAssured.given()
            .auth()
            .preemptive()
            .basic(applicationUsername, applicationPassword)
            .expect()
            .log()
            .ifError()
            .statusCode(403)
            .delete(url);

    LOGGER.info("Received Response: " + response.getStatusCode());

    JsonPath jsonData = response.jsonPath();
    String errorCode = jsonData.get("requestError.serviceException.messageId");
    String errorMessage = jsonData.get("requestError.serviceException.variables[0]");

    LOGGER.info("Error Code: " + errorCode);
    LOGGER.info("Error Message: " + errorMessage);

    endTest(test);
  }
  @Test
  public void updateSubscriptionForUnsubscribedUser() {
    String userID = user3;
    int i = 3;

    startNotificationChannel(userID, i);
    // subscribeToAddressBookNotifications(userID, i);

    String test = "Updating/Extending the Subscription to Address Book Notifications for User 2";
    startTest(test);

    String clientCorrelator = Long.toString(System.currentTimeMillis());
    String callback = callbackURL[i];
    String requestData = requestDataClean(updateAddressBookRequestData, clientCorrelator, callback);
    String url = replace(addressBookSubscriptionURL, apiVersion, userID);
    url = url + "/" + userID;

    RestAssured.authentication = RestAssured.basic(userID, applicationPassword);

    Response response =
        RestAssured.given()
            .contentType("application/json")
            .body(requestData)
            .expect()
            .log()
            .ifError()
            .statusCode(400)
            .put(url);

    LOGGER.info("Response Received = " + response.getStatusCode());

    JsonPath jsonData = response.jsonPath();
    String errorCode = jsonData.get("requestError.serviceException.messageId");
    String errorMessage = jsonData.get("requestError.serviceException.variables[0]");

    LOGGER.info("Error Code: " + errorCode);
    LOGGER.info("Error Message: " + errorMessage);

    endTest(test);
  }
 public String createWrestler() {
   String myJson = wrestlerData.getNewWrestler();
   Map<String, String> cookies = authorization();
   Response response =
       given()
           .contentType(ContentType.JSON)
           .body(myJson)
           .with()
           .cookies(cookies)
           .post("http://streamtv.net.ua/base/php/wrestler/create.php");
   String JSONResponseBody = response.getBody().asString();
   JsonPath jsonPath = new JsonPath(JSONResponseBody);
   return jsonPath.get("id").toString();
 }
  public void startNotificationChannel(String userID, int i) {
    String test = "Starting the Notification Channel";
    startTest(test);

    String url = replace(notificationChannelURL, apiVersion, userID);
    RestAssured.authentication = RestAssured.basic(userID, applicationPassword);

    // Make HTTP POST Request...
    Response response =
        RestAssured.given().body(validLongPoll).expect().log().ifError().statusCode(201).post(url);

    JsonPath jsonData = response.jsonPath();
    resourceURL[i] = jsonData.get("notificationChannel.resourceURL");
    channelURL[i] = jsonData.get("notificationChannel.channelData.channelURL");
    callbackURL[i] = jsonData.get("notificationChannel.callbackURL");

    LOGGER.info("" + response.getStatusCode());
    LOGGER.info("Resource URL: " + resourceURL[i]);
    LOGGER.info("Channel URL: " + channelURL[i]);
    LOGGER.info("Callback URL: " + callbackURL[i]);

    endTest(test);
  }
Esempio n. 9
0
  public static Object getSystemDefinedCodes(
      final RequestSpecification requestSpec, final ResponseSpecification responseSpec) {

    final String getResponse =
        given()
            .spec(requestSpec)
            .expect()
            .spec(responseSpec)
            .when()
            .get(CodeHelper.CODE_URL + "?" + Utils.TENANT_IDENTIFIER)
            .asString();

    final JsonPath getResponseJsonPath = new JsonPath(getResponse);

    // get any systemDefined code
    return getResponseJsonPath.get("find { e -> e.systemDefined == true }");
  }
  private void testJsonMarshalling(final List<Video> videos) throws Exception {
    final JsonPath json = toJson(populateJaxbVideos(new JaxbVideosJson(), videos));

    // test generated json
    assertEquals(0, json.getInt("start"));
    assertEquals(videos.size(), json.getInt("limit"));
    assertEquals(videos.size() * 2, json.getInt("total"));

    // test for videos in the generated json
    assertTrue("videos is not an array", json.get("videos") instanceof List);
    assertEquals(videos.size(), json.getInt("videos.size()"));
    for (int i = 0; i < videos.size(); i++) {
      final String base = "videos[" + Integer.valueOf(i).toString() + "]";
      final Video video = videos.get(i);
      assertEquals(video.getId(), json.getLong(base + ".id"));
    }
  }
Esempio n. 11
0
 private List getFilesFromDatasetEndpoint(Integer datasetId, String apiToken) {
   List<Integer> fileList = new ArrayList<>();
   Response getDatasetFilesResponse =
       given().get("api/datasets/" + datasetId + "/versions/:latest/files?key=" + apiToken);
   JsonPath jsonPath = JsonPath.from(getDatasetFilesResponse.body().asString());
   //        Integer fileId = jsonPath.get("data[0].datafile.id");
   Map dataFiles = jsonPath.get("data[0]");
   if (dataFiles != null) {
     Map datafile = (Map) dataFiles.get("datafile");
     if (datafile != null) {
       Integer fileId = (Integer) datafile.get("id");
       if (fileId != null) {
         fileList.add(fileId);
       }
     }
   }
   return fileList;
 }
Esempio n. 12
0
 /**
  * Assumes you have turned on experimental non-public search
  * https://github.com/IQSS/dataverse/issues/1299
  *
  * <p>curl -X PUT -d true http://localhost:8080/api/admin/settings/:SearchApiNonPublicAllowed
  *
  * @return The Integer found or null.
  */
 private static Integer findDatasetIdFromGlobalId(String globalId, String apiToken) {
   Response searchForGlobalId =
       given()
           .get(
               "api/search?key="
                   + apiToken
                   + "&q=dsPersistentId:\""
                   + globalId.replace(":", "\\:")
                   + "\"&show_entity_ids=true");
   JsonPath jsonPath = JsonPath.from(searchForGlobalId.body().asString());
   int id;
   try {
     id = jsonPath.get("data.items[0].entity_id");
   } catch (IllegalArgumentException ex) {
     return null;
   }
   return id;
 }
  @Test
  public void b_shouldListAllMailInBox() {

    enviaEmailSimples();

    final String json =
        given()
            .contentType(ContentType.JSON)
            .accept(ContentType.JSON)
            .pathParam("nNumber", myMessageProvider.getnNumber())
            .expect()
            .statusCode(OK)
            .log()
            .ifError()
            .when()
            .get(SHOW_ALL)
            .asString();

    JsonPath jp = new JsonPath(json);
    final Collection<?> inbox = jp.get("");

    assertThat(inbox, is(not((nullValue()))));
  }
Esempio n. 14
0
 private static String getDataverseAlias(long dataverseId, String apiToken) {
   Response getDataverse = given().get("api/dataverses/" + dataverseId + "?key=" + apiToken);
   JsonPath jsonPath = JsonPath.from(getDataverse.body().asString());
   String dataverseAlias = jsonPath.get("data.alias");
   return dataverseAlias;
 }