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