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);
  }
Exemplo n.º 2
0
  @Test
  @RunAsClient
  public void testResourceOwnerPasswordFlowWithFormClientCredentials() throws Exception {
    RestAssured.enableLoggingOfRequestAndResponseIfValidationFails();

    Response response =
        given()
            .redirects()
            .follow(false)
            .contentType("application/x-www-form-urlencoded")
            .formParam("grant_type", "password")
            .formParam("username", "jduke")
            .formParam("password", "1234")
            .formParam("client_id", "sample")
            .formParam("client_secret", "password")
            .when()
            .post(SampleRequest.TOKEN_ENDPOINT)
            .then()
            .statusCode(200)
            .body("access_token", Matchers.not(Matchers.isEmptyOrNullString()))
            .body("refresh_token", Matchers.not(Matchers.isEmptyOrNullString()))
            .body("expires_in", Matchers.not(Matchers.isEmptyOrNullString()))
            .body("token_type", Matchers.is("Bearer"))
            .header("Pragma", "no-cache")
            .header("Cache-Control", "no-store")
            .extract()
            .response();
    System.out.println(response.asString());
    String accessToken = response.jsonPath().getString("access_token");

    SampleRequest.verify(accessToken);
  }
Exemplo n.º 3
0
  @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();
  }
Exemplo n.º 4
0
  @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();
  }
Exemplo n.º 5
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();
  }
Exemplo n.º 6
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;
  }
  @Override
  public EDITOR read(CONTEXT context, String id) {
    Response response =
        context
            .getSession()
            .given()
            .contentType(getContentType())
            .header(Headers.acceptJson())
            .get(
                "/rest/applications/{variantID}/installations/{installationID}",
                context.getParent().getVariantID(),
                id);

    UnexpectedResponseException.verifyResponse(response, HttpStatus.SC_OK);

    return demarshall(context, response.jsonPath());
  }
Exemplo n.º 9
0
  @Test
  public void sessionIMChatAccept4()
      throws JsonGenerationException, JsonMappingException, IOException {
    Setup.startTest("Sending IM chat from User 3 to User 4");

    ChatMessage chatMessage = new ChatMessage("hello user4", "Displayed");
    ObjectMapper mapper = new ObjectMapper();
    String jsonRequestData = "{\"chatMessage\":" + mapper.writeValueAsString(chatMessage) + "}";

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

    RestAssured.authentication = RestAssured.basic(Setup.TestUser3, Setup.applicationPassword);
    Response resp =
        RestAssured.given()
            .contentType("application/json")
            .body(jsonRequestData)
            .expect()
            .log()
            .ifError()
            .statusCode(201)
            .body(
                "resourceReference.resourceURL",
                StringContains.containsString(
                    Setup.encodedValue(Setup.TestUser3)
                        + "/oneToOne/"
                        + Setup.encodedValue(Setup.TestUser4Contact)
                        + "/"
                        + sessionID
                        + "/messages/"))
            .post(Setup.sendIMURL(Setup.TestUser3, Setup.TestUser4Contact, sessionID));

    sendMessageStatusURL = resp.jsonPath().getString("resourceReference.resourceURL");
    String[] parts = sendMessageStatusURL.split("/messages/");
    sentMessageID = parts[1].replaceAll("/status", "");
    System.out.println("Response = " + resp.getStatusCode() + " / " + resp.asString());
    System.out.println("resourceURL = " + sendMessageStatusURL);
    System.out.println("sentMessageID = " + sentMessageID);
    try {
      Thread.sleep(1500);
    } catch (InterruptedException e) {
    }
    Setup.endTest();
  }
  @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);
  }
  @Override
  public List<EDITOR> create(CONTEXT context, Collection<? extends BLUEPRINT> blueprints) {
    List<EDITOR> editors = new ArrayList<EDITOR>();
    for (InstallationBlueprint blueprint : blueprints) {
      Response response =
          context
              .getSession()
              .given()
              .contentType(getContentType())
              .auth()
              .basic(context.getParent().getVariantID(), context.getParent().getSecret())
              .header(Headers.acceptJson())
              .body(marshall(blueprint))
              .post("/rest/registry/device");

      UnexpectedResponseException.verifyResponse(response, HttpStatus.SC_OK);

      editors.add(demarshall(context, response.jsonPath()));
    }
    return editors;
  }
  @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);
  }
Exemplo n.º 13
0
  @Test
  public void adhocIMChat() throws JsonGenerationException, JsonMappingException, IOException {
    Setup.majorTest("Chat/IM", "Adhoc chat between users 1 and 2");

    restart();
    Setup.startTest("Testing initiating IM chat between User 1 and User 2");

    ChatMessage chatMessage = new ChatMessage("hello", "Displayed");
    ObjectMapper mapper = new ObjectMapper();
    String jsonRequestData = "{\"chatMessage\":" + mapper.writeValueAsString(chatMessage) + "}";

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

    RestAssured.authentication = RestAssured.basic(Setup.TestUser1, Setup.applicationPassword);
    Response resp =
        RestAssured.given()
            .contentType("application/json")
            .body(jsonRequestData)
            .expect()
            .log()
            .ifError()
            .statusCode(201)
            .body(
                "resourceReference.resourceURL",
                StringContains.containsString(
                    Setup.encodedValue(Setup.TestUser1)
                        + "/oneToOne/"
                        + Setup.encodedValue(Setup.TestUser2Contact)))
            .post(Setup.sendIMURL(Setup.TestUser1, Setup.TestUser2Contact, "adhoc"));

    sendMessageStatusURL = resp.jsonPath().getString("resourceReference.resourceURL");
    System.out.println("Response = " + resp.getStatusCode() + " / " + resp.asString());
    System.out.println("resourceURL = " + sendMessageStatusURL);
    try {
      Thread.sleep(1500);
    } catch (InterruptedException e) {
    }
    Setup.endTest();
  }
  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);
  }
Exemplo n.º 15
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();
  }