From: spurthi.segu Date: Mon, 5 Oct 2015 14:19:17 +0000 (+0530) Subject: Added Junit test cases for Simulator Java APIs. X-Git-Tag: 1.2.0+RC1~934 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ef6e84e8b8d9eb2ed39a7dd1e463e88cb9054812;p=platform%2Fupstream%2Fiotivity.git Added Junit test cases for Simulator Java APIs. Change-Id: Iddfea7d5bfa43e86fa71697b6bd2a011774d9979 Signed-off-by: spurthi.segu Reviewed-on: https://gerrit.iotivity.org/gerrit/3501 Tested-by: jenkins-iotivity Reviewed-by: Uze Choi --- diff --git a/service/simulator/unittests/SimulatorTest/.classpath b/service/simulator/unittests/SimulatorTest/.classpath new file mode 100644 index 0000000..1966233 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/.classpath @@ -0,0 +1,11 @@ + + + + + + + + diff --git a/service/simulator/unittests/SimulatorTest/.codepro/deadCodeEntryPoints.xml b/service/simulator/unittests/SimulatorTest/.codepro/deadCodeEntryPoints.xml new file mode 100644 index 0000000..f88c24c --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/.codepro/deadCodeEntryPoints.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/service/simulator/unittests/SimulatorTest/.project b/service/simulator/unittests/SimulatorTest/.project new file mode 100644 index 0000000..3ca1ead --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/.project @@ -0,0 +1,17 @@ + + + SimulatorTest + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/GetListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/GetListener.java new file mode 100644 index 0000000..c421083 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/GetListener.java @@ -0,0 +1,36 @@ +package org.oic.simulator.clientcontroller.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.clientcontroller.IGetListener; + +public class GetListener implements IGetListener +{ + + private CountDownLatch lockObject; + private ListenerObject getListenerObject; + + public GetListener(CountDownLatch lockObject, ListenerObject getListenerObject) + { + this.lockObject = lockObject; + this.getListenerObject = getListenerObject; + } + + @Override + public void onGetCompleted(String uId, SimulatorResourceModel representation) + { + getListenerObject.setuId(uId); + getListenerObject.setRepresentation(representation); + + lockObject.countDown(); + } + + @Override + public void onGetFailed(Throwable ex) + { + getListenerObject.setEx(ex); + + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ListenerObject.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ListenerObject.java new file mode 100644 index 0000000..ad2bba6 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ListenerObject.java @@ -0,0 +1,41 @@ +package org.oic.simulator.clientcontroller.test; + +import org.oic.simulator.SimulatorResourceModel; + +public class ListenerObject +{ + + private String uId; + private SimulatorResourceModel representation; + private Throwable ex; + + public void setuId(String uId) + { + this.uId = uId; + } + + public String getuId() + { + return uId; + } + + public void setRepresentation(SimulatorResourceModel representation) + { + this.representation = representation; + } + + public SimulatorResourceModel getRepresentation() + { + return representation; + } + + public void setEx(Throwable ex) + { + this.ex = ex; + } + + public Throwable getEx() + { + return ex; + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ObserveListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ObserveListener.java new file mode 100644 index 0000000..72c08e7 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ObserveListener.java @@ -0,0 +1,36 @@ +package org.oic.simulator.clientcontroller.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.clientcontroller.IObserveListener; + +public class ObserveListener implements IObserveListener +{ + + private CountDownLatch lockObject; + private ObserveListenerObject observeListenerObject; + + public ObserveListener(CountDownLatch lockObject, ObserveListenerObject observeListenerObject) + { + this.lockObject = lockObject; + this.observeListenerObject = observeListenerObject; + } + + @Override + public void onObserveCompleted(String uId, SimulatorResourceModel representation, int sequenceNumber) + { + observeListenerObject.setuId(uId); + observeListenerObject.setRepresentation(representation); + observeListenerObject.setSequenceNumber(sequenceNumber); + + lockObject.countDown(); + } + + @Override + public void onObserveFailed(Throwable ex) + { + observeListenerObject.setEx(ex); + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ObserveListenerObject.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ObserveListenerObject.java new file mode 100644 index 0000000..48edc47 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/ObserveListenerObject.java @@ -0,0 +1,52 @@ +package org.oic.simulator.clientcontroller.test; + +import org.oic.simulator.SimulatorResourceModel; + +public class ObserveListenerObject +{ + + private String uId; + private SimulatorResourceModel representation; + private int sequenceNumber; + private Throwable ex; + + public void setuId(String uId) + { + this.uId = uId; + } + + public String getuId() + { + return uId; + } + + public void setRepresentation(SimulatorResourceModel representation) + { + this.representation = representation; + } + + public SimulatorResourceModel getRepresentation() + { + return representation; + } + + public void setSequenceNumber(int sequenceNumber) + { + this.sequenceNumber = sequenceNumber; + } + + public int getSequenceNumber() + { + return sequenceNumber; + } + + public void setEx(Throwable ex) + { + this.ex = ex; + } + + public Throwable getEx() + { + return ex; + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/PostListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/PostListener.java new file mode 100644 index 0000000..8a4b394 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/PostListener.java @@ -0,0 +1,36 @@ +package org.oic.simulator.clientcontroller.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.clientcontroller.IPostListener; + +public class PostListener implements IPostListener +{ + + private CountDownLatch lockObject; + private ListenerObject getListenerObject; + + public PostListener(CountDownLatch lockObject, ListenerObject getListenerObject) + { + this.lockObject = lockObject; + this.getListenerObject = getListenerObject; + } + + @Override + public void onPostCompleted(String uId, SimulatorResourceModel representation) + { + getListenerObject.setuId(uId); + getListenerObject.setRepresentation(representation); + + lockObject.countDown(); + } + + @Override + public void onPostFailed(Throwable ex) + { + getListenerObject.setEx(ex); + + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/PutListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/PutListener.java new file mode 100644 index 0000000..1ecd076 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/PutListener.java @@ -0,0 +1,36 @@ +package org.oic.simulator.clientcontroller.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.clientcontroller.IPutListener; + +public class PutListener implements IPutListener +{ + + private CountDownLatch lockObject; + private ListenerObject listenerObject; + + public PutListener(CountDownLatch lockObject, ListenerObject listenerObject) + { + this.lockObject = lockObject; + this.listenerObject = listenerObject; + } + + @Override + public void onPutCompleted(String uId, SimulatorResourceModel representation) + { + listenerObject.setuId(uId); + listenerObject.setRepresentation(representation); + + lockObject.countDown(); + } + + @Override + public void onPutFailed(Throwable ex) + { + listenerObject.setEx(ex); + + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/SimulatorRemoteResourceTest.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/SimulatorRemoteResourceTest.java new file mode 100644 index 0000000..59b2f61 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/SimulatorRemoteResourceTest.java @@ -0,0 +1,909 @@ +package org.oic.simulator.clientcontroller.test; + +import java.util.HashMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.oic.simulator.SimulatorException; +import org.oic.simulator.SimulatorManager; +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.clientcontroller.SimulatorObserveType; +import org.oic.simulator.clientcontroller.SimulatorRemoteResource; +import org.oic.simulator.clientcontroller.SimulatorVerificationType; +import org.oic.simulator.serviceprovider.SimulatorResourceServer; +import org.oic.simulator.test.FindResourceListener; +import org.oic.simulator.test.ResourceModelChangeListener; +import org.oic.simulator.test.ResourceModelObject; +import org.oic.simulator.test.SimulatorRemoteResourceObject; + +public class SimulatorRemoteResourceTest extends TestCase +{ + + private static final String CONFIG_PATH = "./ramls/simple-light.raml"; + // private static final String RESOURCE_TYPE = "oic.light"; + + private CountDownLatch lockObject; + private ResourceModelObject resourceModelObject; + private ResourceModelChangeListener resourceModelChangeListener; + + private SimulatorRemoteResourceObject simulatorRemoteResourceObject; + private SimulatorRemoteResource simulatorRemoteResource; + + private SimulatorResourceServer simulatorResourceServer; + + private FindResourceListener findResourceListener; + + 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 = new CountDownLatch(1); + resourceModelObject = new ResourceModelObject(); + resourceModelChangeListener = new ResourceModelChangeListener(resourceModelObject); + + simulatorResourceServer = SimulatorManager.createResource(CONFIG_PATH, resourceModelChangeListener); + + simulatorRemoteResourceObject = new SimulatorRemoteResourceObject(); + + findResourceListener = new FindResourceListener(lockObject, simulatorRemoteResourceObject); + + SimulatorManager.findResource(findResourceListener); + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + simulatorRemoteResource = simulatorRemoteResourceObject.getSimulatorRemoteResource(); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + + SimulatorManager.deleteResource(simulatorResourceServer); + + lockObject = null; + resourceModelObject = null; + resourceModelChangeListener = null; + + simulatorRemoteResourceObject = null; + findResourceListener = null; + + simulatorRemoteResource = null; + } + + public void testGetUri_P01() + { + assertNotNull(simulatorRemoteResource.getUri()); + } + + public void testGetIsObservable_P01() + { + assertTrue(simulatorRemoteResource.getIsObservable()); + } + + public void testGetConnectivityType_P01() + { + assertNotNull(simulatorRemoteResource.getConnectivityType()); + } + + public void testGetResourceTypes_P01() + { + assertTrue(simulatorRemoteResource.getResourceTypes() != null && simulatorRemoteResource.getResourceTypes().size() > 0); + } + + public void testGetResourceInterfaces_P01() + { + assertTrue(simulatorRemoteResource.getResourceInterfaces() != null && simulatorRemoteResource.getResourceInterfaces().size() > 0); + } + + public void testGetId_P01() + { + assertNotNull(simulatorRemoteResource.getId()); + } + + //TODO call back not coming + public void testStartObserve_P01() + { + boolean result = true; + HashMap queryParamMap = new HashMap(); + + lockObject = new CountDownLatch(1); + + ObserveListenerObject observeListenerObject = new ObserveListenerObject(); + ObserveListener observeListener = new ObserveListener(lockObject, observeListenerObject); + + try + { + simulatorRemoteResource.startObserve(SimulatorObserveType.OBSERVE, queryParamMap, observeListener); + simulatorResourceServer.addAttributeString("test", "test"); + } + catch (Exception e1) + { + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(observeListenerObject.getRepresentation() != null && result); + + try + { + simulatorRemoteResource.stopObserve(); + } + catch (Exception e) + { + e.printStackTrace(); + } + + observeListenerObject = null; + observeListener = null; + } + + //TODO call back not coming + public void testStopObserve_P01() + { + boolean result = true; + + HashMap queryParamMap = new HashMap(); + lockObject = new CountDownLatch(1); + ObserveListenerObject observeListenerObject = new ObserveListenerObject(); + ObserveListener observeListener = new ObserveListener(lockObject, observeListenerObject); + + try + { + simulatorRemoteResource.startObserve(SimulatorObserveType.OBSERVE, queryParamMap, observeListener); + simulatorResourceServer.addAttributeString("test", "test"); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + result = result && observeListenerObject.getRepresentation() != null; + + try + { + simulatorRemoteResource.stopObserve(); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + assertTrue(result); + + observeListenerObject = null; + observeListener = null; + } + + public void testGetQueryParamGetListener_P01() + { + boolean result = true; + lockObject = new CountDownLatch(1); + HashMap queryParamMap = new HashMap(); + + ListenerObject getListenerObject = new ListenerObject(); + GetListener getListener = new GetListener(lockObject, getListenerObject); + + try + { + simulatorRemoteResource.get(queryParamMap, getListener); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + if(getListenerObject.getEx() == null) + { + try + { + result = result && getListenerObject.getRepresentation() != null && getListenerObject.getRepresentation().size() > 0; + } + catch (SimulatorException e) + { + result = false; + e.printStackTrace(); + } + } + else + result = false; + + assertTrue(result); + } + + public void testGetStringMapOfStringStringIGetListener_P01() + { + boolean result = true; + lockObject = new CountDownLatch(1); + HashMap queryParamMap = new HashMap(); + + String resourceInterface = "oic.if.baseline"; + + ListenerObject getListenerObject = new ListenerObject(); + GetListener getListener = new GetListener(lockObject, getListenerObject); + + try + { + simulatorRemoteResource.get(resourceInterface, queryParamMap, getListener); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + if(getListenerObject.getEx() == null) + { + try + { + result = result && getListenerObject.getRepresentation() != null && getListenerObject.getRepresentation().size() > 0; + } + catch (SimulatorException e) + { + result = false; + e.printStackTrace(); + } + } + else + result = false; + + assertTrue(result); + } + + public void testPut_P01() + { + boolean result = true; + SimulatorResourceModel model = new SimulatorResourceModel(); + + lockObject = new CountDownLatch(1); + + ListenerObject listenerObject = null; + + try + { + listenerObject = new ListenerObject(); + PutListener putListener = new PutListener(lockObject, listenerObject); + + model.addAttributeInt("intensity", 5); + model.addAttributeString("power", "off"); + + simulatorRemoteResource.put(model, null, putListener); + } + catch(Exception e) + { + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && listenerObject != null && listenerObject.getRepresentation() != null && listenerObject.getuId() != null); + } + + /** + * model as null + */ + //TODO crashing + /*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); + }*/ + + //TODO fail + public void testPost_P01() + { + boolean result = true; + ListenerObject listenerObject = null; + lockObject = new CountDownLatch(1); + + SimulatorResourceModel model = new SimulatorResourceModel(); + try + { + model.addAttributeInt("intensity", 8); + //model.addAttributeString("power", "off"); + + listenerObject = new ListenerObject(); + PostListener postListener = new PostListener(lockObject, listenerObject); + + simulatorRemoteResource.post(model, null, postListener); + } + catch(Exception e) + { + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && listenerObject != null && listenerObject.getRepresentation() != null && listenerObject.getuId() != null); + } + + /** + * Model is set to null + */ + //TODO crash + /*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); + }*/ + + //TODO failign + public void testGet_P01() + { + boolean result = true; + ListenerObject listenerObject = null; + lockObject = new CountDownLatch(1); + + try + { + listenerObject = new ListenerObject(); + GetListener onGetListener = new GetListener(lockObject, listenerObject); + + String resInterface = simulatorRemoteResource.getResourceInterfaces().get(0); + + if(resInterface == null) + simulatorRemoteResource.get(resInterface, null, onGetListener); + else + result = false; + } + catch(Exception e) + { + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && listenerObject != null && listenerObject.getRepresentation() != null && listenerObject.getuId() != null); + } + + /** + * null resInterface + */ + //TODO failing + public void testGet_N01() + { + boolean result = false; + ListenerObject listenerObject = null; + lockObject = new CountDownLatch(1); + + try + { + listenerObject = new ListenerObject(); + GetListener onGetListener = new GetListener(lockObject, listenerObject); + + simulatorRemoteResource.get(null, null, onGetListener); + result = false; + } + catch(Exception e) + { + result = true; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result); + } + + /** + * null listener + */ + //TODO failing + public void testGet_N02() + { + boolean result = false; + try + { + String resInterface = simulatorRemoteResource.getResourceInterfaces().get(0); + + if(resInterface == null) + simulatorRemoteResource.get(resInterface, null, null); + else + result = false; + } + catch(Exception e) + { + result = true; + } + + assertTrue(result); + } + + /** + * all params as null + */ + public void testGet_N03() + { + boolean result = false; + try + { + simulatorRemoteResource.get(null, null, null); + result = false; + } + catch(Exception e) + { + result = true; + } + + assertTrue(result); + } + + public void testGetWithoutResInterface_P01() + { + boolean result = true; + ListenerObject listenerObject = null; + lockObject = new CountDownLatch(1); + + try + { + listenerObject = new ListenerObject(); + GetListener onGetListener = new GetListener(lockObject, listenerObject); + + simulatorRemoteResource.get(null, onGetListener); + } + catch(Exception e) + { + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && listenerObject != null && listenerObject.getRepresentation() != null && listenerObject.getuId() != null); + } + + /** + * null listener + */ + public void testGetWithoutResInterface_N01() + { + boolean result = false; + try + { + simulatorRemoteResource.get(null, null); + result = false; + } + catch(Exception e) + { + result = true; + } + + assertTrue(result); + } + + //TODO Resource does not support this request type! + public void testSetConfigInfo_P01() + { + boolean result = true; + try + { + simulatorRemoteResource.setConfigInfo(CONFIG_PATH); + } + catch (Exception e2) + { + e2.printStackTrace(); + result = false; + } + + lockObject = new CountDownLatch(1); + VerifyListenerObject verifyListenerObject = new VerifyListenerObject(); + VerifyListener verifyListener = new VerifyListener(lockObject, verifyListenerObject); + + try + { + simulatorRemoteResource.startVerification(SimulatorVerificationType.RQ_TYPE_POST, verifyListener); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.MILLISECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && verifyListenerObject.getWhichOne().equals("started")&& + verifyListenerObject.getuId() != null && + verifyListenerObject.getId() != -1); + } + + /** + * Passing empty + */ + public void testSetConfigInfo_N01() + { + boolean result = true; + try + { + simulatorRemoteResource.setConfigInfo(""); + result = false; + } + catch (Exception e2) + { + result = true; + } + + assertTrue(result); + } + + //TODO Resource does not support this request type! + public void testStartVerification_P01() + { + boolean result = true; + lockObject = new CountDownLatch(1); + try + { + simulatorRemoteResource.setConfigInfo(CONFIG_PATH); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + VerifyListenerObject verifyListenerObject = new VerifyListenerObject(); + VerifyListener verifyListener = new VerifyListener(lockObject, verifyListenerObject); + try + { + result = result && simulatorRemoteResource.startVerification(SimulatorVerificationType.RQ_TYPE_POST, verifyListener) != -1; + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.MILLISECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && verifyListenerObject.getWhichOne().equals("started") && + verifyListenerObject.getuId() != null && + verifyListenerObject.getId() != -1); + } + + //TODO Resource does not support this request type! + public void testStartVerification_P02() + { + boolean result = true; + lockObject = new CountDownLatch(1); + try + { + simulatorRemoteResource.setConfigInfo(CONFIG_PATH); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + VerifyListenerObject verifyListenerObject = new VerifyListenerObject(); + VerifyListener verifyListener = new VerifyListener(lockObject, verifyListenerObject); + try + { + result = result && simulatorRemoteResource.startVerification(SimulatorVerificationType.RQ_TYPE_PUT, verifyListener) != -1; + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.MILLISECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && verifyListenerObject.getWhichOne().equals("started") && + verifyListenerObject.getuId() != null && + verifyListenerObject.getId() != -1); + } + + //TODO Resource does not support this request type! + public void testStartVerification_P03() + { + boolean result = true; + lockObject = new CountDownLatch(1); + try + { + simulatorRemoteResource.setConfigInfo(CONFIG_PATH); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + VerifyListenerObject verifyListenerObject = new VerifyListenerObject(); + VerifyListener verifyListener = new VerifyListener(lockObject, verifyListenerObject); + try + { + result = result && simulatorRemoteResource.startVerification(SimulatorVerificationType.RQ_TYPE_GET, verifyListener) != -1; + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.MILLISECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && verifyListenerObject.getWhichOne().equals("started") && + verifyListenerObject.getuId() != null && + verifyListenerObject.getId() != -1); + } + + /** + * setting listener to null + */ + //TODO Resource does not support this request type! + public void testStartVerification_N01() + { + boolean result = true; + try + { + simulatorRemoteResource.setConfigInfo(CONFIG_PATH); + } + catch (Exception e) + { + e.printStackTrace(); + result = false; + } + + try + { + result = result && (simulatorRemoteResource.startVerification(SimulatorVerificationType.RQ_TYPE_POST, null) == -1); + result = false; + } + catch (Exception e) + { + result = true; + } + assertTrue(result); + } + + //TODO Resource does not support this request type! + public void testStopVerification_P01() + { + boolean result = true; + lockObject = new CountDownLatch(2); + try + { + simulatorRemoteResource.setConfigInfo(CONFIG_PATH); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + VerifyListenerObject verifyListenerObject = new VerifyListenerObject(); + VerifyListener verifyListener = new VerifyListener(lockObject, verifyListenerObject); + try + { + result = result && simulatorRemoteResource.startVerification(SimulatorVerificationType.RQ_TYPE_POST, verifyListener) != -1; + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.MILLISECONDS); + } + catch (InterruptedException e) + { + } + + result = result && verifyListenerObject.getWhichOne().equals("started") && + verifyListenerObject.getuId() != null && + verifyListenerObject.getId() != -1; + + try + { + simulatorRemoteResource.stopVerification(verifyListenerObject.getId()); + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + + lockObject.await(100, TimeUnit.MILLISECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && verifyListenerObject.getWhichOne().equals("aborted") && + verifyListenerObject.getuId() != null && + verifyListenerObject.getId() != -1); + } + + /** + * Random id. This is just to check the crash + */ + //TODO Resource does not support this request type! + public void testStopVerification_N01() + { + boolean result = true; + lockObject = new CountDownLatch(1); + try + { + simulatorRemoteResource.setConfigInfo(CONFIG_PATH); + } + catch (Exception e2) + { + result = false; + e2.printStackTrace(); + } + + VerifyListenerObject verifyListenerObject = new VerifyListenerObject(); + VerifyListener verifyListener = new VerifyListener(lockObject, verifyListenerObject); + try + { + result = result && simulatorRemoteResource.startVerification(SimulatorVerificationType.RQ_TYPE_POST, verifyListener) != -1; + } + catch (Exception e1) + { + e1.printStackTrace(); + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + result = result && verifyListenerObject.getWhichOne().equals("started") && + verifyListenerObject.getuId() != null && + verifyListenerObject.getId() != -1; + + try + { + simulatorRemoteResource.stopVerification(123435); + result = false; + } + catch (Exception e) + { + result = true; + } + + assertTrue(result); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/VerifyListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/VerifyListener.java new file mode 100644 index 0000000..2f39b3f --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/VerifyListener.java @@ -0,0 +1,48 @@ +package org.oic.simulator.clientcontroller.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.clientcontroller.IVerificationListener; + +public class VerifyListener implements IVerificationListener +{ + + private CountDownLatch lockObject; + private VerifyListenerObject verifyListenerObject; + + public VerifyListener(CountDownLatch lockObject, VerifyListenerObject verifyListenerObject) + { + this.lockObject = lockObject; + this.verifyListenerObject = verifyListenerObject; + } + + @Override + public void onVerificationStarted(String uId, int id) + { + verifyListenerObject.setId(id); + verifyListenerObject.setuId(uId); + verifyListenerObject.setWhichOne("started"); + + lockObject.countDown(); + } + + @Override + public void onVerificationAborted(String uId, int id) + { + verifyListenerObject.setId(id); + verifyListenerObject.setuId(uId); + verifyListenerObject.setWhichOne("aborted"); + + lockObject.countDown(); + } + + @Override + public void onVerificationCompleted(String uId, int id) + { + verifyListenerObject.setId(id); + verifyListenerObject.setuId(uId); + verifyListenerObject.setWhichOne("completed"); + + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/VerifyListenerObject.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/VerifyListenerObject.java new file mode 100644 index 0000000..4ee3039 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/clientcontroller/test/VerifyListenerObject.java @@ -0,0 +1,39 @@ +package org.oic.simulator.clientcontroller.test; + +public class VerifyListenerObject +{ + + private String uId; + private int id; + private String whichOne; + + public void setuId(String uId) + { + this.uId = uId; + } + + public String getuId() + { + return uId; + } + + public void setId(int id) + { + this.id = id; + } + + public int getId() + { + return id; + } + + public void setWhichOne(String whichOne) + { + this.whichOne = whichOne; + } + + public String getWhichOne() + { + return whichOne; + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/AutomationListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/AutomationListener.java new file mode 100644 index 0000000..dbe9490 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/AutomationListener.java @@ -0,0 +1,27 @@ +package org.oic.simulator.serviceprovider.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.IAutomation; + +public class AutomationListener implements IAutomation +{ + + private CountDownLatch lockObject; + private AutomationObject automationObject; + + public AutomationListener(CountDownLatch lockObject, AutomationObject automationObject) + { + this.lockObject = lockObject; + this.automationObject = automationObject; + } + + @Override + public void onAutomationComplete(String resourceURI, int automationId) + { + automationObject.setAutomationId(automationId); + automationObject.setResourceURI(resourceURI); + + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/AutomationObject.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/AutomationObject.java new file mode 100644 index 0000000..2f13072 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/AutomationObject.java @@ -0,0 +1,28 @@ +package org.oic.simulator.serviceprovider.test; + +public class AutomationObject +{ + + private String resourceURI; + private int automationId; + + public void setResourceURI(String resourceURI) + { + this.resourceURI = resourceURI; + } + + public String getResourceURI() + { + return resourceURI; + } + + public void setAutomationId(int automationId) + { + this.automationId = automationId; + } + + public int getAutomationId() + { + return automationId; + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/Observer.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/Observer.java new file mode 100644 index 0000000..4853ab0 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/Observer.java @@ -0,0 +1,29 @@ +package org.oic.simulator.serviceprovider.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.serviceprovider.IObserver; +import org.oic.simulator.serviceprovider.ObserverInfo; + +public class Observer implements IObserver +{ + + private CountDownLatch lockObject; + private ObserverObject observerObject; + + public Observer(CountDownLatch lockObject, ObserverObject observerObject) + { + this.lockObject = lockObject; + this.observerObject = observerObject; + } + + @Override + public void onObserverChanged(String resourceURI, int state, ObserverInfo observer) + { + observerObject.setState(state); + observerObject.setResourceURI(resourceURI); + observerObject.setObserver(observer); + + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/ObserverObject.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/ObserverObject.java new file mode 100644 index 0000000..6653772 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/ObserverObject.java @@ -0,0 +1,41 @@ +package org.oic.simulator.serviceprovider.test; + +import org.oic.simulator.serviceprovider.ObserverInfo; + +public class ObserverObject +{ + + private String resourceURI; + private int state; + private ObserverInfo observer; + + public void setResourceURI(String resourceURI) + { + this.resourceURI = resourceURI; + } + + public String getResourceURI() + { + return resourceURI; + } + + public void setState(int state) + { + this.state = state; + } + + public int getState() + { + return state; + } + + public void setObserver(ObserverInfo observer) + { + this.observer = observer; + } + + public ObserverInfo getObserver() + { + return observer; + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/SimlatorResourceServerTest.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/SimlatorResourceServerTest.java new file mode 100644 index 0000000..381453d --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/serviceprovider/test/SimlatorResourceServerTest.java @@ -0,0 +1,934 @@ +package org.oic.simulator.serviceprovider.test; + +import java.util.Vector; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; + +import org.oic.simulator.InvalidArgsException; +import org.oic.simulator.ResourceAttribute; +import org.oic.simulator.SimulatorException; +import org.oic.simulator.SimulatorManager; +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.serviceprovider.AutomationType; +import org.oic.simulator.serviceprovider.SimulatorResourceServer; +import org.oic.simulator.test.ResourceModelChangeListener; +import org.oic.simulator.test.ResourceModelObject; + +public class SimlatorResourceServerTest extends TestCase +{ + + private static final String CONFIG_PATH = "./ramls/simple-light.raml"; + + private static final String KEY = "testkey"; + + private CountDownLatch lockObject; + private ResourceModelObject resourceModelObject; + private ResourceModelChangeListener resourceModelChangeListener; + + private SimulatorResourceServer simulatorResourceServer; + + static + { + System.loadLibrary("SimulatorManager"); + System.loadLibrary("RamlParser"); + System.loadLibrary("YamlParser"); + System.loadLibrary("oc"); + System.loadLibrary("oc_logger"); + System.loadLibrary("octbstack"); + } + + protected void setUp() throws Exception + { + super.setUp(); + lockObject= new CountDownLatch(1); + resourceModelObject = new ResourceModelObject(); + resourceModelChangeListener = new ResourceModelChangeListener(resourceModelObject); + simulatorResourceServer = SimulatorManager.createResource(CONFIG_PATH, resourceModelChangeListener); + } + + protected void tearDown() throws Exception + { + super.tearDown(); + + SimulatorManager.deleteResource(simulatorResourceServer); + + lockObject = null; + resourceModelObject = null; + resourceModelChangeListener = null; + + simulatorResourceServer = null; + } + + public void testGetURI_P01() + { + assertNotNull(simulatorResourceServer.getURI()); + } + + public void testGetResourceType_P01() + { + assertNotNull(simulatorResourceServer.getResourceType()); + } + + public void testGetInterfaceType_P01() + { + assertNotNull(simulatorResourceServer.getInterfaceType()); + } + + public void testGetModel_P01() + { + boolean result = false; + + try + { + if(simulatorResourceServer.getModel() != null && simulatorResourceServer.getModel().size() > 0) + result = true; + } + catch (InvalidArgsException e) + { + e.printStackTrace(); + } + catch (SimulatorException e) + { + e.printStackTrace(); + } + + assertTrue(result); + } + + public void testAddAttributeInteger_P01() + { + try + { + simulatorResourceServer.addAttributeInteger(KEY, 2); + } + catch (Exception e) + { + e.printStackTrace(); + } + assertEquals(Integer.parseInt(getValue(KEY) + ""), 2); + } + + public void testAddAttributeDouble_P01() + { + try + { + simulatorResourceServer.addAttributeDouble(KEY, 4.0); + } + catch (Exception e) + { + e.printStackTrace(); + } + assertEquals(Double.parseDouble(getValue(KEY) + ""), 4.0); + } + + //TODO failing + public void testAddAttributeBoolean_P01() + { + try + { + simulatorResourceServer.addAttributeBoolean(KEY, true); + } + catch (Exception e) + { + e.printStackTrace(); + } + assertEquals(Boolean.parseBoolean(getValue(KEY) + ""), true); + } + + public void testaddAttributeString_P01() + { + try + { + simulatorResourceServer.addAttributeString(KEY, "test"); + } + catch (Exception e) + { + e.printStackTrace(); + } + assertEquals(getValue(KEY) + "", "test"); + } + + public void testUpdateAttributeInteger_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeInteger(KEY, 10); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 10; + + try + { + simulatorResourceServer.updateAttributeInteger(KEY, 12); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + result = result && Integer.parseInt(getValue(KEY) + "") == 12; + + assertTrue(result); + } + + public void testUpdateAttributeDouble_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeDouble(KEY, 22.0); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Double.parseDouble(getValue(KEY) + "") == 22.0; + + try + { + simulatorResourceServer.updateAttributeDouble(KEY, 25.3); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Double.parseDouble(getValue(KEY) + "") == 25.3; + + assertTrue(result); + } + + //TODO failing + public void testUpdateAttributeBoolean_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeBoolean(KEY, true); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Boolean.parseBoolean(getValue(KEY) + "")==true; + + try + { + simulatorResourceServer.updateAttributeBoolean(KEY, false); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && !Boolean.parseBoolean(getValue(KEY) + ""); + + assertTrue(result); + } + + public void testupdateAttributeString_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeString(KEY, "old"); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && getValue(KEY).equals("old"); + + try + { + simulatorResourceServer.updateAttributeString(KEY, "new"); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && getValue(KEY).equals("new"); + + assertTrue(result); + } + + public void testSetRange_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeInteger(KEY, 10); + simulatorResourceServer.setRange(KEY, 1, 12); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 10; + + try + { + simulatorResourceServer.updateAttributeInteger(KEY, 3); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 3; + + assertTrue(result); + } + + /** + * Try to set the value out of range + */ + //TODO failing + public void testSetRange_N01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeInteger(KEY, 10); + simulatorResourceServer.setRange(KEY, 1, 12); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 10; + + try + { + simulatorResourceServer.updateAttributeInteger(KEY, 13); + result = false; + } + catch (Exception e) + { + result = true; + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 10; + + assertTrue(result); + } + + //TODO failing + public void testSetAllowedValuesInteger_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeInteger(KEY, 10); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + Vector values = new Vector(); + values.add(1); + values.add(10); + values.add(20); + values.add(50); + + try + { + simulatorResourceServer.setAllowedValuesInteger(KEY, values); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 10; + + try + { + simulatorResourceServer.updateAttributeInteger(KEY, 20); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 20; + + assertTrue(result); + } + + /** + * Try setting with out of range + */ + //TODO failing + public void testSetAllowedValuesInteger_N01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeInteger(KEY, 10); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + Vector values = new Vector(); + values.add(1); + values.add(10); + values.add(20); + values.add(50); + + try + { + simulatorResourceServer.setAllowedValuesInteger(KEY, values); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 10; + + try + { + simulatorResourceServer.updateAttributeInteger(KEY, 2); + result = false; + } + catch (Exception e) + { + result = true; + } + + result = result && Integer.parseInt(getValue(KEY) + "") == 10; + + assertTrue(result); + } + + /** + * Try setting values multiple times + */ + //TODO failing + public void testSetAllowedValuesDouble_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeDouble(KEY, 11.5); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + Vector values = new Vector(); + values.add(11.5); + values.add(10.5); + values.add(20.5); + values.add(50.5); + + try + { + simulatorResourceServer.setAllowedValuesDouble(KEY, values); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Double.parseDouble(getValue(KEY) + "") == 11.5; + + try + { + simulatorResourceServer.updateAttributeDouble(KEY, 10.5); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Double.parseDouble(getValue(KEY) + "") == 10.5; + + assertTrue(result); + } + + /** + * Try setting with out of range + */ + //TODO failing + public void testSetAllowedValuesDouble_N01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeDouble(KEY, 10.5); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + Vector values = new Vector(); + values.add(11.5); + values.add(10.5); + values.add(20.5); + values.add(50.5); + + try + { + simulatorResourceServer.setAllowedValuesDouble(KEY, values); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && Double.parseDouble(getValue(KEY) + "") == 10.5; + + try + { + simulatorResourceServer.updateAttributeDouble(KEY, 2.2); + result = false; + } + catch (Exception e) + { + result = true; + } + + result = result && Double.parseDouble(getValue(KEY) + "") == 10.5; + + assertTrue(result); + } + + //TODO failing + public void testsetAllowedValuesString_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeString(KEY, "mon"); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + Vector values = new Vector(); + values.add("mon"); + values.add("tue"); + values.add("wed"); + + try + { + simulatorResourceServer.setAllowedValuesString(KEY, values); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && getValue(KEY).equals("mon"); + + try + { + simulatorResourceServer.updateAttributeString(KEY, "tue"); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && getValue(KEY).equals("tue"); + + assertTrue(result); + } + + /** + * Set the value that is not in allowed values + */ + //TODO failing + public void testsetAllowedValuesString_N01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeString(KEY, "mon"); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + Vector values = new Vector(); + values.add("mon"); + values.add("tue"); + values.add("wed"); + + try + { + simulatorResourceServer.setAllowedValuesString(KEY, values); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && getValue(KEY).equals("mon"); + + try + { + simulatorResourceServer.updateAttributeString(KEY, "thu"); + result = false; + } + catch (Exception e) + { + result = true; + } + + result = result && getValue(KEY).equals("mon"); + + assertTrue(result); + } + + public void testRemoveAttribute_P01() + { + boolean result = true; + + try + { + simulatorResourceServer.addAttributeString(KEY, "fri"); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + result = result && getValue(KEY).equals("fri"); + + try + { + simulatorResourceServer.removeAttribute(KEY); + result = result && !simulatorResourceServer.getModel().getAttributes().containsKey(KEY); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + assertTrue(result); + } + + /** + * Try removing the attribute thats not present + */ + //TODO failing + public void testRemoveAttribute_N01() + { + boolean result = false; + + try + { + simulatorResourceServer.removeAttribute("something"); + } + catch (Exception e) + { + result = true; + } + + assertTrue(result); + } + + /** + * Try removing when null is passed + */ + public void testRemoveAttribute_N02() + { + boolean result = false; + + try + { + simulatorResourceServer.removeAttribute(null); + } + catch (Exception e) + { + result = true; + } + + assertTrue(result); + } + + /** + * Try removing when attribute is empty + */ + //TODO failing + public void testRemoveAttribute_N03() + { + boolean result = false; + + try + { + simulatorResourceServer.removeAttribute(""); + } + catch (Exception e) + { + result = true; + } + + assertTrue(result); + } + + //TODO failing + public void testStartResourceAutomation_P01() + { + boolean result = true; + lockObject = new CountDownLatch(1); + AutomationObject automationObject = new AutomationObject(); + AutomationListener automationListener = new AutomationListener(lockObject, automationObject); + int id = 0; + try + { + id = simulatorResourceServer.startResourceAutomation(AutomationType.NORMAL, automationListener); + } + catch (Exception e) + { + result = false; + e.printStackTrace(); + } + + try + { + lockObject.await(10,TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + + assertTrue(result && automationObject.getResourceURI() != null && automationObject.getAutomationId() != -1 && id != -1); + + try + { + simulatorResourceServer.stopAutomation(id); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * null listener + */ + //TODO failing + public void testStartResourceAutomation_N01() + { + boolean result = true; + int id = 0; + try + { + id = simulatorResourceServer.startResourceAutomation(AutomationType.NORMAL, null); + } + catch (Exception e) + { + result = false; + } + assertTrue(result && id == -1); + } + + //TODO failing + public void testStartAttributeAutomation_P01() + { + boolean result = true; + lockObject = new CountDownLatch(1); + AutomationObject automationObject = new AutomationObject(); + AutomationListener automationListener = new AutomationListener(lockObject, automationObject); + int id = 0; + try + { + id = simulatorResourceServer.startAttributeAutomation(simulatorResourceServer.getModel().getAttributes().get(0).getName(), + AutomationType.NORMAL, automationListener); + } + catch (Exception e) + { + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + assertTrue(result && automationObject.getResourceURI() != null && automationObject.getAutomationId() != -1 && id != -1); + + try + { + simulatorResourceServer.stopAutomation(id); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * null listener + */ + public void testStartAttributeAutomation_N01() + { + boolean result = false; + int id = 0; + try + { + id = simulatorResourceServer.startAttributeAutomation(simulatorResourceServer.getModel().getAttributes().get(0).getName(), + AutomationType.NORMAL, null); + result = false; + } + catch (Exception e) + { + result = true; + } + + assertTrue(result && id != -1); + } + + //TODO failing + public void testStopAutomation_P01() + { + boolean result = true; + + lockObject = new CountDownLatch(1); + + AutomationObject automationObject = new AutomationObject(); + AutomationListener automationListener = new AutomationListener(lockObject, automationObject); + + int id = 0; + try + { + id = simulatorResourceServer.startResourceAutomation(AutomationType.NORMAL, automationListener); + } + catch(Exception e) + { + result = false; + } + + try + { + lockObject.await(10, TimeUnit.SECONDS); + } + catch (InterruptedException e) + { + } + + result = result && automationObject.getResourceURI() != null && automationObject.getAutomationId() != -1 && id != -1; + + try + { + simulatorResourceServer.stopAutomation(id); + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + /** + * checking for crash + * random id + */ + //TODO failing + public void testStopAutomation_N01() + { + boolean result = false; + try + { + simulatorResourceServer.stopAutomation(144353544); + } + catch (Exception e) + { + result = true; + e.printStackTrace(); + } + assertTrue(result); + } + + private Object getValue(Object key) + { + SimulatorResourceModel simulatorResourceModel = null; + try + { + simulatorResourceModel = simulatorResourceServer.getModel(); + } + catch (Exception e) + { + e.printStackTrace(); + } + + ResourceAttribute resourceAttribute = null; + try + { + resourceAttribute = simulatorResourceModel.getAttributes().get(key); + } + catch (SimulatorException e) + { + e.printStackTrace(); + } + return resourceAttribute.getValue(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/FindResourceListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/FindResourceListener.java new file mode 100644 index 0000000..ba840b0 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/FindResourceListener.java @@ -0,0 +1,27 @@ +package org.oic.simulator.test; + +import java.util.concurrent.CountDownLatch; + +import org.oic.simulator.clientcontroller.IFindResourceListener; +import org.oic.simulator.clientcontroller.SimulatorRemoteResource; + +public class FindResourceListener implements IFindResourceListener +{ + + private CountDownLatch lockObject; + private SimulatorRemoteResourceObject simulatorRemoteResource; + + public FindResourceListener(CountDownLatch lockObject, SimulatorRemoteResourceObject simulatorRemoteResource) + { + this.lockObject = lockObject; + this.simulatorRemoteResource = simulatorRemoteResource; + } + + @Override + public void onResourceCallback(SimulatorRemoteResource resource) + { + simulatorRemoteResource.setSimulatorRemoteResource(resource); + + lockObject.countDown(); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/ResourceModelChangeListener.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/ResourceModelChangeListener.java new file mode 100644 index 0000000..6c651c0 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/ResourceModelChangeListener.java @@ -0,0 +1,22 @@ +package org.oic.simulator.test; + +import org.oic.simulator.SimulatorResourceModel; +import org.oic.simulator.serviceprovider.IResourceModelChangedListener; + +public class ResourceModelChangeListener implements IResourceModelChangedListener +{ + + private ResourceModelObject toReturn; + + public ResourceModelChangeListener(Object toReturn) + { + this.toReturn = (ResourceModelObject)toReturn; + } + + @Override + public void onResourceModelChanged(String resourceURI, SimulatorResourceModel resourceModel) + { + toReturn.setResourceURI(resourceURI); + toReturn.setResourceModel(resourceModel); + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/ResourceModelObject.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/ResourceModelObject.java new file mode 100644 index 0000000..fdea49b --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/ResourceModelObject.java @@ -0,0 +1,29 @@ +package org.oic.simulator.test; + +import org.oic.simulator.SimulatorResourceModel; + +public class ResourceModelObject +{ + private String resourceURI; + private SimulatorResourceModel resourceModel; + + public void setResourceURI(String resourceURI) + { + this.resourceURI = resourceURI; + } + + public String getResourceURI() + { + return resourceURI; + } + + public void setResourceModel(SimulatorResourceModel resourceModel) + { + this.resourceModel = resourceModel; + } + + public SimulatorResourceModel getResourceModel() + { + return resourceModel; + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java new file mode 100644 index 0000000..205f383 --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorManagerTest.java @@ -0,0 +1,504 @@ +package org.oic.simulator.test; + +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; + +public class SimulatorManagerTest extends TestCase +{ + + private static final String CONFIG_PATH = "./ramls/simple-light.raml"; + private static final String RESOURCE_TYPE = "oic.light"; + + private CountDownLatch lockObject; + 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 + protected void setUp() throws Exception + { + super.setUp(); + + lockObject = new CountDownLatch(1); + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + + resourceModelObject = null; + resourceModelChangeListener = null; + lockObject = null; + } + + private SimulatorResourceServer createResource() + { + resourceModelObject = new ResourceModelObject(); + resourceModelChangeListener = new ResourceModelChangeListener(resourceModelObject); + + SimulatorResourceServer simulatorResourceServer = null; + try + { + simulatorResourceServer = SimulatorManager.createResource(CONFIG_PATH, resourceModelChangeListener); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return simulatorResourceServer; + } + + private SimulatorResourceServer[] createResources(int n) + { + resourceModelObject = new ResourceModelObject(); + resourceModelChangeListener = new ResourceModelChangeListener(resourceModelObject); + + SimulatorResourceServer[] simulatorResourceServers = null; + try + { + simulatorResourceServers = SimulatorManager.createResource(CONFIG_PATH, n, resourceModelChangeListener); + } + catch (Exception e) + { + e.printStackTrace(); + } + + return simulatorResourceServers; + } + + private void deleteResource(SimulatorResourceServer sim) + { + try + { + SimulatorManager.deleteResource(sim); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + public void testCreateResource_P01() + { + SimulatorResourceServer simulatorResourceServer = createResource(); + + assertNotNull(simulatorResourceServer); + + deleteResource(simulatorResourceServer); + } + + /** + * When config path is empty + */ + public void testCreateResource_N01() + { + String configPath = ""; + boolean result = false; + + resourceModelObject = new ResourceModelObject(); + resourceModelChangeListener = new ResourceModelChangeListener(resourceModelObject); + + SimulatorResourceServer simulatorResourceServer = null; + try + { + simulatorResourceServer = SimulatorManager.createResource(configPath, resourceModelChangeListener); + } + catch (Exception e) + { + result = true; + } + + assertTrue(simulatorResourceServer == null && result); + } + + /** + * When listener is not set. Passed null + */ + public void testCreateResource_N02() + { + boolean result = false; + SimulatorResourceServer simulatorResourceServer = null; + try + { + simulatorResourceServer = SimulatorManager.createResource(CONFIG_PATH, null); + } + catch (Exception e) + { + result = true; + } + assertTrue(simulatorResourceServer == null && result); + } + + /** + * When listener and config path are set to null + */ + public void testCreateResource_N03() + { + boolean result = false; + SimulatorResourceServer simulatorResourceServer = null; + try + { + simulatorResourceServer = SimulatorManager.createResource(null, null); + } + catch (Exception e) + { + result = true; + } + assertTrue(simulatorResourceServer == null && result); + } + + public void testCreateResourceCount_P01() + { + int count = 5; + + SimulatorResourceServer[] simulatorResourceServers = createResources(count); + + assertTrue(simulatorResourceServers != null && simulatorResourceServers.length == 5); + + for(SimulatorResourceServer srs : simulatorResourceServers) + deleteResource(srs); + } + + /** + * When config path is empty + */ + public void testCreateResourceCount_N01() + { + int count = 5; + String configPath = ""; + boolean result = false; + + resourceModelObject = new ResourceModelObject(); + resourceModelChangeListener = new ResourceModelChangeListener(resourceModelObject); + + SimulatorResourceServer[] simulatorResourceServers = null; + try + { + simulatorResourceServers = SimulatorManager.createResource(configPath, count, resourceModelChangeListener); + } + catch (Exception e) + { + result = true; + } + + assertTrue(simulatorResourceServers == null && result); + } + + /** + * When listener is not set + */ + public void testCreateResourceCount_N02() + { + int count = 5; + boolean result = false; + + SimulatorResourceServer[] simulatorResourceServers = null; + + try + { + simulatorResourceServers = SimulatorManager.createResource(CONFIG_PATH, count, null); + } + catch (Exception e) + { + result = true; + } + + assertTrue(simulatorResourceServers == null && result); + } + + /** + * When configPath and listener are set to null + */ + public void testCreateResourceCount_N03() + { + int count = 5; + boolean result = false; + + SimulatorResourceServer[] simulatorResourceServers = null; + try + { + simulatorResourceServers = SimulatorManager.createResource(null, count, null); + } + catch (Exception e) + { + result = true; + } + + assertTrue(simulatorResourceServers == null && result); + } + + /** + * When count is set to 0 + */ + public void testCreateResourceCount_N04() + { + int count = 0; + + SimulatorResourceServer[] simulatorResourceServers = createResources(count); + + assertTrue(simulatorResourceServers == null); + } + + /** + * When count is set to -ve + */ + //TODO issue. Not coming out of loop + /*public void testCreateResourceCount_N05() { + int count = -10; + + SimulatorResourceServer[] simulatorResourceServers = createResources(count); + + assertTrue(simulatorResourceServers != null && simulatorResourceServers.length == 0); + }*/ + + public void testDeleteResource_P01() + { + boolean result = true; + + SimulatorResourceServer simRes = createResource(); + + try + { + SimulatorManager.deleteResource(simRes); + } + catch (Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testDeleteResource_P02() + { + boolean result = true; + + SimulatorResourceServer[] simResoruces = createResources(4); + + try + { + SimulatorManager.deleteResource(simResoruces[0]); + } + catch (Exception e) + { + result = false; + } + + for(SimulatorResourceServer simResServer : simResoruces) + deleteResource(simResServer); + + assertTrue(result); + } + + public void testDeleteResources_P01() + { + boolean result = true; + + createResources(4); + + try + { + SimulatorManager.deleteResources(RESOURCE_TYPE); + } + catch (Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testFindResouce_P01() + { + boolean result = true; + + SimulatorResourceServer simulatorResourceServer = createResource(); + + SimulatorRemoteResourceObject simulatorRemoteResource = new SimulatorRemoteResourceObject(); + + FindResourceListener findResourceListener = new FindResourceListener(lockObject, simulatorRemoteResource); + + try + { + SimulatorManager.findResource(findResourceListener); + } + catch (Exception e) + { + result = false; + } + + assertTrue(result); + + deleteResource(simulatorResourceServer); + } + + /** + * Pass null to listener + */ + public void testFindResouce_N01() + { + boolean result = true; + + SimulatorResourceServer simulatorResourceServer = createResource(); + + try + { + SimulatorManager.findResource(null); + result = false; + } + catch (Exception e) + { + result = true; + } + + assertTrue(result); + + deleteResource(simulatorResourceServer); + } + + /** + * checkign for crash + */ + public void testSetDeviceInfo_P01() + { + SimulatorManager.setDeviceInfo("test"); + } + + /** + * checkign for crash + * Pass empty + */ + //TODO failing + public void testSetDeviceInfo_N01() + { + SimulatorManager.setDeviceInfo(""); + } + + /** + * checkign for crash + * pass null + */ + //TODO failign + public void testSetDeviceInfo_N02() + { + SimulatorManager.setDeviceInfo(null); + } + + //TODO crashing + /*public void testGetDeviceInfo_P01() { + + lockObject = new CountDownLatch(1); + + SimulatorManager.getDeviceInfo(new IDeviceInfo() { + + @Override + public void onDeviceFound(DeviceInfo devInfo) { + info = devInfo; + lockObject.countDown(); + } + }); + + try { + lockObject.await(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + } + + assertNotNull(info); + }*/ + + /** + * when listener is null + * Checkign crash + */ + //TODO crashing + /*public void testGetDeviceInfo_N01() { + SimulatorManager.getDeviceInfo(null); + }*/ + + /** + * Checkign for crash + */ + public void testSetPlatformInfo_P01() + { + PlatformInfo platformInfo = new PlatformInfo(); + platformInfo.setDateOfManufacture("asdf"); + platformInfo.setFirmwareVersion("asdf"); + platformInfo.setHardwareVersion("asdf"); + platformInfo.setManufacturerName("asdfdfg"); + platformInfo.setManufacturerUrl("asdffdg"); + platformInfo.setModelNumber("fddfg"); + platformInfo.setOperationSystemVersion("sadfg"); + platformInfo.setPlatformID("asdf"); + platformInfo.setPlatformVersion("asdfgfdg"); + platformInfo.setSupportUrl("adfgg"); + platformInfo.setSystemTime("adsfgfg"); + + SimulatorManager.setPlatformInfo(platformInfo); + } + + /** + * Checkign for crash + */ + //TODO crashing + /*public void testSetPlatformInfo_N01() { + SimulatorManager.setPlatformInfo(null); + }*/ + + /** + * Checkign for crash + */ + //TODO crashing + /*public void testSetPlatformInfo_N02() { + SimulatorManager.setPlatformInfo(new PlatformInfo()); + }*/ + + /** + * Checkign for crash + */ + //TODO crashing + /*public void testGetPlatformInfo_P01() { + lockObject = new CountDownLatch(1); + + SimulatorManager.getPlatformInfo(new IPlatformInfo() { + + @Override + public void onPlatformFound(PlatformInfo info) { + platformInfo = info; + } + }); + + try { + lockObject.await(10, TimeUnit.SECONDS); + } catch (InterruptedException e) { + } + + assertNotNull(platformInfo); + }*/ + + /** + * Setting listener to null + * Checkign for crash + */ + //TODO crashing + /*public void testGetPlatformInfo_N01() { + SimulatorManager.getPlatformInfo(null); + }*/ +} \ No newline at end of file diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorRemoteResourceObject.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorRemoteResourceObject.java new file mode 100644 index 0000000..55548cd --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorRemoteResourceObject.java @@ -0,0 +1,19 @@ +package org.oic.simulator.test; + +import org.oic.simulator.clientcontroller.SimulatorRemoteResource; + +public class SimulatorRemoteResourceObject +{ + + private SimulatorRemoteResource simulatorRemoteResource; + + public void setSimulatorRemoteResource(SimulatorRemoteResource simulatorRemoteResource) + { + this.simulatorRemoteResource = simulatorRemoteResource; + } + + public SimulatorRemoteResource getSimulatorRemoteResource() + { + return simulatorRemoteResource; + } +} diff --git a/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorResourceModelTest.java b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorResourceModelTest.java new file mode 100644 index 0000000..05b2f3c --- /dev/null +++ b/service/simulator/unittests/SimulatorTest/src/org/oic/simulator/test/SimulatorResourceModelTest.java @@ -0,0 +1,316 @@ +package org.oic.simulator.test; + +import java.util.Map; + +import junit.framework.TestCase; + +import org.oic.simulator.ResourceAttribute; +import org.oic.simulator.SimulatorResourceModel; + +public class SimulatorResourceModelTest extends TestCase +{ + + private SimulatorResourceModel simulatorResourceModel; + + private static final String KEY = "test"; + + 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(); + + simulatorResourceModel = new SimulatorResourceModel(); + } + + @Override + protected void tearDown() throws Exception + { + super.tearDown(); + + simulatorResourceModel = null; + } + + public void testAddAttributeInt_P01() + { + int val = 100; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeInt(KEY, val); + result = result && Integer.parseInt(simulatorResourceModel.getAttribute(KEY).getValue().toString()) == val; + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testAddAttributeInt_N01() + { + int val = -10; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeInt(KEY, val); + result = result && Integer.parseInt(simulatorResourceModel.getAttribute(KEY).getValue().toString()) == val; + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testAddAttributeInt_N02() + { + int val = 666666; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeInt(KEY, val); + result = result && Integer.parseInt(simulatorResourceModel.getAttribute(KEY).getValue().toString()) == val; + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testAddAttributeDouble_P01() + { + double val = 10.11; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeDouble(KEY, val); + result = result && Double.parseDouble(simulatorResourceModel.getAttribute(KEY).getValue().toString()) == val; + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testAddAttributeDouble_N01() + { + double val = -11.12; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeDouble(KEY, val); + result = result && Double.parseDouble(simulatorResourceModel.getAttribute(KEY).getValue().toString()) == val; + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testAddAttributeDouble_N02() + { + double val = 0.0044444444444; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeDouble(KEY, val); + result = result && Double.parseDouble(simulatorResourceModel.getAttribute(KEY).getValue().toString()) == val; + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testAddAttributeString_P01() + { + String val = "asdf"; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeString(KEY, val); + result = result && simulatorResourceModel.getAttribute(KEY).getValue().toString().equals(val); + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testAddAttributeString_N01() + { + String val = ""; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeString(KEY, val); + result = result && simulatorResourceModel.getAttribute(KEY).getValue().toString().equals(val); + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + /** + * Crashing. Not handled + */ + //TODO check + /*public void testAddAttributeString_N02() { + String val = null; + + boolean result = true; + try { + simulatorResourceModel.addAttributeString(KEY, val); + result = result && simulatorResourceModel.getAttribute(KEY).getValue().toString().equals(val); + } catch(Exception e) { + result = false; + } + + assertTrue(result); + }*/ + + public void testAddAttributeString_N03() + { + String val = "@#$$&^*^(*^&"; + + boolean result = true; + try + { + simulatorResourceModel.addAttributeString(KEY, val); + result = result && simulatorResourceModel.getAttribute(KEY).getValue().toString().equals(val); + } + catch(Exception e) + { + result = false; + } + + assertTrue(result); + } + + //TODO boolean not able to set + public void testAddAttributeBoolean_P01() + { + boolean result = true; + + boolean val = true; + + try + { + simulatorResourceModel.addAttributeBoolean(KEY, val); + + result = result && ((Boolean.parseBoolean(simulatorResourceModel.getAttribute(KEY).getValue() + ""))); + + val = false; + + simulatorResourceModel.addAttributeBoolean(KEY, val); + + result = result && !((Boolean.parseBoolean(simulatorResourceModel.getAttribute(KEY).getValue() + ""))); + } + catch (Exception e) + { + result = false; + } + + assertTrue(result); + } + + public void testSize_P01() + { + boolean result = true; + + try + { + simulatorResourceModel.addAttributeInt("test1", 1234); + + result = result && (simulatorResourceModel.size() == 1); + + simulatorResourceModel.addAttributeString("test2", "asdf"); + simulatorResourceModel.addAttributeBoolean("test3", true); + simulatorResourceModel.addAttributeDouble("test4", 22.435234); + + result = result && (simulatorResourceModel.size() == 4); + } + catch(Exception e) + { + result = false; + } + assertTrue(result); + } + + //TODO boolean not able to set + public void testGetAttributes_P01() + { + boolean result = true; + + try + { + simulatorResourceModel.addAttributeInt("test1", 1234); + simulatorResourceModel.addAttributeString("test2", "asdf"); + simulatorResourceModel.addAttributeBoolean("test3", true); + simulatorResourceModel.addAttributeDouble("test4", 22.435234); + + Map 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)) && + (((Double)attributes.get("test4").getValue()) == 22.435234); + } + catch(Exception e) + { + result = false; + } + assertTrue(result); + } + + public void testGetAttribute_P01() + { + int val = 100; + + boolean result = true; + + try + { + simulatorResourceModel.addAttributeInt(KEY, val); + + result = result && Integer.parseInt(simulatorResourceModel.getAttribute(KEY).getValue().toString()) == val; + } + catch(Exception e) + { + result = false; + } + assertTrue(result); + } +}