Search in sources :

Example 1 with RestClient

use of org.wso2.iot.integration.common.RestClient in project product-iots by wso2.

the class OAuthUtil method getOAuthTokenPair.

public static JSONObject getOAuthTokenPair(String backendHTTPURL, String backendHTTPSURL) throws Exception {
    String AuthString = "Basic YWRtaW46YWRtaW4=";
    RestClient client = new RestClient(backendHTTPURL, Constants.APPLICATION_JSON, AuthString);
    HttpResponse oAuthData = client.post(Constants.APIApplicationRegistration.API_APP_REGISTRATION_ENDPOINT, Constants.APIApplicationRegistration.API_APP_REGISTRATION_PAYLOAD);
    JSONObject jsonObj = new JSONObject(oAuthData.getData());
    String clientId = jsonObj.get(Constants.OAUTH_CLIENT_ID).toString();
    String clientSecret = jsonObj.get(Constants.OAUTH_CLIENT_SECRET).toString();
    byte[] bytesEncoded = Base64.encodeBase64((clientId + ":" + clientSecret).getBytes());
    String basicAuthString = "Basic " + new String(bytesEncoded);
    // Initiate a RestClient to get OAuth token
    client = new RestClient(backendHTTPSURL, Constants.APPLICATION_URL_ENCODED, basicAuthString);
    oAuthData = client.post(Constants.APIApplicationRegistration.TOKEN_ENDPOINT, Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD);
    jsonObj = new JSONObject(oAuthData.getData());
    return jsonObj;
}
Also used : JSONObject(org.json.JSONObject) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse)

Example 2 with RestClient

use of org.wso2.iot.integration.common.RestClient in project product-iots by wso2.

the class MobileQSGTestCase method initTest.

@BeforeClass(alwaysRun = true)
public void initTest() throws Exception {
    super.init(TestUserMode.SUPER_TENANT_ADMIN);
    username1 = "alex";
    username2 = "chris";
    this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
}
Also used : RestClient(org.wso2.iot.integration.common.RestClient) BeforeClass(org.testng.annotations.BeforeClass)

Example 3 with RestClient

use of org.wso2.iot.integration.common.RestClient in project product-iots by wso2.

the class AndroidOperation method initTest.

@BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP })
public void initTest() throws Exception {
    super.init(userMode);
    this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
    // Enroll a device
    JsonObject enrollmentData = PayloadGenerator.getJsonPayload(Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST);
    client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
}
Also used : RestClient(org.wso2.iot.integration.common.RestClient) JsonObject(com.google.gson.JsonObject) BeforeClass(org.testng.annotations.BeforeClass)

Example 4 with RestClient

use of org.wso2.iot.integration.common.RestClient in project product-iots by wso2.

the class VirtualFireAlarmTestCase method initTest.

@BeforeClass(alwaysRun = true)
public void initTest() throws Exception {
    super.init(userMode);
    restClient = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
    if (userMode == TestUserMode.TENANT_ADMIN) {
        HttpResponse response = restClient.post(Constants.VirtualFireAlarmConstants.ANALYTICS_ARTIFACTS_DEPLOYMENT_ENDPOINT, "");
        Assert.assertEquals(HttpStatus.SC_CREATED, response.getResponseCode());
    }
}
Also used : RestClient(org.wso2.iot.integration.common.RestClient) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) BeforeClass(org.testng.annotations.BeforeClass)

Example 5 with RestClient

use of org.wso2.iot.integration.common.RestClient in project product-iots by wso2.

the class VirtualFireAlarmTestCase method testEnrollment.

@Test(description = "This test case tests the virtual fire alarm enrollment")
public void testEnrollment() throws Exception {
    // Time for deploying the carbon apps
    Thread.sleep(30000);
    RestClient client = new RestClient(backendHTTPSURL, Constants.APPLICATION_ZIP, accessTokenString);
    // Enroll an advanced agent and check whether that enrollment succeeds without issues.
    HttpResponse response = client.get(Constants.VirtualFireAlarmConstants.ENROLLMENT_ENDPOINT + "?deviceName=advanced&sketchType=virtual_firealarm_advanced");
    Assert.assertEquals("Advance fire alarm advance agent enrollment failed", HttpStatus.SC_OK, response.getResponseCode());
    // Enroll an simple agent and check whether that enrollment succeeds without issues.
    response = client.get(Constants.VirtualFireAlarmConstants.ENROLLMENT_ENDPOINT + "?deviceName=simple&sketchType=virtual_firealarm");
    Assert.assertEquals("Advance fire alarm advance agent enrollment failed", HttpStatus.SC_OK, response.getResponseCode());
    response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT + "?type=virtual_firealarm");
    JsonArray jsonArray = new JsonParser().parse(response.getData()).getAsJsonObject().getAsJsonArray("devices");
    Assert.assertEquals("Virtual fire alarm enrollment failed ", 2, jsonArray.size());
    if (userMode != TestUserMode.TENANT_ADMIN) {
        deviceId1 = jsonArray.get(0).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
        deviceId2 = jsonArray.get(1).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
    } else {
        tenantDeviceId1 = jsonArray.get(0).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
        tenantDeviceId2 = jsonArray.get(1).getAsJsonObject().getAsJsonPrimitive("deviceIdentifier").getAsString();
    }
}
Also used : JsonArray(com.google.gson.JsonArray) RestClient(org.wso2.iot.integration.common.RestClient) HttpResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse) JsonParser(com.google.gson.JsonParser) Test(org.testng.annotations.Test)

Aggregations

RestClient (org.wso2.iot.integration.common.RestClient)11 BeforeClass (org.testng.annotations.BeforeClass)9 HttpResponse (org.wso2.carbon.automation.test.utils.http.client.HttpResponse)5 Test (org.testng.annotations.Test)2 JsonArray (com.google.gson.JsonArray)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JSONObject (org.json.JSONObject)1 User (org.wso2.carbon.automation.engine.context.beans.User)1