Implementation of SimulatorRequestModel class.
authorHarish Kumara Marappa <h.marappa@samsung.com>
Thu, 18 Feb 2016 15:08:32 +0000 (20:38 +0530)
committerMadan Lanka <lanka.madan@samsung.com>
Fri, 19 Feb 2016 01:59:21 +0000 (01:59 +0000)
1. Adding SimulatorRequestModel class.
2. Updated JUnit test cases as per new SimulatorResourceModel.

Change-Id: I145dd2053cf6939c1ccf0148900983e005d7ec79
Signed-off-by: Harish Kumara Marappa <h.marappa@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/4989
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Madan Lanka <lanka.madan@samsung.com>
14 files changed:
service/simulator/java/sdk/src/org/oic/simulator/SimulatorManager.java
service/simulator/java/sdk/src/org/oic/simulator/SimulatorResourceModel.java
service/simulator/java/sdk/src/org/oic/simulator/client/FindResourceListener.java
service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorRemoteResource.java
service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorRequestModel.java [new file with mode: 0644]
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorCollectionResource.java
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorResource.java
service/simulator/java/sdk/src/org/oic/simulator/server/SimulatorSingleResource.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/client/test/SimulatorRemoteResourceTest.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/server/test/SimulatorResourceTest.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/server/test/SimulatorSingleResourceTest.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/AttributeValueTest.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java
service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorResourceModelTest.java

