mirror of
https://repository.entgra.net/community/product-iots.git
synced 2025-09-16 23:32:19 +00:00
Removed Thread.sleep usages.
This commit is contained in:
parent
962623f257
commit
816657a117
@ -33,6 +33,7 @@ public final class Constants {
|
||||
public static final String OAUTH_CLIENT_ID = "client_id";
|
||||
public static final String OAUTH_CLIENT_SECRET = "client_secret";
|
||||
public static final String OAUTH_ACCESS_TOKEN = "access_token";
|
||||
public static final String SCOPE = "scope";
|
||||
public static final String ANDROID_DEVICE_TYPE = "android";
|
||||
public static final String HTTP_METHOD_POST = "POST";
|
||||
public static final String HTTP_METHOD_PUT = "PUT";
|
||||
@ -61,6 +62,36 @@ public final class Constants {
|
||||
+ " \"applicationName\":\"app_12345\",\n" + " \"isAllowedToAllDomains\":false,\n"
|
||||
+ " \"tags\":[\"android\", \"device_management\"],\n" + " \"isMappingAnExistingOAuthApp\":false\n"
|
||||
+ "}").toString();
|
||||
public static final String PERMISSION_LIST = "default perm:admin-groups:count perm:admin-groups:view "
|
||||
+ "perm:admin-users:view perm:admin:certificates:add perm:admin:certificates:delete "
|
||||
+ "perm:admin:certificates:details perm:admin:certificates:verify perm:admin:certificates:view "
|
||||
+ "perm:admin:devices:view perm:android:blacklist-applications perm:android:change-lock-code "
|
||||
+ "perm:android:clear-password perm:android:configure-vpn perm:android:configure-wifi "
|
||||
+ "perm:android:control-camera perm:android:disenroll perm:android:encrypt-storage "
|
||||
+ "perm:android:enroll perm:android:enterprise-wipe perm:android:info "
|
||||
+ "perm:android:install-application perm:android:location perm:android:lock-devices "
|
||||
+ "perm:android:logcat perm:android:manage-configuration perm:android:mute perm:android:reboot "
|
||||
+ "perm:android:ring perm:android:send-notification perm:android:set-password-policy "
|
||||
+ "perm:android:set-webclip perm:android:uninstall-application perm:android:unlock-devices "
|
||||
+ "perm:android:update-application perm:android:upgrade-firmware perm:android:view-configuration "
|
||||
+ "perm:android:wipe perm:applications:install perm:applications:uninstall perm:dashboard:by-groups "
|
||||
+ "perm:dashboard:count-overview perm:dashboard:details perm:dashboard:device-counts "
|
||||
+ "perm:dashboard:feature-non-compliant perm:dashboard:filtered-count perm:dashboard:non-compliant "
|
||||
+ "perm:dashboard:non-compliant-count perm:dashboard:vulnerabilities perm:device-types:features "
|
||||
+ "perm:device-types:types perm:devices:applications perm:devices:compliance-data perm:devices:delete"
|
||||
+ " perm:devices:details perm:devices:effective-policy perm:devices:features perm:devices:operations "
|
||||
+ "perm:devices:search perm:devices:update perm:devices:view perm:get-activity perm:groups:add "
|
||||
+ "perm:groups:assign perm:groups:count perm:groups:device perm:groups:devices "
|
||||
+ "perm:groups:devices-add perm:groups:devices-count perm:groups:devices-remove perm:groups:groups "
|
||||
+ "perm:groups:groups-view perm:groups:remove perm:groups:roles perm:groups:share perm:groups:update "
|
||||
+ "perm:manage-configuration perm:notifications:mark-checked perm:notifications:view "
|
||||
+ "perm:policies:activate perm:policies:changes perm:policies:deactivate perm:policies:get-details "
|
||||
+ "perm:policies:get-policy-details perm:policies:manage perm:policies:priorities "
|
||||
+ "perm:policies:remove perm:policies:update perm:roles:add perm:roles:add-users "
|
||||
+ "perm:roles:create-combined-role perm:roles:delete perm:roles:details perm:roles:permissions "
|
||||
+ "perm:roles:update perm:roles:view perm:users:add perm:users:count perm:users:credentials "
|
||||
+ "perm:users:delete perm:users:details perm:users:is-exist perm:users:roles perm:users:search "
|
||||
+ "perm:users:send-invitation perm:users:update perm:users:user-details perm:view-configuration";
|
||||
|
||||
private APIApplicationRegistration() {
|
||||
throw new AssertionError();
|
||||
|
||||
@ -27,9 +27,15 @@ import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
|
||||
*/
|
||||
public class OAuthUtil {
|
||||
|
||||
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL)
|
||||
throws Exception {
|
||||
Thread.sleep(10000);
|
||||
public static String getScopes(String backendHTTPURL, String backendHTTPSURL) throws Exception {
|
||||
return getOAuthTokenPair(backendHTTPURL, backendHTTPSURL).get(Constants.SCOPE).toString();
|
||||
}
|
||||
|
||||
public static String getOAuthToken(String backendHTTPURL, String backendHTTPSURL) throws Exception {
|
||||
return getOAuthTokenPair(backendHTTPURL, backendHTTPSURL).get(Constants.OAUTH_ACCESS_TOKEN).toString();
|
||||
}
|
||||
|
||||
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,
|
||||
@ -45,6 +51,6 @@ public class OAuthUtil {
|
||||
Constants.APIApplicationRegistration.OAUTH_TOKEN_PAYLOAD);
|
||||
System.out.println(oAuthData.getData());
|
||||
jsonObj = new JSONObject(oAuthData.getData());
|
||||
return jsonObj.get(Constants.OAUTH_ACCESS_TOKEN).toString();
|
||||
return jsonObj;
|
||||
}
|
||||
}
|
||||
|
||||
@ -17,11 +17,13 @@
|
||||
*/
|
||||
package org.wso2.iot.integration.common;
|
||||
|
||||
import org.wso2.carbon.automation.engine.exceptions.AutomationFrameworkException;
|
||||
import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil;
|
||||
import org.wso2.carbon.automation.test.utils.http.client.HttpResponse;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.Charset;
|
||||
@ -73,7 +75,7 @@ public class RestClient {
|
||||
this.requestHeaders.remove(headerName);
|
||||
}
|
||||
|
||||
public HttpResponse post(String endpoint, String body) throws Exception {
|
||||
public HttpResponse post(String endpoint, String body) throws MalformedURLException, AutomationFrameworkException {
|
||||
return HttpRequestUtil.doPost(new URL(backEndUrl + endpoint), body, requestHeaders);
|
||||
}
|
||||
|
||||
|
||||
@ -41,8 +41,7 @@ public class MobileDeviceManagement extends TestBase {
|
||||
@Test(description = "Add an Android device.")
|
||||
public void addEnrollment() throws Exception {
|
||||
JsonObject enrollmentData = PayloadGenerator.getJsonPayload(
|
||||
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME,
|
||||
Constants.HTTP_METHOD_POST);
|
||||
Constants.AndroidEnrollment.ENROLLMENT_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST);
|
||||
enrollmentData.addProperty(Constants.DEVICE_IDENTIFIER_KEY, Constants.DEVICE_ID);
|
||||
IOTResponse response = client.post(Constants.AndroidEnrollment.ENROLLMENT_ENDPOINT, enrollmentData.toString());
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
|
||||
@ -55,7 +54,7 @@ public class MobileDeviceManagement extends TestBase {
|
||||
public void testCountDevices() throws Exception {
|
||||
IOTResponse response = client.get(Constants.MobileDeviceManagement.GET_DEVICE_COUNT_ENDPOINT);
|
||||
Assert.assertEquals(HttpStatus.SC_OK, response.getStatus());
|
||||
Assert.assertTrue(response.getBody().toString().equals(Constants.MobileDeviceManagement.NO_OF_DEVICES));
|
||||
Assert.assertTrue(response.getBody().equals(Constants.MobileDeviceManagement.NO_OF_DEVICES));
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -22,6 +22,7 @@ import junit.framework.Assert;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.junit.experimental.theories.Theories;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.BeforeSuite;
|
||||
import org.testng.annotations.Test;
|
||||
import org.wso2.carbon.automation.engine.context.TestUserMode;
|
||||
import org.wso2.iot.integration.common.*;
|
||||
@ -34,10 +35,25 @@ import java.util.concurrent.TimeUnit;
|
||||
public class MobileDeviceManagementWithNoDevices extends TestBase {
|
||||
private IOTHttpClient client;
|
||||
|
||||
/**
|
||||
* @BeforeSuite annotation is added to run this verification before the test suite starts.
|
||||
* As in IoT server, apis are published after the server startup. Due to that the generated token doesn't get
|
||||
* required scope.
|
||||
* This method delays test suit startup until the tokens get required scopes.
|
||||
* @throws Exception
|
||||
*/
|
||||
@BeforeSuite
|
||||
public void verifyApiPublishing() throws Exception {
|
||||
super.init(TestUserMode.SUPER_TENANT_ADMIN);
|
||||
|
||||
while (!checkScopes(Constants.APIApplicationRegistration.PERMISSION_LIST)) {
|
||||
TimeUnit.SECONDS.sleep(5);
|
||||
}
|
||||
}
|
||||
|
||||
@BeforeClass(alwaysRun = true, groups = { Constants.MobileDeviceManagement.MOBILE_DEVICE_MANAGEMENT_GROUP})
|
||||
public void initTest() throws Exception {
|
||||
super.init(TestUserMode.SUPER_TENANT_ADMIN);
|
||||
Thread.sleep(10000);
|
||||
|
||||
String accessTokenString = "Bearer " + OAuthUtil.getOAuthToken(backendHTTPSURL, backendHTTPSURL);
|
||||
this.client = new IOTHttpClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString);
|
||||
}
|
||||
@ -49,5 +65,9 @@ public class MobileDeviceManagementWithNoDevices extends TestBase {
|
||||
Assert.assertEquals(Constants.MobileDeviceManagement.NO_DEVICE, response.getBody());
|
||||
}
|
||||
|
||||
private boolean checkScopes(String permissionsList) throws Exception {
|
||||
String tokenString = OAuthUtil.getScopes(backendHTTPSURL, backendHTTPSURL);
|
||||
return tokenString.contains(permissionsList);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1,3 @@
|
||||
{
|
||||
"default perm:admin-groups:count perm:admin-groups:view perm:admin-users:view perm:admin:certificates:add perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:verify perm:admin:certificates:view perm:admin:devices:view perm:android:blacklist-applications perm:android:change-lock-code perm:android:clear-password perm:android:configure-vpn perm:android:configure-wifi perm:android:control-camera perm:android:disenroll perm:android:encrypt-storage perm:android:enroll perm:android:enterprise-wipe perm:android:info perm:android:install-application perm:android:location perm:android:lock-devices perm:android:logcat perm:android:manage-configuration perm:android:mute perm:android:reboot perm:android:ring perm:android:send-notification perm:android:set-password-policy perm:android:set-webclip perm:android:uninstall-application perm:android:unlock-devices perm:android:update-application perm:android:upgrade-firmware perm:android:view-configuration perm:android:wipe perm:applications:install perm:applications:uninstall perm:dashboard:by-groups perm:dashboard:count-overview perm:dashboard:details perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:filtered-count perm:dashboard:non-compliant perm:dashboard:non-compliant-count perm:dashboard:vulnerabilities perm:device-types:features perm:device-types:types perm:devices:applications perm:devices:compliance-data perm:devices:delete perm:devices:details perm:devices:effective-policy perm:devices:features perm:devices:operations perm:devices:search perm:devices:update perm:devices:view perm:get-activity perm:groups:add perm:groups:assign perm:groups:count perm:groups:device perm:groups:devices perm:groups:devices-add perm:groups:devices-count perm:groups:devices-remove perm:groups:groups perm:groups:groups-view perm:groups:remove perm:groups:roles perm:groups:share perm:groups:update perm:manage-configuration perm:notifications:mark-checked perm:notifications:view perm:policies:activate perm:policies:changes perm:policies:deactivate perm:policies:get-details perm:policies:get-policy-details perm:policies:manage perm:policies:priorities perm:policies:remove perm:policies:update perm:roles:add perm:roles:add-users perm:roles:create-combined-role perm:roles:delete perm:roles:details perm:roles:permissions perm:roles:update perm:roles:view perm:users:add perm:users:count perm:users:credentials perm:users:delete perm:users:details perm:users:is-exist perm:users:roles perm:users:search perm:users:send-invitation perm:users:update perm:users:user-details perm:view-configuration"
|
||||
}
|
||||
@ -18,16 +18,14 @@
|
||||
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="mdm-suite-initializer">
|
||||
<suite name="iot-suite-initializer">
|
||||
<parameter name="useDefaultListeners" value="false"/>
|
||||
<listeners>
|
||||
<listener
|
||||
class-name="org.wso2.carbon.automation.engine.testlisteners.TestExecutionListener"/>
|
||||
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestExecutionListener"/>
|
||||
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestManagerListener"/>
|
||||
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestReportListener"/>
|
||||
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestSuiteListener"/>
|
||||
<listener
|
||||
class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/>
|
||||
<listener class-name="org.wso2.carbon.automation.engine.testlisteners.TestTransformerListener"/>
|
||||
</listeners>
|
||||
|
||||
<test name="mobile-device-mgt-no-devices" preserve-order="true" parallel="false">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user