From 4d485c39c153fb83cfa42570a8d62e6e15ddfcfd Mon Sep 17 00:00:00 2001 From: Menaka Jayawardena Date: Thu, 26 Jan 2017 22:44:44 +0530 Subject: [PATCH] Merge PR #272 from menakaj --- .../org/wso2/iot/integration/common/OAuthUtil.java | 12 +++++++++--- .../MobileDeviceManagementWithNoDevices.java | 6 ++++-- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/OAuthUtil.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/OAuthUtil.java index 61eb466d..8e5be4a9 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/OAuthUtil.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/common/OAuthUtil.java @@ -28,9 +28,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, diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java index 07aa8eb9..eeaa37a9 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/mobileDevice/MobileDeviceManagementWithNoDevices.java @@ -54,8 +54,6 @@ public class MobileDeviceManagementWithNoDevices extends TestBase { @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); } @@ -67,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); + } }