index 0612ebf..efe406e 100644 (file)
@@ -27,7 +27,12 @@ import org.oic.simulator.server.SimulatorResource;
  */
 public class SimulatorManager {
 
-    private SimulatorManager() {
+    static {
+        System.loadLibrary("oc_logger");
+        System.loadLibrary("octbstack");
+        System.loadLibrary("oc");
+        System.loadLibrary("RamlParser");
+        System.loadLibrary("SimulatorManager");
     }
 
     /**
@@ -44,8 +49,10 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static native SimulatorResource createResource(String configPath)
-            throws InvalidArgsException, SimulatorException;
+    public static SimulatorResource createResource(String configPath)
+            throws InvalidArgsException, SimulatorException {
+        return nativeCreateResource(configPath);
+    }
 
     /**
      * API for creating a set of resources from a RAML configuration file.
@@ -65,7 +72,7 @@ public class SimulatorManager {
      */
     public static Vector<SimulatorResource> createResource(String configPath,
             int count) throws InvalidArgsException, SimulatorException {
-        return createResources(configPath, count);
+        return nativeCreateResources(configPath, count);
     };
 
     /**
@@ -93,9 +100,9 @@ public class SimulatorManager {
             throws InvalidArgsException, SimulatorException {
         SimulatorResource resource = null;
         if (type == SimulatorResource.Type.SINGLE)
-            resource = createSingleResource(name, uri, resourceType);
+            resource = nativeCreateSingleResource(name, uri, resourceType);
         else
-            resource = createCollectionResource(name, uri, resourceType);
+            resource = nativeCreateCollectionResource(name, uri, resourceType);
         return resource;
     }
 
@@ -113,7 +120,7 @@ public class SimulatorManager {
      */
     public static void findResource(FindResourceListener listener)
             throws InvalidArgsException, SimulatorException {
-        searchResource(null, listener);
+        nativeSearchResource(null, listener);
     }
 
     /**
@@ -139,7 +146,7 @@ public class SimulatorManager {
                     "Invalid resource type!");
         }
 
-        searchResource(resourceType, listener);
+        nativeSearchResource(resourceType, listener);
     }
 
     /**
@@ -153,8 +160,10 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static native void setDeviceInfo(String deviceInfo)
-            throws InvalidArgsException, SimulatorException;
+    public static void setDeviceInfo(String deviceInfo)
+            throws InvalidArgsException, SimulatorException {
+        nativeSetDeviceInfo(deviceInfo);
+    }
 
     /**
      * API to search for devices on the given host in the network.
@@ -169,9 +178,10 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static native void findDevices(String hostUri,
-            DeviceListener listener) throws InvalidArgsException,
-            SimulatorException;
+    public static void findDevices(String hostUri, DeviceListener listener)
+            throws InvalidArgsException, SimulatorException {
+        nativeFindDevices(hostUri, listener);
+    }
 
     /**
      * API to set the platform information.
@@ -184,8 +194,10 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static native void setPlatformInfo(PlatformInfo platformInfo)
-            throws InvalidArgsException, SimulatorException;
+    public static void setPlatformInfo(PlatformInfo platformInfo)
+            throws InvalidArgsException, SimulatorException {
+        nativeSetPlatformInfo(platformInfo);
+    }
 
     /**
      * API to find the platform information of the given host in the network.
@@ -200,9 +212,11 @@ public class SimulatorManager {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public static native void getPlatformInformation(String hostUri,
+    public static void getPlatformInformation(String hostUri,
             PlatformListener listener) throws InvalidArgsException,
-            SimulatorException;
+            SimulatorException {
+        nativeGetPlatformInformation(hostUri, listener);
+    }
 
     /**
      * API to set the listener for receiving log messages.
@@ -210,17 +224,37 @@ public class SimulatorManager {
      * @param logger
      *            {@link ILogger} to receive the log messages.
      */
-    public static native void setLogger(ILogger logger);
+    public static void setLogger(ILogger logger) {
+        nativeSetLogger(logger);
+    }
+
+    private SimulatorManager() {
+    }
+
+    private static native SimulatorResource nativeCreateResource(
+            String configPath);
 
-    private static native Vector<SimulatorResource> createResources(
+    private static native Vector<SimulatorResource> nativeCreateResources(
             String configPath, int count);
 
-    private static native SimulatorResource createSingleResource(String name,
-            String uri, String resourceType);
+    private static native SimulatorResource nativeCreateSingleResource(
+            String name, String uri, String resourceType);
 
-    private static native SimulatorResource createCollectionResource(
+    private static native SimulatorResource nativeCreateCollectionResource(
             String name, String uri, String resourceType);
 
-    private static native void searchResource(String resourceType,
+    private static native void nativeSearchResource(String resourceType,
             FindResourceListener listener);
+
+    private static native void nativeSetDeviceInfo(String deviceInfo);
+
+    private static native void nativeFindDevices(String hostUri,
+            DeviceListener listener);
+
+    private static native void nativeSetPlatformInfo(PlatformInfo platformInfo);
+
+    private static native void nativeGetPlatformInformation(String hostUri,
+            PlatformListener listener);
+
+    private static native void nativeSetLogger(ILogger logger);
 }
\ No newline at end of file
index 6ea68a9..1f1b959 100644 (file)
@@ -143,10 +143,6 @@ public class SimulatorResourceModel {
         return mValues.size();
     }
 
-    /**
-     * These methods used by native layer.
-     */
-    @SuppressWarnings("unused")
     private SimulatorResourceModel(Map<String, AttributeValue> values) {
         mValues = values;
     }
index be935ae..1faa369 100644 (file)
@@ -16,8 +16,6 @@
 
 package org.oic.simulator.client;
 
-import org.oic.simulator.client.SimulatorRemoteResource;
-
 /**
  * Listener for getting notification when resources are discovered in network.
  */
index c1e6927..12a8615 100644 (file)
@@ -41,16 +41,10 @@ public final class SimulatorRemoteResource {
     private Vector<String> mResInterfaces;
     private boolean        mIsObservable;
 
-    private native void dispose();
-
-    private SimulatorRemoteResource(long nativeHandle) {
-        mNativeHandle = nativeHandle;
-    }
-
     @Override
     protected void finalize() throws Throwable {
         try {
-            dispose();
+            nativeDispose();
         } catch (Throwable t) {
             throw t;
         } finally {
@@ -62,8 +56,8 @@ public final class SimulatorRemoteResource {
      * Enum to represent the verification types which can be used by the client
      * to verify the resource model of the remote resource.
      */
-    public enum VerificationType {
-        GET, PUT, POST, DELETE;
+    public enum RequestType {
+        UKNOWN, GET, PUT, POST, DELETE;
     }
 
     /**
@@ -314,7 +308,7 @@ public final class SimulatorRemoteResource {
      */
     public void observe(ObserveNotificationListener onObserveListener)
             throws InvalidArgsException, SimulatorException {
-        startObserve(null, onObserveListener);
+        nativeStartObserve(null, onObserveListener);
     }
 
     /**
@@ -342,7 +336,7 @@ public final class SimulatorRemoteResource {
             throw new InvalidArgsException(
                     SimulatorResult.SIMULATOR_INVALID_PARAM,
                     "Invalid Query Parameters!");
-        startObserve(queryParams, onObserveListener);
+        nativeStartObserve(queryParams, onObserveListener);
     }
 
     /**
@@ -354,8 +348,9 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void stopObserve() throws InvalidArgsException,
-            SimulatorException;
+    public void stopObserve() throws InvalidArgsException, SimulatorException {
+        nativeStopObserve();
+    }
 
     /**
      * API to provide remote resource configure information, which is required
@@ -372,8 +367,10 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public native SimulatorResourceModel setConfigInfo(String path)
-            throws InvalidArgsException, SimulatorException;
+    public Map<RequestType, SimulatorRequestModel> setConfigInfo(String path)
+            throws InvalidArgsException, SimulatorException {
+        return nativeSetConfigInfo(path);
+    }
 
     /**
      * API to send multiple requests for the resource, based on the configure
@@ -400,11 +397,11 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public int startVerification(VerificationType type,
+    public int startVerification(RequestType type,
             VerificationListener onVerifyListener) throws InvalidArgsException,
             NoSupportException, OperationInProgressException,
             SimulatorException {
-        return startVerification(type.ordinal(), onVerifyListener);
+        return nativeStartAutoRequesting(type, onVerifyListener);
     }
 
     /**
@@ -419,8 +416,10 @@ public final class SimulatorRemoteResource {
      * @throws SimulatorException
      *             Thrown for other errors.
      */
-    public native void stopVerification(int id) throws InvalidArgsException,
-            SimulatorException;
+    public void stopVerification(int id) throws InvalidArgsException,
+            SimulatorException {
+        nativeStopAutoRequesting(id);
+    }
 
     /**
      * Listener for receiving asynchronous response for GET request.
@@ -532,6 +531,10 @@ public final class SimulatorRemoteResource {
         public void onVerificationCompleted(String uid, int id);
     }
 
+    private SimulatorRemoteResource(long nativeHandle) {
+        mNativeHandle = nativeHandle;
+    }
+
     private native void nativeGet(String resourceInterface,
             Map<String, String> queryParamsMap,
             GetResponseListener onGetListener);
@@ -546,9 +549,18 @@ public final class SimulatorRemoteResource {
             SimulatorResourceModel representation,
             PostResponseListener onPostListener);
 
-    private native void startObserve(Map<String, String> queryParams,
+    private native void nativeStartObserve(Map<String, String> queryParams,
             ObserveNotificationListener onObserveListener);
 
-    private native int startVerification(int type,
+    private native void nativeStopObserve();
+
+    private native Map<RequestType, SimulatorRequestModel> nativeSetConfigInfo(
+            String path);
+
+    private native int nativeStartAutoRequesting(RequestType type,
             VerificationListener onVerifyListener);
+
+    private native void nativeStopAutoRequesting(int id);
+
+    private native void nativeDispose();
 }
diff --git a/service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorRequestModel.java b/service/simulator/java/sdk/src/org/oic/simulator/client/SimulatorRequestModel.java
new file mode 100644 (file)
index 0000000..e56d8c9
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2016 Samsung Electronics All Rights Reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.oic.simulator.client;
+
+import java.util.Map;
+import java.util.Vector;
+
+import org.oic.simulator.ModelProperty;
+import org.oic.simulator.client.SimulatorRemoteResource.RequestType;
+
+public class SimulatorRequestModel {
+    private RequestType                 mType         = RequestType.UKNOWN;
+    private Map<String, Vector<String>> mQueryParams  = null;
+    private ModelProperty               mReqBodyModel = null;
+
+    public SimulatorRequestModel(RequestType type) {
+        mType = type;
+    }
+
+    public SimulatorRequestModel(RequestType type,
+            Map<String, Vector<String>> queryParams) {
+        mType = type;
+        mQueryParams = queryParams;
+    }
+
+    public SimulatorRequestModel(RequestType type,
+            Map<String, Vector<String>> queryParams, ModelProperty reqBodyModel) {
+        mType = type;
+        mQueryParams = queryParams;
+        mReqBodyModel = reqBodyModel;
+    }
+
+    public RequestType getType() {
+        return mType;
+    }
+
+    public Map<String, Vector<String>> getQueryParams() {
+        return mQueryParams;
+    }
+
+    public ModelProperty getRequestBodyModel() {
+        return mReqBodyModel;
+    }
+}
index 6abfc41..65ff45c 100644 (file)
@@ -28,10 +28,6 @@ import org.oic.simulator.SimulatorException;
  */
 public final class SimulatorCollectionResource extends SimulatorResource {
 
-    private SimulatorCollectionResource(long nativeHandle) {
-        mNativeHandle = nativeHandle;
-    }
-
     /**
      * API to add child resource to collection.
      *
@@ -44,8 +40,10 @@ public final class SimulatorCollectionResource extends SimulatorResource {
      *             This exception will be thrown on occurrence of error in
      *             native.
      */
-    public native void addChildResource(SimulatorResource resource)
-            throws InvalidArgsException, SimulatorException;
+    public void addChildResource(SimulatorResource resource)
+            throws InvalidArgsException, SimulatorException {
+        nativeAddChildResource(resource);
+    }
 
     /**
      * API to remove child resource from collection.
@@ -59,8 +57,10 @@ public final class SimulatorCollectionResource extends SimulatorResource {
      *             This exception will be thrown on occurrence of error in
      *             native.
      */
-    public native void removeChildResource(SimulatorResource resource)
-            throws InvalidArgsException, SimulatorException;
+    public void removeChildResource(SimulatorResource resource)
+            throws InvalidArgsException, SimulatorException {
+        nativeRemoveChildResource(resource);
+    }
 
     /**
      * API to remove child resource from collection.
@@ -74,8 +74,10 @@ public final class SimulatorCollectionResource extends SimulatorResource {
      *             This exception will be thrown on occurrence of error in
      *             native.
      */
-    public native void removeChildResourceByUri(String uri)
-            throws InvalidArgsException, SimulatorException;
+    public void removeChildResourceByUri(String uri)
+            throws InvalidArgsException, SimulatorException {
+        nativeRemoveChildResourceByUri(uri);
+    }
 
     /**
      * API to get list of child resources.
@@ -86,6 +88,20 @@ public final class SimulatorCollectionResource extends SimulatorResource {
      *             This exception will be thrown on occurrence of error in
      *             native.
      */
-    public native Vector<SimulatorResource> getChildResource()
-            throws SimulatorException;
+    public Vector<SimulatorResource> getChildResources()
+            throws SimulatorException {
+        return nativeGetChildResources();
+    }
+
+    private SimulatorCollectionResource(long nativeHandle) {
+        mNativeHandle = nativeHandle;
+    }
+
+    private native void nativeAddChildResource(SimulatorResource resource);
+
+    private native void nativeRemoveChildResource(SimulatorResource resource);
+
+    private native void nativeRemoveChildResourceByUri(String uri);
+
+    private native Vector<SimulatorResource> nativeGetChildResources();
 }
index 3a39ac1..3a90584 100644 (file)
@@ -32,17 +32,12 @@ import org.oic.simulator.SimulatorResourceModel;
  */
 public class SimulatorResource {
 
-    private native void dispose();
-
     protected long mNativeHandle;
 
-    protected SimulatorResource() {
-    }
-
     @Override
     protected void finalize() throws Throwable {
         try {
-            dispose();
+            nativeDispose();
         } catch (Throwable t) {
             throw t;
         } finally {
@@ -105,7 +100,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native String getName() throws SimulatorException;
+    public String getName() throws SimulatorException {
+        return nativeGetName();
+    }
 
     /**
      * API to get the resource URI.
@@ -116,7 +113,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native String getURI() throws SimulatorException;
+    public String getURI() throws SimulatorException {
+        return nativeGetURI();
+    }
 
     /**
      * API to get the resource type.
@@ -127,7 +126,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native String getResourceType() throws SimulatorException;
+    public String getResourceType() throws SimulatorException {
+        return nativeGetResourceType();
+    }
 
     /**
      * API to get the interfaces resource is bound with.
@@ -138,7 +139,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native Vector<String> getInterface() throws SimulatorException;
+    public Vector<String> getInterface() throws SimulatorException {
+        return nativeGetInterface();
+    }
 
     /**
      * API to get the observable state of resource.
@@ -150,7 +153,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native boolean isObservable() throws SimulatorException;
+    public boolean isObservable() throws SimulatorException {
+        return nativeIsObservable();
+    }
 
     /**
      * API to get the discoverable state of resource.
@@ -162,7 +167,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native boolean isDiscoverable() throws SimulatorException;
+    public boolean isDiscoverable() throws SimulatorException {
+        return nativeIsDiscoverable();
+    }
 
     /**
      * API to get the start state of resource.
@@ -173,7 +180,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native boolean isStarted() throws SimulatorException;
+    public boolean isStarted() throws SimulatorException {
+        return nativeIsStarted();
+    }
 
     /**
      * API to set the name of the resource.
@@ -188,8 +197,10 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void setName(String name) throws InvalidArgsException,
-            SimulatorException;
+    public void setName(String name) throws InvalidArgsException,
+            SimulatorException {
+        nativeSetName(name);
+    }
 
     /**
      * API to set the resource URI.
@@ -204,8 +215,10 @@ public class SimulatorResource {
      *             calling this API. This exception will be thrown if the native
      *             resource object has not yet been stopped.
      */
-    public native void setURI(String uri) throws InvalidArgsException,
-            SimulatorException;
+    public void setURI(String uri) throws InvalidArgsException,
+            SimulatorException {
+        nativeSetURI(uri);
+    }
 
     /**
      * API to set the resource type.
@@ -220,8 +233,10 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void setResourceType(String resourceType)
-            throws InvalidArgsException, SimulatorException;
+    public void setResourceType(String resourceType)
+            throws InvalidArgsException, SimulatorException {
+        nativeSetResourceType(resourceType);
+    }
 
     /**
      * API to set interface to resource. Resource should be stopped before
@@ -238,8 +253,10 @@ public class SimulatorResource {
      *             does not exist or resource is still running or for some
      *             general errors.
      */
-    public native void setInterface(String interfaceType)
-            throws InvalidArgsException, SimulatorException;
+    public void setInterface(String interfaceType) throws InvalidArgsException,
+            SimulatorException {
+        nativeSetInterface(interfaceType);
+    }
 
     /**
      * API to set a list of interfaces to resource. Resource should be stopped
@@ -258,12 +275,9 @@ public class SimulatorResource {
      */
     public void setInterface(Vector<String> interfaceTypes)
             throws InvalidArgsException, SimulatorException {
-        setInterfaces(interfaceTypes);
+        nativeSetInterfaces(interfaceTypes);
     }
 
-    private native void setInterfaces(Vector<String> interfaceTypes)
-            throws InvalidArgsException, SimulatorException;
-
     /**
      * API to add interface type for resource.
      *
@@ -277,8 +291,10 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void addInterface(String interfaceType)
-            throws InvalidArgsException, NoSupportException, SimulatorException;
+    public void addInterface(String interfaceType) throws InvalidArgsException,
+            NoSupportException, SimulatorException {
+        nativeAddInterface(interfaceType);
+    }
 
     /**
      * API to make the resource observable or not observable.
@@ -290,7 +306,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void setObservable(boolean state) throws SimulatorException;
+    public void setObservable(boolean state) throws SimulatorException {
+        nativeSetObservable(state);
+    }
 
     /**
      * API to make the resource discoverable or not discoverable.
@@ -303,7 +321,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void setDiscoverable(boolean state) throws SimulatorException;
+    public void setDiscoverable(boolean state) throws SimulatorException {
+        nativeSetDiscoverable(state);
+    }
 
     /**
      * API to set the listener for receiving the notifications when observer is
@@ -318,8 +338,10 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void setObserverListener(ObserverListener listener)
-            throws InvalidArgsException, SimulatorException;
+    public void setObserverListener(ObserverListener listener)
+            throws InvalidArgsException, SimulatorException {
+        nativeSetObserverListener(listener);
+    }
 
     /**
      * API to set listener for receiving notifications when resource's model
@@ -333,9 +355,11 @@ public class SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native void setResourceModelChangeListener(
+    public void setResourceModelChangeListener(
             ResourceModelChangeListener listener) throws InvalidArgsException,
-            SimulatorException;
+            SimulatorException {
+        nativeSetResourceModelChangeListener(listener);
+    }
 
     /**
      * API to start(register) the resource.
@@ -344,7 +368,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void start() throws SimulatorException;
+    public void start() throws SimulatorException {
+        nativeStart();
+    }
 
     /**
      * API to stop(unregister) the resource.
@@ -353,7 +379,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void stop() throws SimulatorException;
+    public void stop() throws SimulatorException {
+        nativeStop();
+    }
 
     /**
      * API to get the {@link SimulatorResourceModel} of the simulated resource.
@@ -364,8 +392,9 @@ public class SimulatorResource {
      *             This exception will be thrown if simulated resource is not
      *             proper.
      */
-    public native SimulatorResourceModel getResourceModel()
-            throws SimulatorException;
+    public SimulatorResourceModel getResourceModel() throws SimulatorException {
+        return nativeGetResourceModel();
+    }
 
     /**
      * API to get observers which are registered with resource.
@@ -376,7 +405,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native Vector<Observer> getObservers() throws SimulatorException;
+    public Vector<Observer> getObservers() throws SimulatorException {
+        return nativeGetObservers();
+    }
 
     /**
      * API to notify current resource model to a specific observer.
@@ -388,7 +419,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void notifyObserver(int observerId) throws SimulatorException;
+    public void notifyObserver(int observerId) throws SimulatorException {
+        nativeNotify(observerId);
+    }
 
     /**
      * API to notify current resource model to all registered observers.
@@ -397,7 +430,9 @@ public class SimulatorResource {
      *             This exception will be thrown if the native resource object
      *             does not exist or for some general errors.
      */
-    public native void notifyAllObservers() throws SimulatorException;
+    public void notifyAllObservers() throws SimulatorException {
+        nativeNotifyAll();
+    }
 
     /**
      * Listener for receiving notification when observer is registered or
@@ -461,4 +496,56 @@ public class SimulatorResource {
         public void onResourceModelChanged(String uri,
                 SimulatorResourceModel resourceModel);
     }
+
+    protected SimulatorResource() {
+    }
+
+    private native String nativeGetName();
+
+    private native String nativeGetURI();
+
+    private native String nativeGetResourceType();
+
+    private native Vector<String> nativeGetInterface();
+
+    private native boolean nativeIsObservable();
+
+    private native boolean nativeIsDiscoverable();
+
+    private native boolean nativeIsStarted();
+
+    private native void nativeSetName(String name);
+
+    private native void nativeSetURI(String uri);
+
+    private native void nativeSetResourceType(String resourceType);
+
+    private native void nativeSetInterface(String interfaceType);
+
+    private native void nativeSetInterfaces(Vector<String> interfaceTypes);
+
+    private native void nativeAddInterface(String interfaceType);
+
+    private native void nativeSetObservable(boolean state);
+
+    private native void nativeSetDiscoverable(boolean state);
+
+    private native void nativeSetObserverListener(ObserverListener listener);
+
+    private native void nativeSetResourceModelChangeListener(
+            ResourceModelChangeListener listener);
+
+    private native void nativeStart();
+
+    private native void nativeStop();
+
+    private native SimulatorResourceModel nativeGetResourceModel();
+
+    private native Vector<Observer> nativeGetObservers();
+
+    private native void nativeNotify(int observerId);
+
+    private native void nativeNotifyAll();
+
+    private native void nativeDispose();
 }
index e0e7b32..bfc8a55 100644 (file)
@@ -31,10 +31,6 @@ import org.oic.simulator.SimulatorResourceAttribute;
  */
 public final class SimulatorSingleResource extends SimulatorResource {
 
-    private SimulatorSingleResource(long nativeHandle) {
-        mNativeHandle = nativeHandle;
-    }
-
     /**
      * API to get attribute of resource.
      *
@@ -51,8 +47,10 @@ public final class SimulatorSingleResource extends SimulatorResource {
      *             This exception will be thrown either if the resource model is
      *             not found or for some general errors.
      */
-    public native SimulatorResourceAttribute getAttribute(String attrName)
-            throws InvalidArgsException, SimulatorException;
+    public SimulatorResourceAttribute getAttribute(String attrName)
+            throws InvalidArgsException, SimulatorException {
+        return nativeGetAttribute(attrName);
+    }
 
     /**
      * API to get all the attributes of the resource.
@@ -67,8 +65,10 @@ public final class SimulatorSingleResource extends SimulatorResource {
      *             This exception will be thrown either if the resource model is
      *             not found or for some general errors.
      */
-    public native Map<String, SimulatorResourceAttribute> getAttributes()
-            throws InvalidArgsException, SimulatorException;
+    public Map<String, SimulatorResourceAttribute> getAttributes()
+            throws InvalidArgsException, SimulatorException {
+        return nativeGetAttributes();
+    }
 
     /**
      * API to add an attribute to resource's representation model. Observers
@@ -82,8 +82,10 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native boolean addAttribute(SimulatorResourceAttribute attribute)
-            throws InvalidArgsException, SimulatorException;
+    public boolean addAttribute(SimulatorResourceAttribute attribute)
+            throws InvalidArgsException, SimulatorException {
+        return nativeAddAttribute(attribute);
+    }
 
     /**
      * API to remove an attribute from the simulated resource. Observers will be
@@ -97,8 +99,10 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native boolean removeAttribute(String attrName)
-            throws InvalidArgsException, SimulatorException;
+    public boolean removeAttribute(String attrName)
+            throws InvalidArgsException, SimulatorException {
+        return nativeRemoveAttribute(attrName);
+    }
 
     /**
      * API to update the value of an attribute. Observers will be notified on
@@ -114,8 +118,10 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native boolean updateAttribute(String attrName, AttributeValue value)
-            throws InvalidArgsException, SimulatorException;
+    public boolean updateAttribute(String attrName, AttributeValue value)
+            throws InvalidArgsException, SimulatorException {
+        return nativeUpdateAttribute(attrName, value);
+    }
 
     /**
      * API to start the resource level automation. This automation involves
@@ -137,9 +143,11 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native int startResourceUpdation(AutoUpdateType type, int interval,
+    public int startResourceUpdation(AutoUpdateType type, int interval,
             AutoUpdateListener listener) throws InvalidArgsException,
-            SimulatorException;
+            SimulatorException {
+        return nativeStartResourceUpdation(type, interval, listener);
+    }
 
     /**
      * API to start the attribute level automation. This automation involves
@@ -163,9 +171,11 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for other errors.
      */
-    public native int startAttributeUpdation(String attrName,
-            AutoUpdateType type, int interval, AutoUpdateListener listener)
-            throws InvalidArgsException, SimulatorException;
+    public int startAttributeUpdation(String attrName, AutoUpdateType type,
+            int interval, AutoUpdateListener listener)
+            throws InvalidArgsException, SimulatorException {
+        return nativeStartAttributeUpdation(attrName, type, interval, listener);
+    }
 
     /**
      * API to stop the automation based on automation id.
@@ -176,5 +186,31 @@ public final class SimulatorSingleResource extends SimulatorResource {
      * @throws SimulatorException
      *             This exception will be thrown for general errors.
      */
-    public native void stopUpdation(int id) throws SimulatorException;
+    public void stopUpdation(int id) throws SimulatorException {
+        nativeStopUpdation(id);
+    }
+
+    private SimulatorSingleResource(long nativeHandle) {
+        mNativeHandle = nativeHandle;
+    }
+
+    private native SimulatorResourceAttribute nativeGetAttribute(String attrName);
+
+    private native Map<String, SimulatorResourceAttribute> nativeGetAttributes();
+
+    private native boolean nativeAddAttribute(
+            SimulatorResourceAttribute attribute);
+
+    private native boolean nativeRemoveAttribute(String attrName);
+
+    private native boolean nativeUpdateAttribute(String attrName,
+            AttributeValue value);
+
+    private native int nativeStartResourceUpdation(AutoUpdateType type,
+            int interval, AutoUpdateListener listener);
+
+    private native int nativeStartAttributeUpdation(String attrName,
+            AutoUpdateType type, int interval, AutoUpdateListener listener);
+
+    private native void nativeStopUpdation(int id);
 }
index 0687158..392e010 100644 (file)
@@ -44,14 +44,6 @@ public class SimulatorRemoteResourceTest extends TestCase {
     private static SimulatorSingleResource singleResource  = null;
     private static SimulatorRemoteResource remoteResource  = null;
 
-    static {
-        System.loadLibrary("SimulatorManager");
-        System.loadLibrary("RamlParser");
-        System.loadLibrary("oc");
-        System.loadLibrary("oc_logger");
-        System.loadLibrary("octbstack");
-    }
-
     protected void setUp() throws Exception {
         super.setUp();
 
@@ -428,7 +420,6 @@ public class SimulatorRemoteResourceTest extends TestCase {
                 lockObject, response);
 
         try {
-            SimulatorResourceModel resModel = singleResource.getResourceModel();
             Map<String, String> queryParams = new HashMap<>();
             remoteResource.put(queryParams, null, listener);
 
@@ -632,7 +623,6 @@ public class SimulatorRemoteResourceTest extends TestCase {
                 lockObject, response);
 
         try {
-            SimulatorResourceModel resModel = singleResource.getResourceModel();
             Map<String, String> queryParams = new HashMap<>();
             remoteResource.post(queryParams, null, listener);
 
@@ -717,7 +707,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
 
         try {
             Map<String, String> queryParams = new HashMap<>();
-            remoteResource.startObserve(queryParams, listener);
+            remoteResource.observe(queryParams, listener);
             singleResource.addAttribute(new SimulatorResourceAttribute(
                     "boolean", new AttributeValue(true), null));
             singleResource.removeAttribute("boolean");
@@ -749,7 +739,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
                 lockObject, response);
 
         try {
-            remoteResource.startObserve(null, listener);
+            remoteResource.observe(listener);
             singleResource.addAttribute(new SimulatorResourceAttribute(
                     "boolean", new AttributeValue(true), null));
             singleResource.removeAttribute("boolean");
@@ -778,7 +768,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
 
         try {
             Map<String, String> queryParams = new HashMap<>();
-            remoteResource.startObserve(queryParams, null);
+            remoteResource.observe(queryParams, null);
 
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
@@ -798,7 +788,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
 
         try {
             Map<String, String> queryParams = new HashMap<>();
-            remoteResource.startObserve(queryParams, listener);
+            remoteResource.observe(queryParams, listener);
 
             try {
                 lockObject.await(10, TimeUnit.SECONDS);
@@ -879,7 +869,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
         try {
             remoteResource.setConfigInfo(SINGLE_RES_RAML);
             remoteResource.startVerification(
-                    SimulatorRemoteResource.VerificationType.GET, listener);
+                    SimulatorRemoteResource.RequestType.GET, listener);
 
             try {
                 lockObject.await(10, TimeUnit.SECONDS);
@@ -908,7 +898,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
         try {
             remoteResource.setConfigInfo(SINGLE_RES_RAML);
             remoteResource.startVerification(
-                    SimulatorRemoteResource.VerificationType.PUT, listener);
+                    SimulatorRemoteResource.RequestType.PUT, listener);
 
             try {
                 lockObject.await(10, TimeUnit.SECONDS);
@@ -937,7 +927,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
         try {
             remoteResource.setConfigInfo(SINGLE_RES_RAML);
             remoteResource.startVerification(
-                    SimulatorRemoteResource.VerificationType.POST, listener);
+                    SimulatorRemoteResource.RequestType.POST, listener);
 
             try {
                 lockObject.await(10, TimeUnit.SECONDS);
@@ -962,7 +952,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
         try {
             remoteResource.setConfigInfo(SINGLE_RES_RAML);
             remoteResource.startVerification(
-                    SimulatorRemoteResource.VerificationType.GET, null);
+                    SimulatorRemoteResource.RequestType.GET, null);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -982,7 +972,7 @@ public class SimulatorRemoteResourceTest extends TestCase {
         try {
             remoteResource.setConfigInfo(SINGLE_RES_RAML);
             int id = remoteResource.startVerification(
-                    SimulatorRemoteResource.VerificationType.POST, listener);
+                    SimulatorRemoteResource.RequestType.POST, listener);
             remoteResource.stopVerification(id);
             syncResult = true;
         } catch (InvalidArgsException e) {
index 33cde70..4508d2f 100644 (file)
@@ -21,11 +21,14 @@ import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
 import org.oic.simulator.InvalidArgsException;
+import org.oic.simulator.NoSupportException;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorManager;
+import org.oic.simulator.SimulatorResourceModel;
 import org.oic.simulator.client.FindResourceListener;
 import org.oic.simulator.client.SimulatorRemoteResource;
 import org.oic.simulator.server.SimulatorResource;
+import org.oic.simulator.server.SimulatorSingleResource;
 import org.oic.simulator.test.ExceptionType;
 import org.oic.simulator.utils.ObjectHolder;
 
@@ -40,14 +43,6 @@ public class SimulatorResourceTest extends TestCase {
     private static final String RES_TYPE = "test.resource";
     private SimulatorResource   resource = null;
 
-    static {
-        System.loadLibrary("SimulatorManager");
-        System.loadLibrary("RamlParser");
-        System.loadLibrary("oc");
-        System.loadLibrary("oc_logger");
-        System.loadLibrary("octbstack");
-    }
-
     protected void setUp() throws Exception {
         super.setUp();
         resource = SimulatorManager.createResource(
@@ -59,27 +54,42 @@ public class SimulatorResourceTest extends TestCase {
         resource = null;
     }
 
-    public void testGetName_P01() {
-        String name = null;
+    public void testIsCollection_P01() {
+        boolean isCollection = false;
+        isCollection = resource.isCollection();
+        assertFalse(isCollection);
+    }
+
+    public void testIsCollection_P02() {
+        boolean isCollection = true;
 
         try {
-            name = resource.getName();
+            SimulatorResource res = SimulatorManager.createResource(
+                    SimulatorResource.Type.COLLECTION, RES_NAME, RES_URI,
+                    RES_TYPE);
+            isCollection = res.isCollection();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals(RES_NAME, name);
+        assertTrue(isCollection);
     }
 
-    public void testGetType_P01() {
-        SimulatorResource.Type type = SimulatorResource.Type.SINGLE;
+    public void testGetName_P01() {
+        String name = null;
 
         try {
-            type = resource.getType();
+            name = resource.getName();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
+        assertEquals(RES_NAME, name);
+    }
+
+    public void testGetType_P01() {
+        SimulatorResource.Type type = SimulatorResource.Type.SINGLE;
+        type = resource.getType();
         assertEquals(SimulatorResource.Type.SINGLE, type);
     }
 
@@ -258,6 +268,226 @@ public class SimulatorResourceTest extends TestCase {
         assertEquals(ExceptionType.INVALID_ARGS, exType);
     }
 
+    public void testSetInterface_P01() {
+        String newInterface = "oic.if.r";
+        Vector<String> interfaces = null;
+
+        try {
+            resource.setInterface(newInterface);
+            interfaces = resource.getInterface();
+        } catch (InvalidArgsException e) {
+            e.printStackTrace();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertNotNull(interfaces);
+        assertTrue(interfaces.size() == 1
+                && interfaces.get(0).equals(newInterface));
+    }
+
+    public void testSetInterface_N01() {
+        String newInterface = "";
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            resource.setInterface(newInterface);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
+    }
+
+    public void testSetInterface_N02() {
+        String newInterface = null;
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            resource.setInterface(newInterface);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
+    }
+
+    public void testSetInterface_N03() {
+        String newInterface = "oic.if.s";
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            resource.start();
+            resource.setInterface(newInterface);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        try {
+            resource.stop();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertEquals(ExceptionType.SIMULATOR, exType);
+    }
+
+    public void testSetInterfaces_P01() {
+        String interface1 = "oic.if.s";
+        String interface2 = "oic.if.a";
+        Vector<String> interfaces = null;
+        Vector<String> newInterfaces = new Vector<String>();
+        newInterfaces.add(interface1);
+        newInterfaces.add(interface2);
+        try {
+            resource.setInterface(newInterfaces);
+            interfaces = resource.getInterface();
+        } catch (InvalidArgsException e) {
+            e.printStackTrace();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertNotNull(interfaces);
+        assertTrue(interfaces.size() == 2 && interfaces.contains(interface1)
+                && interfaces.contains(interface2));
+    }
+
+    public void testSetInterfaces_N01() {
+        Vector<String> newInterfaces = new Vector<String>();
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            resource.setInterface(newInterfaces);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
+    }
+
+    public void testSetInterfaces_N02() {
+        Vector<String> newInterfaces = null;
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            resource.setInterface(newInterfaces);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
+    }
+
+    public void testSetInterfaces_N03() {
+        String interface1 = "oic.if.s";
+        String interface2 = "oic.if.a";
+        ExceptionType exType = ExceptionType.UNKNOWN;
+        Vector<String> newInterfaces = new Vector<String>();
+        newInterfaces.add(interface1);
+        newInterfaces.add(interface2);
+
+        try {
+            resource.start();
+            resource.setInterface(newInterfaces);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        try {
+            resource.stop();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertEquals(ExceptionType.SIMULATOR, exType);
+    }
+
+    public void testAddInterface_P01() {
+        String newInterface = "oic.if.rw";
+        Vector<String> interfaces = null;
+
+        try {
+            resource.addInterface(newInterface);
+            interfaces = resource.getInterface();
+        } catch (InvalidArgsException e) {
+            e.printStackTrace();
+        } catch (NoSupportException e) {
+            e.printStackTrace();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertNotNull(interfaces);
+        assertTrue(interfaces.contains(newInterface));
+    }
+
+    public void testAddInterface_N01() {
+        String newInterface = "";
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            resource.addInterface(newInterface);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (NoSupportException e) {
+            exType = ExceptionType.NOT_SUPPORTED;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
+    }
+
+    public void testAddInterface_N02() {
+        String newInterface = null;
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            resource.addInterface(newInterface);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (NoSupportException e) {
+            exType = ExceptionType.NOT_SUPPORTED;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
+    }
+
+    public void testAddInterface_N03() {
+        String newInterface = "oic.if.a";
+        ExceptionType exType = ExceptionType.UNKNOWN;
+
+        try {
+            SimulatorResource res = SimulatorManager.createResource(
+                    SimulatorResource.Type.COLLECTION, RES_NAME, RES_URI,
+                    RES_TYPE);
+            res.addInterface(newInterface);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
+        } catch (NoSupportException e) {
+            exType = ExceptionType.NOT_SUPPORTED;
+        } catch (SimulatorException e) {
+            exType = ExceptionType.SIMULATOR;
+        }
+
+        assertEquals(ExceptionType.NOT_SUPPORTED, exType);
+    }
+
     public void testSetObservable_P01() {
         boolean newState = true;
         boolean state = false;
@@ -284,6 +514,32 @@ public class SimulatorResourceTest extends TestCase {
         assertEquals(newState, state);
     }
 
+    public void testSetDiscoverable_P01() {
+        boolean newState = true;
+        boolean state = false;
+        try {
+            resource.setDiscoverable(newState);
+            state = resource.isDiscoverable();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertEquals(newState, state);
+    }
+
+    public void testSetDiscoverable_P02() {
+        boolean newState = false;
+        boolean state = true;
+        try {
+            resource.setDiscoverable(newState);
+            state = resource.isDiscoverable();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertEquals(newState, state);
+    }
+
     public void testIsObservable_P01() {
         boolean state = false;
 
@@ -296,6 +552,33 @@ public class SimulatorResourceTest extends TestCase {
         assertEquals(true, state);
     }
 
+    public void testIsDiscoverable_P01() {
+        boolean state = false;
+
+        try {
+            state = resource.isDiscoverable();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertEquals(true, state);
+    }
+
+    public void testGetResourceModel_P01() {
+        SimulatorResourceModel resModel = null;
+        String singleResourceRaml = "./ramls/oic.r.light.raml";
+        try {
+            SimulatorSingleResource resource = (SimulatorSingleResource) SimulatorManager
+                    .createResource(singleResourceRaml);
+            resModel = resource.getResourceModel();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        assertNotNull(resModel);
+        assertTrue(resModel.size() > 0);
+    }
+
     public void testIsStarted_P01() {
         boolean state = true;
 
index b6bcc94..842fb72 100644 (file)
 
 package org.oic.simulator.server.test;
 
+import java.util.Map;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-import org.oic.simulator.AttributeProperty;
 import org.oic.simulator.AttributeValue;
+import org.oic.simulator.BooleanProperty;
+import org.oic.simulator.DoubleProperty;
+import org.oic.simulator.IntegerProperty;
 import org.oic.simulator.InvalidArgsException;
 import org.oic.simulator.SimulatorException;
 import org.oic.simulator.SimulatorManager;
 import org.oic.simulator.SimulatorResourceAttribute;
-import org.oic.simulator.SimulatorResourceModel;
+import org.oic.simulator.StringProperty;
 import org.oic.simulator.server.SimulatorResource;
 import org.oic.simulator.server.SimulatorResource.AutoUpdateListener;
 import org.oic.simulator.server.SimulatorSingleResource;
@@ -35,16 +38,8 @@ import org.oic.simulator.utils.ObjectHolder;
 import junit.framework.TestCase;
 
 public class SimulatorSingleResourceTest extends TestCase {
-    static {
-        System.loadLibrary("SimulatorManager");
-        System.loadLibrary("RamlParser");
-        System.loadLibrary("oc");
-        System.loadLibrary("oc_logger");
-        System.loadLibrary("octbstack");
-    }
-
     private static final String     SINGLE_RES_RAML = "./ramls/oic.r.light.raml";
-    private static final String     INT_KEY         = "Interger";
+    private static final String     INT_KEY         = "Integer";
     private static final String     DOUBLE_KEY      = "Double";
     private static final String     BOOL_KEY        = "Boolean";
     private static final String     STRING_KEY      = "String";
@@ -62,399 +57,303 @@ public class SimulatorSingleResourceTest extends TestCase {
         singleResource = null;
     }
 
-    SimulatorSingleResource createResourceFromRAML() {
+    public void testGetAttribute_P01() {
+        SimulatorResourceAttribute attribute = null;
+
         try {
-            return (SimulatorSingleResource) SimulatorManager
-                    .createResource(SINGLE_RES_RAML);
+            IntegerProperty property = new IntegerProperty.Builder().build();
+            SimulatorResourceAttribute intAttribute = new SimulatorResourceAttribute(
+                    INT_KEY, new AttributeValue(2), property);
+
+            assertTrue(singleResource.addAttribute(intAttribute));
+            attribute = singleResource.getAttribute(INT_KEY);
+            assertTrue(singleResource.removeAttribute(INT_KEY));
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        return null;
+        assertNotNull(attribute);
     }
 
-    public void testGetResourceModel_P01() {
-        SimulatorResourceModel resModel = null;
+    public void testGetAttribute_N01() {
+        ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            SimulatorSingleResource resource = createResourceFromRAML();
-            resModel = resource.getResourceModel();
+            singleResource.getAttribute(null);
+        } catch (InvalidArgsException e) {
+            exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
-            e.printStackTrace();
+            exType = ExceptionType.SIMULATOR;
         }
 
-        assertNotNull(resModel);
-        assertTrue(resModel.size() > 0);
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
     }
 
-    public void testAddAttributeInteger_P01() {
-        int result = -1;
+    public void testGetAttribute_N02() {
+        SimulatorResourceAttribute att = null;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    INT_KEY, new AttributeValue(2), null);
-            singleResource.addAttribute(attribute);
-            result = ((Integer) singleResource.getAttribute(INT_KEY).value()
-                    .get()).intValue();
+            att = singleResource.getAttribute("PQRS");
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals(2, result);
+        assertNull(att);
     }
 
-    public void testAddAttributeDouble_P01() {
-        double result = 0.0;
+    public void testAddAttributeInteger_P01() {
+        int result = -1;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    DOUBLE_KEY, new AttributeValue(4.0), null);
-            singleResource.addAttribute(attribute);
-            result = ((Double) singleResource.getAttribute(DOUBLE_KEY).value()
-                    .get()).doubleValue();
-        } catch (InvalidArgsException e) {
-            e.printStackTrace();
-        } catch (SimulatorException e) {
-            e.printStackTrace();
-        }
+            IntegerProperty property = new IntegerProperty.Builder().build();
+            SimulatorResourceAttribute intAttribute = new SimulatorResourceAttribute(
+                    INT_KEY, new AttributeValue(2), property);
 
-        assertEquals(4.0, result);
-    }
+            assertTrue(singleResource.addAttribute(intAttribute));
 
-    public void testAddAttributeBoolean_P01() {
-        boolean result = false;
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(INT_KEY);
+            assertNotNull(attribute);
 
-        try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    BOOL_KEY, new AttributeValue(true), null);
-            singleResource.addAttribute(attribute);
-            result = ((Boolean) singleResource.getAttribute(BOOL_KEY).value()
-                    .get()).booleanValue();
+            result = ((Integer) attribute.value().get()).intValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals(true, result);
+        assertEquals(2, result);
     }
 
-    public void testaddAttributeString_P01() {
-        String result = null;
+    public void testAddAttributeDouble_P01() {
+        double result = 0.0;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    STRING_KEY, new AttributeValue("string-value"), null);
-            singleResource.addAttribute(attribute);
-            result = (String) singleResource.getAttribute(STRING_KEY).value()
-                    .get();
-        } catch (InvalidArgsException e) {
-            e.printStackTrace();
-        } catch (SimulatorException e) {
-            e.printStackTrace();
-        }
+            DoubleProperty property = new DoubleProperty.Builder().build();
+            SimulatorResourceAttribute doubleAttribute = new SimulatorResourceAttribute(
+                    DOUBLE_KEY, new AttributeValue(4.0), property);
 
-        assertEquals("string-value", result);
-    }
+            assertTrue(singleResource.addAttribute(doubleAttribute));
 
-    public void testUpdateAttributeInteger_P01() {
-        int result = -1;
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(DOUBLE_KEY);
+            assertNotNull(attribute);
 
-        try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    INT_KEY, new AttributeValue(10), null);
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(INT_KEY, new AttributeValue(12));
-            result = ((Integer) singleResource.getAttribute(INT_KEY).value()
-                    .get()).intValue();
+            result = ((Double) attribute.value().get()).doubleValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals(12, result);
+        assertEquals(4.0, result);
     }
 
-    public void testUpdateAttributeDouble_P01() {
-        double result = 0.0;
+    public void testAddAttributeBoolean_P01() {
+        boolean result = false;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    DOUBLE_KEY, new AttributeValue(22.0), null);
-            singleResource.addAttribute(attribute);
-            singleResource
-                    .updateAttribute(DOUBLE_KEY, new AttributeValue(25.3));
-            result = ((Double) singleResource.getAttribute(DOUBLE_KEY).value()
-                    .get()).doubleValue();
-        } catch (InvalidArgsException e) {
-            e.printStackTrace();
-        } catch (SimulatorException e) {
-            e.printStackTrace();
-        }
+            BooleanProperty property = new BooleanProperty.Builder().build();
+            SimulatorResourceAttribute boolAttribute = new SimulatorResourceAttribute(
+                    BOOL_KEY, new AttributeValue(true), property);
 
-        assertEquals(25.3, result);
-    }
+            assertTrue(singleResource.addAttribute(boolAttribute));
 
-    public void testUpdateAttributeBoolean_P01() {
-        boolean result = true;
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(BOOL_KEY);
+            assertNotNull(attribute);
 
-        try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    BOOL_KEY, new AttributeValue(true), null);
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(BOOL_KEY, new AttributeValue(false));
-            result = ((Boolean) singleResource.getAttribute(BOOL_KEY).value()
-                    .get()).booleanValue();
+            result = ((Boolean) attribute.value().get()).booleanValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals(false, result);
+        assertEquals(true, result);
     }
 
-    public void testupdateAttributeString_P01() {
+    public void testAddAttributeString_P01() {
         String result = null;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    STRING_KEY, new AttributeValue("old-value"), null);
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(STRING_KEY, new AttributeValue(
-                    "new-value"));
-            result = (String) singleResource.getAttribute(STRING_KEY).value()
-                    .get();
+            StringProperty property = new StringProperty.Builder().build();
+            SimulatorResourceAttribute stringAttribute = new SimulatorResourceAttribute(
+                    STRING_KEY, new AttributeValue("string-value"), property);
+
+            assertTrue(singleResource.addAttribute(stringAttribute));
+
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(STRING_KEY);
+            assertNotNull(attribute);
+
+            result = (String) attribute.value().get();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals("new-value", result);
+        assertEquals("string-value", result);
     }
 
-    public void testSetRange_P01() {
-        int result = -1;
+    public void testRemoveAttribute_P01() {
+        SimulatorResourceAttribute result = null;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    INT_KEY, new AttributeValue(10), new AttributeProperty(1,
-                            12));
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(INT_KEY, new AttributeValue(3));
-            result = ((Integer) singleResource.getAttribute(INT_KEY).value()
-                    .get()).intValue();
+            StringProperty property = new StringProperty.Builder().build();
+            SimulatorResourceAttribute stringAttribute = new SimulatorResourceAttribute(
+                    STRING_KEY, new AttributeValue("friday"), property);
+
+            assertTrue(singleResource.addAttribute(stringAttribute));
+            assertTrue(singleResource.removeAttribute(STRING_KEY));
+
+            result = singleResource.getAttribute(STRING_KEY);
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals(3, result);
+        assertNull(result);
     }
 
-    public void testSetRange_N01() {
-        int result = -1;
+    public void testRemoveAttribute_N02() {
+        ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    INT_KEY, new AttributeValue(10), new AttributeProperty(1,
-                            12));
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(INT_KEY, new AttributeValue(13));
-            result = ((Integer) singleResource.getAttribute(INT_KEY).value()
-                    .get()).intValue();
+            StringProperty property = new StringProperty.Builder().build();
+            SimulatorResourceAttribute stringAttribute = new SimulatorResourceAttribute(
+                    STRING_KEY, new AttributeValue("friday"), property);
+
+            assertTrue(singleResource.addAttribute(stringAttribute));
+            singleResource.removeAttribute(null);
         } catch (InvalidArgsException e) {
-            e.printStackTrace();
+            exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
-            e.printStackTrace();
+            exType = ExceptionType.SIMULATOR;
         }
 
-        assertEquals(10, result);
+        assertEquals(ExceptionType.INVALID_ARGS, exType);
     }
 
-    public void testSetAllowedValuesInteger_P01() {
-        int result = -1;
-
+    public void testRemoveAttribute_N03() {
+        boolean result = false;
         try {
-            int[] values = { 1, 10, 20, 50 };
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    INT_KEY, new AttributeValue(10), new AttributeProperty(
-                            values));
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(INT_KEY, new AttributeValue(20));
-            result = ((Integer) singleResource.getAttribute(INT_KEY).value()
-                    .get()).intValue();
+            result = singleResource.removeAttribute("");
         } catch (InvalidArgsException e) {
-            e.printStackTrace();
         } catch (SimulatorException e) {
-            e.printStackTrace();
         }
 
-        assertEquals(20, result);
+        assertFalse(result);
     }
 
-    public void testSetAllowedValuesInteger_N01() {
+    public void testUpdateAttributeInteger_P01() {
         int result = -1;
 
         try {
-            int[] values = { 1, 10, 20, 50 };
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    INT_KEY, new AttributeValue(10), new AttributeProperty(
-                            values));
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(INT_KEY, new AttributeValue(15));
-            result = ((Integer) singleResource.getAttribute(INT_KEY).value()
-                    .get()).intValue();
-        } catch (InvalidArgsException e) {
-            e.printStackTrace();
-        } catch (SimulatorException e) {
-            e.printStackTrace();
-        }
+            IntegerProperty property = new IntegerProperty.Builder().build();
+            SimulatorResourceAttribute intAttribute = new SimulatorResourceAttribute(
+                    INT_KEY, new AttributeValue(10), property);
 
-        assertEquals(10, result);
-    }
+            assertTrue(singleResource.addAttribute(intAttribute));
+            assertTrue(singleResource.updateAttribute(INT_KEY,
+                    new AttributeValue(12)));
 
-    public void testSetAllowedValuesDouble_P01() {
-        double result = 0.0;
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(INT_KEY);
+            assertNotNull(attribute);
 
-        try {
-            double[] values = { 11.5, 10.5, 20.5, 50.5 };
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    DOUBLE_KEY, new AttributeValue(11.5),
-                    new AttributeProperty(values));
-            singleResource.addAttribute(attribute);
-            singleResource
-                    .updateAttribute(DOUBLE_KEY, new AttributeValue(10.5));
-            result = ((Double) singleResource.getAttribute(DOUBLE_KEY).value()
-                    .get()).doubleValue();
+            result = ((Integer) attribute.value().get()).intValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals(10.5, result);
+        assertEquals(12, result);
     }
 
-    public void testSetAllowedValuesDouble_N01() {
+    public void testUpdateAttributeDouble_P01() {
         double result = 0.0;
 
         try {
-            double[] values = { 11.5, 10.5, 20.5, 50.5 };
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    DOUBLE_KEY, new AttributeValue(11.5),
-                    new AttributeProperty(values));
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(DOUBLE_KEY, new AttributeValue(2.2));
-            result = ((Double) singleResource.getAttribute(DOUBLE_KEY).value()
-                    .get()).doubleValue();
-        } catch (InvalidArgsException e) {
-            e.printStackTrace();
-        } catch (SimulatorException e) {
-            e.printStackTrace();
-        }
+            DoubleProperty property = new DoubleProperty.Builder().build();
+            SimulatorResourceAttribute doubleAttribute = new SimulatorResourceAttribute(
+                    DOUBLE_KEY, new AttributeValue(22.0), property);
 
-        assertEquals(11.5, result);
-    }
+            assertTrue(singleResource.addAttribute(doubleAttribute));
+            assertTrue(singleResource.updateAttribute(DOUBLE_KEY,
+                    new AttributeValue(25.3)));
 
-    public void testsetAllowedValuesString_P01() {
-        String result = null;
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(DOUBLE_KEY);
+            assertNotNull(attribute);
 
-        try {
-            String[] values = { "monday", "tuesday", "wednesday" };
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    STRING_KEY, new AttributeValue("monday"),
-                    new AttributeProperty(values));
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(STRING_KEY, new AttributeValue(
-                    "tuesday"));
-            result = (String) singleResource.getAttribute(STRING_KEY).value()
-                    .get();
+            result = ((Double) attribute.value().get()).doubleValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertEquals("tuesday", result);
+        assertEquals(25.3, result);
     }
 
-    public void testsetAllowedValuesString_N01() {
-        String result = null;
+    public void testUpdateAttributeBoolean_P01() {
+        boolean result = true;
 
         try {
-            String[] values = { "monday", "tuesday", "wednesday" };
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    STRING_KEY, new AttributeValue("monday"),
-                    new AttributeProperty(values));
-            singleResource.addAttribute(attribute);
-            singleResource.updateAttribute(STRING_KEY, new AttributeValue(
-                    "friday"));
-            result = (String) singleResource.getAttribute(STRING_KEY).value()
-                    .get();
-        } catch (InvalidArgsException e) {
-            e.printStackTrace();
-        } catch (SimulatorException e) {
-            e.printStackTrace();
-        }
+            BooleanProperty property = new BooleanProperty.Builder().build();
+            SimulatorResourceAttribute boolAttribute = new SimulatorResourceAttribute(
+                    BOOL_KEY, new AttributeValue(true), property);
 
-        assertEquals("monday", result);
-    }
+            assertTrue(singleResource.addAttribute(boolAttribute));
+            assertTrue(singleResource.updateAttribute(BOOL_KEY,
+                    new AttributeValue(false)));
 
-    public void testRemoveAttribute_P01() {
-        SimulatorResourceAttribute result = null;
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(BOOL_KEY);
+            assertNotNull(attribute);
 
-        try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    STRING_KEY, new AttributeValue("friday"), null);
-            singleResource.addAttribute(attribute);
-            singleResource.removeAttribute(STRING_KEY);
-            result = singleResource.getAttribute(STRING_KEY);
+            result = ((Boolean) attribute.value().get()).booleanValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
 
-        assertNull(result);
+        assertEquals(false, result);
     }
 
-    public void testRemoveAttribute_N02() {
-        ExceptionType exType = ExceptionType.UNKNOWN;
+    public void testupdateAttributeString_P01() {
+        String result = null;
 
         try {
-            SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                    STRING_KEY, new AttributeValue("friday"), null);
-            singleResource.addAttribute(attribute);
-            singleResource.removeAttribute(null);
-        } catch (InvalidArgsException e) {
-            exType = ExceptionType.INVALID_ARGS;
-        } catch (SimulatorException e) {
-            exType = ExceptionType.SIMULATOR;
-        }
+            StringProperty property = new StringProperty.Builder().build();
+            SimulatorResourceAttribute stringAttribute = new SimulatorResourceAttribute(
+                    STRING_KEY, new AttributeValue("old-value"), property);
 
-        assertEquals(ExceptionType.INVALID_ARGS, exType);
-    }
+            assertTrue(singleResource.addAttribute(stringAttribute));
+            assertTrue(singleResource.updateAttribute(STRING_KEY,
+                    new AttributeValue("new-value")));
 
-    public void testRemoveAttribute_N03() {
-        ExceptionType exType = ExceptionType.UNKNOWN;
+            SimulatorResourceAttribute attribute = singleResource
+                    .getAttribute(STRING_KEY);
+            assertNotNull(attribute);
 
-        try {
-            singleResource.removeAttribute("");
+            result = (String) attribute.value().get();
         } catch (InvalidArgsException e) {
-            exType = ExceptionType.INVALID_ARGS;
+            e.printStackTrace();
         } catch (SimulatorException e) {
-            exType = ExceptionType.SIMULATOR;
+            e.printStackTrace();
         }
 
-        assertEquals(ExceptionType.INVALID_ARGS, exType);
+        assertEquals("new-value", result);
     }
 
     public void testStartResourceAutomation_P01() {
@@ -475,7 +374,7 @@ public class SimulatorSingleResourceTest extends TestCase {
                     automationListener);
 
             try {
-                lockObject.await(10, TimeUnit.SECONDS);
+                lockObject.await(3, TimeUnit.SECONDS);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
@@ -489,7 +388,6 @@ public class SimulatorSingleResourceTest extends TestCase {
 
         try {
             resource.stop();
-            resource.stopUpdation(id);
         } catch (SimulatorException e) {
             e.printStackTrace();
         }
@@ -520,9 +418,13 @@ public class SimulatorSingleResourceTest extends TestCase {
 
         String attributeName = null;
         try {
-            for (SimulatorResourceAttribute resAttribute : resource
-                    .getResourceModel().getAttributes().values())
-                attributeName = resAttribute.name();
+            for (Map.Entry<String, AttributeValue> entry : resource
+                    .getResourceModel().get().entrySet()) {
+                attributeName = entry.getKey();
+                if (null != attributeName && !attributeName.isEmpty()) {
+                    break;
+                }
+            }
         } catch (SimulatorException e1) {
             e1.printStackTrace();
         }
@@ -539,11 +441,11 @@ public class SimulatorSingleResourceTest extends TestCase {
         try {
             resource.start();
             id = resource.startAttributeUpdation(attributeName,
-                    SimulatorResource.AutoUpdateType.REPEAT, 100,
+                    SimulatorResource.AutoUpdateType.REPEAT, 1000,
                     automationListener);
 
             try {
-                lockObject.await(10, TimeUnit.SECONDS);
+                lockObject.await(3, TimeUnit.SECONDS);
             } catch (InterruptedException e) {
                 e.printStackTrace();
             }
@@ -611,6 +513,19 @@ public class SimulatorSingleResourceTest extends TestCase {
 
         assertTrue(result);
     }
+
+    private SimulatorSingleResource createResourceFromRAML() {
+        try {
+            return (SimulatorSingleResource) SimulatorManager
+                    .createResource(SINGLE_RES_RAML);
+        } catch (InvalidArgsException e) {
+            e.printStackTrace();
+        } catch (SimulatorException e) {
+            e.printStackTrace();
+        }
+
+        return null;
+    }
 }
 
 class AutoUpdateInfo {
index f382716..b24ee5d 100644 (file)
@@ -118,10 +118,10 @@ public class AttributeValueTest extends TestCase {
     public void testAttributeValueSimulatorResourceModel() {
         SimulatorResourceModel model = new SimulatorResourceModel();
         try {
-            model.addAttribute(INT_KEY, new AttributeValue(1));
-            model.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
-            model.addAttribute(BOOL_KEY, new AttributeValue(true));
-            model.addAttribute(STRING_KEY, new AttributeValue("string"));
+            model.set(INT_KEY, new AttributeValue(1));
+            model.set(DOUBLE_KEY, new AttributeValue(1.00));
+            model.set(BOOL_KEY, new AttributeValue(true));
+            model.set(STRING_KEY, new AttributeValue("string"));
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -228,10 +228,10 @@ public class AttributeValueTest extends TestCase {
     public void testAttributeValueSimulatorResourceModelArray() {
         SimulatorResourceModel childModel = new SimulatorResourceModel();
         try {
-            childModel.addAttribute(INT_KEY, new AttributeValue(1));
-            childModel.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
-            childModel.addAttribute(BOOL_KEY, new AttributeValue(true));
-            childModel.addAttribute(STRING_KEY, new AttributeValue("string"));
+            childModel.set(INT_KEY, new AttributeValue(1));
+            childModel.set(DOUBLE_KEY, new AttributeValue(1.00));
+            childModel.set(BOOL_KEY, new AttributeValue(true));
+            childModel.set(STRING_KEY, new AttributeValue("string"));
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -341,10 +341,10 @@ public class AttributeValueTest extends TestCase {
     public void testAttributeValueSimulatorResourceModelArrayArray() {
         SimulatorResourceModel childModel = new SimulatorResourceModel();
         try {
-            childModel.addAttribute(INT_KEY, new AttributeValue(1));
-            childModel.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
-            childModel.addAttribute(BOOL_KEY, new AttributeValue(true));
-            childModel.addAttribute(STRING_KEY, new AttributeValue("string"));
+            childModel.set(INT_KEY, new AttributeValue(1));
+            childModel.set(DOUBLE_KEY, new AttributeValue(1.00));
+            childModel.set(BOOL_KEY, new AttributeValue(true));
+            childModel.set(STRING_KEY, new AttributeValue("string"));
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -455,10 +455,10 @@ public class AttributeValueTest extends TestCase {
     public void testAttributeValueSimulatorResourceModelArrayArrayArray() {
         SimulatorResourceModel childModel = new SimulatorResourceModel();
         try {
-            childModel.addAttribute(INT_KEY, new AttributeValue(1));
-            childModel.addAttribute(DOUBLE_KEY, new AttributeValue(1.00));
-            childModel.addAttribute(BOOL_KEY, new AttributeValue(true));
-            childModel.addAttribute(STRING_KEY, new AttributeValue("string"));
+            childModel.set(INT_KEY, new AttributeValue(1));
+            childModel.set(DOUBLE_KEY, new AttributeValue(1.00));
+            childModel.set(BOOL_KEY, new AttributeValue(true));
+            childModel.set(STRING_KEY, new AttributeValue("string"));
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
index 4d195a1..1014320 100644 (file)
@@ -42,14 +42,6 @@ public class SimulatorManagerTest extends TestCase {
     private static final String SINGLE_RES_RAML     = "./ramls/oic.r.light.raml";
     private static final String COLLECTION_RES_RAML = "./ramls/oic.d.airconditioner.raml";
 
-    static {
-        System.loadLibrary("SimulatorManager");
-        System.loadLibrary("RamlParser");
-        System.loadLibrary("oc");
-        System.loadLibrary("oc_logger");
-        System.loadLibrary("octbstack");
-    }
-
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -99,8 +91,7 @@ public class SimulatorManagerTest extends TestCase {
 
         try {
             String configPath = "";
-            SimulatorResource resource = SimulatorManager
-                    .createResource(configPath);
+            SimulatorManager.createResource(configPath);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -114,7 +105,7 @@ public class SimulatorManagerTest extends TestCase {
         ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            SimulatorResource resource = SimulatorManager.createResource(null);
+            SimulatorManager.createResource(null);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -165,8 +156,7 @@ public class SimulatorManagerTest extends TestCase {
 
         try {
             String configPath = "";
-            Vector<SimulatorResource> resource = SimulatorManager
-                    .createResource(configPath, 1);
+            SimulatorManager.createResource(configPath, 1);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -180,8 +170,7 @@ public class SimulatorManagerTest extends TestCase {
         ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            Vector<SimulatorResource> resource = SimulatorManager
-                    .createResource(null, 1);
+            SimulatorManager.createResource(null, 1);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -195,8 +184,7 @@ public class SimulatorManagerTest extends TestCase {
         ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            Vector<SimulatorResource> resource = SimulatorManager
-                    .createResource(SINGLE_RES_RAML, 0);
+            SimulatorManager.createResource(SINGLE_RES_RAML, 0);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -210,8 +198,7 @@ public class SimulatorManagerTest extends TestCase {
         ExceptionType exType = ExceptionType.UNKNOWN;
 
         try {
-            Vector<SimulatorResource> resource = SimulatorManager
-                    .createResource(SINGLE_RES_RAML, -1);
+            SimulatorManager.createResource(SINGLE_RES_RAML, -1);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -273,8 +260,8 @@ public class SimulatorManagerTest extends TestCase {
             String uri = "/test/resource";
             String resourceType = "test.resource";
 
-            SimulatorResource resource = SimulatorManager.createResource(
-                    SimulatorResource.Type.SINGLE, name, uri, resourceType);
+            SimulatorManager.createResource(SimulatorResource.Type.SINGLE,
+                    name, uri, resourceType);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -292,8 +279,8 @@ public class SimulatorManagerTest extends TestCase {
             String uri = "/test/resource";
             String resourceType = "test.resource";
 
-            SimulatorResource resource = SimulatorManager.createResource(
-                    SimulatorResource.Type.SINGLE, name, uri, resourceType);
+            SimulatorManager.createResource(SimulatorResource.Type.SINGLE,
+                    name, uri, resourceType);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -311,8 +298,8 @@ public class SimulatorManagerTest extends TestCase {
             String uri = "";
             String resourceType = "test.resource";
 
-            SimulatorResource resource = SimulatorManager.createResource(
-                    SimulatorResource.Type.SINGLE, name, uri, resourceType);
+            SimulatorManager.createResource(SimulatorResource.Type.SINGLE,
+                    name, uri, resourceType);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -330,8 +317,8 @@ public class SimulatorManagerTest extends TestCase {
             String uri = null;
             String resourceType = "test.resource";
 
-            SimulatorResource resource = SimulatorManager.createResource(
-                    SimulatorResource.Type.SINGLE, name, uri, resourceType);
+            SimulatorManager.createResource(SimulatorResource.Type.SINGLE,
+                    name, uri, resourceType);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -349,8 +336,8 @@ public class SimulatorManagerTest extends TestCase {
             String uri = "/test/resource";;
             String resourceType = "";
 
-            SimulatorResource resource = SimulatorManager.createResource(
-                    SimulatorResource.Type.SINGLE, name, uri, resourceType);
+            SimulatorManager.createResource(SimulatorResource.Type.SINGLE,
+                    name, uri, resourceType);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -368,8 +355,8 @@ public class SimulatorManagerTest extends TestCase {
             String uri = "/test/resource";;
             String resourceType = null;
 
-            SimulatorResource resource = SimulatorManager.createResource(
-                    SimulatorResource.Type.SINGLE, name, uri, resourceType);
+            SimulatorManager.createResource(SimulatorResource.Type.SINGLE,
+                    name, uri, resourceType);
         } catch (InvalidArgsException e) {
             exType = ExceptionType.INVALID_ARGS;
         } catch (SimulatorException e) {
@@ -714,7 +701,7 @@ class DeviceInfoListener implements DeviceListener {
     }
 
     @Override
-    public void onDeviceFound(DeviceInfo devInfo) {
+    public void onDeviceFound(String hostUri, DeviceInfo devInfo) {
         mInfoHolder.set(devInfo);
         mLockObject.countDown();
     }
@@ -732,7 +719,7 @@ class PlatformInfoListener implements PlatformListener {
     }
 
     @Override
-    public void onPlatformFound(PlatformInfo platformInfo) {
+    public void onPlatformFound(String hostUri, PlatformInfo platformInfo) {
         mInfoHolder.set(platformInfo);
         mLockObject.countDown();
     }
index 76ae00e..20b6689 100644 (file)
@@ -49,16 +49,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertNotNull(resModel);
     }
 
-    public void testAddAttributeInt_P01() {
+    public void testSetInt_P01() {
         int result = -1;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                INT_KEY, new AttributeValue(10), null);
         try {
-            resModel.addAttribute(attribute);
-            result = ((Integer) resModel.getAttribute(INT_KEY).value().get())
-                    .intValue();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(INT_KEY, new AttributeValue(10));
+            result = ((Integer) resModel.get(INT_KEY).get()).intValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -66,16 +63,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals(10, result);
     }
 
-    public void testAddAttributeInt_P02() {
+    public void testSetInt_P02() {
         int result = -1;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                INT_KEY, new AttributeValue(-10), null);
         try {
-            resModel.addAttribute(attribute);
-            result = ((Integer) resModel.getAttribute(INT_KEY).value().get())
-                    .intValue();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(INT_KEY, new AttributeValue(-10));
+            result = ((Integer) resModel.get(INT_KEY).get()).intValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -83,16 +77,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals(-10, result);
     }
 
-    public void testAddAttributeDouble_P01() {
+    public void testSetDouble_P01() {
         double result = 0.0;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                DOUBLE_KEY, new AttributeValue(4.0), null);
         try {
-            resModel.addAttribute(attribute);
-            result = ((Double) resModel.getAttribute(DOUBLE_KEY).value().get())
-                    .doubleValue();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(DOUBLE_KEY, new AttributeValue(4.0));
+            result = ((Double) resModel.get(DOUBLE_KEY).get()).doubleValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -100,16 +91,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals(4.0, result);
     }
 
-    public void testAddAttributeDouble_P02() {
+    public void testSetDouble_P02() {
         double result = 0.0;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                DOUBLE_KEY, new AttributeValue(-4.0), null);
         try {
-            resModel.addAttribute(attribute);
-            result = ((Double) resModel.getAttribute(DOUBLE_KEY).value().get())
-                    .doubleValue();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(DOUBLE_KEY, new AttributeValue(-4.0));
+            result = ((Double) resModel.get(DOUBLE_KEY).get()).doubleValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -117,16 +105,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals(-4.0, result);
     }
 
-    public void testAddAttributeBoolean_P01() {
+    public void testSetBoolean_P01() {
         boolean result = false;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                BOOL_KEY, new AttributeValue(true), null);
         try {
-            resModel.addAttribute(attribute);
-            result = ((Boolean) resModel.getAttribute(BOOL_KEY).value().get())
-                    .booleanValue();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(BOOL_KEY, new AttributeValue(true));
+            result = ((Boolean) resModel.get(BOOL_KEY).get()).booleanValue();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -134,15 +119,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals(true, result);
     }
 
-    public void testAddAttributeString_P01() {
+    public void testSetString_P01() {
         String result = null;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                STRING_KEY, new AttributeValue("string-value"), null);
         try {
-            resModel.addAttribute(attribute);
-            result = (String) resModel.getAttribute(STRING_KEY).value().get();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(STRING_KEY, new AttributeValue("string-value"));
+            result = (String) resModel.get(STRING_KEY).get();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -150,15 +133,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals("string-value", result);
     }
 
-    public void testAddAttributeString_P02() {
+    public void testSetString_P02() {
         String result = null;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                STRING_KEY, new AttributeValue(""), null);
         try {
-            resModel.addAttribute(attribute);
-            result = (String) resModel.getAttribute(STRING_KEY).value().get();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(STRING_KEY, new AttributeValue(""));
+            result = (String) resModel.get(STRING_KEY).get();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -166,15 +147,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals("", result);
     }
 
-    public void testAddAttributeString_P03() {
+    public void testSetString_P03() {
         String result = null;
 
-        SimulatorResourceModel resModel = new SimulatorResourceModel();
-        SimulatorResourceAttribute attribute = new SimulatorResourceAttribute(
-                STRING_KEY, new AttributeValue("@#$$&^*^(*^&"), null);
         try {
-            resModel.addAttribute(attribute);
-            result = (String) resModel.getAttribute(STRING_KEY).value().get();
+            SimulatorResourceModel resModel = new SimulatorResourceModel();
+            resModel.set(STRING_KEY, new AttributeValue("@#$$&^*^(*^&"));
+            result = (String) resModel.get(STRING_KEY).get();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -196,14 +175,10 @@ public class SimulatorResourceModelTest extends TestCase {
 
         SimulatorResourceModel resModel = new SimulatorResourceModel();
         try {
-            resModel.addAttribute(new SimulatorResourceAttribute(INT_KEY,
-                    new AttributeValue(1234), null));
-            resModel.addAttribute(new SimulatorResourceAttribute(DOUBLE_KEY,
-                    new AttributeValue(1.234), null));
-            resModel.addAttribute(new SimulatorResourceAttribute(BOOL_KEY,
-                    new AttributeValue(true), null));
-            resModel.addAttribute(new SimulatorResourceAttribute(STRING_KEY,
-                    new AttributeValue("string-value"), null));
+            resModel.set(INT_KEY, new AttributeValue(1234));
+            resModel.set(DOUBLE_KEY, new AttributeValue(1.234));
+            resModel.set(BOOL_KEY, new AttributeValue(true));
+            resModel.set(STRING_KEY, new AttributeValue("string-value"));
             result = resModel.size();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
@@ -212,14 +187,13 @@ public class SimulatorResourceModelTest extends TestCase {
         assertEquals(4, result);
     }
 
-    public void testGetAttribute_P01() {
-        SimulatorResourceAttribute result = null;
+    public void testGet_P01() {
+        AttributeValue result = null;
 
         SimulatorResourceModel resModel = new SimulatorResourceModel();
         try {
-            resModel.addAttribute(new SimulatorResourceAttribute(INT_KEY,
-                    new AttributeValue(10), null));
-            result = resModel.getAttribute(INT_KEY);
+            resModel.set(INT_KEY, new AttributeValue(10));
+            result = resModel.get(INT_KEY);
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }
@@ -227,20 +201,16 @@ public class SimulatorResourceModelTest extends TestCase {
         assertNotNull(result);
     }
 
-    public void testGetAttributes_P01() {
-        Map<String, SimulatorResourceAttribute> result = null;
+    public void testGet_P02() {
+        Map<String, AttributeValue> result = null;
 
         SimulatorResourceModel resModel = new SimulatorResourceModel();
         try {
-            resModel.addAttribute(new SimulatorResourceAttribute(INT_KEY,
-                    new AttributeValue(1234), null));
-            resModel.addAttribute(new SimulatorResourceAttribute(DOUBLE_KEY,
-                    new AttributeValue(1.234), null));
-            resModel.addAttribute(new SimulatorResourceAttribute(BOOL_KEY,
-                    new AttributeValue(true), null));
-            resModel.addAttribute(new SimulatorResourceAttribute(STRING_KEY,
-                    new AttributeValue("string-value"), null));
-            result = resModel.getAttributes();
+            resModel.set(INT_KEY, new AttributeValue(1234));
+            resModel.set(DOUBLE_KEY, new AttributeValue(1.234));
+            resModel.set(BOOL_KEY, new AttributeValue(true));
+            resModel.set(STRING_KEY, new AttributeValue("string-value"));
+            result = resModel.get();
         } catch (InvalidArgsException e) {
             e.printStackTrace();
         }