From: Tim Kourt Date: Wed, 26 Aug 2015 22:56:08 +0000 (-0700) Subject: Re-enabled some of the Android smoke tests X-Git-Tag: 1.2.0+RC1~1161 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=761de16326c0cb76b68088523d04cbca3be02e95;p=platform%2Fupstream%2Fiotivity.git Re-enabled some of the Android smoke tests Change-Id: If90118088be6f4663196bd1dd05cdd5c7d1ec161 Signed-off-by: Tim Kourt Reviewed-on: https://gerrit.iotivity.org/gerrit/2294 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz --- diff --git a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java index eb981b5..b0fadd7 100644 --- a/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java +++ b/android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java @@ -112,85 +112,85 @@ public class SmokeTest extends InstrumentationTestCase { assertTrue(false); } } -// TODO - this test fails currently -// public void testStartStopListenForPresence() throws InterruptedException { -// final String resourceType = "unit.test.resource" + -// new Date().getTime(); -// final CountDownLatch signal = new CountDownLatch(1); -// -// OcPlatform.EntityHandler entityHandler = new OcPlatform.EntityHandler() { -// @Override -// public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest) { -// return EntityHandlerResult.OK; -// } -// }; -// -// final OcPlatform.OnPresenceListener presenceListener = new OcPlatform.OnPresenceListener() { -// @Override -// public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress) { -// Log.i(TAG, "onPresence status " + ocPresenceStatus.toString() + " nonce " + nonce); -// signal.countDown(); -// } -// }; -// -// OcPlatform.OnResourceFoundListener resourceFoundListener = -// new OcPlatform.OnResourceFoundListener() { -// @Override -// public void onResourceFound(OcResource resource) { -// try { -// //client -// OcPresenceHandle presenceHandle = OcPlatform.subscribePresence( -// resource.getHost(), -// EnumSet.of(OcConnectivityType.CT_DEFAULT), -// presenceListener -// ); -// -// //wait for onPresence event -// assertTrue(signal.await(60, TimeUnit.SECONDS)); -// -// //client -// OcPlatform.unsubscribePresence(presenceHandle); -// } catch (OcException e) { -// assertTrue(false); -// } catch (InterruptedException e) { -// assertTrue(false); -// } -// } -// }; -// -// try { -// //server -// OcResourceHandle resourceHandle = OcPlatform.registerResource( -// "/a/unittest", -// resourceType, -// OcPlatform.DEFAULT_INTERFACE, -// entityHandler, -// EnumSet.of(ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE) -// ); -// -// //client -// OcPlatform.findResource("", -// OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, -// EnumSet.of(OcConnectivityType.CT_DEFAULT), -// resourceFoundListener); -// -// //server -// OcPlatform.startPresence(OcPlatform.DEFAULT_PRESENCE_TTL); -// -// //wait for onPresence event -// assertTrue(signal.await(60, TimeUnit.SECONDS)); -// -// //server -// OcPlatform.stopPresence(); -// -// //client -// OcPlatform.unregisterResource(resourceHandle); -// -// } catch (OcException e) { -// Log.e(TAG, e.getMessage()); -// assertTrue(false); -// } -// } + + public void testStartStopListenForPresence() throws InterruptedException { + final String resourceType = "unit.test.resource" + + new Date().getTime(); + final CountDownLatch signal = new CountDownLatch(1); + + OcPlatform.EntityHandler entityHandler = new OcPlatform.EntityHandler() { + @Override + public EntityHandlerResult handleEntity(OcResourceRequest ocResourceRequest) { + return EntityHandlerResult.OK; + } + }; + + final OcPlatform.OnPresenceListener presenceListener = new OcPlatform.OnPresenceListener() { + @Override + public void onPresence(OcPresenceStatus ocPresenceStatus, int nonce, String hostAddress) { + Log.i(TAG, "onPresence status " + ocPresenceStatus.toString() + " nonce " + nonce); + signal.countDown(); + } + }; + + OcPlatform.OnResourceFoundListener resourceFoundListener = + new OcPlatform.OnResourceFoundListener() { + @Override + public void onResourceFound(OcResource resource) { + try { + //client + OcPresenceHandle presenceHandle = OcPlatform.subscribePresence( + resource.getHost(), + EnumSet.of(OcConnectivityType.CT_DEFAULT), + presenceListener + ); + + //wait for onPresence event + assertTrue(signal.await(60, TimeUnit.SECONDS)); + + //client + OcPlatform.unsubscribePresence(presenceHandle); + } catch (OcException e) { + assertTrue(false); + } catch (InterruptedException e) { + assertTrue(false); + } + } + }; + + try { + //server + OcResourceHandle resourceHandle = OcPlatform.registerResource( + "/a/unittest", + resourceType, + OcPlatform.DEFAULT_INTERFACE, + entityHandler, + EnumSet.of(ResourceProperty.DISCOVERABLE, ResourceProperty.OBSERVABLE) + ); + + //client + OcPlatform.findResource("", + OcPlatform.WELL_KNOWN_QUERY + "?rt=" + resourceType, + EnumSet.of(OcConnectivityType.CT_DEFAULT), + resourceFoundListener); + + //server + OcPlatform.startPresence(OcPlatform.DEFAULT_PRESENCE_TTL); + + //wait for onPresence event + assertTrue(signal.await(60, TimeUnit.SECONDS)); + + //server + OcPlatform.stopPresence(); + + //client + OcPlatform.unregisterResource(resourceHandle); + + } catch (OcException e) { + Log.e(TAG, e.getMessage()); + assertTrue(false); + } + } public void testHandleGetRequest() throws InterruptedException { final String someKey = "SomeKey"; @@ -248,7 +248,7 @@ public class SmokeTest extends InstrumentationTestCase { ocResourceList.add(resource); try { resource.get(queryParamsMap, onGetListener); - //TODO there is a bug in the stack that prevents the usage of the following APIs +// TODO there is a bug in the stack that prevents the usage of the following APIs // resource.get(resourceType, OcPlatform.DEFAULT_INTERFACE, queryParamsMap, // onGetListener); // @@ -291,11 +291,11 @@ public class SmokeTest extends InstrumentationTestCase { case GET: Map queryParams = ocResourceRequest.getQueryParameters(); -//TODO after the merge with CA, the query params are missing -// if (!(queryParams.containsKey(someKey) && -// someValue.equals(queryParams.get(someKey)))) { -// assertTrue(false); -// } + + if (!(queryParams.containsKey(someKey) && + someValue.equals(queryParams.get(someKey)))) { + assertTrue(false); + } ocResourceResponse.setErrorCode(200); ocResourceResponse.setResponseResult(EntityHandlerResult.OK);