1 //******************************************************************
3 // Copyright 2015 Samsung Electronics All Rights Reserved.
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
11 // http://www.apache.org/licenses/LICENSE-2.0
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20 package org.iotivity.service.easysetup.mediator;
22 import android.net.wifi.WifiConfiguration;
23 import android.test.AndroidTestCase;
24 import android.util.Log;
26 import java.io.IOException;
28 public class EasySetupServiceTest extends AndroidTestCase {
31 public void testStartSetupWithWiFiOnboarding() {
33 EasySetupService mService;
34 EnrolleeDevice mDevice;
35 EnrolleeDeviceFactory mFactory;
37 final Object lock = new Object();
40 /* Create Easy Setup service */
41 mService = EasySetupService.getInstance(getContext(), new EasySetupStatus() {
43 public void onFinished(EnrolleeDevice enrolledevice) {
45 //countDownLatch.countDown();
46 Utility.toNotify(lock);
48 if (enrolledevice.isSetupSuccessful()) {
50 if (enrolledevice.mOnBoardingConfig.getConnType() == WiFiOnBoardingConfig.ConnType.WiFi) {
51 IpOnBoardingConnection conn = (IpOnBoardingConnection) enrolledevice.getConnection();
52 String ip = conn.getIp();
53 if (ip == null || ip.isEmpty()) {
57 String mac = conn.getHardwareAddress();
58 if (mac == null || mac.isEmpty()) {
62 // Device configured successfully
72 public void onProgress(EnrolleeDevice enrolleeDevice) {
73 // Handled in EasySetupStatusTest
78 /* Create On boarding configuration */
79 WiFiOnBoardingConfig mWiFiOnBoardingConfig = new WiFiOnBoardingConfig();
80 mWiFiOnBoardingConfig.setSSId("EasySetup123");
81 mWiFiOnBoardingConfig.setSharedKey("EasySetup123");
82 mWiFiOnBoardingConfig.setAuthAlgo(WifiConfiguration.AuthAlgorithm.OPEN);
83 mWiFiOnBoardingConfig.setKms(WifiConfiguration.KeyMgmt.WPA_PSK);
85 /* Create provisioning configuration */
86 WiFiProvConfig mWiFiProvConfig = new WiFiProvConfig("hub2.4G", "11112222");
88 /* Create enrolling device factory instance */
89 mFactory = EnrolleeDeviceFactory.newInstance(getContext());
91 /* Check if the factory created successfully */
92 assertTrue(mFactory != null);
94 /* Create enrolling device */
95 mDevice = mFactory.newEnrolleeDevice(mWiFiOnBoardingConfig, mWiFiProvConfig);
97 /* Check if the the device is created successfully*/
98 assertTrue(mDevice != null);
100 /* Check if the the correct device is created as per the given configuration*/
101 assertTrue((mDevice instanceof EnrolleeDeviceWiFiOnboarding));
105 mService.startSetup(mDevice);
106 // If no exception is thrown means setup started successfully.
109 } catch (IOException e) {
115 Utility.toWait(lock);
117 Log.i("EasySetupTest", "Lock is released");
119 if (!mDevice.isSetupSuccessful()) {
124 IpOnBoardingConnection conn = (IpOnBoardingConnection) mDevice.getConnection();
130 String ip = conn.getIp();
131 if (ip == null || ip.isEmpty()) {
136 String mac = conn.getHardwareAddress();
137 if (mac == null || mac.isEmpty()) {
142 Log.i("EasySetupTest", "Ip" + conn.getIp());
143 Log.i("EasySetupTest", "MAC" + conn.getHardwareAddress());
145 // Device configured successfully
148 } catch (Exception e) {