From: Hemant Mahsky Date: Fri, 18 Sep 2015 12:29:32 +0000 (+0530) Subject: Ble on-boarding Junit test cases X-Git-Tag: 1.2.0+RC1~597^2^2~38 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6ea4aa9728a2aeb4949276947fbdf6b570a2da26;p=platform%2Fupstream%2Fiotivity.git Ble on-boarding Junit test cases Change-Id: I7eafc6535c55a9588eedc6aa94a2de28fb10b843 Signed-off-by: Hemant Mahsky Reviewed-on: https://gerrit.iotivity.org/gerrit/2711 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java index 6caae74..fd9f645 100644 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EasySetupServiceTest.java @@ -24,22 +24,19 @@ import android.test.AndroidTestCase; import android.test.mock.MockApplication; import android.util.Log; +import org.iotivity.service.easysetup.impl.BLEOnBoardingConfig; +import org.iotivity.service.easysetup.impl.EnrolleeDeviceBLEOnBoarding; 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; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; public class EasySetupServiceTest extends AndroidTestCase { - public void testFunction() { - - // final CountDownLatch countDownLatch = new CountDownLatch(1); - + public void testStartSetupWithWiFiOnboarding() { EasySetupService mService; EnrolleeDevice mDevice; @@ -127,6 +124,11 @@ public class EasySetupServiceTest extends AndroidTestCase { Log.i("EasySetupTest", "Lock is released"); + if(! mDevice.isSetupSuccessful()) { + assertTrue(false); + return; + } + IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection(); if (conn == null) { assertTrue(false); @@ -158,4 +160,145 @@ public class EasySetupServiceTest extends AndroidTestCase { } + public void testStartSetupWithBleOnboarding() { + + final String UUID = "ade3d529-c784-4f63-a987-eb69f70ee816"; + + EasySetupService mService; + EnrolleeDevice mDevice; + EnrolleeDeviceFactory mFactory; + + final Object lock = new Object(); + + + /* Create Easy Setup service */ + mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() { + @Override + public void onFinished(EnrolleeDevice enrolledevice) { + + //countDownLatch.countDown(); + Utility.toNotify(lock); + + if (enrolledevice.isSetupSuccessful()) { + + if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.BLE) { + BleConnection conn = (BleConnection) enrolledevice.getConnection(); + String mac = conn.getMacaddress(); + if (mac == null || mac.isEmpty()) { + assertTrue(false); + return; + } + + String uuid = conn.getmServiceUUID(); + if (uuid == null || uuid.isEmpty()) { + assertTrue(false); + return; + } + + // Conform that device are same + if (!uuid.equals(UUID)) { + assertTrue(false); + return; + } + + // Device configured successfully + assertTrue(true); + } + + } else { + assertTrue(false); + } + } + + @Override + public void onProgress(EnrolleeState state) { + // TODO + } + }); + + + /* Create On boarding configuration */ + + BLEOnBoardingConfig bleOnBoardingConfig = new BLEOnBoardingConfig(); + bleOnBoardingConfig.setUuid("ade3d529-c784-4f63-a987-eb69f70ee816"); + + /* Create provisioning configuration */ + WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222"); + + /* Create enrolling device factory instance */ + mFactory = EnrolleeDeviceFactory.newInstance(getContext()); + + /* Check if the factory created successfully */ + assertTrue(mFactory != null); + + /* Create enrolling device */ + mDevice = mFactory.newEnrolleeDevice(bleOnBoardingConfig, mWiFiProvConfig); + + /* Check if the the device is created successfully*/ + assertTrue(mDevice != null); + + /* Check if the the correct device is created as per the given configuration*/ + + /* Check if the the correct device is created as per the given configuration*/ + assertTrue((mDevice instanceof EnrolleeDeviceBLEOnBoarding)); + + + try { + mService.startSetup(mDevice); + // If no exception is thrown means setup started successfully. + assertTrue(true); + + } catch (IOException e) { + assertTrue(false); + } + + try { + + Utility.toWait(lock); + + Log.i("EasySetupTest", "Lock is released"); + + if(! mDevice.isSetupSuccessful()) { + assertTrue(false); + return; + } + + + BleConnection conn = (BleConnection) mDevice.getConnection(); + if (conn == null) { + assertTrue(false); + return; + } + + String mac = conn.getMacaddress(); + if (mac == null || mac.isEmpty()) { + assertTrue(false); + return; + } + + String uuid = conn.getmServiceUUID(); + if (uuid == null || uuid.isEmpty()) { + assertTrue(false); + return; + } + + if (!uuid.equals(UUID)) { + assertTrue(false); + return; + } + + Log.i("EasySetupTest", "MAC " + mac); + Log.i("EasySetupTest", "UUID " + uuid); + + // Device configured successfully + assertTrue(true); + + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + + } + + } \ No newline at end of file diff --git a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EnrolleeDeviceFactoryTest.java b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EnrolleeDeviceFactoryTest.java index f8e0b0c..f8f826a 100644 --- a/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EnrolleeDeviceFactoryTest.java +++ b/service/easy-setup/sdk/mediator/android/EasySetupCore/src/androidTest/java/org/iotivity/service/easysetup/core/EnrolleeDeviceFactoryTest.java @@ -25,6 +25,8 @@ package org.iotivity.service.easysetup.core; import android.net.wifi.WifiConfiguration; import android.test.AndroidTestCase; +import org.iotivity.service.easysetup.impl.BLEOnBoardingConfig; +import org.iotivity.service.easysetup.impl.EnrolleeDeviceBLEOnBoarding; import org.iotivity.service.easysetup.impl.EnrolleeDeviceFactory; import org.iotivity.service.easysetup.impl.EnrolleeDeviceWiFiOnboarding; import org.iotivity.service.easysetup.impl.WiFiOnBoardingConfig; @@ -49,7 +51,7 @@ public class EnrolleeDeviceFactoryTest extends AndroidTestCase { } - public void testNewEnrolleeDeviceWiFiOnboarding() { + public void testNewEnrolleeDevice_with_WiFiOnboarding() { /* Create On boarding configuration */ WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig(); @@ -72,5 +74,27 @@ public class EnrolleeDeviceFactoryTest extends AndroidTestCase { } + public void testNewEnrolleeDevice_with_BleOnboarding() { + + /* Create On boarding configuration */ + + BLEOnBoardingConfig bleOnBoardingConfig = new BLEOnBoardingConfig(); + bleOnBoardingConfig.setUuid("ade3d529-c784-4f63-a987-eb69f70ee816"); + + /* Create provisioning configuration */ + WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222"); + + /* Create enrolling device */ + EnrolleeDevice device = mFactory.newEnrolleeDevice(bleOnBoardingConfig, mWiFiProvConfig); + + /* Check if the the device is created */ + assertTrue(device != null); + + /* Check if the the correct device is created as per the given configuration*/ + assertTrue((device instanceof EnrolleeDeviceBLEOnBoarding)); + + } + + }