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>
*/
public class SimulatorManager {
- private SimulatorManager() {
+ static {
+ System.loadLibrary("oc_logger");
+ System.loadLibrary("octbstack");
+ System.loadLibrary("oc");
+ System.loadLibrary("RamlParser");
+ System.loadLibrary("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.
*/
public static Vector<SimulatorResource> createResource(String configPath,
int count) throws InvalidArgsException, SimulatorException {
- return createResources(configPath, count);
+ return nativeCreateResources(configPath, count);
};
/**
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;
}
*/
public static void findResource(FindResourceListener listener)
throws InvalidArgsException, SimulatorException {
- searchResource(null, listener);
+ nativeSearchResource(null, listener);
}
/**
"Invalid resource type!");
}
- searchResource(resourceType, listener);
+ nativeSearchResource(resourceType, listener);
}
/**
* @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.
* @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.
* @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.
* @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.
* @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
return mValues.size();
}
- /**
- * These methods used by native layer.
- */
- @SuppressWarnings("unused")
private SimulatorResourceModel(Map<String, AttributeValue> values) {
mValues = values;
}
package org.oic.simulator.client;
-import org.oic.simulator.client.SimulatorRemoteResource;
-
/**
* Listener for getting notification when resources are discovered in network.
*/
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 {
* 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;
}
/**
*/
public void observe(ObserveNotificationListener onObserveListener)
throws InvalidArgsException, SimulatorException {
- startObserve(null, onObserveListener);
+ nativeStartObserve(null, onObserveListener);
}
/**
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM,
"Invalid Query Parameters!");
- startObserve(queryParams, onObserveListener);
+ nativeStartObserve(queryParams, onObserveListener);
}
/**
* @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
* @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
* @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);
}
/**
* @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.
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);
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();
}
--- /dev/null
+/*
+ * 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;
+ }
+}
*/
public final class SimulatorCollectionResource extends SimulatorResource {
- private SimulatorCollectionResource(long nativeHandle) {
- mNativeHandle = nativeHandle;
- }
-
/**
* API to add child resource to collection.
*
* 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.
* 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.
* 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.
* 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();
}
*/
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 {
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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
* 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
*/
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.
*
* 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.
* 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.
* 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
* 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
* @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.
* 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.
* 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.
* 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.
* 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.
* 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.
* 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
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();
}
*/
public final class SimulatorSingleResource extends SimulatorResource {
- private SimulatorSingleResource(long nativeHandle) {
- mNativeHandle = nativeHandle;
- }
-
/**
* API to get attribute of resource.
*
* 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.
* 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
* @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
* @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
* @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
* @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
* @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.
* @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);
}
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();
lockObject, response);
try {
- SimulatorResourceModel resModel = singleResource.getResourceModel();
Map<String, String> queryParams = new HashMap<>();
remoteResource.put(queryParams, null, listener);
lockObject, response);
try {
- SimulatorResourceModel resModel = singleResource.getResourceModel();
Map<String, String> queryParams = new HashMap<>();
remoteResource.post(queryParams, null, listener);
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");
lockObject, response);
try {
- remoteResource.startObserve(null, listener);
+ remoteResource.observe(listener);
singleResource.addAttribute(new SimulatorResourceAttribute(
"boolean", new AttributeValue(true), null));
singleResource.removeAttribute("boolean");
try {
Map<String, String> queryParams = new HashMap<>();
- remoteResource.startObserve(queryParams, null);
+ remoteResource.observe(queryParams, null);
} catch (InvalidArgsException e) {
exType = ExceptionType.INVALID_ARGS;
try {
Map<String, String> queryParams = new HashMap<>();
- remoteResource.startObserve(queryParams, listener);
+ remoteResource.observe(queryParams, listener);
try {
lockObject.await(10, TimeUnit.SECONDS);
try {
remoteResource.setConfigInfo(SINGLE_RES_RAML);
remoteResource.startVerification(
- SimulatorRemoteResource.VerificationType.GET, listener);
+ SimulatorRemoteResource.RequestType.GET, listener);
try {
lockObject.await(10, TimeUnit.SECONDS);
try {
remoteResource.setConfigInfo(SINGLE_RES_RAML);
remoteResource.startVerification(
- SimulatorRemoteResource.VerificationType.PUT, listener);
+ SimulatorRemoteResource.RequestType.PUT, listener);
try {
lockObject.await(10, TimeUnit.SECONDS);
try {
remoteResource.setConfigInfo(SINGLE_RES_RAML);
remoteResource.startVerification(
- SimulatorRemoteResource.VerificationType.POST, listener);
+ SimulatorRemoteResource.RequestType.POST, listener);
try {
lockObject.await(10, TimeUnit.SECONDS);
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) {
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) {
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;
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(
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);
}
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;
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;
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;
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;
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";
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() {
automationListener);
try {
- lockObject.await(10, TimeUnit.SECONDS);
+ lockObject.await(3, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
resource.stop();
- resource.stopUpdation(id);
} catch (SimulatorException e) {
e.printStackTrace();
}
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();
}
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();
}
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 {
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();
}
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();
}
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();
}
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();
}
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();
try {
String configPath = "";
- SimulatorResource resource = SimulatorManager
- .createResource(configPath);
+ SimulatorManager.createResource(configPath);
} catch (InvalidArgsException e) {
exType = ExceptionType.INVALID_ARGS;
} catch (SimulatorException e) {
ExceptionType exType = ExceptionType.UNKNOWN;
try {
- SimulatorResource resource = SimulatorManager.createResource(null);
+ SimulatorManager.createResource(null);
} catch (InvalidArgsException e) {
exType = ExceptionType.INVALID_ARGS;
} catch (SimulatorException e) {
try {
String configPath = "";
- Vector<SimulatorResource> resource = SimulatorManager
- .createResource(configPath, 1);
+ SimulatorManager.createResource(configPath, 1);
} catch (InvalidArgsException e) {
exType = ExceptionType.INVALID_ARGS;
} catch (SimulatorException e) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
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) {
}
@Override
- public void onDeviceFound(DeviceInfo devInfo) {
+ public void onDeviceFound(String hostUri, DeviceInfo devInfo) {
mInfoHolder.set(devInfo);
mLockObject.countDown();
}
}
@Override
- public void onPlatformFound(PlatformInfo platformInfo) {
+ public void onPlatformFound(String hostUri, PlatformInfo platformInfo) {
mInfoHolder.set(platformInfo);
mLockObject.countDown();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
}
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();
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();
}
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();
}