*
* @param attrName - Name of the attribute to be automated.
* @param type - Automation type.
+ * @param updateInterval -Interval time in milliseconds for attribute value update automation.
* @param callback - Callback to get notifiy when update automation is finished.
* @param id - Identifier for automation.
*
import java.util.List;
import oic.simulator.clientcontroller.Activator;
-import oic.simulator.clientcontroller.manager.ResourceManager;
import oic.simulator.clientcontroller.remoteresource.PutPostAttributeModel;
import oic.simulator.clientcontroller.utils.Constants;
import org.eclipse.jface.viewers.ColumnLabelProvider;
import org.eclipse.jface.viewers.EditingSupport;
import org.eclipse.jface.viewers.IStructuredContentProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StyledCellLabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.TableViewerColumn;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerCell;
import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
+import org.eclipse.swt.widgets.Text;
/**
* This dialog is used for generating a POST request.
"Select" };
private final Integer[] attTblColWidth = { 200, 200, 50 };
- private ResourceManager resourceManager;
-
private List<PutPostAttributeModel> modelList = null;
public PostRequestDialog(Shell parentShell,
List<PutPostAttributeModel> modelList) {
super(parentShell);
this.modelList = modelList;
- resourceManager = Activator.getDefault().getResourceManager();
}
@Override
class AttributeValueEditor extends EditingSupport {
private final TableViewer viewer;
private final CellEditor editor;
-
+ private final Text txt;
public AttributeValueEditor(TableViewer viewer) {
super(viewer);
this.viewer = viewer;
editor = new TextCellEditor(viewer.getTable());
+ txt = (Text)editor.getControl();
+ if(null != txt) {
+ txt.addModifyListener(new ModifyListener() {
+ @Override
+ public void modifyText(ModifyEvent e) {
+ IStructuredSelection selection = (IStructuredSelection)AttributeValueEditor.this.viewer.getSelection();
+ PutPostAttributeModel att = (PutPostAttributeModel)selection.getFirstElement();
+ if(null == att) {
+ return;
+ }
+ String newValue = txt.getText();
+ if(null != newValue && !newValue.isEmpty()) {
+ att.setModified(true);
+ }
+ else {
+ att.setModified(false);
+ }
+ AttributeValueEditor.this.viewer.update(att, null);
+ }
+ });
+
+ }
}
@Override
// If there is a change, then its corresponding check box should be
// checked.
String newValue = String.valueOf(value);
- String actualValue = resourceManager.getAttributeValue(
- resourceManager.getCurrentResourceInSelection(),
- model.getAttName());
- if (newValue.equals(actualValue)) {
- model.setModified(false);
- } else {
- model.setModified(true);
- }
model.setAttValue(newValue);
viewer.update(element, null);
}
if (!m_env)
return nullptr;
- jmethodID constr = m_env->GetMethodID(gSimulatorClassRefs.classDeviceInfo, "<init>", "(V)V");
- if (constr)
+ jmethodID deviceInfoMId = m_env->GetMethodID(gSimulatorClassRefs.classDeviceInfo, "<init>", "(V)V");
+ if (!deviceInfoMId)
return nullptr;
- jobject jDeviceInfo = (jobject) m_env->NewObject(gSimulatorClassRefs.classDeviceInfo, constr);
- if (jDeviceInfo)
+ jobject jDeviceInfo = (jobject) m_env->NewObject(gSimulatorClassRefs.classDeviceInfo, deviceInfoMId);
+ if (!jDeviceInfo)
return nullptr;
setFieldValue(jDeviceInfo, "mName", deviceInfo.getName());
if (!jConfigPath)
{
throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM,
- "Configuration file path is empty!");
+ "Configuration file path is null!");
return;
}
}
}
+JNIEXPORT void JNICALL Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_dispose
+(JNIEnv *env, jobject thiz)
+{
+ JniSimulatorRemoteResource *resource = GetHandle<JniSimulatorRemoteResource>(env, thiz);
+ delete resource;
+}
\ No newline at end of file
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopVerification
(JNIEnv *env, jobject thiz, jint jId);
+JNIEXPORT void JNICALL
+Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_dispose
+(JNIEnv *, jobject);
+
#ifdef __cplusplus
}
#endif
return;
}
+ if (!jvalue)
+ {
+ throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Attribute value cannot be null!");
+ return;
+ }
+
SimulatorResourceModelSP resModelPtr;
resModelPtr = JSimulatorResourceModel::getResourceModelPtr(env, thiz);
if (!resModelPtr)
return;
}
+ if (!jValue)
+ {
+ throwInvalidArgsException(env, SIMULATOR_INVALID_PARAM, "Attribute value cannot be null!");
+ return;
+ }
+
SimulatorResourceServerSP resource = JniSimulatorResource::getJniSimulatorResourceSP(env,
jobject);
if (!resource)
}
std::string str = env->GetStringUTFChars(jKey, NULL);
- resource->removeAttribute(str);
+ try
+ {
+ resource->removeAttribute(str);
+ }
+ catch (InvalidArgsException &e)
+ {
+ throwInvalidArgsException(env, e.code(), e.what());
+ return;
+ }
+ catch (SimulatorException &e)
+ {
+ throwSimulatorException(env, e.code(), e.what());
+ return;
+ }
+ catch (...)
+ {
+ throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
+ return;
+ }
}
JNIEXPORT jobjectArray JNICALL
protected void finalize() throws Throwable {
try {
dispose();
- } catch(Throwable t){
- throw t;
- } finally{
+ } finally {
super.finalize();
}
}
protected void finalize() throws Throwable {
try {
dispose();
- } catch(Throwable t){
- throw t;
- } finally{
+ } finally {
super.finalize();
}
}
* @param typeOfAutomation
* {@link AutomationType} indicating whether the automation is
* one-time or recursive.
+ * @param updateInterval
+ * Interval time in milliseconds for attribute value update automation.
* @param listener
* Listener to be notified when automation ends.
*
* @param typeOfAutomation
* {@link AutomationType} indicating whether the automation is
* one-time or recursive.
+ * @param updateInterval
+ * Interval time in milliseconds for attribute value update automation.
* @param listener
* Listener to be notified when automation ends.
*
protected void finalize() throws Throwable {
try {
dispose();
- } catch(Throwable t){
- throw t;
- } finally{
+ } finally {
super.finalize();
}
}
{
if (path.empty())
{
- OC_LOG(ERROR, TAG, "Invalid path given for configuration !");
+ OC_LOG(ERROR, TAG, "Invalid path given for configuration!");
throw InvalidArgsException(SIMULATOR_INVALID_PARAM, "Empty path string!");
}
******************************************************************/
#include "simulator_resource_model.h"
+#include "simulator_exceptions.h"
+#include "logger.h"
#include "OCPlatform.h"
#include <sstream>
#include <boost/lexical_cast.hpp>
void SimulatorResourceModel::removeAttribute(const std::string &attrName)
{
- if (m_attributes.end() == m_attributes.find(attrName))
+ if (attrName.empty() || m_attributes.end() == m_attributes.find(attrName))
{
- return;
+ OC_LOG(ERROR, TAG, "Attribute name is empty or not found in model!");
+ throw InvalidArgsException(SIMULATOR_INVALID_PARAM, "Attribute not found in model!");
}
m_attributes.erase(attrName);
assertTrue(result && listenerObject != null && listenerObject.getRepresentation() != null && listenerObject.getuId() != null);
}
+ /**
+ * model as null
+ */
+
+ public void testPut_N01() {
+ boolean result = true;
+ ListenerObject listenerObject = new ListenerObject();
+ PutListener putListener = new PutListener(lockObject, listenerObject);
+
+ try {
+ simulatorRemoteResource.put(null, null, putListener);
+ result = false;
+ } catch (Exception e1) {
+ result = true;
+ }
+
+ try {
+ lockObject.await(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ }
+
+ assertTrue(result && listenerObject.getRepresentation() == null && listenerObject.getuId() == null);
+ }
+
public void testPost_P01()
{
boolean result = true;
try
{
model.addAttributeInt("intensity", 8);
- //model.addAttributeString("power", "off");
listenerObject = new ListenerObject();
PostListener postListener = new PostListener(lockObject, listenerObject);
assertTrue(result && listenerObject != null && listenerObject.getRepresentation() != null && listenerObject.getuId() != null);
}
+ /**
+ * Model is set to null
+ */
+
+ public void testPost_N01() {
+ boolean result = true;
+
+ lockObject = new CountDownLatch(1);
+
+ ListenerObject listenerObject = new ListenerObject();
+ PostListener postListener = new PostListener(lockObject, listenerObject);
+
+ try {
+ simulatorRemoteResource.post(null, null, postListener);
+ result = false;
+ } catch (Exception e1) {
+ result = true;
+ }
+
+ try {
+ lockObject.await(10, TimeUnit.SECONDS);
+ } catch (InterruptedException e) {
+ }
+
+ assertTrue(result && listenerObject.getRepresentation() == null && listenerObject.getuId() == null);
+ }
+
public void testGet_P01()
{
boolean result = true;
String resInterface = simulatorRemoteResource.getResourceInterfaces().get(0);
- if(resInterface == null)
- simulatorRemoteResource.get(resInterface, null, onGetListener);
+ if(resInterface != null)
+ simulatorRemoteResource.get(resInterface,null, onGetListener);
else
result = false;
}
{
String resInterface = simulatorRemoteResource.getResourceInterfaces().get(0);
- if(resInterface == null)
- simulatorRemoteResource.get(resInterface, null, null);
- else
- result = false;
+ if(resInterface != null)
+ {
+ simulatorRemoteResource.get( resInterface,null, null);
+ }
+
+ result = false;
}
catch(Exception e)
{
try
{
-
lockObject.await(100, TimeUnit.MILLISECONDS);
}
catch (InterruptedException e)
{
System.loadLibrary("SimulatorManager");
System.loadLibrary("RamlParser");
- System.loadLibrary("YamlParser");
System.loadLibrary("oc");
System.loadLibrary("oc_logger");
System.loadLibrary("octbstack");
{
try
{
- simulatorResourceServer.addAttributeBoolean(KEY, true);
+ simulatorResourceServer.addAttributeBoolean(KEY, Boolean.parseBoolean("true"));
}
catch (Exception e)
{
e.printStackTrace();
}
- assertEquals(Boolean.parseBoolean(getValue(KEY) + ""), true);
+ assertEquals(Boolean.parseBoolean(getValue(KEY).toString() + ""), true);
}
public void testaddAttributeString_P01()
try
{
- simulatorResourceServer.addAttributeBoolean(KEY, true);
+ simulatorResourceServer.addAttributeBoolean(KEY, Boolean.parseBoolean("true"));
}
catch (Exception e)
{
try
{
- simulatorResourceServer.updateAttributeBoolean(KEY, false);
+ simulatorResourceServer.updateAttributeBoolean(KEY, Boolean.parseBoolean("false"));
}
catch (Exception e)
{
try
{
- lockObject.await(10,TimeUnit.SECONDS);
+ lockObject.await(15,TimeUnit.SECONDS);
}
catch (InterruptedException e)
{
{
result = false;
}
- assertTrue(result && id == -1);
+ assertTrue(!result && id == 0);
}
public void testStartAttributeAutomation_P01()
int id = 0;
try
{
- id = simulatorResourceServer.startAttributeAutomation(simulatorResourceServer.getModel().getAttributes().get(0).getName(),
+ simulatorResourceServer.addAttributeInteger(KEY, 10);
+ id = simulatorResourceServer.startAttributeAutomation(KEY,
AutomationType.NORMAL, automationListener);
}
catch (Exception e)
try
{
- lockObject.await(10, TimeUnit.SECONDS);
+ lockObject.await(05, TimeUnit.SECONDS);
}
catch (InterruptedException e)
{
}
- result = result && automationObject.getResourceURI() != null && automationObject.getAutomationId() != -1 && id != -1;
-
try
{
simulatorResourceServer.stopAutomation(id);
import java.util.concurrent.CountDownLatch;
import junit.framework.TestCase;
-import org.oic.simulator.DeviceInfo;
import org.oic.simulator.PlatformInfo;
import org.oic.simulator.SimulatorManager;
import org.oic.simulator.serviceprovider.SimulatorResourceServer;
private ResourceModelObject resourceModelObject;
private ResourceModelChangeListener resourceModelChangeListener;
- private DeviceInfo info;
- private PlatformInfo platformInfo;
static
{
System.loadLibrary("SimulatorManager");
- System.loadLibrary("RamlParser");
- System.loadLibrary("oc");
- System.loadLibrary("oc_logger");
- System.loadLibrary("octbstack");
}
@Override
SimulatorResourceServer[] simulatorResourceServers = null;
try
{
+ SimulatorManager.setDeviceInfo("test");
simulatorResourceServers = SimulatorManager.createResource(configPath, count, resourceModelChangeListener);
}
catch (Exception e)
boolean result = false;
SimulatorResourceServer[] simulatorResourceServers = null;
-
try
{
simulatorResourceServers = SimulatorManager.createResource(CONFIG_PATH, count, null);
assertTrue(simulatorResourceServers == null);
}
+ /**
+ * When count is set to -ve
+ */
+
+ public void testCreateResourceCount_N05()
+ {
+ int count = -10;
+
+ SimulatorResourceServer[] simulatorResourceServers = createResources(count);
+
+ assertTrue(simulatorResourceServers == null );
+ }
+
public void testDeleteResource_P01()
{
boolean result = true;
*/
public void testSetDeviceInfo_N01()
{
- SimulatorManager.setDeviceInfo("");
+ try
+ {
+ SimulatorManager.setDeviceInfo("");
+ }
+ catch(Exception e)
+ {
+ System.out.println("Exception hit");
+ }
+ }
+
+ /**
+ * checking for crash
+ * pass null
+ */
+ public void testSetDeviceInfo_N02()
+ {
+ try
+ {
+ SimulatorManager.setDeviceInfo(null);
+ }
+ catch(Exception e)
+ {
+ System.out.println("Exception hit");
+ }
+ }
+
+ public void testGetDeviceInfo_N01()
+ {
+ try
+ {
+ SimulatorManager.getDeviceInfo(null);
+ }
+ catch(Exception e)
+ {
+ System.out.println(" Exception hit");
+ }
}
/**
SimulatorManager.setPlatformInfo(platformInfo);
}
+
+ /**
+ * Checking for crash
+ */
+ public void testSetPlatformInfo_N01()
+ {
+ try
+ {
+ SimulatorManager.setPlatformInfo(null);
+ }
+ catch(Exception e)
+ {
+ System.out.println("Exception Hit");
+ }
+ }
+
+ public void testGetPlatformInfo_N01()
+ {
+ try
+ {
+ SimulatorManager.getPlatformInfo(null);
+ }
+ catch (Exception e)
+ {
+ System.out.println("Exception Hit");
+ }
+ }
}
assertTrue(result);
}
+ public void testAddAttributeString_N02() {
+ String val = null;
+
+ boolean result = false;
+ try {
+
+ simulatorResourceModel.addAttributeString(KEY, val);
+
+ result = result && simulatorResourceModel.getAttribute(KEY).getValue().toString().equals(val);
+
+ } catch(Exception e) {
+ result = true;
+ }
+
+ assertTrue(result);
+ }
+
public void testAddAttributeString_N03()
{
String val = "@#$$&^*^(*^&";
{
boolean result = true;
- boolean val = true;
+ boolean val;
try
{
+ val=Boolean.parseBoolean("true");
simulatorResourceModel.addAttributeBoolean(KEY, val);
- result = result && ((Boolean.parseBoolean(simulatorResourceModel.getAttribute(KEY).getValue() + "")));
+ result = result && ((Boolean.parseBoolean(simulatorResourceModel.getAttribute(KEY).getValue().toString()+"")));
- val = false;
+ val = Boolean.parseBoolean("false");
simulatorResourceModel.addAttributeBoolean(KEY, val);
- result = result && !((Boolean.parseBoolean(simulatorResourceModel.getAttribute(KEY).getValue() + "")));
+ result = result && !((Boolean.parseBoolean(simulatorResourceModel.getAttribute(KEY).getValue().toString()+"")));
}
catch (Exception e)
{
result = result && (simulatorResourceModel.size() == 1);
simulatorResourceModel.addAttributeString("test2", "asdf");
- simulatorResourceModel.addAttributeBoolean("test3", true);
+ simulatorResourceModel.addAttributeBoolean("test3", Boolean.parseBoolean("true"));
simulatorResourceModel.addAttributeDouble("test4", 22.435234);
result = result && (simulatorResourceModel.size() == 4);
{
simulatorResourceModel.addAttributeInt("test1", 1234);
simulatorResourceModel.addAttributeString("test2", "asdf");
- simulatorResourceModel.addAttributeBoolean("test3", true);
+ simulatorResourceModel.addAttributeBoolean("test3", Boolean.parseBoolean("true"));
simulatorResourceModel.addAttributeDouble("test4", 22.435234);
Map<String, ResourceAttribute> attributes = simulatorResourceModel.getAttributes();
result = result && (((Integer)attributes.get("test1").getValue()) == 1234) &&
(((String)attributes.get("test2").getValue()).equals("asdf")) &&
- ((Boolean.parseBoolean(attributes.get("test3").getValue() + "")==true)) &&
+ ((Boolean.parseBoolean(attributes.get("test3").getValue().toString() + "")==true)) &&
(((Double)attributes.get("test4").getValue()) == 22.435234);
}
catch(Exception e)