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;
}
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);
}
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());
}
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());
}
}
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();
}
}
Aggregations