From 8ee4c2dbbac63005e683394c006bd37e19d39699 Mon Sep 17 00:00:00 2001 From: megala21 Date: Tue, 16 May 2017 14:36:11 +0530 Subject: [PATCH] Adding test cases for quick start guide --- .../iot/integration/common/Constants.java | 24 ++++- .../wso2/iot/integration/common/TestBase.java | 2 +- .../samples/MobileQSGTestCase.java | 102 ++++++++++++++++++ 3 files changed, 123 insertions(+), 5 deletions(-) create mode 100644 modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/samples/MobileQSGTestCase.java diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java index 96974b20..c2cee1a6 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/Constants.java @@ -59,7 +59,15 @@ public final class Constants { public static final String TOKEN_ENDPOINT = "/token"; public static final String MULTI_TENANT_OAUTH_TOKEN_PAYLOAD = "&grant_type=password&scope=perm:android:enroll" + " perm:android:wipe perm:android:ring perm:android:lock-devices perm:android:configure-vpn " - + "perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application perm:android:manage-configuration perm:android:location perm:android:install-application perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password perm:android:enterprise-wipe perm:android:info perm:android:view-configuration perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification perm:android:disenroll perm:android:update-application perm:android:unlock-devices perm:android:control-camera perm:android:reboot perm:android:logcat appm:subscribe perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin perm:android:applications"; + + "perm:android:configure-wifi perm:android:enroll perm:android:uninstall-application " + + "perm:android:manage-configuration perm:android:location perm:android:install-application " + + "perm:android:mute perm:android:change-lock-code perm:android:blacklist-applications " + + "perm:android:set-password-policy perm:android:encrypt-storage perm:android:clear-password " + + "perm:android:enterprise-wipe perm:android:info perm:android:view-configuration " + + "perm:android:upgrade-firmware perm:android:set-webclip perm:android:send-notification " + + "perm:android:disenroll perm:android:update-application perm:android:unlock-devices " + + "perm:android:control-camera perm:android:reboot perm:android:logcat appm:read appm:subscribe " + + "perm:sign-csr perm:admin:devices:view perm:roles:add perm:roles:add-users perm:roles:update perm:roles:permissions perm:roles:details perm:roles:view perm:roles:create-combined-role perm:roles:delete perm:dashboard:vulnerabilities perm:dashboard:non-compliant-count perm:dashboard:non-compliant perm:dashboard:by-groups perm:dashboard:device-counts perm:dashboard:feature-non-compliant perm:dashboard:count-overview perm:dashboard:filtered-count perm:dashboard:details perm:get-activity perm:devices:delete perm:devices:applications perm:devices:effective-policy perm:devices:compliance-data perm:devices:features perm:devices:operations perm:devices:search perm:devices:details perm:devices:update perm:devices:view perm:view-configuration perm:manage-configuration perm:policies:remove perm:policies:priorities perm:policies:deactivate perm:policies:get-policy-details perm:policies:manage perm:policies:activate perm:policies:update perm:policies:changes perm:policies:get-details perm:users:add perm:users:details perm:users:count perm:users:delete perm:users:roles perm:users:user-details perm:users:credentials perm:users:search perm:users:is-exist perm:users:update perm:users:send-invitation perm:admin-users:view perm:groups:devices perm:groups:update perm:groups:add perm:groups:device perm:groups:devices-count perm:groups:remove perm:groups:groups perm:groups:groups-view perm:groups:share perm:groups:count perm:groups:roles perm:groups:devices-remove perm:groups:devices-add perm:groups:assign perm:device-types:features perm:device-types:types perm:applications:install perm:applications:uninstall perm:admin-groups:count perm:admin-groups:view perm:notifications:mark-checked perm:notifications:view perm:admin:certificates:delete perm:admin:certificates:details perm:admin:certificates:view perm:admin:certificates:add perm:admin:certificates:verify perm:ios:enroll perm:ios:view-device perm:ios:apn perm:ios:ldap perm:ios:enterprise-app perm:ios:store-application perm:ios:remove-application perm:ios:app-list perm:ios:profile-list perm:ios:lock perm:ios:enterprise-wipe perm:ios:device-info perm:ios:restriction perm:ios:email perm:ios:cellular perm:ios:applications perm:ios:wifi perm:ios:ring perm:ios:location perm:ios:notification perm:ios:airplay perm:ios:caldav perm:ios:cal-subscription perm:ios:passcode-policy perm:ios:webclip perm:ios:vpn perm:ios:per-app-vpn perm:ios:app-to-per-app-vpn perm:ios:app-lock perm:ios:clear-passcode perm:ios:remove-profile perm:ios:get-restrictions perm:ios:wipe-data perm:admin perm:android:applications"; public static final String OAUTH_TOKEN_PAYLOAD = "username=admin&password=admin" + MULTI_TENANT_OAUTH_TOKEN_PAYLOAD; @@ -68,8 +76,8 @@ public final class Constants { + " \"applicationName\":\"app_123456\",\n" + " \"isAllowedToAllDomains\":false,\n" + " \"tags\":[\"android\", \"device_management\"],\n" + " \"isMappingAnExistingOAuthApp\":false\n" + "}").toString(); - public static final String PERMISSION_LIST = "appm:subscribe perm:admin-groups:count perm:admin-groups:view " - + "perm:admin-users:view perm:admin:certificates:add perm:admin:certificates:delete " + public static final String PERMISSION_LIST = "appm:read appm:subscribe 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:applications perm:android:blacklist-applications " + "perm:android:change-lock-code perm:android:clear-password perm:android:configure-vpn perm:android:configure-wifi " @@ -343,7 +351,7 @@ public final class Constants { public static final String UPDATE_POLICY_ENDPOINT = "/mdm-admin/policies/1"; public static final String REMOVE_POLICY_ENDPOINT = "/mdm-admin/policies/bulk-remove"; public static final String REMOVE_POLICY_PAYLOAD_FILE_NAME = "[1]"; - public static final String VIEW_POLICY_LIST_ENDPOINT = "/mdm-admin/policies"; + public static final String VIEW_POLICY_LIST_ENDPOINT = "/api/device-mgt/v1.0/policies"; private PolicyManagement() { throw new AssertionError(); @@ -393,4 +401,12 @@ public final class Constants { } } + + public static final class QSGManagement { + public static final String GET_MOBILE_APPS_ENDPONT = "/api/appm/publisher/v1.1/apps/mobileapp"; + + private QSGManagement() { + throw new AssertionError(); + } + } } diff --git a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java index 8915356a..3393e7cd 100644 --- a/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java +++ b/modules/integration/tests-common/integration-common/src/main/java/org/wso2/iot/integration/common/TestBase.java @@ -40,7 +40,7 @@ public class TestBase { protected void init(TestUserMode userMode) throws Exception { automationContext = new AutomationContext(Constants.AUTOMATION_CONTEXT, userMode); String tenantDomain = automationContext.getContextTenant().getDomain(); - backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants + backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps().replace("9443", String.valueOf(Constants .HTTPS_GATEWAY_PORT)).replace("/t/" + tenantDomain , ""); backendHTTPURL = automationContext.getContextUrls().getWebAppURL().replace("9763", String.valueOf(Constants .HTTP_GATEWAY_PORT)).replace("/t/" + tenantDomain , ""); diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/samples/MobileQSGTestCase.java b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/samples/MobileQSGTestCase.java new file mode 100644 index 00000000..a6d2e815 --- /dev/null +++ b/modules/integration/tests-integration/src/test/java/org/wso2/iot/integration/samples/MobileQSGTestCase.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.iot.integration.samples; + +import junit.framework.Assert; +import org.apache.commons.httpclient.HttpStatus; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.context.TestUserMode; +import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.iot.integration.common.Constants; +import org.wso2.iot.integration.common.RestClient; +import org.wso2.iot.integration.common.TestBase; + +import java.io.File; +import java.io.IOException; + +/** + * This class tests the functionality of the mobile qsg. + */ +public class MobileQSGTestCase extends TestBase { + private RestClient client; + + @BeforeClass(alwaysRun = true, groups = { Constants.UserManagement.USER_MANAGEMENT_GROUP}) + public void initTest() throws Exception { + super.init(TestUserMode.SUPER_TENANT_ADMIN); + backendHTTPSURL = automationContext.getContextUrls().getWebAppURLHttps(); + this.client = new RestClient(backendHTTPSURL, Constants.APPLICATION_JSON, accessTokenString); + } + + @Test(description = "This test case tests the execution of QSG script, whether it executes without any exceptions") + public void executeQSGScript() throws IOException, InterruptedException { + String scriptPath = + FrameworkPathUtil.getCarbonHome() + File.separator + "samples" + File.separator + "mobile-qsg"; + File scriptFile = new File(scriptPath); + String[] cmdArray = new String[] { "sh", "mobile-qsg.sh" }; + Runtime.getRuntime().exec(cmdArray, null, scriptFile); + // Allow some time to finish its execution + Thread.sleep(10000); + } + + @Test(description = "This test case tests whether user and roles are created as expected", dependsOnMethods = + {"executeQSGScript"}) + public void testUserRoleCreation() throws Exception { + // Two users will be created with the quick start script, check whether those two users are created + // successfully, + String username1 = "alex"; + String url = Constants.UserManagement.USER_ENDPOINT + "/" + username1; + HttpResponse response = client.get(url); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + String username2 = "chris"; + url = Constants.UserManagement.USER_ENDPOINT + "/" + username2; + response = client.get(url); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + + // A single role will be created with the quick start script, checking whether that role creation happens + // without problem + String rolename = "iotMobileUser"; + response = client.get(Constants.RoleManagement.ROLE_MANAGEMENT_END_POINT + "/" + rolename); + Assert.assertEquals(HttpStatus.SC_OK, response.getResponseCode()); + } + + @Test(description = "This test case tests whether app-catalogue is created from qsg script", dependsOnMethods = + {"executeQSGScript"}) + public void testMobileApp() throws Exception { + RestClient appManagerRestClient = new RestClient(automationContext.getContextUrls().getWebAppURLHttps(), + Constants.APPLICATION_JSON, accessTokenString); + HttpResponse response = appManagerRestClient.get(Constants.QSGManagement.GET_MOBILE_APPS_ENDPONT); + Assert.assertEquals("Catalog mobile app is not uploaded successfully", HttpStatus.SC_OK, + response.getResponseCode()); + Assert.assertTrue("Catalog app addition through script is not successful", + response.getData().contains("Catalog")); + } + + @Test(description = "This test case tests the policy creation through qsg script", dependsOnMethods = {"executeQSGScript"}) + public void testPolicyCreation() throws Exception { + HttpResponse response = client.get(Constants.PolicyManagement.VIEW_POLICY_LIST_ENDPOINT + "?offset=0&limit=10"); + Assert.assertEquals("Policy upload view mobile-qsg script failed", HttpStatus.SC_OK, + response.getResponseCode()); + Assert.assertTrue("Android pass-code policy is not added from qsg script", + response.getData().contains("android-passcode-policy1")); + Assert.assertTrue("Windows pass-code policy is not added from qsg script", + response.getData().contains("windows-passcode-policy1")); + } +}