From 461372548f7b9421a836c5ef4c63608d2f8cba20 Mon Sep 17 00:00:00 2001 From: "spurthi.segu" Date: Wed, 7 Oct 2015 18:07:34 +0530 Subject: [PATCH] Junit fixes and review comment fixes for Simulator. Change-Id: I215a83ef94b8b503018cf983bf36fc14bbe66c77 Signed-off-by: spurthi.segu Reviewed-on: https://gerrit.iotivity.org/gerrit/3727 Tested-by: jenkins-iotivity Reviewed-by: Madan Lanka --- service/simulator/inc/simulator_error_codes.h | 2 +- .../serviceprovider/manager/ResourceManager.java | 22 +--------------------- .../java/jni/simulator_resource_server_jni.cpp | 12 ++++++------ .../clientcontroller/SimulatorRemoteResource.java | 20 +++++++++++--------- .../serviceprovider/SimulatorResourceServer.java | 2 +- .../resource_update_automation_mngr.cpp | 4 ++-- 6 files changed, 22 insertions(+), 40 deletions(-) diff --git a/service/simulator/inc/simulator_error_codes.h b/service/simulator/inc/simulator_error_codes.h index fe2b6e1..76092a2 100644 --- a/service/simulator/inc/simulator_error_codes.h +++ b/service/simulator/inc/simulator_error_codes.h @@ -75,7 +75,7 @@ typedef enum SIMULATOR_TYPE_MISMATCH, SIMULATOR_BAD_VALUE, SIMULATOR_BAD_OBJECT, - /** Simulator specific error codes - START */ + /** Simulator specific error codes - END */ SIMULATOR_ERROR = 255 } SimulatorResult; diff --git a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java index d7b5feb..ebc34e0 100644 --- a/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java +++ b/service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java @@ -1384,17 +1384,7 @@ public class ResourceManager { if (null != resourceServerN) { try { resourceServerN.stopAutomation(autoId); - } catch (InvalidArgsException e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), - new Date(), - "[" + e.getClass().getSimpleName() + "]" - + e.code().toString() + "-" - + e.message()); - return; - }catch (SimulatorException e) { + } catch (SimulatorException e) { Activator .getDefault() .getLogManager() @@ -1533,16 +1523,6 @@ public class ResourceManager { // Call native method try { resourceServer.stopAutomation(autoId); - } catch (InvalidArgsException e) { - Activator - .getDefault() - .getLogManager() - .log(Level.ERROR.ordinal(), - new Date(), - "[" + e.getClass().getSimpleName() + "]" - + e.code().toString() + "-" - + e.message()); - return false; } catch (SimulatorException e) { Activator .getDefault() diff --git a/service/simulator/java/jni/simulator_resource_server_jni.cpp b/service/simulator/java/jni/simulator_resource_server_jni.cpp index 50affa6..c9b08c9 100644 --- a/service/simulator/java/jni/simulator_resource_server_jni.cpp +++ b/service/simulator/java/jni/simulator_resource_server_jni.cpp @@ -603,20 +603,20 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!"); return; } - - try + + try { resource->stopUpdateAutomation(automationId); } - catch (InvalidArgsException &e) + catch (SimulatorException &e) { - throwInvalidArgsException(env, e.code(), e.what()); + throwSimulatorException(env, e.code(), e.what()); } catch (...) { throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception"); - } - + } + SIM_LOG(ILogger::INFO, "Automation has been forcibly stopped.") } diff --git a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorRemoteResource.java b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorRemoteResource.java index daed3b7..096e65e 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorRemoteResource.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorRemoteResource.java @@ -161,7 +161,7 @@ public class SimulatorRemoteResource { throw new InvalidArgsException( SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(), "Parameter passed in invalid"); - this.get(null, queryParamsMap, onGetListener); + this.nativeGet(null, queryParamsMap, onGetListener); } /** @@ -188,11 +188,11 @@ public class SimulatorRemoteResource { public void get(String resourceInterface, Map queryParamsMap, IGetListener onGetListener) throws InvalidArgsException, NoSupportException, SimulatorException { - if (resourceInterface.isEmpty() || null == onGetListener) + if (null == resourceInterface || resourceInterface.isEmpty() || null == onGetListener) throw new InvalidArgsException( SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(), "Parameter passed in invalid"); - this.get(resourceInterface, queryParamsMap, onGetListener); + this.nativeGet(resourceInterface, queryParamsMap, onGetListener); } private native void nativeGet(String resourceInterface, @@ -228,7 +228,7 @@ public class SimulatorRemoteResource { throw new InvalidArgsException( SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(), "Parameter passed in invalid"); - this.put(null, representation, queryParamsMap, onPutListener); + this.nativePut(null, representation, queryParamsMap, onPutListener); } /** @@ -259,11 +259,12 @@ public class SimulatorRemoteResource { SimulatorResourceModel representation, Map queryParamsMap, IPutListener onPutListener) throws InvalidArgsException, NoSupportException, SimulatorException { - if (resourceInterface.isEmpty() || null == representation || null == onPutListener) + if (null == resourceInterface || resourceInterface.isEmpty() || + null == representation || null == onPutListener) throw new InvalidArgsException( SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(), "Parameter passed in invalid"); - this.put(resourceInterface, representation, queryParamsMap, onPutListener); + this.nativePut(resourceInterface, representation, queryParamsMap, onPutListener); } private native void nativePut(String resourceInterface, @@ -300,7 +301,7 @@ public class SimulatorRemoteResource { throw new InvalidArgsException( SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(), "Parameter passed in invalid"); - this.post(null, representation, queryParamsMap, onPostListener); + this.nativePost(null, representation, queryParamsMap, onPostListener); } /** @@ -331,11 +332,12 @@ public class SimulatorRemoteResource { SimulatorResourceModel representation, Map queryParamsMap, IPostListener onPostListener) throws InvalidArgsException, NoSupportException, SimulatorException { - if (resourceInterface.isEmpty() || null == representation || null == onPostListener) + if (null == resourceInterface || resourceInterface.isEmpty() || + null == representation || null == onPostListener) throw new InvalidArgsException( SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(), "Parameter passed in invalid"); - this.post(resourceInterface, representation, queryParamsMap, onPostListener); + this.nativePost(resourceInterface, representation, queryParamsMap, onPostListener); } private native void nativePost(String resourceInterface, diff --git a/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java b/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java index a42a12f..0d9accd 100644 --- a/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java +++ b/service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java @@ -389,7 +389,7 @@ public class SimulatorResourceServer { * This exception will be thrown for other errors. */ public native void stopAutomation(int automationId) - throws InvalidArgsException, SimulatorException; + throws SimulatorException; /** * API to remove an attribute from the simulated resource. diff --git a/service/simulator/src/service-provider/resource_update_automation_mngr.cpp b/service/simulator/src/service-provider/resource_update_automation_mngr.cpp index c5ec75e..94eb2c5 100644 --- a/service/simulator/src/service-provider/resource_update_automation_mngr.cpp +++ b/service/simulator/src/service-provider/resource_update_automation_mngr.cpp @@ -114,8 +114,8 @@ void UpdateAutomationMngr::stop(int id) return; } - //Throw InvalidArgsException - throw InvalidArgsException(SIMULATOR_INVALID_PARAM, "Invalid Automation Id!"); + //Throw SimulatorException + throw SimulatorException(SIMULATOR_ERROR, "No automation is currently in progress for the given automation Id!"); } void UpdateAutomationMngr::stopAll() -- 2.7.4