Commit f8611049 authored by spurthi.segu's avatar spurthi.segu Committed by Uze Choi

Junit testing fixes for Simulator APIs.

Change-Id: Id55390d0476be0349b2d2bbaa84adbbd36e4a8dd
Signed-off-by: default avatarspurthi.segu <spurthi.segu@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/3631Tested-by: default avatarjenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: default avatarUze Choi <uzchoi@samsung.com>
parent a2525774
......@@ -47,6 +47,7 @@ import oic.simulator.clientcontroller.utils.Utility;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.graphics.Image;
import org.oic.simulator.ILogger.Level;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.ResourceAttribute;
import org.oic.simulator.ResourceAttribute.Range;
import org.oic.simulator.ResourceAttribute.Type;
......@@ -1482,6 +1483,16 @@ public class ResourceManager {
}
try {
resourceN.stopVerification(autoId);
} catch (InvalidArgsException e) {
Activator
.getDefault()
.getLogManager()
.log(Level.ERROR.ordinal(),
new Date(),
"[" + e.getClass().getSimpleName() + "]"
+ e.code().toString() + "-"
+ e.message());
return;
} catch (SimulatorException e) {
Activator
.getDefault()
......
......@@ -44,6 +44,7 @@ import oic.simulator.serviceprovider.utils.Utility;
import org.eclipse.swt.graphics.Image;
import org.oic.simulator.IAutomation;
import org.oic.simulator.ILogger.Level;
import org.oic.simulator.InvalidArgsException;
import org.oic.simulator.ResourceAttribute;
import org.oic.simulator.ResourceAttribute.Range;
import org.oic.simulator.ResourceAttribute.Type;
......@@ -403,7 +404,7 @@ public class ResourceManager {
orderedResourceUriMap.remove(resourceType);
}
}
} else if (null != resourceURI) {
} else if (null != resourceType) {
orderedResourceUriMap.remove(resourceType);
} else {
orderedResourceUriMap.clear();
......@@ -1383,7 +1384,17 @@ public class ResourceManager {
if (null != resourceServerN) {
try {
resourceServerN.stopAutomation(autoId);
} catch (SimulatorException e) {
} catch (InvalidArgsException e) {
Activator
.getDefault()
.getLogManager()
.log(Level.ERROR.ordinal(),
new Date(),
"[" + e.getClass().getSimpleName() + "]"
+ e.code().toString() + "-"
+ e.message());
return;
}catch (SimulatorException e) {
Activator
.getDefault()
.getLogManager()
......@@ -1522,6 +1533,16 @@ public class ResourceManager {
// Call native method
try {
resourceServer.stopAutomation(autoId);
} catch (InvalidArgsException e) {
Activator
.getDefault()
.getLogManager()
.log(Level.ERROR.ordinal(),
new Date(),
"[" + e.getClass().getSimpleName() + "]"
+ e.code().toString() + "-"
+ e.message());
return false;
} catch (SimulatorException e) {
Activator
.getDefault()
......@@ -1643,4 +1664,4 @@ public class ResourceManager {
public void shutdown() {
threadHandle.interrupt();
}
}
\ No newline at end of file
}
......@@ -515,7 +515,7 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
}
JNIEXPORT void JNICALL
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_get
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativeGet
(JNIEnv *env, jobject thiz, jstring jResourceInterface,
jobject jQueryParamsMap, jobject jListener)
{
......@@ -585,7 +585,7 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_get
}
JNIEXPORT void JNICALL
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_put
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePut
(JNIEnv *env, jobject thiz, jstring jResourceInterface,
jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
{
......@@ -659,7 +659,7 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_put
}
JNIEXPORT void JNICALL
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_post
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePost
(JNIEnv *env, jobject thiz, jstring jResourceInterface,
jobject jRepresentation, jobject jQueryParamsMap, jobject jListener)
{
......
......@@ -47,17 +47,17 @@ Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_stopObserve
(JNIEnv *env, jobject thiz);
JNIEXPORT void JNICALL
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_get
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativeGet
(JNIEnv *env, jobject thiz, jstring jResourceInterface,
jobject jQueryParamsMap, jobject jListener);
JNIEXPORT void JNICALL
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_put
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePut
(JNIEnv *env, jobject thiz, jstring jResourceInterface,
jobject jRepresentation, jobject jQueryParamsMap, jobject jListener);
JNIEXPORT void JNICALL
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_post
Java_org_oic_simulator_clientcontroller_SimulatorRemoteResource_nativePost
(JNIEnv *env, jobject thiz, jstring jResourceInterface,
jobject jRepresentation, jobject jQueryParamsMap, jobject jListener);
......
......@@ -603,8 +603,20 @@ Java_org_oic_simulator_serviceprovider_SimulatorResourceServer_stopAutomation
throwSimulatorException(env, SIMULATOR_BAD_OBJECT, "No resource!");
return;
}
resource->stopUpdateAutomation(automationId);
try
{
resource->stopUpdateAutomation(automationId);
}
catch (InvalidArgsException &e)
{
throwInvalidArgsException(env, e.code(), e.what());
}
catch (...)
{
throwSimulatorException(env, SIMULATOR_ERROR, "Unknown Exception");
}
SIM_LOG(ILogger::INFO, "Automation has been forcibly stopped.")
}
......
......@@ -47,6 +47,10 @@ public class SimulatorManager {
public static SimulatorResourceServer createResource(String configPath,
IResourceModelChangedListener listener)
throws InvalidArgsException, SimulatorException {
if (configPath.isEmpty() || null == listener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
SimulatorResourceServer simulatorResourceServerObj;
simulatorResourceServerObj = SimulatorManagerNativeInterface
.createResource(configPath, listener);
......@@ -76,6 +80,10 @@ public class SimulatorManager {
public static SimulatorResourceServer[] createResource(String configPath,
int count, IResourceModelChangedListener listener)
throws InvalidArgsException, SimulatorException {
if (configPath.isEmpty() || count < 0 || null == listener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
SimulatorResourceServer[] simulatorResourceServers;
simulatorResourceServers = SimulatorManagerNativeInterface
.createResources(configPath, count, listener);
......
......@@ -24,6 +24,7 @@ import org.oic.simulator.NoSupportException;
import org.oic.simulator.OperationInProgressException;
import org.oic.simulator.SimulatorException;
import org.oic.simulator.SimulatorResourceModel;
import org.oic.simulator.SimulatorResult;
/**
* SimulatorRemoteResource represents a Resource running in the remote Simulator
......@@ -156,6 +157,10 @@ public class SimulatorRemoteResource {
public void get(Map<String, String> queryParamsMap,
IGetListener onGetListener) throws InvalidArgsException,
NoSupportException, SimulatorException {
if (null == onGetListener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
this.get(null, queryParamsMap, onGetListener);
}
......@@ -180,7 +185,17 @@ public class SimulatorRemoteResource {
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
public native void get(String resourceInterface,
public void get(String resourceInterface,
Map<String, String> queryParamsMap, IGetListener onGetListener)
throws InvalidArgsException, NoSupportException, SimulatorException {
if (resourceInterface.isEmpty() || null == onGetListener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
this.get(resourceInterface, queryParamsMap, onGetListener);
}
private native void nativeGet(String resourceInterface,
Map<String, String> queryParamsMap, IGetListener onGetListener)
throws InvalidArgsException, NoSupportException, SimulatorException;
......@@ -209,6 +224,10 @@ public class SimulatorRemoteResource {
public void put(SimulatorResourceModel representation,
Map<String, String> queryParamsMap, IPutListener onPutListener)
throws InvalidArgsException, NoSupportException, SimulatorException {
if (null == representation || null == onPutListener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
this.put(null, representation, queryParamsMap, onPutListener);
}
......@@ -236,7 +255,18 @@ public class SimulatorRemoteResource {
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
private native void put(String resourceInterface,
public void put(String resourceInterface,
SimulatorResourceModel representation,
Map<String, String> queryParamsMap, IPutListener onPutListener)
throws InvalidArgsException, NoSupportException, SimulatorException {
if (resourceInterface.isEmpty() || null == representation || null == onPutListener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
this.put(resourceInterface, representation, queryParamsMap, onPutListener);
}
private native void nativePut(String resourceInterface,
SimulatorResourceModel representation,
Map<String, String> queryParamsMap, IPutListener onPutListener)
throws InvalidArgsException, NoSupportException, SimulatorException;
......@@ -266,6 +296,10 @@ public class SimulatorRemoteResource {
public void post(SimulatorResourceModel representation,
Map<String, String> queryParamsMap, IPostListener onPostListener)
throws InvalidArgsException, NoSupportException, SimulatorException {
if (null == representation || null == onPostListener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
this.post(null, representation, queryParamsMap, onPostListener);
}
......@@ -293,7 +327,18 @@ public class SimulatorRemoteResource {
* @throws SimulatorException
* This exception will be thrown for other errors.
*/
public native void post(String resourceInterface,
public void post(String resourceInterface,
SimulatorResourceModel representation,
Map<String, String> queryParamsMap, IPostListener onPostListener)
throws InvalidArgsException, NoSupportException, SimulatorException {
if (resourceInterface.isEmpty() || null == representation || null == onPostListener)
throw new InvalidArgsException(
SimulatorResult.SIMULATOR_INVALID_PARAM.ordinal(),
"Parameter passed in invalid");
this.post(resourceInterface, representation, queryParamsMap, onPostListener);
}
private native void nativePost(String resourceInterface,
SimulatorResourceModel representation,
Map<String, String> queryParamsMap, IPostListener onPostListener)
throws InvalidArgsException, NoSupportException, SimulatorException;
......
......@@ -389,7 +389,7 @@ public class SimulatorResourceServer {
* This exception will be thrown for other errors.
*/
public native void stopAutomation(int automationId)
throws SimulatorException;
throws InvalidArgsException, SimulatorException;
/**
* API to remove an attribute from the simulated resource.
......
......@@ -311,6 +311,11 @@ void SimulatorResourceModel::updateAttributeFromAllowedValues(const std::string
void SimulatorResourceModel::removeAttribute(const std::string &attrName)
{
if (m_attributes.end() == m_attributes.find(attrName))
{
return;
}
m_attributes.erase(attrName);
return;
}
......
......@@ -105,12 +105,17 @@ void UpdateAutomationMngr::stop(int id)
{
m_resourceUpdationList[id]->stop();
m_resourceUpdationList.erase(m_resourceUpdationList.find(id));
return;
}
else if (m_attrUpdationList.end() != m_attrUpdationList.find(id))
{
m_attrUpdationList[id]->stop();
m_attrUpdationList.erase(m_attrUpdationList.find(id));
return;
}
//Throw InvalidArgsException
throw InvalidArgsException(SIMULATOR_INVALID_PARAM, "Invalid Automation Id!");
}
void UpdateAutomationMngr::stopAll()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment