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

Commit a7f5371

Browse files
committed
Merge pull request #2 from GuttaRaghavendra/refactor
Modified Test Runner
2 parents 62ad99c + f71ba41 commit a7f5371

File tree

6 files changed

+65
-33
lines changed

6 files changed

+65
-33
lines changed

TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.intel.iotkitlib.AlertManagement;
2727
import com.intel.iotkitlib.RequestStatusHandler;
2828
import com.intel.iotkitlib.http.CloudResponse;
29+
import com.intel.iotkitlib.utils.Utilities;
2930

3031
import org.json.JSONException;
3132

@@ -88,7 +89,7 @@ public void readResponse(CloudResponse response) {
8889
serverResponse = true;
8990
}
9091
});
91-
CloudResponse response = alertManagement.addCommentsToTheAlert(alertId.toString(), "xxxx@example.com",
92+
CloudResponse response = alertManagement.addCommentsToTheAlert(alertId.toString(), Utilities.sharedPreferences.getString("email", ""),
9293
System.currentTimeMillis(), "iotkit_wrapper comment");
9394
assertEquals(true, response.getStatus());
9495
waitForServerResponse(alertManagement);

TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void readResponse(CloudResponse response) {
5050
});
5151
//for getting token
5252
CloudResponse response = getToken.getNewAuthorizationToken
53-
("intel.aricent.iot3@gmail.com", "Password2529");
53+
("xxxx@gmail.com", "xxxx");
5454
assertEquals(true, response.getStatus());
5555
waitForServerResponse(getToken);
5656
}

TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,32 +33,41 @@ public class TestRunner extends InstrumentationTestRunner {
3333
public TestSuite getAllTests() {
3434
TestSuite suite = new InstrumentationTestSuite(this);
3535

36-
//User management
37-
//need to execute separately, because manually need to activate user by clicking link in mail
38-
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testCreateNewUser"));
36+
/*****need to execute manually & separately, because manually need to activate user by
37+
*clicking activation link in mail. After creating user need a new auth token for further requests
38+
//suite.addTest(TestSuite.createTest(UserManagementTest.class, "testCreateNewUser"));
39+
//suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken"));//new token needed
40+
******/
3941

40-
suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken"));
41-
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testGetUserInfo"));
42-
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateUserAttributes"));
43-
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testChangePassword"));
44-
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testRequestChangePassword"));
45-
//need to execute separately, because manually need to enter change pwd token
46-
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateForgotPassword"));
42+
/***All the following test cases assumed to run on existing user with no account created(zero accounts),
43+
* user mail id(activated with enableIot server) is expected to input manually in "testGetNewAuthorizationToken"
44+
* before running this test suite***/
4745

4846
//Authorization Tests
4947
suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken"));
5048
suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetAuthorizationTokenInfo"));
5149
suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testValidateAuthToken"));
5250

51+
//User management
52+
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testGetUserInfo"));
53+
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateUserAttributes"));
54+
suite.addTest(TestSuite.createTest(UserManagementTest.class, "testRequestChangePassword"));
55+
/****need to be executed manually, after executing "testRequestChangePassword" token will be sent to mail,
56+
* manually need to input the token to "testUpdateForgotPassword"
57+
//suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateForgotPassword"));
58+
* ****/
59+
/****need to be executed manually, because on executing "testChangePassword",
60+
* password need to be altered in "testGetNewAuthorizationToken" for getting new token
61+
//suite.addTest(TestSuite.createTest(UserManagementTest.class, "testChangePassword"));
62+
*****/
63+
5364
//Account Management
5465
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testCreateAnAccount"));
5566
//need fresh token after account creation, going for testGetNewAuthorizationToken again
5667
suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken"));
5768
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testGetAccountInformation"));
5869
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testRenewAccountActivationCode"));
5970
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testGetAccountActivationCode"));
60-
//need to provide invitee userId manually in this test case as a param
61-
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testAddAnotherUserToYourAccount"));
6271
//will work with single account,because not handling multiple accounts locally, behaviour of this test case with multiple accounts not defined.
6372
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testUpdateAnAccount"));
6473

@@ -68,15 +77,11 @@ public TestSuite getAllTests() {
6877
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetDeviceList"));
6978
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetMyDeviceInfo"));
7079
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetInfoOnDevice"));
71-
//activation-code refresh, methods running again
72-
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testRenewAccountActivationCode"));
73-
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testGetAccountActivationCode"));
7480
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testActivateADevice"));
7581
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testAddComponentToDevice"));
7682
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetAllAttributes"));
7783
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testGetAllTags"));
78-
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteAComponent"));
79-
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteADevice"));
84+
8085

8186
//Component Types Catalog
8287
suite.addTest(TestSuite.createTest(ComponentCatalogManagementTest.class, "testListAllComponentTypesCatalog"));
@@ -91,9 +96,11 @@ public TestSuite getAllTests() {
9196

9297
//Invitation Management
9398
suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testCreateInvitation"));
94-
suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken"));
95-
//suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetInvitationListSendToSpecificUser"));//unauthorized error, need to verify
99+
/***unauthorized error, need to verify with Server team***/
100+
//suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetInvitationListSendToSpecificUser"));
96101
suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetListOfInvitation"));
102+
//Adding another user can be executed after creating invitation only
103+
suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testAddAnotherUserToYourAccount"));
97104
suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testDeleteInvitations"));
98105

99106
//Rule Management
@@ -103,7 +110,8 @@ public TestSuite getAllTests() {
103110
suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testDeleteADraftRule"));
104111
suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testGetInformationOnRule"));
105112
suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testGetListOfRules"));
106-
//suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testUpdateStatusOfRule"));//Internal server error,need to verify
113+
//Internal server error,need to verify with Server team
114+
//suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testUpdateStatusOfRule"));
107115

108116
//Advanced Data Inquiry
109117
suite.addTest(TestSuite.createTest(AdvancedDataInquiryTest.class, "testAdvancedDataEnquiry"));
@@ -113,11 +121,12 @@ public TestSuite getAllTests() {
113121

114122
//Alert management
115123
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testGetListOfAlerts"));
116-
//need to provide alertId manually for the following alert test cases
117-
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testGetInfoOnAlert"));
118-
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testUpdateAlertStatus"));
119-
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testAddCommentsToTheAlert"));
120-
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testResetAlert"));
124+
/***need to provide alertId manually for the following alert test cases
125+
/*suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testGetInfoOnAlert"));
126+
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testUpdateAlertStatus"));
127+
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testAddCommentsToTheAlert"));
128+
suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testResetAlert"));
129+
****/
121130

122131
//Delete All Account and user details
123132
suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteAComponent"));

TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public void readResponse(CloudResponse response) {
5555
serverResponse = true;
5656
}
5757
});
58-
CloudResponse response = userManagement.createNewUser("intel.aricent.iot@gmail.com", "Password2529");
58+
CloudResponse response = userManagement.createNewUser("xxxxx@gmail.com", "xxxx");
5959
assertEquals(true, response.getStatus());
6060
waitForServerResponse(userManagement);
6161
}
@@ -99,7 +99,7 @@ public void readResponse(CloudResponse response) {
9999
serverResponse = true;
100100
}
101101
});
102-
CloudResponse response = userManagement.requestChangePassword("intel.aricent.iot@gmail.com");
102+
CloudResponse response = userManagement.requestChangePassword(Utilities.sharedPreferences.getString("email", ""));
103103
assertEquals(true, response.getStatus());
104104
waitForServerResponse(userManagement);
105105
}
@@ -125,7 +125,8 @@ public void readResponse(CloudResponse response) {
125125
serverResponse = true;
126126
}
127127
});
128-
CloudResponse response = userManagement.changePassword("intel.aricent.iot@gmail.com", "Password2529", "Password25292");
128+
CloudResponse response = userManagement.changePassword(Utilities.sharedPreferences.getString("email", "")
129+
, "Password2529", "Password25292");
129130
assertEquals(true, response.getStatus());
130131
waitForServerResponse(userManagement);
131132
}

iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,21 @@ public CloudResponse getUserInfo(String userId) {
160160
Log.d(TAG, ERR_INVALID_ID);
161161
return new CloudResponse(false, ERR_INVALID_ID);
162162
}
163+
RequestStatusHandler preProcessing = new RequestStatusHandler() {
164+
@Override
165+
public void readResponse(CloudResponse response) {
166+
Log.d(TAG, String.valueOf(response.getCode()));
167+
Log.d(TAG, response.getResponse());
168+
try {
169+
AuthorizationToken.parseAndStoreUserMailId(response.getResponse(), response.getCode());
170+
} catch (JSONException e) {
171+
e.printStackTrace();
172+
}
173+
}
174+
};
163175
getUserInfo.setHeaders(basicHeaderList);
164176
String url = objIotKit.prepareUrl(objIotKit.getUserInfo, createHashMapWithUserID(tempUserId));
165-
return super.invokeHttpExecuteOnURL(url, getUserInfo);
177+
return super.invokeHttpExecuteOnURL(url, getUserInfo, preProcessing);
166178
}
167179

168180
/**
@@ -304,12 +316,12 @@ private String createBodyForRequestingChangePassword(String emailId) throws JSON
304316
return requestChangePwdJson.toString();
305317
}
306318

307-
private String createBodyForTermsAndConditionsAcceptance(String userId, boolean accept) throws JSONException {
319+
/*private String createBodyForTermsAndConditionsAcceptance(String userId, boolean accept) throws JSONException {
308320
JSONObject acceptTermsAndConditions = new JSONObject();
309321
acceptTermsAndConditions.put("id", userId);
310322
acceptTermsAndConditions.put("termsAndConditions", accept);
311323
return acceptTermsAndConditions.toString();
312-
}
324+
}*/
313325

314326
private String createBodyForUserAttributesUpdation(String userId, List<NameValuePair> userAttributes) throws JSONException {
315327
JSONObject updateAttributesJson = new JSONObject();

iotkitlib/src/main/java/com/intel/iotkitlib/models/AuthorizationToken.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ public static void parseAndStoreActivationCode(String response) throws JSONExcep
157157
Utilities.editor.commit();
158158
}
159159

160+
public static void parseAndStoreUserMailId(String response, int responseCode) throws JSONException {
161+
if (responseCode == 200) {
162+
//Set the first account details to shared prefs
163+
JSONObject accountJson = new JSONObject(response);
164+
Utilities.editor.putString("email", accountJson.getString("email"));
165+
Utilities.editor.commit();
166+
}
167+
}
168+
160169
public static void parseAndStoreAccountName(String accountName, int responseCode) throws JSONException {
161170
if (responseCode == 200) {
162171
Utilities.editor.putString("account_name", accountName);

0 commit comments

Comments
 (0)