Junit testing fixes for Simulator APIs.
authorspurthi.segu <spurthi.segu@samsung.com>
Tue, 6 Oct 2015 15:04:31 +0000 (20:34 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Wed, 7 Oct 2015 10:57:03 +0000 (10:57 +0000)
Change-Id: Id55390d0476be0349b2d2bbaa84adbbd36e4a8dd
Signed-off-by: spurthi.segu <spurthi.segu@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3629
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
service/simulator/java/eclipse-plugin/ClientControllerPlugin/src/oic/simulator/clientcontroller/manager/ResourceManager.java
service/simulator/java/eclipse-plugin/ServiceProviderPlugin/src/oic/simulator/serviceprovider/manager/ResourceManager.java
service/simulator/java/jni/simulator_remote_resource_jni.cpp
service/simulator/java/jni/simulator_remote_resource_jni.h
service/simulator/java/jni/simulator_resource_server_jni.cpp
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/clientcontroller/SimulatorRemoteResource.java
service/simulator/java/sdk/src/org/oic/simulator/serviceprovider/SimulatorResourceServer.java
service/simulator/src/common/simulator_resource_model.cpp
service/simulator/src/service-provider/resource_update_automation_mngr.cpp

index 565a9ae..9b8bdb4 100644 (file)
@@ -47,6 +47,7 @@ import oic.simulator.clientcontroller.utils.Utility;
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.graphics.Image;
 import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.ResourceAttribute;
 import org.oic.simulator.ResourceAttribute.Range;
 import org.oic.simulator.ResourceAttribute.Type;
@@ -1482,6 +1483,16 @@ public class ResourceManager {
         }
         try {
             resourceN.stopVerification(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) {
             Activator
                     .getDefault()
index febfbb6..ae89c0d 100644 (file)
@@ -44,6 +44,7 @@ import oic.simulator.serviceprovider.utils.Utility;
 import org.eclipse.swt.graphics.Image;
 import org.oic.simulator.IAutomation;
 import org.oic.simulator.ILogger.Level;
+import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.ResourceAttribute;
 import org.oic.simulator.ResourceAttribute.Range;
 import org.oic.simulator.ResourceAttribute.Type;
@@ -403,7 +404,7 @@ public class ResourceManager {
                         orderedResourceUriMap.remove(resourceType);
                     }
                 }
-            } else if (null != resourceURI) {
+            } else if (null != resourceType) {
                 orderedResourceUriMap.remove(resourceType);
             } else {
                 orderedResourceUriMap.clear();
@@ -1383,7 +1384,17 @@ public class ResourceManager {
             if (null != resourceServerN) {
                 try {
                     resourceServerN.stopAutomation(autoId);
-                } catch (SimulatorException e) {
+                } catch (InvalidArgsException e) {
+                    Activator
+                    .getDefault()
+                    .getLogManager()
+                    .log(Level.ERROR.ordinal(),
+                            new Date(),
+                            "[" + e.getClass().getSimpleName() + "]"
+                                    + e.code().toString() + "-"
+                                    + e.message());
+                    return;
+               }catch (SimulatorException e) {
                     Activator
                             .getDefault()
                             .getLogManager()
@@ -1522,6 +1533,16 @@ 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()
index 0b41841..3b62939 100644 (file)
@@ -515,7 +515,7 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_get
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativeGet
 (JNIEnv *env, jobject thiz, jstring jResourceInterface,
  jobject jQueryParamsMap, jobject jListener)
 {
@@ -585,7 +585,7 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_get
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_put
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePut
 (JNIEnv *env, jobject thiz, jstring jResourceInterface,
  jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
 {
@@ -659,7 +659,7 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_put
 }
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_post
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePost
 (JNIEnv *env, jobject thiz, jstring jResourceInterface,
  jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
 {
index 2fd681a..50befef 100644 (file)
@@ -47,17 +47,17 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
 (JNIEnv *env, jobject thiz);
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_get
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativeGet
 (JNIEnv *env, jobject thiz, jstring jResourceInterface,
  jobject jQueryParamsMap, jobject jListener);
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_put
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePut
 (JNIEnv *env, jobject thiz, jstring jResourceInterface,
  jobject jRepresentation, jobject jQueryParamsMap, jobject jListener);
 
 JNIEXPORT void JNICALL
-Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_post
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePost
 (JNIEnv *env, jobject thiz, jstring jResourceInterface,
  jobject jRepresentation, jobject jQueryParamsMap, jobject jListener);
 
index b9cadf2..50affa6 100644 (file)
@@ -603,8 +603,20 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
         throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
         return;
     }
-
-    resource->stopUpdateAutomation(automationId);
+    
+       try
+    {
+        resource->stopUpdateAutomation(automationId);
+    }
+    catch (InvalidArgsException &e)
+    {
+        throwInvalidArgsException(env, e.code(), e.what());
+    }
+    catch (...)
+    {
+        throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
+    }  
+    
     SIM_LOG(ILogger::INFO, "Automation has been forcibly stopped.")
 }
 
index d9f502c..a16ce67 100644 (file)
@@ -47,6 +47,10 @@ public class SimulatorManager {
     public static SimulatorResourceServer createResource(String configPath,
             IResourceModelChangedListener listener)
             throws InvalidArgsException, SimulatorException {
+        if (configPath.isEmpty() || null == listener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
         SimulatorResourceServer simulatorResourceServerObj;
         simulatorResourceServerObj = SimulatorManagerNativeInterface
                 .createResource(configPath, listener);
@@ -76,6 +80,10 @@ public class SimulatorManager {
     public static SimulatorResourceServer[] createResource(String configPath,
             int count, IResourceModelChangedListener listener)
             throws InvalidArgsException, SimulatorException {
+        if (configPath.isEmpty() || count < 0 || null == listener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
         SimulatorResourceServer[] simulatorResourceServers;
         simulatorResourceServers = SimulatorManagerNativeInterface
                 .createResources(configPath, count, listener);
index c35e1fd..daed3b7 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,6 +157,10 @@ public class SimulatorRemoteResource {
     public void get(Map<String, String> queryParamsMap,
             IGetListener onGetListener) throws InvalidArgsException,
             NoSupportException, SimulatorException {
+        if (null == onGetListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
         this.get(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 (resourceInterface.isEmpty() || null == onGetListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
+        this.get(resourceInterface, queryParamsMap, onGetListener);
+    }
+
+    private native void nativeGet(String resourceInterface,
             Map<String, String> queryParamsMap, IGetListener onGetListener)
             throws InvalidArgsException, NoSupportException, SimulatorException;
 
@@ -209,6 +224,10 @@ public class SimulatorRemoteResource {
     public void put(SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPutListener onPutListener)
             throws InvalidArgsException, NoSupportException, SimulatorException {
+        if (null == representation || null == onPutListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
         this.put(null, representation, queryParamsMap, onPutListener);
     }
 
@@ -236,7 +255,18 @@ 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 (resourceInterface.isEmpty() || null == representation || null == onPutListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
+        this.put(resourceInterface, representation, queryParamsMap, onPutListener);
+    }
+
+    private native void nativePut(String resourceInterface,
             SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPutListener onPutListener)
             throws InvalidArgsException, NoSupportException, SimulatorException;
@@ -266,6 +296,10 @@ public class SimulatorRemoteResource {
     public void post(SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPostListener onPostListener)
             throws InvalidArgsException, NoSupportException, SimulatorException {
+        if (null == representation || null == onPostListener)
+            throw new InvalidArgsException(
+                    SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                    "Parameter passed in invalid");
         this.post(null, representation, queryParamsMap, onPostListener);
     }
 
@@ -293,7 +327,18 @@ 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 (resourceInterface.isEmpty() || null == representation || null == onPostListener)
+            throw new InvalidArgsException(
+                SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
+                "Parameter passed in invalid");
+        this.post(resourceInterface, representation, queryParamsMap, onPostListener);
+    }
+
+    private native void nativePost(String resourceInterface,
             SimulatorResourceModel representation,
             Map<String, String> queryParamsMap, IPostListener onPostListener)
             throws InvalidArgsException, NoSupportException, SimulatorException;
index 0d9accd..a42a12f 100644 (file)
@@ -389,7 +389,7 @@ public class SimulatorResourceServer {
      *             This exception will be thrown for other errors.
      */
     public native void stopAutomation(int automationId)
-            throws SimulatorException;
+            throws InvalidArgsException, SimulatorException;
 
     /**
      * API to remove an attribute from the simulated resource.
index 417bb84..dcd7988 100644 (file)
@@ -311,6 +311,11 @@ void SimulatorResourceModel::updateAttributeFromAllowedValues(const std::string
 
 void SimulatorResourceModel::removeAttribute(const std::string &attrName)
 {
+   if (m_attributes.end() == m_attributes.find(attrName))
+   {
+       return;
+   }
+
     m_attributes.erase(attrName);
     return;
 }
index 1567f4f..c5ec75e 100644 (file)
@@ -105,12 +105,17 @@ void UpdateAutomationMngr::stop(int id)
     {
         m_resourceUpdationList[id]->stop();
         m_resourceUpdationList.erase(m_resourceUpdationList.find(id));
+        return;
     }
     else if (m_attrUpdationList.end() != m_attrUpdationList.find(id))
     {
         m_attrUpdationList[id]->stop();
         m_attrUpdationList.erase(m_attrUpdationList.find(id));
+        return;
     }
+
+    //Throw InvalidArgsException
+    throw InvalidArgsException(SIMULATOR_INVALID_PARAM, "Invalid Automation Id!");
 }
 
 void UpdateAutomationMngr::stopAll()