From 09657759b94d48fe7ee4f785cf0caba80781dc02 Mon Sep 17 00:00:00 2001 From: "Gutta, RaghavendraX" Date: Mon, 2 Mar 2015 17:56:36 +0530 Subject: [PATCH] 1)Test cases modified as per new design. 2)TestApp changed to demo changed lib. 3)Accept Terms and conditions no longer supported.Instead CreateUser includes json field for "acceptTermsAndConditions". 4)Some of the lib methods added with preProcessing handler to store values to shared prefs(account activation code, RuleId's). --- .../intel/iotkit/AccountManagementTest.java | 72 +++++----- .../intel/iotkit/AdvancedDataInquiryTest.java | 84 +++++------ .../iotkit/AggregatedReportInterfaceTest.java | 38 ++--- .../com/intel/iotkit/AlertManagementTest.java | 37 +++-- .../com/intel/iotkit/ApplicationTest.java | 56 +++++++- .../com/intel/iotkit/AuthorizationTest.java | 30 ++-- .../ComponentCatalogManagementTest.java | 51 ++++--- .../com/intel/iotkit/DataManagementTest.java | 33 +++-- .../intel/iotkit/DeviceManagementTest.java | 94 ++++++++----- .../iotkit/InvitationManagementTest.java | 35 ++--- .../com/intel/iotkit/RuleManagementTest.java | 133 +++++++++--------- .../java/com/intel/iotkit/TestRunner.java | 59 +++++--- .../com/intel/iotkit/UserManagementTest.java | 63 ++++----- .../java/com/intel/iotkit/MyActivity.java | 27 +++- .../intel/iotkitlib/AccountManagement.java | 39 +++-- .../intel/iotkitlib/AdvancedDataInquiry.java | 36 +++-- .../com/intel/iotkitlib/DataManagement.java | 33 ++--- .../com/intel/iotkitlib/RuleManagement.java | 80 +++++++++-- .../com/intel/iotkitlib/UserManagement.java | 58 +++----- .../iotkitlib/models/AuthorizationToken.java | 7 + 20 files changed, 622 insertions(+), 443 deletions(-) diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/AccountManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/AccountManagementTest.java index 92476b1..7089b38 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/AccountManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/AccountManagementTest.java @@ -33,6 +33,8 @@ import com.intel.iotkitlib.AccountManagement; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; +import com.intel.iotkitlib.utils.Utilities; import org.json.JSONException; @@ -51,42 +53,42 @@ private void waitForServerResponse(Object object) { public void testCreateAnAccount() { AccountManagement accountManagement = new AccountManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(201, response.getCode()); serverResponse = true; } }); - - assertEquals(true, accountManagement.createAnAccount("UnitTesting")); + CloudResponse response = accountManagement.createAnAccount(getAccountName()); + assertEquals(true, response.getStatus()); waitForServerResponse(accountManagement); } public void testGetAccountInformation() { AccountManagement accountManagement = new AccountManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, accountManagement.getAccountInformation()); + CloudResponse response = accountManagement.getAccountInformation(); + assertEquals(true, response.getStatus()); waitForServerResponse(accountManagement); } public void testGetAccountActivationCode() { AccountManagement accountManagement = new AccountManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, accountManagement.getAccountActivationCode()); + CloudResponse response = accountManagement.getAccountActivationCode(); + assertEquals(true, response.getStatus()); waitForServerResponse(accountManagement); } @@ -94,56 +96,56 @@ public void readResponse(int responseCode, String response) { public void testRenewAccountActivationCode() { AccountManagement accountManagement = new AccountManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, accountManagement.renewAccountActivationCode()); + CloudResponse response = accountManagement.renewAccountActivationCode(); + assertEquals(true, response.getStatus()); waitForServerResponse(accountManagement); } public void testUpdateAnAccount() { AccountManagement accountManagement = new AccountManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, accountManagement.updateAnAccount("UnitTestingNewName")); + CloudResponse response = accountManagement.updateAnAccount(accountName); + assertEquals(true, response.getStatus()); waitForServerResponse(accountManagement); } public void testDeleteAnAccount() { AccountManagement accountManagement = new AccountManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(204, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(204, response.getCode()); serverResponse = true; } }); - - assertEquals(true, accountManagement.deleteAnAccount()); + CloudResponse response = accountManagement.deleteAnAccount(); + assertEquals(true, response.getStatus()); waitForServerResponse(accountManagement); } public void testAddAnotherUserToYourAccount() throws JSONException { AccountManagement accountManagement = new AccountManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, accountManagement.addAnotherUserToYourAccount("1e5f2301-b121-4933-8f32-1abb0af3d777", "545b0cb707024be10dec1152", false)); + CloudResponse response = accountManagement.addAnotherUserToYourAccount(Utilities.sharedPreferences.getString("account_id", ""), "545b0cb707024be10dec1152", true); + assertEquals(true, response.getStatus()); waitForServerResponse(accountManagement); } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/AdvancedDataInquiryTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/AdvancedDataInquiryTest.java index 6c6d2ab..fd5d37c 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/AdvancedDataInquiryTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/AdvancedDataInquiryTest.java @@ -25,7 +25,9 @@ import com.intel.iotkitlib.AdvancedDataInquiry; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; import com.intel.iotkitlib.models.AttributeFilter; +import com.intel.iotkitlib.utils.Utilities; import org.json.JSONException; @@ -40,76 +42,64 @@ private void waitForServerResponse(Object object) { } } - public void testAdvancedDataInquiry() throws JSONException { - AdvancedDataInquiry objAdvancedDataInquiry = new AdvancedDataInquiry(new RequestStatusHandler() { + public void testAdvancedDataEnquiry() throws JSONException { + AdvancedDataInquiry objAdvancedDataEnquiry = new AdvancedDataInquiry(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - objAdvancedDataInquiry.addGatewayId("qwertyPAD1"); - objAdvancedDataInquiry.addGatewayId("devTest"); - //objAdvancedDataInquiry.addGatewayId("02-00-86-81-77-15"); - objAdvancedDataInquiry.addDeviceId("qwertyPAD1"); - objAdvancedDataInquiry.addDeviceId("devTest"); - //objAdvancedDataInquiry.addDeviceId("02-00-86-81-77-19"); + objAdvancedDataEnquiry.addGatewayId(deviceName); + objAdvancedDataEnquiry.addDeviceId(deviceName); + objAdvancedDataEnquiry.addComponentId(Utilities.getSensorMatch(deviceComponentName).getValue().toString()); - objAdvancedDataInquiry.addComponentId("5C09B9F0-E06B-404A-A882-EAC64675A63E"); - objAdvancedDataInquiry.addComponentId("BB9E347D-7895-437E-9ECA-8069879090B7"); - objAdvancedDataInquiry.addComponentId("b780757a-4a45-40f3-9804-60eee953e8d2"); - //objAdvancedDataInquiry.addComponentId("c4d1f4c1-6fb6-4793-b85d-431c6cba647b"); + objAdvancedDataEnquiry.setStartTimestamp(0L); + objAdvancedDataEnquiry.setEndTimestamp(System.currentTimeMillis()); - objAdvancedDataInquiry.setStartTimestamp(0L); - objAdvancedDataInquiry.setEndTimestamp(System.currentTimeMillis()); + /*objAdvancedDataEnquiry.addReturnedMeasureAttributes("attr_1"); + objAdvancedDataEnquiry.addReturnedMeasureAttributes("attr_2"); + objAdvancedDataEnquiry.addReturnedMeasureAttributes("attr_3");*/ - /*objAdvancedDataInquiry.addReturnedMeasureAttribute("attr_1"); - objAdvancedDataInquiry.addReturnedMeasureAttribute("attr_2"); - objAdvancedDataInquiry.addReturnedMeasureAttribute("attr_3");*/ - - //objAdvancedDataInquiry.setShowMeasureLocation(true); + //objAdvancedDataEnquiry.setShowMeasureLocation(true); //dev comp attrs AttributeFilter devCompAttributeFilter1 = new AttributeFilter("Tags"); - devCompAttributeFilter1.addAttributeFilterValue("created from MAC book pro"); devCompAttributeFilter1.addAttributeFilterValue("intel"); - //devCompAttributeFilter1.addAttributeFilterValues("Sacramento"); AttributeFilter devCompAttributeFilter2 = new AttributeFilter("componentType"); - devCompAttributeFilter2.addAttributeFilterValue("temperature"); - /*devCompAttributeFilter2.addAttributeFilterValue("value22"); - devCompAttributeFilter2.addAttributeFilterValue("value33");*/ + devCompAttributeFilter2.addAttributeFilterValue("temperature.v1.0"); - objAdvancedDataInquiry.addDevCompAttributeFilter(devCompAttributeFilter1); - objAdvancedDataInquiry.addDevCompAttributeFilter(devCompAttributeFilter2); + objAdvancedDataEnquiry.addDevCompAttributeFilter(devCompAttributeFilter1); + objAdvancedDataEnquiry.addDevCompAttributeFilter(devCompAttributeFilter2); //measure comp attrs /*AttributeFilter measurementAttributeFilter1 = new AttributeFilter("mfilter_1"); - measurementAttributeFilter1.addAttributeFilterValue("mValue1"); - measurementAttributeFilter1.addAttributeFilterValue("mValue2"); - measurementAttributeFilter1.addAttributeFilterValue("mValue3"); + measurementAttributeFilter1.addAttributeFilterValues("mValue1"); + measurementAttributeFilter1.addAttributeFilterValues("mValue2"); + measurementAttributeFilter1.addAttributeFilterValues("mValue3"); AttributeFilter measurementAttributeFilter2 = new AttributeFilter("mfilter_2"); - measurementAttributeFilter2.addAttributeFilterValue("mValue11"); - measurementAttributeFilter2.addAttributeFilterValue("mValue22"); - measurementAttributeFilter2.addAttributeFilterValue("mValue33"); + measurementAttributeFilter2.addAttributeFilterValues("mValue11"); + measurementAttributeFilter2.addAttributeFilterValues("mValue22"); + measurementAttributeFilter2.addAttributeFilterValues("mValue33"); - objAdvancedDataInquiry.addMeasurementAttributeFilter(measurementAttributeFilter1); - objAdvancedDataInquiry.addMeasurementAttributeFilter(measurementAttributeFilter2); + objAdvancedDataEnquiry.addMeasurementAttributeFilter(measurementAttributeFilter1); + objAdvancedDataEnquiry.addMeasurementAttributeFilter(measurementAttributeFilter2); //value filter AttributeFilter valueFilter = new AttributeFilter("value"); - valueFilter.addAttributeFilterValue("filter_value1"); - valueFilter.addAttributeFilterValue("filter_value2"); - valueFilter.addAttributeFilterValue("filter_value3"); - objAdvancedDataInquiry.addValueFilter(valueFilter);*/ + valueFilter.addAttributeFilterValues("filter_value1"); + valueFilter.addAttributeFilterValues("filter_value2"); + valueFilter.addAttributeFilterValues("filter_value3"); + objAdvancedDataEnquiry.addValueFilter(valueFilter);*/ - /*objAdvancedDataInquiry.setComponentRowLimit(5); - objAdvancedDataInquiry.setCountOnly(true);*/ + /*objAdvancedDataEnquiry.setComponentRowLimit(5); + objAdvancedDataEnquiry.setCountOnly(true);*/ //sort - objAdvancedDataInquiry.addSortInfo("Timestamp", "Asc"); - objAdvancedDataInquiry.addSortInfo("Value", "Desc"); - - assertEquals(true, objAdvancedDataInquiry.request()); - waitForServerResponse(objAdvancedDataInquiry); + objAdvancedDataEnquiry.addSortInfo("Timestamp", "Asc"); + objAdvancedDataEnquiry.addSortInfo("Value", "Desc"); + CloudResponse response = objAdvancedDataEnquiry.request(); + assertEquals(true, response.getStatus()); + waitForServerResponse(objAdvancedDataEnquiry); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/AggregatedReportInterfaceTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/AggregatedReportInterfaceTest.java index e266759..3d42f22 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/AggregatedReportInterfaceTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/AggregatedReportInterfaceTest.java @@ -24,7 +24,9 @@ import com.intel.iotkitlib.AggregatedReportInterface; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; import com.intel.iotkitlib.models.AttributeFilter; +import com.intel.iotkitlib.utils.Utilities; import org.json.JSONException; @@ -42,50 +44,38 @@ private void waitForServerResponse(Object object) { public void testAggregatedReportInterface() throws JSONException { AggregatedReportInterface aggregatedReportInterface = new AggregatedReportInterface(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - aggregatedReportInterface.addGatewayId("qwertyPAD1"); - //aggregatedReportInterface.addGatewayId("xxxx"); - //advancedDataEnquiry.addGatewayId("02-00-86-81-77-15"); - aggregatedReportInterface.addDeviceId("qwertyPAD1"); - //aggregatedReportInterface.addDeviceId("xxxx"); - //advancedDataEnquiry.addDeviceId("02-00-86-81-77-19"); - - /* aggregatedReportInterface.addComponentId("436e9e78-8772-4898-9957-26930f5eb7e1"); - aggregatedReportInterface.addComponentId("9d44c354-7252-4494-8ade-39508bfdbdaf"); - aggregatedReportInterface.addComponentId("c4d1f4c1-6fb6-4793-b85d-431c6cba647b");*/ - aggregatedReportInterface.addComponentId("5C09B9F0-E06B-404A-A882-EAC64675A63E"); - aggregatedReportInterface.addComponentId("BB9E347D-7895-437E-9ECA-8069879090B7"); + aggregatedReportInterface.addGatewayId(deviceName); + aggregatedReportInterface.addDeviceId(deviceName); + aggregatedReportInterface.addComponentId(Utilities.getSensorMatch(deviceComponentName).getValue().toString()); aggregatedReportInterface.setStartTimestamp(0L); aggregatedReportInterface.setEndTimestamp(System.currentTimeMillis()); //report filters AttributeFilter filter1 = new AttributeFilter("Tags"); - filter1.addAttributeFilterValue("created from MAC book pro"); - /*filter1.addAttributeFilterValue("California"); - filter1.addAttributeFilterValue("Sacramento");*/ + filter1.addAttributeFilterValue("intel"); aggregatedReportInterface.addFilter(filter1); aggregatedReportInterface.setOutputType("json"); - aggregatedReportInterface.setLimit(10); + aggregatedReportInterface.setLimit(100); aggregatedReportInterface.setOffset(0); aggregatedReportInterface.addAggregationMethod("average"); aggregatedReportInterface.addAggregationMethod("min"); - /*aggregatedReportInterface.addDimension("dim1"); - aggregatedReportInterface.addDimension("dim2"); - aggregatedReportInterface.setCountOnly(true);*/ + /*aggregatedReportInterface.addDimensions("dim1"); + aggregatedReportInterface.addDimensions("dim2"); + aggregatedReportInterface.setReportCountOnly(true);*/ //sort aggregatedReportInterface.addSortInfo("timeHour", "Asc"); - //aggregatedReportInterface.addSortInfo("sortField2", "Desc"); - - assertEquals(true, aggregatedReportInterface.request()); + CloudResponse response = aggregatedReportInterface.request(); + assertEquals(true, response.getStatus()); waitForServerResponse(aggregatedReportInterface); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java index 297e726..a18cd5b 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/AlertManagementTest.java @@ -25,6 +25,7 @@ import com.intel.iotkitlib.AlertManagement; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; import org.json.JSONException; @@ -43,60 +44,66 @@ private void waitForServerResponse(Object object) { public void testGetListOfAlerts() { AlertManagement alertManagement = new AlertManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, alertManagement.getListOfAlerts()); + CloudResponse response = alertManagement.getListOfAlerts(); + assertEquals(true, response.getStatus()); waitForServerResponse(alertManagement); } public void testGetInfoOnAlert() { AlertManagement alertManagement = new AlertManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, alertManagement.getInfoOnAlert("1111")); + CloudResponse response = alertManagement.getInfoOnAlert(alertId.toString()); + assertEquals(true, response.getStatus()); waitForServerResponse(alertManagement); } public void testUpdateAlertStatus() { AlertManagement alertManagement = new AlertManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, alertManagement.updateAlertStatus("1111", "open")); + CloudResponse response = alertManagement.updateAlertStatus(alertId.toString(), "Open"); + assertEquals(true, response.getStatus()); waitForServerResponse(alertManagement); } public void testAddCommentsToTheAlert() throws JSONException { AlertManagement alertManagement = new AlertManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, alertManagement.addCommentsToTheAlert("1111", "raghu", System.currentTimeMillis(), "iotkit_wrapper comment")); + CloudResponse response = alertManagement.addCommentsToTheAlert(alertId.toString(), "xxxx@example.com", + System.currentTimeMillis(), "iotkit_wrapper comment"); + assertEquals(true, response.getStatus()); waitForServerResponse(alertManagement); } public void testResetAlert() throws JSONException { AlertManagement alertManagement = new AlertManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, alertManagement.resetAlert("1111")); + CloudResponse response = alertManagement.resetAlert(alertId.toString()); + assertEquals(true, response.getStatus()); waitForServerResponse(alertManagement); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/ApplicationTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/ApplicationTest.java index 64f5b37..47b5189 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/ApplicationTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/ApplicationTest.java @@ -28,8 +28,18 @@ import com.intel.iotkitlib.utils.Utilities; import java.lang.ref.WeakReference; +import java.util.Random; public class ApplicationTest extends ActivityUnitTestCase { + final static Integer startingValue = 1; + final static Integer endValue = 10000; + static String accountName; + static String deviceName; + static String componentName; + static String deviceComponentName; + static String ruleName; + static Integer alertId; + public ApplicationTest() { super(MyActivity.class); } @@ -40,8 +50,50 @@ protected void setUp() throws Exception { Utilities.createSharedPreferences(new WeakReference(getInstrumentation().getTargetContext())); } + public String getRandomValueString() { + Random r = new Random(); + Integer randomValue = r.nextInt(endValue - startingValue) + startingValue; + return randomValue.toString(); + } + + public Integer getRandomValueWithInFifty() { + Random r = new Random(); + Integer randomValue = (r.nextInt(endValue - startingValue) + startingValue) % 50; + return randomValue; + } + + public String getAccountName() { + accountName = "DemoIoT" + getRandomValueString(); + return accountName; + } + + public String getDeviceName() { + deviceName = "DemoDevice" + getRandomValueString(); + return deviceName; + } + + public String getComponentName() { + componentName = "DemoComponent" + getRandomValueString(); + return componentName; + } + + public String getDeviceComponentName() { + deviceComponentName = "DeviceDemoComponent" + getRandomValueString(); + return deviceComponentName; + } + + public String getRuleName() { + ruleName = "DemoRule" + getRandomValueString(); + return ruleName; + } + + public Integer getAlertId() { + alertId = Integer.parseInt(getRandomValueString()); + return alertId; + } + /*public void testSharedPreferences() { - assertNotNull(Utilities.sharedPreferences); - assertNotNull(Utilities.editor); + assertNotNull(IoTAppUtilities.sharedPreferences); + assertNotNull(IoTAppUtilities.editor); }*/ } \ No newline at end of file diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java index e235a5b..b43d02e 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/AuthorizationTest.java @@ -24,6 +24,7 @@ import com.intel.iotkitlib.Authorization; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; public class AuthorizationTest extends ApplicationTest { @@ -41,43 +42,46 @@ private void waitForServerResponse(Object object) { public void testGetNewAuthorizationToken() throws InterruptedException { Authorization getToken = new Authorization(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); //for getting token - assertEquals(true, getToken.getNewAuthorizationToken - ("intel.aricent.iot4@gmail.com", "Password2529")); + CloudResponse response = getToken.getNewAuthorizationToken + ("intel.aricent.iot3@gmail.com", "Password2529"); + assertEquals(true, response.getStatus()); waitForServerResponse(getToken); } public void testGetAuthorizationTokenInfo() throws InterruptedException { Authorization getToken = new Authorization(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); //for getting tokenInfo - assertEquals(true, getToken.getAuthorizationTokenInfo()); + CloudResponse response = getToken.getAuthorizationTokenInfo(); + assertEquals(true, response.getStatus()); waitForServerResponse(getToken); } public void testValidateAuthToken() throws InterruptedException { Authorization getToken = new Authorization(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); //for validating token - assertEquals(true, getToken.validateAuthToken()); + CloudResponse response = getToken.validateAuthToken(); + assertEquals(true, response.getStatus()); waitForServerResponse(getToken); } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/ComponentCatalogManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/ComponentCatalogManagementTest.java index 4321c90..0756d54 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/ComponentCatalogManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/ComponentCatalogManagementTest.java @@ -23,8 +23,9 @@ package com.intel.iotkit; import com.intel.iotkitlib.ComponentCatalogManagement; -import com.intel.iotkitlib.models.ComponentCatalog; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; +import com.intel.iotkitlib.models.ComponentCatalog; import org.json.JSONException; @@ -43,53 +44,56 @@ private void waitForServerResponse(Object object) { public void testListAllComponentTypesCatalog() { ComponentCatalogManagement objCatalog = new ComponentCatalogManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objCatalog.listAllComponentTypesCatalog()); + CloudResponse response = objCatalog.listAllComponentTypesCatalog(); + assertEquals(true, response.getStatus()); waitForServerResponse(objCatalog); } public void testListAllDetailsOfComponentTypesCatalog() { ComponentCatalogManagement objCatalog = new ComponentCatalogManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objCatalog.listAllDetailsOfComponentTypesCatalog()); + CloudResponse response = objCatalog.listAllDetailsOfComponentTypesCatalog(); + assertEquals(true, response.getStatus()); waitForServerResponse(objCatalog); } public void testListComponentTypeDetails() { ComponentCatalogManagement objCatalog = new ComponentCatalogManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objCatalog.listComponentTypeDetails("temperature.v1.0")); + CloudResponse response = objCatalog.listComponentTypeDetails("temperature.v1.0"); + assertEquals(true, response.getStatus()); waitForServerResponse(objCatalog); } public void testCreateCustomComponent() throws JSONException { ComponentCatalogManagement objCatalog = new ComponentCatalogManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(201, response.getCode()); serverResponse = true; } }); ComponentCatalog createComponentCatalog = new - ComponentCatalog("IntelODCAC3", "1.0", "actuator", "Number", "float", "Degrees Celsius", "timeSeries"); + ComponentCatalog(getComponentName(), "1.0", "actuator", "Number", "float", "Degrees Celsius", "timeSeries"); createComponentCatalog.setMinValue(5.0); createComponentCatalog.setMaxValue(100.0); createComponentCatalog.setCommandString("Intel actuator"); @@ -98,16 +102,17 @@ public void readResponse(int responseCode, String response) { createComponentCatalog.addCommandParameters("AC3", "32-38"); createComponentCatalog.addCommandParameters("TrueAC", "20-30"); createComponentCatalog.addCommandParameters("LiveAC", "10-20"); - assertEquals(true, objCatalog.createCustomComponent(createComponentCatalog)); + CloudResponse response = objCatalog.createCustomComponent(createComponentCatalog); + assertEquals(true, response.getStatus()); waitForServerResponse(objCatalog); } public void testUpdateAComponent() throws JSONException { ComponentCatalogManagement objCatalog = new ComponentCatalogManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - //setResponse(responseCode, response); - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + //setResponse(response.getCode(), response); + assertEquals(201, response.getCode()); serverResponse = true; } }); @@ -121,8 +126,8 @@ public void readResponse(int responseCode, String response) { updateComponentCatalog.addCommandParameters("AC3", "31-38"); updateComponentCatalog.addCommandParameters("TrueAC", "20-30"); updateComponentCatalog.addCommandParameters("LiveAC", "10-20"); - - assertEquals(true, objCatalog.updateAComponent(updateComponentCatalog, "IntelODCAC3.V1.0")); + CloudResponse response = objCatalog.updateAComponent(updateComponentCatalog, componentName + ".V1.0"); + assertEquals(true, response.getStatus()); waitForServerResponse(objCatalog); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/DataManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/DataManagementTest.java index 28d916f..7d3dbdc 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/DataManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/DataManagementTest.java @@ -23,8 +23,10 @@ package com.intel.iotkit; import com.intel.iotkitlib.DataManagement; -import com.intel.iotkitlib.models.TimeSeriesData; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; +import com.intel.iotkitlib.models.TimeSeriesData; +import com.intel.iotkitlib.utils.Utilities; import org.json.JSONException; @@ -43,37 +45,34 @@ private void waitForServerResponse(Object object) { public void testSubmitData() throws JSONException { DataManagement dataManagement = new DataManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(201, response.getCode()); serverResponse = true; } }); - - assertEquals(true, dataManagement.submitData("real", "50", 25.0, 50.0, 100.0)); + CloudResponse response = dataManagement.submitData(deviceComponentName, getRandomValueWithInFifty().toString(), + 25.0, 50.0, 100.0); + assertEquals(true, response.getStatus()); waitForServerResponse(dataManagement); } public void testRetrieveData() throws JSONException { DataManagement dataManagement = new DataManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); //retrieve data - TimeSeriesData timeSeriesData = new + TimeSeriesData retrieveData = new TimeSeriesData(0L, System.currentTimeMillis()); - /*retrieveData.addDeviceId("22-a5-80-21-5b-29"); - retrieveData.addDeviceId("xxxx"); - retrieveData.addComponentId("9d44c354-7252-4494-8ade-39508bfdbdaf"); - retrieveData.addComponentId("c4d1f4c1-6fb6-4793-b85d-431c6cba647b");*/ - timeSeriesData.addDeviceId("dev1"); - timeSeriesData.addDeviceId("dev"); - timeSeriesData.addComponentId("8cb8bf40-d46f-4a02-8203-d3d4acad9760"); - //retrieveData.addComponentId("c4d1f4c1-6fb6-4793-b85d-431c6cba647b"); + retrieveData.addDeviceId(deviceName); - assertEquals(true, dataManagement.retrieveData(timeSeriesData)); + retrieveData.addComponentId(Utilities.getSensorMatch(deviceComponentName).getValue().toString()); + //retrieveData.addComponentId("c4d1f4c1-6fb6-4793-b85d-431c6cba647b"); + CloudResponse response = dataManagement.retrieveData(retrieveData); + assertEquals(true, response.getStatus()); waitForServerResponse(dataManagement); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/DeviceManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/DeviceManagementTest.java index f9be2a5..ee948ab 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/DeviceManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/DeviceManagementTest.java @@ -22,9 +22,11 @@ */ package com.intel.iotkit; -import com.intel.iotkitlib.models.Device; import com.intel.iotkitlib.DeviceManagement; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; +import com.intel.iotkitlib.models.Device; +import com.intel.iotkitlib.utils.Utilities; import org.json.JSONException; @@ -44,22 +46,24 @@ private void waitForServerResponse(Object object) { public void testCreateNewDevice() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(201, response.getCode()); serverResponse = true; } }); + String deviceNameRandom = getDeviceName(); //create a device Device objDeviceDetails = new - Device("iotkit_wrapper-Device-retrieve-data2", "devTest", "devTest"); + Device("iotkit Device" + getRandomValueString(), deviceNameRandom, deviceNameRandom); objDeviceDetails.setLocation(12.0, 16.0, 18.0); objDeviceDetails.addTagName("Intel ODC test dev"); - objDeviceDetails.addAttributeInfo("processor", "Intel"); + objDeviceDetails.addAttributeInfo("processor", "AMD"); objDeviceDetails.addAttributeInfo("Camera", "8Mp with flash"); objDeviceDetails.addAttributeInfo("Wifi", "Yes"); - objDeviceDetails.addAttributeInfo("Retina", "Yes"); + objDeviceDetails.addAttributeInfo("Retina", "No"); try { - assertEquals(true, objDevice.createNewDevice(objDeviceDetails)); + CloudResponse response = objDevice.createNewDevice(objDeviceDetails); + assertEquals(true, response.getStatus()); } catch (JSONException je) { je.printStackTrace(); } @@ -69,8 +73,8 @@ public void readResponse(int responseCode, String response) { public void testUpdateADevice() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); @@ -83,14 +87,16 @@ public void readResponse(int responseCode, String response) { objDeviceDetails.addAttributeInfo("Camera", "5Mp with flash"); objDeviceDetails.addAttributeInfo("Wifi", "Yes");*/ Device objDeviceDetails = new - Device("iot dev", null, "devTest"); + Device("iotkit Device" + getRandomValueString(), null, deviceName); objDeviceDetails.setLocation(10.0, 15.0, 15.0); objDeviceDetails.addTagName("intel"); - objDeviceDetails.addAttributeInfo("processor", "AMD"); + objDeviceDetails.addAttributeInfo("processor", "Intel"); objDeviceDetails.addAttributeInfo("Camera", "5Mp with out flash"); objDeviceDetails.addAttributeInfo("Wifi", "no"); + objDeviceDetails.addAttributeInfo("Retina", "Yes"); try { - assertEquals(true, objDevice.updateADevice(objDeviceDetails)); + CloudResponse response = objDevice.updateADevice(objDeviceDetails); + assertEquals(true, response.getStatus()); } catch (JSONException je) { je.printStackTrace(); } @@ -100,108 +106,118 @@ public void readResponse(int responseCode, String response) { public void testGetDeviceList() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.getDeviceList()); + CloudResponse response = objDevice.getDeviceList(); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testGetMyDeviceInfo() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.getMyDeviceInfo()); + CloudResponse response = objDevice.getMyDeviceInfo(); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testGetInfoOnDevice() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.getInfoOnDevice("devTest")); + CloudResponse response = objDevice.getInfoOnDevice(deviceName); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testActivateADevice() throws JSONException { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.activateADevice("L6Nvfy8X")); + //getting activation code from shared prefs + CloudResponse response = objDevice.activateADevice(Utilities.sharedPreferences.getString("activationCode", "")); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testAddComponentToDevice() throws JSONException { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(201, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.addComponentToDevice("real", "temperature.v1.0")); + CloudResponse response = objDevice.addComponentToDevice(getDeviceComponentName(), "temperature.v1.0"); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testDeleteAComponent() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(204, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(204, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.deleteAComponent("real")); + CloudResponse response = objDevice.deleteAComponent(deviceComponentName); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testDeleteADevice() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(204, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(204, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.deleteADevice("devTest")); + CloudResponse response = objDevice.deleteADevice(deviceName); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testGetAllAttributes() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.getAllAttributes()); + CloudResponse response = objDevice.getAllAttributes(); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } public void testGetAllTags() { DeviceManagement objDevice = new DeviceManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, objDevice.getAllTags()); + CloudResponse response = objDevice.getAllTags(); + assertEquals(true, response.getStatus()); waitForServerResponse(objDevice); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/InvitationManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/InvitationManagementTest.java index 14b5705..7bd4ecb 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/InvitationManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/InvitationManagementTest.java @@ -24,6 +24,7 @@ import com.intel.iotkitlib.InvitationManagement; import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.http.CloudResponse; import org.json.JSONException; @@ -42,57 +43,57 @@ private void waitForServerResponse(Object object) { public void testCreateInvitation() throws JSONException { InvitationManagement invitationManagement = new InvitationManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(201, response.getCode()); serverResponse = true; } }); - - assertEquals(true, invitationManagement.createInvitation("intel.aricent.iot3@gmail.com")); + CloudResponse response = invitationManagement.createInvitation("intel.aricent.iot1@gmail.com"); + assertEquals(true, response.getStatus()); waitForServerResponse(invitationManagement); } public void testGetInvitationListSendToSpecificUser() throws JSONException { InvitationManagement invitationManagement = new InvitationManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, invitationManagement.getInvitationListSendToSpecificUser( - "intel.aricent.iot3@gmail.com")); + CloudResponse response = invitationManagement.getInvitationListSendToSpecificUser( + "intel.aricent.iot1@gmail.com"); + assertEquals(true, response.getStatus()); waitForServerResponse(invitationManagement); } public void testGetListOfInvitation() { InvitationManagement invitationManagement = new InvitationManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, invitationManagement.getListOfInvitation()); + CloudResponse response = invitationManagement.getListOfInvitation(); + assertEquals(true, response.getStatus()); waitForServerResponse(invitationManagement); } public void testDeleteInvitations() { InvitationManagement invitationManagement = new InvitationManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, invitationManagement.deleteInvitations("intel.aricent.iot3@gmail.com")); + CloudResponse response = invitationManagement.deleteInvitations("intel.aricent.iot1@gmail.com"); + assertEquals(true, response.getStatus()); waitForServerResponse(invitationManagement); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/RuleManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/RuleManagementTest.java index b1a52fa..8f2df4d 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/RuleManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/RuleManagementTest.java @@ -22,11 +22,15 @@ */ package com.intel.iotkit; +import android.util.Log; + import com.intel.iotkitlib.RequestStatusHandler; +import com.intel.iotkitlib.RuleManagement; +import com.intel.iotkitlib.http.CloudResponse; import com.intel.iotkitlib.models.Rule; import com.intel.iotkitlib.models.RuleAction; import com.intel.iotkitlib.models.RuleConditionValues; -import com.intel.iotkitlib.RuleManagement; +import com.intel.iotkitlib.utils.Utilities; import org.json.JSONException; @@ -45,145 +49,144 @@ private void waitForServerResponse(Object object) { public void testCreateARule() throws JSONException { RuleManagement ruleManagement = new RuleManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(201, response.getCode()); serverResponse = true; } }); - Rule ruleObj = new Rule(); + Rule createRuleObj = new Rule(); RuleAction createRuleActionObj = new RuleAction(); - RuleConditionValues ruleConditionValuesObj = - new RuleConditionValues(); + RuleConditionValues createRuleConditionValuesObj = new RuleConditionValues(); - ruleObj.setRuleName("Test Rule2"); - ruleObj.setRuleDescription("This is a iotkit_wrapper rule"); - ruleObj.setRulePriority("Medium"); - ruleObj.setRuleType("Regular"); - ruleObj.setRuleStatus("Active"); - ruleObj.setRuleResetType("Automatic"); + createRuleObj.setRuleName(getRuleName()); + createRuleObj.setRuleDescription("This is a iotkit_wrapper" + ruleName); + createRuleObj.setRulePriority("Medium"); + createRuleObj.setRuleType("Regular"); + createRuleObj.setRuleStatus("Active"); + createRuleObj.setRuleResetType("Automatic"); createRuleActionObj.setRuleActionType("mail"); createRuleActionObj.addRuleActionTarget("intel.aricent.iot1@gmail.com"); createRuleActionObj.addRuleActionTarget("intel.aricent.iot3@gmail.com"); - ruleObj.setRuleActions(createRuleActionObj); - ruleObj.addRulePopulationId("685.1.1.1"); + createRuleObj.setRuleActions(createRuleActionObj); + createRuleObj.addRulePopulationId("685.1.1.1"); - ruleConditionValuesObj.addConditionComponent("dataType", "Number"); - ruleConditionValuesObj.addConditionComponent("name", "Temp.01.1"); - ruleConditionValuesObj.setConditionType("basic"); - ruleConditionValuesObj.addConditionValues("25"); - ruleConditionValuesObj.setConditionOperator(">"); + createRuleConditionValuesObj.addConditionComponent("dataType", "Number"); + createRuleConditionValuesObj.addConditionComponent("name", "Temp.01.1"); + createRuleConditionValuesObj.setConditionType("basic"); + createRuleConditionValuesObj.addConditionValues(getRandomValueWithInFifty().toString()); + createRuleConditionValuesObj.setConditionOperator(">"); - ruleObj.setRuleOperatorName("OR"); - ruleObj.addRuleConditionValues(ruleConditionValuesObj); - - assertEquals(true, ruleManagement.createARule(ruleObj)); + createRuleObj.setRuleOperatorName("OR"); + createRuleObj.addRuleConditionValues(createRuleConditionValuesObj); + CloudResponse response = ruleManagement.createARule(createRuleObj); + assertEquals(true, response.getStatus()); waitForServerResponse(ruleManagement); } public void testUpdateRule() throws JSONException { RuleManagement ruleManagement = new RuleManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(201, response.getCode()); serverResponse = true; } }); - Rule ruleObj = new Rule(); + Rule createRuleObj = new Rule(); RuleAction createRuleActionObj = new RuleAction(); - RuleConditionValues ruleConditionValuesObj = - new RuleConditionValues(); + RuleConditionValues createRuleConditionValuesObj = new RuleConditionValues(); - ruleObj.setRuleName("Test Rule2"); - ruleObj.setRuleDescription("This is a iotkit_wrapper rule"); - ruleObj.setRulePriority("Medium"); - ruleObj.setRuleType("Regular"); - ruleObj.setRuleStatus("Active"); - ruleObj.setRuleResetType("Automatic"); + createRuleObj.setRuleName(getRuleName()); + createRuleObj.setRuleDescription("This is a iotkit_wrapper" + ruleName); + createRuleObj.setRulePriority("Medium"); + createRuleObj.setRuleType("Regular"); + createRuleObj.setRuleStatus("Active"); + createRuleObj.setRuleResetType("Automatic"); createRuleActionObj.setRuleActionType("mail"); createRuleActionObj.addRuleActionTarget("intel.aricent.iot3@gmail.com"); createRuleActionObj.addRuleActionTarget("intel.aricent.iot1@gmail.com"); - ruleObj.setRuleActions(createRuleActionObj); - ruleObj.addRulePopulationId("685.1.1.1"); - - ruleConditionValuesObj.addConditionComponent("dataType", "Number"); - ruleConditionValuesObj.addConditionComponent("name", "Temp.01.1"); - ruleConditionValuesObj.setConditionType("basic"); - ruleConditionValuesObj.addConditionValues("25"); - ruleConditionValuesObj.setConditionOperator(">"); + createRuleObj.setRuleActions(createRuleActionObj); + createRuleObj.addRulePopulationId("685.1.1.1"); - ruleObj.setRuleOperatorName("OR"); - ruleObj.addRuleConditionValues(ruleConditionValuesObj); + createRuleConditionValuesObj.addConditionComponent("dataType", "Number"); + createRuleConditionValuesObj.addConditionComponent("name", "Temp.01.1"); + createRuleConditionValuesObj.setConditionType("basic"); + createRuleConditionValuesObj.addConditionValues(getRandomValueWithInFifty().toString()); + createRuleConditionValuesObj.setConditionOperator(">"); - assertEquals(true, ruleManagement.updateARule(ruleObj, "90205")); + createRuleObj.setRuleOperatorName("OR"); + createRuleObj.addRuleConditionValues(createRuleConditionValuesObj); + Log.d("rule id extracted from shared prefs", Utilities.sharedPreferences.getString("ruleId", "")); + CloudResponse response = ruleManagement.updateARule(createRuleObj, Utilities.sharedPreferences.getString("ruleId", "")); + assertEquals(true, response.getStatus()); waitForServerResponse(ruleManagement); } public void testCreateRuleAsDraft() throws JSONException { RuleManagement ruleManagement = new RuleManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, ruleManagement.createRuleAsDraft("iotkit_wrapper draft rule 14/11/2014")); + CloudResponse response = ruleManagement.createRuleAsDraft("iotkit_wrapper draft rule" + getRuleName()); + assertEquals(true, response.getStatus()); waitForServerResponse(ruleManagement); } public void testDeleteADraftRule() throws JSONException { RuleManagement ruleManagement = new RuleManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(204, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(204, response.getCode()); serverResponse = true; } }); - - assertEquals(true, ruleManagement.deleteADraftRule("284fb6d048402e17b0cee60a24e426830328d316")); + CloudResponse response = ruleManagement.deleteADraftRule(Utilities.sharedPreferences.getString("DraftRuleId", "")); + assertEquals(true, response.getStatus()); waitForServerResponse(ruleManagement); } public void testGetInformationOnRule() throws JSONException { RuleManagement ruleManagement = new RuleManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, ruleManagement.getInformationOnRule("90205")); + CloudResponse response = ruleManagement.getInformationOnRule(Utilities.sharedPreferences.getString("ruleId", "")); + assertEquals(true, response.getStatus()); waitForServerResponse(ruleManagement); } public void testGetListOfRules() throws JSONException { RuleManagement ruleManagement = new RuleManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, ruleManagement.getListOfRules()); + CloudResponse response = ruleManagement.getListOfRules(); + assertEquals(true, response.getStatus()); waitForServerResponse(ruleManagement); } public void testUpdateStatusOfRule() throws JSONException { RuleManagement ruleManagement = new RuleManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - - assertEquals(true, ruleManagement.updateStatusOfRule("90205", "Archived")); + CloudResponse response = ruleManagement.updateStatusOfRule(Utilities.sharedPreferences.getString("ruleId", ""), "Archived"); + assertEquals(true, response.getStatus()); waitForServerResponse(ruleManagement); } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java b/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java index 09d5b0c..ada7000 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/TestRunner.java @@ -32,23 +32,35 @@ public class TestRunner extends InstrumentationTestRunner { @Override public TestSuite getAllTests() { TestSuite suite = new InstrumentationTestSuite(this); - //suite.addTestSuite(AuthorizationTest.class); + + //User management + //need to execute separately, because manually need to activate user by clicking link in mail + suite.addTest(TestSuite.createTest(UserManagementTest.class, "testCreateNewUser")); + + 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")); + //Authorization Tests suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken")); suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetAuthorizationTokenInfo")); suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testValidateAuthToken")); + //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(AuthorizationTest.class, "testGetAuthorizationTokenInfo")); - 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")); - //suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testDeleteAnAccount")); //Device Management suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testCreateNewDevice")); @@ -56,35 +68,34 @@ 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, "testDeleteAComponent")); - suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteADevice"));*/ 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")); suite.addTest(TestSuite.createTest(ComponentCatalogManagementTest.class, "testListAllDetailsOfComponentTypesCatalog")); suite.addTest(TestSuite.createTest(ComponentCatalogManagementTest.class, "testListComponentTypeDetails")); suite.addTest(TestSuite.createTest(ComponentCatalogManagementTest.class, "testCreateCustomComponent")); suite.addTest(TestSuite.createTest(ComponentCatalogManagementTest.class, "testUpdateAComponent")); + //Data management suite.addTest(TestSuite.createTest(DataManagementTest.class, "testSubmitData")); suite.addTest(TestSuite.createTest(DataManagementTest.class, "testRetrieveData")); - //User management - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testCreateNewUser")); - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testAcceptTermsAndConditions")); - 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")); - suite.addTest(TestSuite.createTest(UserManagementTest.class, "testUpdateForgotPassword")); - //suite.addTest(TestSuite.createTest(UserManagementTest.class, "testDeleteAUser")); + //Invitation Management suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testCreateInvitation")); - suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetInvitationListSendToSpecificUser")); + suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken")); + //suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetInvitationListSendToSpecificUser"));//unauthorized error, need to verify suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testGetListOfInvitation")); suite.addTest(TestSuite.createTest(InvitationManagementTest.class, "testDeleteInvitations")); + //Rule Management suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testCreateARule")); suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testUpdateRule")); @@ -92,24 +103,28 @@ 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")); + //suite.addTest(TestSuite.createTest(RuleManagementTest.class, "testUpdateStatusOfRule"));//Internal server error,need to verify + //Advanced Data Inquiry - //suite.addTest(TestSuite.createTest(AuthorizationTest.class, "testGetNewAuthorizationToken")); - //suite.addTest(TestSuite.createTest(AdvancedDataEnquiryTest.class, "testAdvancedDataEnquiry")); + suite.addTest(TestSuite.createTest(AdvancedDataInquiryTest.class, "testAdvancedDataEnquiry")); + //Aggregated report interface - //suite.addTest(TestSuite.createTest(AggregatedReportInterfaceTest.class, "testAggregatedReportInterface")); + suite.addTest(TestSuite.createTest(AggregatedReportInterfaceTest.class, "testAggregatedReportInterface")); + //Alert management - suite.addTest(TestSuite.createTest(AlertManagementTest.class, "testCreateAlert")); 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")); + //Delete All Account and user details suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteAComponent")); suite.addTest(TestSuite.createTest(DeviceManagementTest.class, "testDeleteADevice")); suite.addTest(TestSuite.createTest(AccountManagementTest.class, "testDeleteAnAccount")); suite.addTest(TestSuite.createTest(UserManagementTest.class, "testDeleteAUser")); + return suite; } } diff --git a/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java b/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java index a70e98c..93ff101 100644 --- a/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java +++ b/TestApp/src/androidTest/java/com/intel/iotkit/UserManagementTest.java @@ -25,6 +25,8 @@ import com.intel.iotkitlib.RequestStatusHandler; import com.intel.iotkitlib.UserManagement; +import com.intel.iotkitlib.http.CloudResponse; +import com.intel.iotkitlib.utils.Utilities; import org.apache.http.NameValuePair; import org.apache.http.message.BasicNameValuePair; @@ -48,44 +50,34 @@ private void waitForServerResponse(Object object) { public void testCreateNewUser() throws JSONException { UserManagement userManagement = new UserManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(201, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(201, response.getCode()); serverResponse = true; } }); - assertEquals(true, userManagement.createNewUser("intel.aricent.iot3@gmail.com", "Password2529")); + CloudResponse response = userManagement.createNewUser("intel.aricent.iot@gmail.com", "Password2529"); + assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } public void testGetUserInfo() throws JSONException { UserManagement userManagement = new UserManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, userManagement.getUserInfo("5465ef05cd7df9c1113aafa3")); - waitForServerResponse(userManagement); - } - - public void testAcceptTermsAndConditions() throws JSONException { - UserManagement userManagement = new UserManagement(new RequestStatusHandler() { - @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); - serverResponse = true; - } - }); - assertEquals(true, userManagement.acceptTermsAndConditions("5465ef05cd7df9c1113aafa3", true)); + CloudResponse response = userManagement.getUserInfo(Utilities.sharedPreferences.getString("user_id", "")); + assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } public void testUpdateUserAttributes() throws JSONException { UserManagement userManagement = new UserManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); @@ -94,55 +86,60 @@ public void readResponse(int responseCode, String response) { attributes.add(new BasicNameValuePair("phone", "123456789")); attributes.add(new BasicNameValuePair("new", "next_string_value")); attributes.add(new BasicNameValuePair("another_attribute", "another_value")); - assertEquals(true, userManagement.updateUserAttributes("5465ef05cd7df9c1113aafa3", attributes)); + CloudResponse response = userManagement.updateUserAttributes(Utilities.sharedPreferences.getString("user_id", ""), attributes); + assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } public void testRequestChangePassword() throws JSONException { UserManagement userManagement = new UserManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, userManagement.requestChangePassword("intel.aricent.iot3@gmail.com")); + CloudResponse response = userManagement.requestChangePassword("intel.aricent.iot@gmail.com"); + assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } public void testUpdateForgotPassword() throws JSONException { UserManagement userManagement = new UserManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, userManagement.updateForgotPassword("3jxo3jP3d1I1Toq7", "Password2529")); + CloudResponse response = userManagement.updateForgotPassword("mFxklxSmmfWCyei8", "Password2529"); + assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } public void testChangePassword() throws JSONException { UserManagement userManagement = new UserManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(200, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(200, response.getCode()); serverResponse = true; } }); - assertEquals(true, userManagement.changePassword("intel.aricent.iot3@gmail.com", "Password2529", "Password25292")); + CloudResponse response = userManagement.changePassword("intel.aricent.iot@gmail.com", "Password2529", "Password25292"); + assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } public void testDeleteAUser() throws JSONException { UserManagement userManagement = new UserManagement(new RequestStatusHandler() { @Override - public void readResponse(int responseCode, String response) { - assertEquals(204, responseCode); + public void readResponse(CloudResponse response) { + assertEquals(204, response.getCode()); serverResponse = true; } }); - assertEquals(true, userManagement.deleteAUser("54533fbbf7e1110732274b51")); + CloudResponse response = userManagement.deleteAUser(Utilities.sharedPreferences.getString("user_id", "")); + assertEquals(true, response.getStatus()); waitForServerResponse(userManagement); } diff --git a/TestApp/src/main/java/com/intel/iotkit/MyActivity.java b/TestApp/src/main/java/com/intel/iotkit/MyActivity.java index 14cbc09..a124b29 100644 --- a/TestApp/src/main/java/com/intel/iotkit/MyActivity.java +++ b/TestApp/src/main/java/com/intel/iotkit/MyActivity.java @@ -66,18 +66,37 @@ public void onClick(View v) {//on click of getAuthToken button, expected to see //This call needed to create shared Prefs for the TestApp and also assigns passed context in utilities for further usage Utilities.createSharedPreferences(new WeakReference(MyActivity.this)); - //written test code to call Authorization module - Authorization getToken = new Authorization(new RequestStatusHandler() { + /****written test code to call Authorization module Asynchronously & Synchronously****/ + + //######Asynchronous Http call########## + //Passing valid anonymous callback creates AsyncTask to handle HTTP requests + Authorization getTokenAsync = new Authorization(new RequestStatusHandler() { //anonymous call back @Override public void readResponse(CloudResponse response) { setResponse(response.getCode(), response.getResponse()); } }); + CloudResponse cloudResponse = getTokenAsync.getNewAuthorizationToken("xxxx@gmail.com", "xxxx"); + setResponse(cloudResponse.getCode(), cloudResponse.getResponse()); + + //######Synchronous Http call########## + //Sync call doing on background thread, doing on UI thread is not valid(creates NetworkOnMainThreadException) + final Authorization getTokenSync = new Authorization();//passing null handler creates Synchronous Http call //for getting token - getToken.getNewAuthorizationToken("intel.aricent.iot4@gmail.com", "Password2529"); + new Thread(new Runnable() { + @Override + public void run() { + final CloudResponse cloudResponse = getTokenSync.getNewAuthorizationToken("xxxx@gmail.com", "xxxx"); + runOnUiThread(new Runnable() {//updating cloud response to activity over UI thread + @Override + public void run() { + setResponse(cloudResponse.getCode(), cloudResponse.getResponse()); + } + }); + } + }).start(); } - }); } } diff --git a/iotkitlib/src/main/java/com/intel/iotkitlib/AccountManagement.java b/iotkitlib/src/main/java/com/intel/iotkitlib/AccountManagement.java index a286ed3..7082b09 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/AccountManagement.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/AccountManagement.java @@ -29,8 +29,6 @@ import com.intel.iotkitlib.http.HttpGetTask; import com.intel.iotkitlib.http.HttpPostTask; import com.intel.iotkitlib.http.HttpPutTask; -import com.intel.iotkitlib.http.HttpTask; -import com.intel.iotkitlib.http.HttpTaskHandler; import com.intel.iotkitlib.models.AuthorizationToken; import com.intel.iotkitlib.utils.Utilities; @@ -44,21 +42,22 @@ */ public class AccountManagement extends ParentModule { - private static final String TAG = "AccountManagement"; - // Errors public static final String ERR_ACCOUNT_NAME = "account Name cannot be empty"; public static final String ERR_INVALID_IDS = "userId or accountId of new user cannot be null"; public static final String ERR_INVALID_BODY = "problem with Http body creation to add user to account"; + private static final String TAG = "AccountManagement"; /** * Module that handles accounts and user related operations; use this to do sync operation */ - public AccountManagement() { super(null); } + public AccountManagement() { + super(null); + } /** * Module that handles accounts and user related operations. - * + *

* For more information, please refer to @link{https://github.com/enableiot/iotkit-api/wiki/Account-Management} * * @param requestStatusHandler The handler for asynchronously request to return data and status @@ -70,6 +69,7 @@ public AccountManagement(RequestStatusHandler requestStatusHandler) { /** * Create an account with a name. + * * @param accountName name of the account to be created. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -106,6 +106,7 @@ public void readResponse(CloudResponse response) { /** * Get the information about an account. + * * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -122,6 +123,7 @@ public CloudResponse getAccountInformation() { /** * Get the account activation code which is the transient code that can be used to activate * devices for the account. It expires after one hour. + * * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -132,18 +134,33 @@ public CloudResponse getAccountActivationCode() { HttpGetTask getAccountActivationCode = new HttpGetTask(); getAccountActivationCode.setHeaders(basicHeaderList); String url = objIotKit.prepareUrl(objIotKit.getActivationCode, null); - return super.invokeHttpExecuteOnURL(url, getAccountActivationCode); + RequestStatusHandler preProcessing = new RequestStatusHandler() { + @Override + public void readResponse(CloudResponse response) { + Log.d(TAG, String.valueOf(response.getCode())); + Log.d(TAG, response.getResponse()); + try { + // Store account and id in preferences + AuthorizationToken.parseAndStoreActivationCode(response.getResponse()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }; + + return super.invokeHttpExecuteOnURL(url, getAccountActivationCode, preProcessing); } /** * Force a renewal of the account activation code. + * * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. * For synch model, return CloudResponse which wraps HTTP return code and response. */ public CloudResponse renewAccountActivationCode() { - //initiating put for account activation code + //initiating put for account activation code HttpPutTask renewActivationCode = new HttpPutTask(); renewActivationCode.setHeaders(basicHeaderList); String url = objIotKit.prepareUrl(objIotKit.renewActivationCode, null); @@ -181,6 +198,7 @@ public void readResponse(CloudResponse response) { /** * Delete the current account. + * * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -198,9 +216,10 @@ public CloudResponse deleteAnAccount() { /** * Add another user to your account. - * @param accountId The account id of the other user. + * + * @param accountId The account id of the other user. * @param inviteeUserId The user id of the other user. - * @param isAdmin The role for this user in the current account. + * @param isAdmin The role for this user in the current account. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. diff --git a/iotkitlib/src/main/java/com/intel/iotkitlib/AdvancedDataInquiry.java b/iotkitlib/src/main/java/com/intel/iotkitlib/AdvancedDataInquiry.java index 168b002..fa1d3f9 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/AdvancedDataInquiry.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/AdvancedDataInquiry.java @@ -22,11 +22,8 @@ */ package com.intel.iotkitlib; -import android.util.Log; - import com.intel.iotkitlib.http.CloudResponse; import com.intel.iotkitlib.http.HttpPostTask; -import com.intel.iotkitlib.http.HttpTaskHandler; import com.intel.iotkitlib.models.AttributeFilter; import org.apache.http.NameValuePair; @@ -42,12 +39,10 @@ * Advanced Data Inquiry module */ public class AdvancedDataInquiry extends ParentModule { - private final static String TAG = "AdvancedDataEnquiry"; - // Errors public final static String ERR_INVALID_REQUEST = "Invalid body for request"; - - String msgType; + //private final static String TAG = "AdvancedDataEnquiry"; + //String msgType; List gatewayIds; List deviceIds; List componentIds; @@ -71,12 +66,14 @@ public class AdvancedDataInquiry extends ParentModule { * Advanced Data Inquiry allows querying measurement data (values, location and attributes) for * a single account using advanced filtering and sorting; use this to do sync operation */ - public AdvancedDataInquiry() { super(null); } + public AdvancedDataInquiry() { + super(null); + } /** * Advanced Data Inquiry allows querying measurement data (values, location and attributes) for * a single account using advanced filtering and sorting. - * + *

* For more information, please refer to @link{https://github.com/enableiot/iotkit-api/wiki/Advanced-Data-Inquiry} * * @param requestStatusHandler The handler for asynchronously request to return data and status @@ -93,6 +90,7 @@ public AdvancedDataInquiry(RequestStatusHandler requestStatusHandler) { /** * Add a gateway id that is requested for the data in the report. + * * @param gatewayId The gateway identifier for gateway data to be included in the report. */ public void addGatewayId(String gatewayId) { @@ -101,8 +99,10 @@ public void addGatewayId(String gatewayId) { } this.gatewayIds.add(gatewayId); } + /** * Add a device id that is requested for the data in the report. + * * @param deviceId The device identifier for device data to be included in the report. */ public void addDeviceId(String deviceId) { @@ -114,6 +114,7 @@ public void addDeviceId(String deviceId) { /** * Add a component id that is requested for the data in the report. + * * @param componentId The component identifier for component data to be included in the report. */ public void addComponentId(String componentId) { @@ -125,6 +126,7 @@ public void addComponentId(String componentId) { /** * Set the start time for query data in be included in the report. + * * @param startTimestamp time in milliseconds since epoch time. */ public void setStartTimestamp(Long startTimestamp) { @@ -133,6 +135,7 @@ public void setStartTimestamp(Long startTimestamp) { /** * Set the end time for query data in be included in the report. + * * @param endTimestamp time in milliseconds since epoch time. */ public void setEndTimestamp(Long endTimestamp) { @@ -141,6 +144,7 @@ public void setEndTimestamp(Long endTimestamp) { /** * Add a requested attribute to a list of attributes that will be return for each measurement. + * * @param attribute The attribute to add to the list of attributes that will be part of the request. */ public void addReturnedMeasureAttribute(String attribute) { @@ -152,6 +156,7 @@ public void addReturnedMeasureAttribute(String attribute) { /** * Request for location (lat, long, alt) as part of each returned measurement. + * * @param measureLocation if true returns location. */ public void setShowMeasureLocation(Boolean measureLocation) { @@ -160,6 +165,7 @@ public void setShowMeasureLocation(Boolean measureLocation) { /** * Filter request based on device and/or component attributes. + * * @param attributeFilter is of name and values. */ public void addDevCompAttributeFilter(AttributeFilter attributeFilter) { @@ -171,6 +177,7 @@ public void addDevCompAttributeFilter(AttributeFilter attributeFilter) { /** * Filter request based on measurement attributes. + * * @param attributeFilter is of name and values. */ public void addMeasurementAttributeFilter(AttributeFilter attributeFilter) { @@ -182,6 +189,7 @@ public void addMeasurementAttributeFilter(AttributeFilter attributeFilter) { /** * Filter request based on value attributes. + * * @param attributeFilter is of name and values. */ public void addValueFilter(AttributeFilter attributeFilter) { @@ -190,6 +198,7 @@ public void addValueFilter(AttributeFilter attributeFilter) { /** * Limits the number of records returned for each component in the report. + * * @param componentRowLimit the number of row that will be returned. */ public void setComponentRowLimit(int componentRowLimit) { @@ -198,6 +207,7 @@ public void setComponentRowLimit(int componentRowLimit) { /** * Setting to true will return the number of rows that would have returned from this report. + * * @param countOnly true will return number of rows. */ public void setCountOnly(Boolean countOnly) { @@ -206,7 +216,8 @@ public void setCountOnly(Boolean countOnly) { /** * Add the sort criteria to the query. - * @param name The sort field name. + * + * @param name The sort field name. * @param value The source value. It must be "Asc" or "Desc". */ public void addSortInfo(String name, String value) { @@ -218,6 +229,7 @@ public void addSortInfo(String name, String value) { /** * Starts a request for the report. + * * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -239,11 +251,11 @@ public CloudResponse request() throws JSONException { private String createBodyForAdvancedDataInquiry() throws JSONException { JSONObject dataInquiryJson = new JSONObject(); - if (this.msgType == null) { + /*if (this.msgType == null) { dataInquiryJson.put("msgType", "advancedDataInquiryRequest"); } else { dataInquiryJson.put("msgType", this.msgType); - } + }*/ if (this.gatewayIds != null) { JSONArray gatewayArray = new JSONArray(); for (String gatewayId : this.gatewayIds) { diff --git a/iotkitlib/src/main/java/com/intel/iotkitlib/DataManagement.java b/iotkitlib/src/main/java/com/intel/iotkitlib/DataManagement.java index 1cd39de..89e4a84 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/DataManagement.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/DataManagement.java @@ -26,7 +26,6 @@ import com.intel.iotkitlib.http.CloudResponse; import com.intel.iotkitlib.http.HttpPostTask; -import com.intel.iotkitlib.http.HttpTaskHandler; import com.intel.iotkitlib.models.TimeSeriesData; import com.intel.iotkitlib.utils.Utilities; @@ -42,17 +41,16 @@ * Data management functions */ public class DataManagement extends ParentModule { - private final static String TAG = "DataManagement"; - // Error strings public final static String ERR_SUBMIT_DATA = "Cannot submit data for device component"; public final static String ERR_CREATE_DATA = "Cannot create request for submit data"; public final static String ERR_INVALID_DATA = "device List or componentId List cannot be null"; + private final static String TAG = "DataManagement"; /** * Submit and retrieve data for a device. This is use to do sync operation. - * + *

* For more information, please refer to @link{https://github.com/enableiot/iotkit-api/wiki/Data-API} */ public DataManagement() { @@ -73,11 +71,12 @@ public DataManagement(RequestStatusHandler requestStatusHandler) { * Submit data for specific device and it's component. Device and component have to be * registered in the cloud before sending observations. The device id * that is used will be the current device that is cached usually after a create new device. - * @param componentName the name of the component to look up the component id. + * + * @param componentName the name of the component to look up the component id. * @param componentValue the value to set for the component. - * @param latitude lat location for the device in decimal - * @param longitude lon location for the device in decimal - * @param height altitude value in meters + * @param latitude lat location for the device in decimal + * @param longitude lon location for the device in decimal + * @param height altitude value in meters * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -85,7 +84,7 @@ public DataManagement(RequestStatusHandler requestStatusHandler) { * @throws JSONException */ public CloudResponse submitData(String componentName, String componentValue, - Double latitude, Double longitude, Double height) throws JSONException { + Double latitude, Double longitude, Double height) throws JSONException { String componentId = validateRequestBodyParametersAndGetcomponentId(componentName, componentValue); if (componentId == null) { Log.d(TAG, ERR_SUBMIT_DATA); @@ -99,7 +98,7 @@ public CloudResponse submitData(String componentName, String componentValue, Log.d(TAG, ERR_CREATE_DATA); return new CloudResponse(false, ERR_CREATE_DATA); } - + submitDeviceData.setHeaders(submitDataHeaders); submitDeviceData.setRequestBody(body); String url = objIotKit.prepareUrl(objIotKit.submitData, null); return super.invokeHttpExecuteOnURL(url, submitDeviceData); @@ -108,12 +107,13 @@ public CloudResponse submitData(String componentName, String componentValue, /** * Submit data for specific device and it's component. Device and component have to be * registered in the cloud before sending observations. - * @param deviceId the identifier for the device to submit the data for. - * @param componentName the name of the component to look up the component id. + * + * @param deviceId the identifier for the device to submit the data for. + * @param componentName the name of the component to look up the component id. * @param componentValue the value to set for the component. - * @param latitude lat location for the device in decimal - * @param longitude lon location for the device in decimal - * @param height altitude value in meters + * @param latitude lat location for the device in decimal + * @param longitude lon location for the device in decimal + * @param height altitude value in meters * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -121,7 +121,7 @@ public CloudResponse submitData(String componentName, String componentValue, * @throws JSONException */ public CloudResponse submitData(String deviceId, String componentName, String componentValue, - Double latitude, Double longitude, Double height) throws JSONException { + Double latitude, Double longitude, Double height) throws JSONException { String componentId = validateRequestBodyParametersAndGetcomponentId(componentName, componentValue); if (componentId == null) { Log.d(TAG, ERR_SUBMIT_DATA); @@ -147,6 +147,7 @@ public CloudResponse submitData(String deviceId, String componentName, String co /** * Retrieve data for an account. + * * @param objTimeSeriesData time series data criteria for retrieve data from the cloud * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from diff --git a/iotkitlib/src/main/java/com/intel/iotkitlib/RuleManagement.java b/iotkitlib/src/main/java/com/intel/iotkitlib/RuleManagement.java index 89c7be7..9fa21e7 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/RuleManagement.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/RuleManagement.java @@ -29,10 +29,10 @@ import com.intel.iotkitlib.http.HttpGetTask; import com.intel.iotkitlib.http.HttpPostTask; import com.intel.iotkitlib.http.HttpPutTask; -import com.intel.iotkitlib.http.HttpTaskHandler; import com.intel.iotkitlib.models.Rule; import com.intel.iotkitlib.models.RuleAction; import com.intel.iotkitlib.models.RuleConditionValues; +import com.intel.iotkitlib.utils.Utilities; import org.apache.http.NameValuePair; import org.json.JSONArray; @@ -45,27 +45,28 @@ * Rule management functions */ public class RuleManagement extends ParentModule { - private final static String TAG = "RuleManagement"; - // Errors - public final static String ERR_INVALID_ID = "rule id cannot be null"; + public final static String ERR_INVALID_ID = "rule id cannot be null"; public final static String ERR_INVALID_STATUS = "status cannot be null"; public final static String ERR_INVALID_BODY = "Invalid body for rule"; public final static String ERR_INVALID_NAME = "rule name cannot be null"; public final static String ERR_INVALID_RULE = "Invalid rule object"; + private final static String TAG = "RuleManagement"; /** * Module that manages rules. manage Rules. A rule is an association between one or more * device's components, a set of conditions for those components, and a number of actions * that have to be triggered in case those conditions are met. Use this to do sync operation. */ - public RuleManagement() { super(null); } + public RuleManagement() { + super(null); + } /** * Module that manages rules. manage Rules. A rule is an association between one or more * device's components, a set of conditions for those components, and a number of actions * that have to be triggered in case those conditions are met. - * + *

* For more information, please refer to @link{https://github.com/enableiot/iotkit-api/wiki/Rule-Management} * * @param requestStatusHandler The handler for asynchronously request to return data and status @@ -75,8 +76,37 @@ public RuleManagement(RequestStatusHandler requestStatusHandler) { super(requestStatusHandler); } + //method added to get info on ruleId in test case runner + public static void parseAndStoreRuleId(String response, int responseCode) throws JSONException { + if (responseCode != 201) { + Log.d(TAG, "problem in storing rule ID"); + return; + } + JSONObject ruleJson = new JSONObject(response); + if (Utilities.editor == null) { + Log.d(TAG, "Not able to access shared pref editor object to store ruleId"); + } + Log.d(TAG, "rule id extracted from server response" + ruleJson.getString("externalId")); + Utilities.editor.putString("ruleId", ruleJson.getString("externalId")); + Utilities.editor.commit(); + } + + public static void parseAndStoreDraftRuleId(String response, int responseCode) throws JSONException { + if (responseCode != 200) { + Log.d(TAG, "problem in storing rule ID"); + return; + } + JSONObject ruleJson = new JSONObject(response); + if (Utilities.editor == null) { + Log.d(TAG, "Not able to access shared pref editor object to store ruleId"); + } + Utilities.editor.putString("DraftRuleId", ruleJson.getString("externalId")); + Utilities.editor.commit(); + } + /** * Get a list of all rules for the specified account. + * * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -92,6 +122,7 @@ public CloudResponse getListOfRules() { /** * Get specific rule details for the account + * * @param ruleId the identifier for the rule to retrieve info for. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -114,6 +145,7 @@ public CloudResponse getInformationOnRule(String ruleId) { /** * Delete a specific draft rule for account. + * * @param ruleId the identifier for the rule to delete. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -137,6 +169,7 @@ public CloudResponse deleteADraftRule(String ruleId) { /** * Update the status of the rule. Cannot be used for changing the status of draft rule. * Status value should be one of the following: ["Active", "Archived", "On-hold"] + * * @param ruleId the identifier for the rule to have the status updated. * @param status value should be one of the following: ["Active", "Archived", "On-hold"] * @return For async model, return CloudResponse which wraps true if the request of REST @@ -170,6 +203,7 @@ public CloudResponse updateStatusOfRule(String ruleId, String status) throws JSO /** * Create a rule with a status - "Draft" for the specified account. + * * @param ruleName the name of the rule to create a draft * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -191,13 +225,26 @@ public CloudResponse createRuleAsDraft(String ruleName) throws JSONException { createDraftRule.setHeaders(basicHeaderList); createDraftRule.setRequestBody(body); String url = objIotKit.prepareUrl(objIotKit.createRuleAsDraft, null); - return super.invokeHttpExecuteOnURL(url, createDraftRule); + RequestStatusHandler preProcessing = new RequestStatusHandler() { + @Override + public void readResponse(CloudResponse response) { + Log.d(TAG, String.valueOf(response.getCode())); + Log.d(TAG, response.getResponse()); + try { + parseAndStoreDraftRuleId(response.getResponse(), response.getCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }; + return super.invokeHttpExecuteOnURL(url, createDraftRule, preProcessing); } /** * Update the rule. + * * @param updateRuleObj the information that is used to update the rule with. - * @param ruleId the identifier for the rule to be updated. + * @param ruleId the identifier for the rule to be updated. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -225,6 +272,7 @@ public CloudResponse updateARule(Rule updateRuleObj, String ruleId) throws JSONE /** * Create a rule. + * * @param ruleObj the information needed to create a new rule with. * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -246,7 +294,20 @@ public CloudResponse createARule(Rule ruleObj) throws JSONException { createRule.setHeaders(basicHeaderList); createRule.setRequestBody(body); String url = objIotKit.prepareUrl(objIotKit.createRule, null); - return super.invokeHttpExecuteOnURL(url, createRule); + RequestStatusHandler preProcessing = new RequestStatusHandler() { + @Override + public void readResponse(CloudResponse response) { + Log.d(TAG, String.valueOf(response.getCode())); + Log.d(TAG, response.getResponse()); + try { + parseAndStoreRuleId(response.getResponse(), response.getCode()); + } catch (JSONException e) { + e.printStackTrace(); + } + } + }; + + return super.invokeHttpExecuteOnURL(url, createRule, preProcessing); } private String createBodyForRuleCreation(Rule ruleObj) throws JSONException { @@ -317,5 +378,6 @@ private String createBodyForUpdateOfRuleStatus(String status) throws JSONExcepti return updateRuleStatusJson.toString(); } + } diff --git a/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java b/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java index e925727..28c9d36 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/UserManagement.java @@ -24,14 +24,11 @@ import android.util.Log; -import com.intel.iotkitlib.ParentModule; -import com.intel.iotkitlib.RequestStatusHandler; import com.intel.iotkitlib.http.CloudResponse; import com.intel.iotkitlib.http.HttpDeleteTask; import com.intel.iotkitlib.http.HttpGetTask; import com.intel.iotkitlib.http.HttpPostTask; import com.intel.iotkitlib.http.HttpPutTask; -import com.intel.iotkitlib.http.HttpTaskHandler; import com.intel.iotkitlib.models.AuthorizationToken; import com.intel.iotkitlib.utils.IotKit; import com.intel.iotkitlib.utils.Utilities; @@ -47,23 +44,24 @@ * User management module */ public class UserManagement extends ParentModule { - private final static String TAG = "UserManagement"; - // Errors public final static String ERR_INVALID_ID = "invalid user id"; public final static String ERR_INVALID_ATTRS = "attributes cannot be empty"; public final static String ERR_INVALID_BODY = "invalid body"; public final static String ERR_INVALID_EMAIL = "emailID cannot be empty"; public final static String ERR_INVALID_TOKEN = "neither token nor newPassword cannot be empty"; + private final static String TAG = "UserManagement"; /** * User management features; use this to do sync operation. */ - public UserManagement() { super(null); } + public UserManagement() { + super(null); + } /** * User management features - * + *

* For more info, please refer to @link{https://github.com/enableiot/iotkit-api/wiki/User-Management} * * @param requestStatusHandler The handler for asynchronously request to return data and status @@ -75,7 +73,8 @@ public UserManagement(RequestStatusHandler requestStatusHandler) { /** * Create a new user - * @param emailID the email id for the user which is used as an identifier + * + * @param emailID the email id for the user which is used as an identifier * @param password the password for the user * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -112,6 +111,7 @@ public void readResponse(CloudResponse response) { /** * Delete a user + * * @param userId the identifier for the user to be deleted from the cloud * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -145,6 +145,7 @@ public void readResponse(CloudResponse response) { /** * Get user information + * * @param userId the identifier for the user for retrieving user information for * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -166,7 +167,8 @@ public CloudResponse getUserInfo(String userId) { /** * Update the user attributes for a given user - * @param userId The identifier for the user to update the attributes for + * + * @param userId The identifier for the user to update the attributes for * @param userAttributes A list of name value pairs that specify the user attributes for the user * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -196,36 +198,9 @@ public CloudResponse updateUserAttributes(String userId, List use return super.invokeHttpExecuteOnURL(url, updateUserAttributes); } - /** - * Accept the terms and conditions for an user - * @param userId The identifier for the user that either accepts or rejects the terms and conditions - * @param accept true for accepting or fals for rejecting the terms and conditions - * @return For async model, return CloudResponse which wraps true if the request of REST - * call is valid; otherwise false. The actual result from - * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. - * For synch model, return CloudResponse which wraps HTTP return code and response. - * @throws JSONException - */ - public CloudResponse acceptTermsAndConditions(String userId, boolean accept) throws JSONException { - String tempUserId = validateAndGetUserId(userId); - if (tempUserId == null) { - Log.d(TAG, ERR_INVALID_ID); - return new CloudResponse(false, ERR_INVALID_ID); - } - String body; - if ((body = createBodyForTermsAndConditionsAcceptance(tempUserId, accept)) == null) { - return new CloudResponse(false, ERR_INVALID_BODY); - } - //initiating put for user acceptance for terms and conditions - HttpPutTask acceptTermsAndConditions = new HttpPutTask(); - acceptTermsAndConditions.setHeaders(basicHeaderList); - acceptTermsAndConditions.setRequestBody(body); - String url = objIotKit.prepareUrl(objIotKit.acceptTermsAndConditions, createHashMapWithUserID(tempUserId)); - return super.invokeHttpExecuteOnURL(url, acceptTermsAndConditions); - } - /** * Request for change of password + * * @param emailId The email address of the user that requests for a change of password * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -252,7 +227,8 @@ public CloudResponse requestChangePassword(String emailId) throws JSONException /** * Update the password - * @param token The token that is used access the cloud backend for updating the password + * + * @param token The token that is used access the cloud backend for updating the password * @param newPassword The new password for the user * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from @@ -279,9 +255,10 @@ public CloudResponse updateForgotPassword(String token, String newPassword) thro /** * Change the password for the user - * @param emailAddress The email address of the user + * + * @param emailAddress The email address of the user * @param currentPassword The current password for the user - * @param newPassword The new password for the user + * @param newPassword The new password for the user * @return For async model, return CloudResponse which wraps true if the request of REST * call is valid; otherwise false. The actual result from * the REST call is return asynchronously as part {@link RequestStatusHandler#readResponse}. @@ -380,6 +357,7 @@ private String validateAndCreateHttpBodyForNewUser(String emailID, String passwo JSONObject createUserJson = new JSONObject(); createUserJson.put("email", emailID); createUserJson.put("password", password); + createUserJson.put("termsAndConditions", true);//accept terms and conditions return createUserJson.toString(); } } 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 d8f848b..d956e0f 100644 --- a/iotkitlib/src/main/java/com/intel/iotkitlib/models/AuthorizationToken.java +++ b/iotkitlib/src/main/java/com/intel/iotkitlib/models/AuthorizationToken.java @@ -150,6 +150,13 @@ public static JSONObject parseAndStoreAccountIdAndName(String response) throws J return accountJson; } + public static void parseAndStoreActivationCode(String response) throws JSONException { + //Set the first account details to shared prefs + JSONObject accountJson = new JSONObject(response); + Utilities.editor.putString("activationCode", accountJson.getString("activationCode")); + Utilities.editor.commit(); + } + public static void parseAndStoreAccountName(String accountName, int responseCode) throws JSONException { if (responseCode == 200) { Utilities.editor.putString("account_name", accountName);