Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2 from GuttaRaghavendra/refactor
Browse files Browse the repository at this point in the history
Modified Test Runner
  • Loading branch information
dzungductran committed Mar 9, 2015
2 parents 62ad99c + f71ba41 commit a7f5371
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -88,7 +89,7 @@ public void readResponse(CloudResponse response) {
serverResponse = true;
}
});
CloudResponse response = alertManagement.addCommentsToTheAlert(alertId.toString(), "[email protected]",
CloudResponse response = alertManagement.addCommentsToTheAlert(alertId.toString(), Utilities.sharedPreferences.getString("email", ""),
System.currentTimeMillis(), "iotkit_wrapper comment");
assertEquals(true, response.getStatus());
waitForServerResponse(alertManagement);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
59 changes: 34 additions & 25 deletions TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,32 +33,41 @@ 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
suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken"));
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"));

Expand All @@ -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"));
Expand All @@ -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
Expand All @@ -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"));
Expand All @@ -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"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -99,7 +99,7 @@ public void readResponse(CloudResponse response) {
serverResponse = true;
}
});
CloudResponse response = userManagement.requestChangePassword("[email protected]");
CloudResponse response = userManagement.requestChangePassword(Utilities.sharedPreferences.getString("email", ""));
assertEquals(true, response.getStatus());
waitForServerResponse(userManagement);
}
Expand All @@ -125,7 +125,8 @@ public void readResponse(CloudResponse response) {
serverResponse = true;
}
});
CloudResponse response = userManagement.changePassword("[email protected]", "Password2529", "Password25292");
CloudResponse response = userManagement.changePassword(Utilities.sharedPreferences.getString("email", "")
, "Password2529", "Password25292");
assertEquals(true, response.getStatus());
waitForServerResponse(userManagement);
}
Expand Down
18 changes: 15 additions & 3 deletions iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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<NameValuePair> userAttributes) throws JSONException {
JSONObject updateAttributesJson = new JSONObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit a7f5371

Please sign in to comment.