Ejemplo n.º 1
0
  @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();
  }
  @Override
  public List<EDITOR> readAll(CONTEXT context) {
    Response response =
        context
            .getSession()
            .given()
            .contentType(getContentType())
            .header(Headers.acceptJson())
            .get(
                "/rest/applications/{variantID}/installations", context.getParent().getVariantID());

    UnexpectedResponseException.verifyResponse(response, HttpStatus.SC_OK);

    List<EDITOR> editors = new ArrayList<EDITOR>();

    JsonPath jsonPath = response.jsonPath();

    List<Map<String, ?>> items = jsonPath.getList("");

    for (int i = 0; i < items.size(); i++) {
      jsonPath.setRoot("[" + i + "]");

      EDITOR editor = demarshall(context, jsonPath);
      editors.add(editor);
    }

    return editors;
  }
Ejemplo n.º 3
0
  @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 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));
  }
Ejemplo n.º 5
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());
  }
  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);
  }
Ejemplo n.º 7
0
  @Test
  public void shouldSendScores() throws UnsupportedEncodingException {
    sender.scheduleUpdate(updateRequestFor("vasya"));

    sender.sendUpdates(screenFor("vasya", 345, "vasyaboard").asMap());

    JsonPath jsonPath = from(response.getContentAsString());
    assertEquals(345, jsonPath.getInt("vasya.score"));
  }
Ejemplo n.º 8
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"));
  }
Ejemplo n.º 9
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();
 }
 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 static List<String> getList(String path) {
    if (contentType.contains("xml")) {
      return XmlPath.from(responseString).setRoot(rootPath).getList(path, String.class);
    }

    return JsonPath.from(responseString).setRoot(rootPath).getList(path, String.class);
  }
  public static Boolean getBoolean(String path) {
    if (contentType.contains("xml")) {
      return XmlPath.from(responseString).setRoot(rootPath).getBoolean(path);
    }

    return JsonPath.from(responseString).setRoot(rootPath).getBoolean(path);
  }
Ejemplo n.º 13
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 }");
  }
Ejemplo n.º 14
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;
 }
Ejemplo n.º 15
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;
 }
  @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);
  }
 @Override
 public EDITOR demarshall(CONTEXT context, JsonPath jsonPath) {
   EDITOR editor = context.createEditor();
   editor.setId(jsonPath.getString("id"));
   editor.setPlatform(jsonPath.getString("platform"));
   editor.setEnabled(jsonPath.getBoolean("enabled"));
   editor.setOperatingSystem(jsonPath.getString("operatingSystem"));
   editor.setOsVersion(jsonPath.getString("osVersion"));
   editor.setAlias(jsonPath.getString("alias"));
   editor.setDeviceType(jsonPath.getString("deviceType"));
   editor.setDeviceToken(jsonPath.getString("deviceToken"));
   editor.setSimplePushEndpoint(jsonPath.getString("simplePushEndpoint"));
   HashSet<String> categories = new HashSet<String>();
   List<String> jsonCategories = jsonPath.getList("categories");
   if (jsonCategories != null) {
     for (String jsonCategory : jsonCategories) {
       categories.add(jsonCategory);
     }
   }
   editor.setCategories(categories);
   return editor;
 }
  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);
  }
Ejemplo n.º 20
0
  @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()))));
  }
  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"));
    }
  }
Ejemplo n.º 22
0
 private void assertContainsPlayerBoard(
     String responseContent, String playerName, String expectedBoard) {
   JsonPath jsonPath = from(responseContent);
   assertEquals(expectedBoard, jsonPath.getString(playerName + ".board"));
 }
Ejemplo n.º 23
0
 private static String getPassword(String jsonStr) {
   String password = JsonPath.from(jsonStr).get(usernameKey);
   return password;
 }
Ejemplo n.º 24
0
 private long getRoleAssignmentId(Response response) {
   JsonPath jsonPath = JsonPath.from(response.body().asString());
   return jsonPath.getInt("data.id");
 }
 public static String getText(String path) {
   if (contentType.contains("xml")) {
     return XmlPath.from(responseString).setRoot(rootPath).getString(path);
   }
   return JsonPath.from(responseString).setRoot(rootPath).getString(path);
 }
