Added JUnit test case
authorVinil Jain <vinil.gj@samsung.com>
Thu, 1 Oct 2015 10:04:39 +0000 (15:34 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 2 Oct 2015 09:21:30 +0000 (09:21 +0000)
-added test case for easysetupstatus
-changed signature of easysetupstatus api
-Updated comments
-Added new states and changed some states

Change-Id: I4afd9318f9f8c8ddf9189f856dbab8307946e8e5
Signed-off-by: Vinil Jain <vinil.gj@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3363
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
(cherry picked from commit 25fc0875be77e18e8d4c8d221325d631cd1737ca)
Reviewed-on: https://gerrit.iotivity.org/gerrit/3395

12 files changed:
service/easy-setup/sampleapp/mediator/android/EasySetup/app/src/main/java/org/iotivity/service/easysetup/MainActivity.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceConfigTest.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupStatusTest.java [new file with mode: 0644]
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupService.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EasySetupStatus.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeDevice.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/EnrolleeState.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/OnBoardingConnection.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/core/ProvisioningCallback.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/EnrolleeDeviceWiFiOnboarding.java
service/easy-setup/sdk/mediator/android/EasySetupCore/src/main/java/org/iotivity/service/easysetup/impl/WiFiProvConfig.java

index cf6d115..63b7f9e 100644 (file)
@@ -116,7 +116,7 @@ public class MainActivity extends Activity {
                     }\r
 \r
                     @Override\r
-                    public void onProgress(EnrolleeState state) {\r
+                    public void onProgress(EnrolleeDevice enrolleeDevice) {\r
                         Log.i("MainActivity", "onProgress() is received ");\r
                         mHandler.sendEmptyMessage(STATE_CHANGED);\r
                     }\r
index 20b4b44..7666a11 100644 (file)
@@ -41,7 +41,7 @@ public class EasySetupServiceConfigTest extends AndroidTestCase {
             }\r
 \r
             @Override\r
-            public void onProgress(EnrolleeState state) {\r
+            public void onProgress(EnrolleeDevice enrolleeDevice) {\r
 \r
             }\r
         });\r
@@ -59,7 +59,7 @@ public class EasySetupServiceConfigTest extends AndroidTestCase {
             }\r
 \r
             @Override\r
-            public void onProgress(EnrolleeState state) {\r
+            public void onProgress(EnrolleeDevice enrolleeDevice) {\r
 \r
             }\r
         });\r
index 1331f3a..3e3058c 100644 (file)
@@ -74,8 +74,8 @@ public class EasySetupServiceTest extends AndroidTestCase {
             }\r
 \r
             @Override\r
-            public void onProgress(EnrolleeState state) {\r
-                // TODO\r
+            public void onProgress(EnrolleeDevice enrolleeDevice) {\r
+                // Handled in EasySetupStatusTest\r
             }\r
         });\r
 \r
