From f71ba4199edc3fe8b55186bec76c1e57dc9f13b8 Mon Sep 17 00:00:00 2001 From: "Gutta, RaghavendraX" Date: Mon, 9 Mar 2015 19:04:37 +0530 Subject: [PATCH] 1)Test Runner enabled with Working & Automated test Cases. 2)Working test cases but need to execute manually are ->testCreateNewUser ->testUpdateForgotPassword ->testChangePassword ->testGetInfoOnAlert ->testUpdateAlertStatus ->testAddCommentsToTheAlert ->testResetAlert 3)Test cases with errors(it could be issue with server) ->testUpdateStatusOfRule ->testGetInvitationListSendToSpecificUser --- .../com/intel/iotkit/AlertManagementTest.java | 3 +- .../com/intel/iotkit/AuthorizationTest.java | 2 +- .../java/com/intel/iotkit/TestRunner.java | 59 +++++++++++-------- .../com/intel/iotkit/UserManagementTest.java | 7 ++- .../com/intel/iotkitlib/UserManagement.java | 18 +++++- .../iotkitlib/models/AuthorizationToken.java | 9 +++ 6 files changed, 65 insertions(+), 33 deletions(-) diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java index a18cd5b..ec7b5a0 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java @@ -26,6 +26,7 @@ import com.intel.iotkitlib.AlertManagement; import com.intel.iotkitlib.RequestStatusHandler; import com.intel.iotkitlib.http.CloudResponse; +import com.intel.iotkitlib.utils.Utilities; import org.json.JSONException; @@ -88,7 +89,7 @@ public void readResponse(CloudResponse response) { serverResponse = true; } }); - CloudResponse response = alertManagement.addCommentsToTheAlert(alertId.toString(), "xxxx@example.com", + CloudResponse response = alertManagement.addCommentsToTheAlert(alertId.toString(), Utilities.sharedPreferences.getString("email", ""), System.currentTimeMillis(), "iotkit_wrapper comment"); assertEquals(true, response.getStatus()); waitForServerResponse(alertManagement); diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java index b43d02e..d806b43 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java @@ -50,7 +50,7 @@ public void readResponse(CloudResponse response) { }); //for getting token CloudResponse response = getToken.getNewAuthorizationToken - ("intel.aricent.iot3@gmail.com", "Password2529"); + ("xxxx@gmail.com", "xxxx"); assertEquals(true, response.getStatus()); waitForServerResponse(getToken); } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java b/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java index ada7000..509e04e 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java @@ -33,23 +33,34 @@ public class TestRunner extends InstrumentationTestRunner { public TestSuite getAllTests() { TestSuite suite = new InstrumentationTestSuite(this); - //User management - //need to execute separately, because manually need to activate user by clicking link in mail - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testCreateNewUser")); + /*****need to execute manually & separately, because manually need to activate user by + *clicking activation link in mail. After creating user need a new auth token for further requests + //suite.addTest(TestSuite.createTest(UserManagementTest.class, "testCreateNewUser")); + //suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken"));//new token needed + ******/ - suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken")); - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testGetUserInfo")); - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateUserAttributes")); - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testChangePassword")); - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testRequestChangePassword")); - //need to execute separately, because manually need to enter change pwd token - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateForgotPassword")); + /***All the following test cases assumed to run on existing user with no account created(zero accounts), + * user mail id(activated with enableIot server) is expected to input manually in "testGetNewAuthorizationToken" + * before running this test suite***/ //Authorization Tests suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken")); suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetAuthorizationTokenInfo")); suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testValidateAuthToken")); + //User management + suite.addTest(TestSuite.createTest(UserManagementTest.class, "testGetUserInfo")); + suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateUserAttributes")); + suite.addTest(TestSuite.createTest(UserManagementTest.class, "testRequestChangePassword")); + /****need to be executed manually, after executing "testRequestChangePassword" token will be sent to mail, + * manually need to input the token to "testUpdateForgotPassword" + //suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateForgotPassword")); + * ****/ + /****need to be executed manually, because on executing "testChangePassword", + * password need to be altered in "testGetNewAuthorizationToken" for getting new token + //suite.addTest(TestSuite.createTest(UserManagementTest.class, "testChangePassword")); + *****/ + //Account Management suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testCreateAnAccount")); //need fresh token after account creation, going for testGetNewAuthorizationToken again @@ -57,8 +68,6 @@ public TestSuite getAllTests() { suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testGetAccountInformation")); suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testRenewAccountActivationCode")); suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testGetAccountActivationCode")); - //need to provide invitee userId manually in this test case as a param - suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testAddAnotherUserToYourAccount")); //will work with single account,because not handling multiple accounts locally, behaviour of this test case with multiple accounts not defined. suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testUpdateAnAccount")); @@ -68,15 +77,11 @@ public TestSuite getAllTests() { suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetDeviceList")); suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetMyDeviceInfo")); suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetInfoOnDevice")); - //activation-code refresh, methods running again - suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testRenewAccountActivationCode")); - suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testGetAccountActivationCode")); suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testActivateADevice")); suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testAddComponentToDevice")); suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetAllAttributes")); suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetAllTags")); - suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteAComponent")); - suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteADevice")); + //Component Types Catalog suite.addTest(TestSuite.createTest(ComponentCatalogManagementTest.class, "testListAllComponentTypesCatalog")); @@ -91,9 +96,11 @@ public TestSuite getAllTests() { //Invitation Management suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testCreateInvitation")); - suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken")); - //suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetInvitationListSendToSpecificUser"));//unauthorized error, need to verify + /***unauthorized error, need to verify with Server team***/ + //suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetInvitationListSendToSpecificUser")); suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetListOfInvitation")); + //Adding another user can be executed after creating invitation only + suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testAddAnotherUserToYourAccount")); suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testDeleteInvitations")); //Rule Management @@ -103,7 +110,8 @@ public TestSuite getAllTests() { suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testDeleteADraftRule")); suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testGetInformationOnRule")); suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testGetListOfRules")); - //suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testUpdateStatusOfRule"));//Internal server error,need to verify + //Internal server error,need to verify with Server team + //suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testUpdateStatusOfRule")); //Advanced Data Inquiry suite.addTest(TestSuite.createTest(AdvancedDataInquiryTest.class, "testAdvancedDataEnquiry")); @@ -113,11 +121,12 @@ public TestSuite getAllTests() { //Alert management suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testGetListOfAlerts")); - //need to provide alertId manually for the following alert test cases - suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testGetInfoOnAlert")); - suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testUpdateAlertStatus")); - suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testAddCommentsToTheAlert")); - suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testResetAlert")); + /***need to provide alertId manually for the following alert test cases + /*suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testGetInfoOnAlert")); + suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testUpdateAlertStatus")); + suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testAddCommentsToTheAlert")); + suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testResetAlert")); + ****/ //Delete All Account and user details suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteAComponent")); diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java index 93ff101..1ec6f30 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java @@ -55,7 +55,7 @@ public void readResponse(CloudResponse response) { serverResponse = true; } }); - CloudResponse response = userManagement.createNewUser("intel.aricent.iot@gmail.com", "Password2529"); + CloudResponse response = userManagement.createNewUser("xxxxx@gmail.com", "xxxx"); assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } @@ -99,7 +99,7 @@ public void readResponse(CloudResponse response) { serverResponse = true; } }); - CloudResponse response = userManagement.requestChangePassword("intel.aricent.iot@gmail.com"); + CloudResponse response = userManagement.requestChangePassword(Utilities.sharedPreferences.getString("email", "")); assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } @@ -125,7 +125,8 @@ public void readResponse(CloudResponse response) { serverResponse = true; } }); - CloudResponse response = userManagement.changePassword("intel.aricent.iot@gmail.com", "Password2529", "Password25292"); + CloudResponse response = userManagement.changePassword(Utilities.sharedPreferences.getString("email", "") + , "Password2529", "Password25292"); assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } diff --git a/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java b/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java index 28c9d36..dcef75d 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java @@ -160,9 +160,21 @@ public CloudResponse getUserInfo(String userId) { Log.d(TAG, ERR_INVALID_ID); return new CloudResponse(false, ERR_INVALID_ID); } + RequestStatusHandler preProcessing = new RequestStatusHandler() { + @Override + public void readResponse(CloudResponse response) { + Log.d(TAG, String.valueOf(response.getCode())); + Log.d(TAG, response.getResponse()); + try { + AuthorizationToken.parseAndStoreUserMailId(response.getResponse(), response.getCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }; getUserInfo.setHeaders(basicHeaderList); String url = objIotKit.prepareUrl(objIotKit.getUserInfo, createHashMapWithUserID(tempUserId)); - return super.invokeHttpExecuteOnURL(url, getUserInfo); + return super.invokeHttpExecuteOnURL(url, getUserInfo, preProcessing); } /** @@ -304,12 +316,12 @@ private String createBodyForRequestingChangePassword(String emailId) throws JSON return requestChangePwdJson.toString(); } - private String createBodyForTermsAndConditionsAcceptance(String userId, boolean accept) throws JSONException { + /*private String createBodyForTermsAndConditionsAcceptance(String userId, boolean accept) throws JSONException { JSONObject acceptTermsAndConditions = new JSONObject(); acceptTermsAndConditions.put("id", userId); acceptTermsAndConditions.put("termsAndConditions", accept); return acceptTermsAndConditions.toString(); - } + }*/ private String createBodyForUserAttributesUpdation(String userId, List userAttributes) throws JSONException { JSONObject updateAttributesJson = new JSONObject(); diff --git a/iotkitlib/src/main/java/com/intel/iotkitlib/models/AuthorizationToken.java b/iotkitlib/src/main/java/com/intel/iotkitlib/models/AuthorizationToken.java index d956e0f..9b6dd19 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/models/AuthorizationToken.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/models/AuthorizationToken.java @@ -157,6 +157,15 @@ public static void parseAndStoreActivationCode(String response) throws JSONExcep Utilities.editor.commit(); } + public static void parseAndStoreUserMailId(String response, int responseCode) throws JSONException { + if (responseCode == 200) { + //Set the first account details to shared prefs + JSONObject accountJson = new JSONObject(response); + Utilities.editor.putString("email", accountJson.getString("email")); + Utilities.editor.commit(); + } + } + public static void parseAndStoreAccountName(String accountName, int responseCode) throws JSONException { if (responseCode == 200) { Utilities.editor.putString("account_name", accountName);