From e8244c228df08843891b44071f6d49b1763359bf Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Wed, 24 Aug 2016 17:21:24 +0530 Subject: [PATCH 1/2] Fixes for integration tests --- .../mdm/integration/common/Constants.java | 10 ++-- .../policy/AndroidPolicyManagement.java | 18 +++---- .../payloads/android-policy-payloads.json | 30 +++++------ .../android-policy-work-profile-payload.json | 51 ++++++++++--------- .../payloads/policy-erroneous-payloads.json | 16 ++++++ .../payloads/policy-response-payloads.json | 6 +-- 6 files changed, 73 insertions(+), 58 deletions(-) diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java index 3119745b5..25ad3202b 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/common/Constants.java @@ -299,7 +299,7 @@ public static final class PolicyManagement { private PolicyManagement() { throw new AssertionError();} public static final String POLICY_MANAGEMENT_GROUP = "policy-mgt"; - public static final String ADD_POLICY_ENDPOINT= "/mdm-admin/policies/active-policy"; + public static final String ADD_POLICY_ENDPOINT= "/api/device-mgt/v1.0/policies"; public static final String GET_ALL_POLICIES_ENDPOINT = "/mdm-admin/policies"; public static final String POLICY_PRIORITIES_ENDPOINT = "/mdm-admin/policies/priorities"; @@ -317,14 +317,16 @@ public static final class PolicyManagement { public static final String POLICY_RESPONSE_PAYLOAD_FILE_NAME = "policy-response-payloads.json"; public static final String POLICY_PRIORITIES_RESPONSE_PAYLOAD_FILE_NAME = "policy-priories-response-payloads.json"; - public static final String UPDATE_ANDROID_POLICY_ENDPOINT = "/mdm-admin/policies/1"; + public static final String UPDATE_ANDROID_POLICY_ENDPOINT = "/api/device-mgt/v1.0/policies/1"; public static String UPDATE_WINDOWS_POLICY_ENDPOINT = ""; + public static final String UPDATE_POLICY_RESPONSE = "\"Policy has successfully been updated.\""; - public static final String REMOVE_POLICY_ENDPOINT = "/mdm-admin/policies/bulk-remove"; + public static final String REMOVE_POLICY_ENDPOINT = "/api/device-mgt/v1.0/policies/remove-policy"; public static final String REMOVE_ANDROID_POLICY_PAYLOAD_FILE_NAME = "[1]"; public static String REMOVE_WINDOWS_POLICY_PAYLOAD_FILE_NAME = ""; + public static final String REMOVE_POLICY_RESPONSE = "\"Policies have been successfully deleted\""; - 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"; } public static final class FeatureManagement { diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java index 3b9dece63..7dcc8a4ab 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java @@ -44,8 +44,6 @@ public void testAddPolicy() throws Exception { PayloadGenerator.getJsonPayload(Constants.PolicyManagement.ANDROID_POLICY_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus()); - Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST).toString(),response.getBody()); } @Test(description = "Test add policy for work-profile") @@ -54,8 +52,6 @@ public void testAddWorkProfilePolicy() throws Exception{ PayloadGenerator.getJsonPayload(Constants.PolicyManagement.ANDROID_POLICY_WORK_PROFILE_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_POST).toString()); Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus()); - Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST).toString(),response.getBody()); } @Test(description = "Test add policy with erroneous payload.") @@ -65,11 +61,11 @@ public void testAddPolicyWithErroneousPayload() throws Exception { Constants.HTTP_METHOD_POST).toString()); Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus()); } + @Test(description = "Test view policy list.", dependsOnMethods = { "testAddPolicy"}) public void testViewPolicyList() throws Exception { MDMResponse response = client.get(Constants.PolicyManagement.VIEW_POLICY_LIST_ENDPOINT); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); - } @Test(description = "Test update policy.", dependsOnMethods = { "testViewPolicyList"}) @@ -79,32 +75,30 @@ public void testUpdatePolicy() throws Exception { PayloadGenerator.getJsonPayload( Constants.PolicyManagement.ANDROID_POLICY_PAYLOAD_FILE_NAME, Constants.HTTP_METHOD_PUT).toString()); - Assert.assertEquals(HttpStatus.SC_CREATED, response.getStatus()); + Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); + Assert.assertEquals(Constants.PolicyManagement.UPDATE_POLICY_RESPONSE,response.getBody()); } @Test(description = "Test update policy with erroneous payload.", dependsOnMethods = { "testAddPolicy"}) public void testUpdatePolicyWithErroneousPayload() throws Exception { MDMResponse response = client.put(Constants.PolicyManagement.UPDATE_ANDROID_POLICY_ENDPOINT, PayloadGenerator.getJsonPayload(Constants.PolicyManagement.ANDROID_POLICY_ERRONEOUS_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_POST).toString()); + Constants.HTTP_METHOD_PUT).toString()); Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus()); } @Test(description = "Test remove policy.", dependsOnMethods = { "testUpdatePolicy" }) public void testRemovePolicy() throws Exception { - MDMResponse response = client.post(Constants.PolicyManagement.REMOVE_POLICY_ENDPOINT, Constants.PolicyManagement.REMOVE_ANDROID_POLICY_PAYLOAD_FILE_NAME); Assert.assertEquals(HttpStatus.SC_OK, response.getStatus()); - Assert.assertEquals(PayloadGenerator.getJsonPayload(Constants.PolicyManagement.POLICY_RESPONSE_PAYLOAD_FILE_NAME, - Constants.HTTP_METHOD_DELETE).toString(), response.getBody()); + Assert.assertEquals(Constants.PolicyManagement.REMOVE_POLICY_RESPONSE, response.getBody()); } @Test(description = "Test remove policy without a policies.", dependsOnMethods = { "testRemovePolicy" }) public void testRemovePolicyWithoutPolicies() throws Exception { - MDMResponse response = client.post(Constants.PolicyManagement.REMOVE_POLICY_ENDPOINT, Constants.PolicyManagement.REMOVE_ANDROID_POLICY_PAYLOAD_FILE_NAME); - Assert.assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, response.getStatus()); + Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); } } \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json index e7f27dafa..2c32e8f4a 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-payloads.json @@ -4,23 +4,23 @@ "description": "Optional", "compliance": "enforce", "ownershipType": "ANY", + "active": false, "profile": { "profileName": "Camera", - "deviceType": { - "id": 1 - }, + "deviceType": "android", "profileFeaturesList": [ { "featureCode": "CAMERA", - "deviceTypeId": 1, + "deviceType": "android", "content": { - "enabled": true + "enabled": false } } ] }, - "users": [], - "roles": [] + "roles": [ + "ANY" + ] }, "PUT": { "policyName": "Camera", @@ -29,26 +29,26 @@ "ownershipType": "ANY", "profile": { "profileName": "Camera", - "deviceType": { - "id": 1 - }, + "deviceType": "android", "profileFeaturesList": [ { "featureCode": "CAMERA", - "deviceTypeId": 1, + "deviceType": "android", "content": { - "enabled": true + "enabled": false } }, { - "featureCode": "ENCRYPT_STORAGE", - "deviceTypeId": 1, + "featureCode": "DISALLOW_ADJUST_VOLUME", + "deviceType": "android", "content": { - "encrypted": true + "enabled": true } } ] }, + "users": [ + ], "roles": [ "ANY" ] diff --git a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json index 9dae9dc04..f7b4eca2e 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/android-policy-work-profile-payload.json @@ -1,26 +1,29 @@ -{"POST": { - "policyName": "Work-Profile", - "description": "", - "compliance": "enforce", - "ownershipType": "ANY", - "profile": { - "profileName": "Work-Profile", - "deviceType": { - "id": 1 +{ + "POST": { + "policyName":"Work-Profile", + "description":"", + "compliance":"enforce", + "ownershipType":"ANY", + "active":false, + "profile":{ + "profileName":"Work-Profile", + "deviceType":"android", + "profileFeaturesList":[ + { + "featureCode":"WORK_PROFILE", + "deviceType":"android", + "content":{ + "profileName":"Work-Profile", + "enableSystemApps":"com.google.android.apps.maps", + "hideSystemApps":"com.google.android.calculator", + "unhideSystemApps":null, + "enablePlaystoreApps":"com.google.android.whity" + } + } + ] }, - "profileFeaturesList": [{ - "featureCode": "WORK_PROFILE", - "deviceTypeId": 1, - "content": { - "DISALLOW_CROSS_PROFILE_COPY_PASTE": true, - "profileName": "WSO2 Profile", - "enableSystemApps": "com.google.android.apps.maps", - "hideSystemApps": "com.google.android.calculator", - "unhideSystemApps": null, - "enablePlaystoreApps": "com.google.android.whity" - } - }] - }, - "roles": ["ANY"] -} + "roles":[ + "ANY" + ] + } } \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json index 7f87a2074..a65e9a91c 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/policy-erroneous-payloads.json @@ -14,5 +14,21 @@ }, "users": [], "roles": [] + }, + "PUT" : { + "compliance": "enforce", + "ownershipType": "ANY", + "profile": { + "profileName": "Camera", + "profileFeaturesList": [ + { + "content": { + "enabled": true + } + } + ] + }, + "users": [], + "roles": [] } } \ No newline at end of file diff --git a/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json b/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json index 396a639c0..9d77f80aa 100644 --- a/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json +++ b/modules/integration/tests-integration/src/test/resources/payloads/policy-response-payloads.json @@ -4,11 +4,11 @@ "messageFromServer": "Policy has been added successfully." }, "PUT": { - "statusCode": 201, - "messageFromServer": "Policy has been updated successfully." + "statusCode": 200, + "messageFromServer": "Policy has successfully been updated." }, "DELETE": { "statusCode": 200, - "messageFromServer": "Policies have been successfully deleted." + "messageFromServer": "Policies have been successfully deleted" } } From ff60b36e8aae6a254921e704d779c75cc9be0256 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Wed, 24 Aug 2016 19:22:22 +0530 Subject: [PATCH 2/2] Fixes for integration tests --- .../wso2/mdm/integration/policy/AndroidPolicyManagement.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java index 7dcc8a4ab..afc4071e5 100644 --- a/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java +++ b/modules/integration/tests-integration/src/test/java/org/wso2/mdm/integration/policy/AndroidPolicyManagement.java @@ -99,6 +99,6 @@ public void testRemovePolicy() throws Exception { public void testRemovePolicyWithoutPolicies() throws Exception { MDMResponse response = client.post(Constants.PolicyManagement.REMOVE_POLICY_ENDPOINT, Constants.PolicyManagement.REMOVE_ANDROID_POLICY_PAYLOAD_FILE_NAME); - Assert.assertEquals(HttpStatus.SC_NOT_FOUND, response.getStatus()); + Assert.assertEquals(HttpStatus.SC_BAD_REQUEST, response.getStatus()); } } \ No newline at end of file