@@ -121,7 +121,7 @@ public class EasySetupServiceTest extends AndroidTestCase {
 \r
             Log.i("EasySetupTest", "Lock is released");\r
 \r
-            if(! mDevice.isSetupSuccessful()) {\r
+            if (!mDevice.isSetupSuccessful()) {\r
                 assertTrue(false);\r
                 return;\r
             }\r
diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupStatusTest.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupStatusTest.java
new file mode 100644 (file)
index 0000000..c52b05c
--- /dev/null
@@ -0,0 +1,168 @@
+//******************************************************************
+//
+// Copyright 2015 Samsung Electronics All Rights Reserved.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+//
+//-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
+package org.iotivity.service.easysetup.core;
+
+import android.net.wifi.WifiConfiguration;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;
+import org.iotivity.service.easysetup.impl.EnrolleeDeviceWiFiOnboarding;
+import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig;
+import org.iotivity.service.easysetup.impl.WiFiProvConfig;
+
+import java.io.IOException;
+
+public class EasySetupStatusTest extends AndroidTestCase {
+
+
+    public void testStartSetupWithWiFiOnboarding() {
+
+        EasySetupService mService;
+        EnrolleeDevice mDevice;
+        EnrolleeDeviceFactory mFactory;
+
+        final Object lock = new Object();
+
+
+        /* Create Easy Setup service */
+        mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
+            EnrolleeState old_state = null;
+
+            @Override
+            public void onFinished(EnrolleeDevice enrolledevice) {
+
+                //countDownLatch.countDown();
+                Utility.toNotify(lock);
+
+                if (enrolledevice.isSetupSuccessful()) {
+
+                    if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.WiFi) {
+                        IpOnBoardingConnection conn = (IpOnBoardingConnection) enrolledevice.getConnection();
+                        String ip = conn.getIp();
+                        if (ip == null || ip.isEmpty()) {
+                            assertTrue(false);
+                            return;
+                        }
+                        String mac = conn.getHardwareAddress();
+                        if (mac == null || mac.isEmpty()) {
+                            assertTrue(false);
+                            return;
+                        }
+                        // Device configured successfully
+                        assertTrue(true);
+                    }
+
+                } else {
+                    assertTrue(false);
+                }
+            }
+
+            @Override
+            public void onProgress(EnrolleeDevice enrolleeDevice) {
+                EnrolleeState state = enrolleeDevice.mState;
+                // TODO
+                switch (state) {
+                    case DEVICE_INIT_STATE:
+                        Log.d("enrollee state", "DEVICE_INIT_STATE");
+                        assertTrue(false);
+                        break;
+                    case DEVICE_ON_BOARDING_STATE:
+                        if (old_state == null)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        old_state = EnrolleeState.DEVICE_ON_BOARDING_STATE;
+                        Log.d("enrollee state", "DEVICE_ON_BOARDING_STATE");
+                        break;
+
+                    case DEVICE_ON_BOARDED_STATE:
+                        if (old_state == EnrolleeState.DEVICE_ON_BOARDING_STATE)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        old_state = EnrolleeState.DEVICE_ON_BOARDED_STATE;
+                        Log.d("enrollee state", "DEVICE_ON_BOARDED_STATE");
+                        break;
+
+                    case DEVICE_PROVISIONING_STATE:
+                        if (old_state == EnrolleeState.DEVICE_ON_BOARDED_STATE)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        old_state = EnrolleeState.DEVICE_PROVISIONING_STATE;
+                        Log.d("enrollee state", "DEVICE_PROVISIONING_STATE");
+                        break;
+
+                    case DEVICE_PROVISIONED_STATE:
+                        if (old_state == EnrolleeState.DEVICE_PROVISIONING_STATE)
+                            assertTrue(true);
+                        else assertTrue(false);
+                        Log.d("enrollee state", "DEVICE_PROVISIONING_SUCCESS_STATE");
+                        break;
+
+                    default:
+                        Log.d("enrollee state", "unknown state");
+                        assertTrue(false);
+                        break;
+                }
+
+            }
+        });
+
+
+        /* Create On boarding configuration */
+        WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();
+        mWiFiOnBoardingConfig.setSSId("EasySetup123");
+        mWiFiOnBoardingConfig.setSharedKey("EasySetup123");
+        mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);
+        mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);
+
+        /* Create provisioning configuration */
+        WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
+
+        /* Create enrolling device factory instance */
+        mFactory = EnrolleeDeviceFactory.newInstance(getContext());
+
+        /* Create enrolling device */
+        mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
+
+        try {
+            mService.startSetup(mDevice);
+        } catch (IOException e) {
+        }
+
+        try {
+
+            Utility.toWait(lock);
+
+            Log.i("EasySetupTest", "Lock is released");
+
+            IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection();
+
+            Log.i("EasySetupTest", "Ip" + conn.getIp());
+            Log.i("EasySetupTest", "MAC" + conn.getHardwareAddress());
+
+            // Device configured successfully
+
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+    }
+
+}
\ No newline at end of file
index dba4cc0..a573416 100644 (file)
@@ -25,7 +25,6 @@ package org.iotivity.service.easysetup.core;
 import android.content.Context;\r
 import android.util.Log;\r
 \r
-import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory;\r
 import org.iotivity.service.easysetup.mediator.EasySetupManager;\r
 import org.iotivity.service.easysetup.mediator.ProvisionEnrollee;\r
 \r
