Junit fixes and review comment fixes for Simulator.
[contrib/iotivity.git] / service / simulator / java / sdk / src / org / oic / simulator / clientcontroller / SimulatorRemoteResource.java
index b0b7ee2..096e65e 100644 (file)
@@ -24,6 +24,7 @@ import org.oic.simulator.NoSupportException;
 import org.oic.simulator.OperationInProgressException;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.SimulatorResult;
 
 /**
  * SimulatorRemoteResource represents a Resource running in the remote Simulator
@@ -156,7 +157,11 @@ public class SimulatorRemoteResource {
     public void get(Map<String, String> queryParamsMap,
             IGetListener onGetListener) throws InvalidArgsException,
             NoSupportException, SimulatorException {
-        this.get(null, queryParamsMap, onGetListener);
+        if (null == onGetListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
+        this.nativeGet(null, queryParamsMap, onGetListener);
     }
 
     /**
@@ -180,7 +185,17 @@ public class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void get(String resourceInterface,
+    public void get(String resourceInterface,
+            Map<String, String> queryParamsMap, IGetListener onGetListener)
+            throws InvalidArgsException, NoSupportException, SimulatorException {
+        if (null == resourceInterface || resourceInterface.isEmpty() || null == onGetListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
+        this.nativeGet(resourceInterface, queryParamsMap, onGetListener);
+    }
+
+    private native void nativeGet(String resourceInterface,
             Map<String, String> queryParamsMap, IGetListener onGetListener)
             throws InvalidArgsException, NoSupportException, SimulatorException;
 
@@ -209,7 +224,11 @@ public class SimulatorRemoteResource {
     public void put(SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPutListener onPutListener)
             throws InvalidArgsException, NoSupportException, SimulatorException {
-        this.put(null, representation, queryParamsMap, onPutListener);
+        if (null == representation || null == onPutListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
+        this.nativePut(null, representation, queryParamsMap, onPutListener);
     }
 
     /**
@@ -236,7 +255,19 @@ public class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    private native void put(String resourceInterface,
+    public void put(String resourceInterface,
+            SimulatorResourceModel representation,
+            Map<String, String> queryParamsMap, IPutListener onPutListener)
+            throws InvalidArgsException, NoSupportException, SimulatorException {
+        if (null == resourceInterface || resourceInterface.isEmpty() ||
+            null == representation || null == onPutListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
+        this.nativePut(resourceInterface, representation, queryParamsMap, onPutListener);
+    }
+
+    private native void nativePut(String resourceInterface,
             SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPutListener onPutListener)
             throws InvalidArgsException, NoSupportException, SimulatorException;
@@ -266,7 +297,11 @@ public class SimulatorRemoteResource {
     public void post(SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPostListener onPostListener)
             throws InvalidArgsException, NoSupportException, SimulatorException {
-        this.post(null, representation, queryParamsMap, onPostListener);
+        if (null == representation || null == onPostListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
+        this.nativePost(null, representation, queryParamsMap, onPostListener);
     }
 
     /**
@@ -293,7 +328,19 @@ public class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void post(String resourceInterface,
+    public void post(String resourceInterface,
+            SimulatorResourceModel representation,
+            Map<String, String> queryParamsMap, IPostListener onPostListener)
+            throws InvalidArgsException, NoSupportException, SimulatorException {
+        if (null == resourceInterface || resourceInterface.isEmpty() ||
+            null == representation || null == onPostListener)
+            throw new InvalidArgsException(
+                SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                "Parameter passed in invalid");
+        this.nativePost(resourceInterface, representation, queryParamsMap, onPostListener);
+    }
+
+    private native void nativePost(String resourceInterface,
             SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPostListener onPostListener)
             throws InvalidArgsException, NoSupportException, SimulatorException;
@@ -368,9 +415,13 @@ public class SimulatorRemoteResource {
 
     @Override
     protected void finalize() throws Throwable {
-        super.finalize();
-
-        dispose();
+        try {
+            dispose();
+        } catch(Throwable t){
+            throw t;
+        } finally{
+            super.finalize();
+        }
     }
 
     private native void dispose();