Ejemplo n.º 26
0
  @Test
  public void sessionIMChatAccept()
      throws JsonGenerationException, JsonMappingException, IOException {
    Setup.majorTest("Chat/IM", "Confirmed chat between users 3 and 4");

    restart();
    Setup.startTest("Testing initiating IM chat session between User 3 and User 4");

    String requestData3 =
        "{\"chatNotificationSubscription\":{ \"callbackReference\":{\"notifyURL\":\""
            + Setup.callbackURL[3]
            + "\",\"callbackData\":\"GSMA3\"},\"clientCorrelator\":\""
            + UUID.randomUUID().toString()
            + "\", \"duration\":900, \"confirmedChatSupported\":true, \"adhocChatSupported\":false}}";
    String requestData4 =
        "{\"chatNotificationSubscription\":{ \"callbackReference\":{\"notifyURL\":\""
            + Setup.callbackURL[4]
            + "\",\"callbackData\":\"GSMA3\"},\"clientCorrelator\":\""
            + UUID.randomUUID().toString()
            + "\", \"duration\":900, \"confirmedChatSupported\":true, \"adhocChatSupported\":false}}";

    System.out.println("Setting chat subscription for confirmed session for user 3");
    RestAssured.authentication = RestAssured.basic(Setup.TestUser3, Setup.applicationPassword);
    Response resp =
        RestAssured.given()
            .contentType("application/json")
            .body(requestData3)
            .expect()
            .log()
            .ifError()
            .statusCode(201)
            .post(Setup.chatSubscriptionURL(Setup.TestUser3));
    System.out.println("Response = " + resp.getStatusCode() + " / " + resp.asString());

    System.out.println("Setting chat subscription for confirmed session for user 4");
    RestAssured.authentication = RestAssured.basic(Setup.TestUser4, Setup.applicationPassword);
    resp =
        RestAssured.given()
            .contentType("application/json")
            .body(requestData4)
            .expect()
            .log()
            .ifError()
            .statusCode(201)
            .post(Setup.chatSubscriptionURL(Setup.TestUser4));
    System.out.println("Response = " + resp.getStatusCode() + " / " + resp.asString());

    ChatSessionInformation chatSessionInformation =
        new ChatSessionInformation(
            "Session based IM", Setup.TestUser3Contact, "MO", Setup.TestUser4Contact, "MT");

    ObjectMapper mapper = new ObjectMapper();
    String jsonRequestData =
        "{\"chatSessionInformation\":" + mapper.writeValueAsString(chatSessionInformation) + "}";

    System.out.println("Sending json=" + jsonRequestData);

    RestAssured.authentication = RestAssured.basic(Setup.TestUser3, Setup.applicationPassword);
    resp =
        RestAssured.given()
            .contentType("application/json")
            .body(jsonRequestData)
            .expect()
            .log()
            .ifError()
            .statusCode(201)
            .body(
                "chatSessionInformation.status", Matchers.equalTo("Invited"),
                "chatSessionInformation.originatorAddress",
                    Matchers.equalTo(Setup.TestUser3Contact),
                "chatSessionInformation.tParticipantAddress",
                    Matchers.equalTo(Setup.TestUser4Contact),
                "chatSessionInformation.resourceURL",
                    StringContains.containsString(
                        Setup.encodedValue(Setup.TestUser3)
                            + "/oneToOne/"
                            + Setup.encodedValue(Setup.TestUser4Contact)))
            .post(Setup.createIMChatSessionURL(Setup.TestUser3, Setup.TestUser4Contact));

    System.out.println("Response = " + resp.getStatusCode() + " / " + resp.asString());

    JsonPath jsonData = resp.jsonPath();

    sendSessionURL = jsonData.getString("chatSessionInformation.resourceURL");
    System.out.println("sendSessionURL = " + sendSessionURL);
    try {
      Thread.sleep(500);
    } catch (InterruptedException e) {
    }
    Setup.endTest();
  }
Ejemplo n.º 27
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;
 }