@@ -41,7 +40,7 @@ import java.util.ArrayList;
  */\r
 public class EasySetupService {\r
 \r
-    public static final String TAG = EasySetupService.class.getName();\r
+    private static final String TAG = EasySetupService.class.getName();\r
 \r
     private static EasySetupService sInstance;\r
 \r
@@ -53,7 +52,6 @@ public class EasySetupService {
 \r
     private static Context mContext;\r
 \r
-    public EnrolleeDeviceFactory mDeviceFactory;\r
 \r
     ProvisionEnrollee mProvisionEnrolleeInstance;\r
 \r
@@ -62,7 +60,7 @@ public class EasySetupService {
         mProvisioningCallback = new ProvisioningCallbackImpl(mCallback);\r
         mEnrolleeDeviceList = new ArrayList<EnrolleeDevice>();\r
         mContext = null;\r
-        mDeviceFactory = null;\r
+\r
     }\r
 \r
     /**\r
@@ -110,7 +108,9 @@ public class EasySetupService {
             enrolledevice.startProvisioning(mProvisioningCallback);\r
             return;\r
         }\r
+        enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDING_STATE;\r
 \r
+        mCallback.onProgress(enrolledevice);\r
         enrolledevice.startOnBoarding(new OnBoardingCallback() {\r
 \r
             @Override\r
@@ -118,10 +118,12 @@ public class EasySetupService {
                 if (connection.isConnected()) {\r
                     Log.i(TAG, "On boarding is successful ");\r
                     // Start provisioning here\r
+                    enrolledevice.mState = EnrolleeState.DEVICE_ON_BOARDED_STATE;\r
+                    mCallback.onProgress(enrolledevice);\r
                     enrolledevice.setConnection(connection);\r
                     enrolledevice.startProvisioning(mProvisioningCallback);\r
                 } else {\r
-                    enrolledevice.mState = EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+                    enrolledevice.mState = EnrolleeState.DEVICE_INIT_STATE;\r
                     mProvisioningCallback.onFinished(enrolledevice);\r
                 }\r
 \r
@@ -137,30 +139,26 @@ public class EasySetupService {
      * @param enrolleedevice Device to be enrolled in network\r
      */\r
     public synchronized void stopSetup(EnrolleeDevice enrolleedevice) {\r
-        if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
-            if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+        if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+            enrolleedevice.mState = EnrolleeState.DEVICE_INIT_STATE;\r
+            mCallback.onProgress(enrolleedevice);\r
+            if (enrolleedevice.mState == EnrolleeState.DEVICE_ON_BOARDING_STATE) {\r
                 Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
                 enrolleedevice.stopOnBoardingProcess();\r
                 mEnrolleeDeviceList.remove(enrolleedevice);\r
-            }\r
-        } else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {\r
-            if (mEnrolleeDeviceList.contains(enrolleedevice)) {\r
+            } else if (enrolleedevice.mState == EnrolleeState.DEVICE_PROVISIONING_STATE) {\r
                 Log.i(TAG, "stopOnBoardingProcess for enrolleedevice");\r
                 enrolleedevice.stopOnBoardingProcess();\r
-\r
                 Log.i(TAG, "stopEnrolleeProvisioning for enrolleedevice");\r
                 //Native Api call to stop on-going enrolling process for the enrolling device\r
                 EasySetupManager.getInstance().stopEnrolleeProvisioning(enrolleedevice\r
                         .mOnBoardingConfig.getConnType().getValue());\r
                 mEnrolleeDeviceList.remove(enrolleedevice);\r
+\r
             }\r
         }\r
     }\r
 \r
-    public synchronized void getEnrolleeDevice(OnBoardingConfig connType) {\r
-        mDeviceFactory = EnrolleeDeviceFactory.newInstance(mContext);\r
-    }\r
-\r
     class ProvisioningCallbackImpl extends ProvisioningCallback {\r
 \r
         private final EasySetupStatus mCallback;\r
@@ -180,7 +178,11 @@ public class EasySetupService {
             }\r
         }\r
 \r
-    }\r
+        @Override\r
+        public void onProgress(EnrolleeDevice enrolledevice) {\r
+            mCallback.onProgress(enrolledevice);\r
+        }\r
 \r
 \r
-}\r
+    }\r
+}
\ No newline at end of file
index 4ba7fba..4ad785a 100644 (file)
@@ -43,8 +43,8 @@ public interface EasySetupStatus {
      * setup process This method is called on worker thread, UI operations to be
      * executed on main / Ui Thread.
      *
-     * @param state Gives state of the device changed during easy setup process
+     * @param enrolleeDevice Gives state of the device changed during easy setup process
      */
-    public void onProgress(EnrolleeState state);
+    public void onProgress(EnrolleeDevice enrolleeDevice);
 
 }
