import org.eclipse.swt.graphics.Image;
import org.oic.simulator.IAutomation;
import org.oic.simulator.ILogger.Level;
-import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.ResourceAttribute;
import org.oic.simulator.ResourceAttribute.Range;
import org.oic.simulator.ResourceAttribute.Type;
public void shutdown() {
threadHandle.interrupt();
}
-}
\ No newline at end of file
+}
public class AutomationSettingDialog extends TitleAreaDialog {
private CCombo autoTypeCmb;
- private CCombo updateFreqCmb;
private String automationType;
private String updateFrequencyInMillis;
gd.grabExcessHorizontalSpace = true;
autoTypeCmb.setLayoutData(gd);
- Label updateFreqLbl = new Label(container, SWT.NONE);
- updateFreqLbl.setText("Update Frequency(ms)");
-
- updateFreqCmb = new CCombo(container, SWT.READ_ONLY | SWT.BORDER);
- gd = new GridData();
- gd.horizontalAlignment = SWT.FILL;
- gd.grabExcessHorizontalSpace = true;
- updateFreqCmb.setLayoutData(gd);
-
populateSettingsData();
addUIListeners();
}
// Select the default value
autoTypeCmb.select(autoTypeCmb.indexOf(value));
- } else if (settingId.equals(Constants.UPDATE_INTERVAL_IN_MS)) {
- itr = allowedValues.iterator();
- while (itr.hasNext()) {
- updateFreqCmb.add(itr.next());
- }
- // Select the default value
- updateFreqCmb.select(updateFreqCmb.indexOf(value));
}
}
}
automationType = autoTypeCmb.getText();
}
});
-
- updateFreqCmb.addSelectionListener(new SelectionAdapter() {
- @Override
- public void widgetSelected(SelectionEvent e) {
- updateFrequencyInMillis = updateFreqCmb.getText();
- }
- });
}
public void setInitialSettings() {
automationType = autoTypeCmb.getText();
- updateFrequencyInMillis = updateFreqCmb.getText();
}
public String getAutomationType() {
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();
}
}
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);
throw SimulatorException(SIMULATOR_NO_RESOURCE, "Invalid resource!");
}
- return m_updateAutomationMgr.startResourceAutomation(this, type, -1, callback);
+ // This fix is temporarily to give 500 ms default delay in automation until the new UI change is merged.
+ return m_updateAutomationMgr.startResourceAutomation(this, type, 500, callback);
}
int SimulatorResourceServerImpl::startUpdateAutomation(const std::string &attrName,
throw SimulatorException(SIMULATOR_NO_RESOURCE, "Invalid resource!");
}
- return m_updateAutomationMgr.startAttributeAutomation(this, attrName, type, -1, callback);
+ // This fix is temporarily to give 500 ms default delay in automation until the new UI change is merged.
+ return m_updateAutomationMgr.startAttributeAutomation(this, attrName, type, 500, callback);
}
std::vector<int> SimulatorResourceServerImpl::getResourceAutomationIds()
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)