Re-enabled some of the Android smoke tests
authorTim Kourt <tim.a.kourt@intel.com>
Wed, 26 Aug 2015 22:56:08 +0000 (15:56 -0700)
committerJon A. Cruz <jonc@osg.samsung.com>
Thu, 27 Aug 2015 04:23:48 +0000 (04:23 +0000)
Change-Id: If90118088be6f4663196bd1dd05cdd5c7d1ec161
Signed-off-by: Tim Kourt <tim.a.kourt@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/2294
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java

index eb981b5..b0fadd7 100644 (file)
@@ -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<String, String> 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);