index ec3bd1b..2d87190 100644 (file)
@@ -83,10 +83,15 @@ public abstract class EnrolleeDevice {
      *\r
      * @param conn Connectivity between Enrollee device & Mediator device.\r
      */\r
-    public void setConnection(OnBoardingConnection conn) {\r
+    protected void setConnection(OnBoardingConnection conn) {\r
         mConnection = conn;\r
     }\r
 \r
+    /**\r
+     * This method returns the OnBoardingConnection object depending on the connection type\r
+     *\r
+     * @return onBoardingConnection object\r
+     */\r
     public OnBoardingConnection getConnection() {\r
         return mConnection;\r
     }\r
@@ -119,13 +124,13 @@ public abstract class EnrolleeDevice {
      */\r
 \r
     public boolean isSetupSuccessful() {\r
-        return (mState == EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE) ? true : false;\r
+        return (mState == EnrolleeState.DEVICE_PROVISIONED_STATE) ? true : false;\r
     }\r
 \r
     /**\r
      * sets error occured during easy setup process\r
      */\r
-    public void setError(EnrolleeSetupError error) {\r
+    protected void setError(EnrolleeSetupError error) {\r
         mError = error;\r
     }\r
 \r
@@ -153,7 +158,7 @@ public abstract class EnrolleeDevice {
      * @return True if on-boarded successfully or False\r
      */\r
 \r
-    public boolean onBoarded() {\r
+    protected boolean onBoarded() {\r
         return (mState == EnrolleeState.DEVICE_PROVISIONING_STATE) ? true : false;\r
     }\r
 \r
index 6b91254..8ce6dcf 100644 (file)
@@ -36,6 +36,11 @@ public enum EnrolleeState {
     /**
      * Device will move to this state after successful on-boarding of the device
      */
+    DEVICE_ON_BOARDED_STATE,
+
+    /**
+     * Device will move to this state once the on boarding begins
+     */
     DEVICE_ON_BOARDING_STATE,
 
     /**
@@ -46,19 +51,20 @@ public enum EnrolleeState {
     /**
      * Easy setup process is successful.
      */
-    DEVICE_PROVISIONING_SUCCESS_STATE,
+    DEVICE_PROVISIONED_STATE,
 
     /**
-     * Device is not able to provisioned.
-     * Easy setup process failed to enrolled the device in the network
+     * This state is arbitrary one, any time device can come into this state
+     * Device will move to this state if the ownership transfer initiated  by the Application
      */
-    DEVICE_PROVISIONING_FAILED_STATE,
+    DEVICE_OWNERSHIP_TRANSFERRING_STATE,
 
     /**
      * This state is arbitrary one, any time device can come into this state
-     * Device will move to this state if the ownership transfer initiated  by the Application
+     * Device will move to this state if the ownership transfer is completed
      */
-    DEVICE_OWNERSHIP_TRANSFER_STATE,
+    DEVICE_OWNERSHIP_TRANSFERRED_STATE,
+
 
     /**
      * This state is arbitrary one, any time device can come into this state
index 80c2fa0..342bd1f 100644 (file)
  */\r
 package org.iotivity.service.easysetup.core;\r
 \r
+/**\r
+ * This interface contains the connection details of the enrollee device\r
+ */\r
 public interface OnBoardingConnection {\r
 \r
-\r
-    // Get the implementation of the Connection\r
+    /**\r
+     * This method returns the implementation of the Connection\r
+     *\r
+     * @return implementation\r
+     */\r
     public Object getConnection();\r
 \r
-    // Any general description on the connectivity.\r
+    /**\r
+     * This method returns description on the connectivity.\r
+     *\r
+     * @return description\r
+     */\r
     public String getDesc();\r
 \r
+    /**\r
+     * This method is used to know if the device is connected or not\r
+     *\r
+     * @return True if connected or False\r
+     */\r
     public boolean isConnected();\r
 \r
 }\r
index 1af6d45..2b022c7 100644 (file)
@@ -135,8 +135,6 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
 \r
     @Override\r
     protected void startProvisioningProcess(OnBoardingConnection conn) {\r
-        mState = EnrolleeState.DEVICE_PROVISIONING_STATE;\r
-\r
         try {\r
             Log.i(TAG, "waiting for 15 seconds to start provisioning");\r
             Thread.sleep(15000);//Sleep for allowing thin device to start the services\r
@@ -144,7 +142,9 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
             e.printStackTrace();\r
         }\r
 \r
-\r
+        mState = EnrolleeState.DEVICE_PROVISIONING_STATE;\r
+        mProvisioningCallback.onProgress(this);\r
+        final EnrolleeDevice device = this;\r
         if (mProvConfig.getConnType() == ProvisioningConfig.ConnType.WiFi) {\r
 \r
             provisionEnrolleInstance = new ProvisionEnrollee(mContext);\r
@@ -154,9 +154,10 @@ public class EnrolleeDeviceWiFiOnboarding extends EnrolleeDevice {
                 public void onFinishProvisioning(int statuscode) {\r
 \r
                     Log.i(TAG, "Provisioning is finished with status code " + statuscode);\r
-                    mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONING_SUCCESS_STATE\r
-                            : EnrolleeState.DEVICE_PROVISIONING_FAILED_STATE;\r
+                    mState = (statuscode == 0) ? EnrolleeState.DEVICE_PROVISIONED_STATE\r
+                            : EnrolleeState.DEVICE_INIT_STATE;\r
                     stopOnBoardingProcess();\r
+                    mProvisioningCallback.onProgress(device);\r
                     mProvisioningCallback.onFinished(EnrolleeDeviceWiFiOnboarding.this);\r
                 }\r
             });\r
index 72ffb5e..8d9ab15 100644 (file)
@@ -53,10 +53,18 @@ public class WiFiProvConfig implements ProvisioningConfig {
         return mConnType;
     }
 
+    /**
+     * This method returns the SSID of the Target WIFI network
+     * @return SSID of Target Network
+     */
     public String getSsId() {
         return mSsId;
     }
 
+    /**
+     * This method returns the password of the Target WIFI network
+     * @return password of Target Network
+     */
     public String getPassword() {
         return mPassword;
     }