aboutsummaryrefslogtreecommitdiff
path: root/id/server/idserverlib/src/test/java/at
diff options
context:
space:
mode:
Diffstat (limited to 'id/server/idserverlib/src/test/java/at')
-rw-r--r--id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java135
1 files changed, 135 insertions, 0 deletions
diff --git a/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java
new file mode 100644
index 000000000..9f1fc5f2d
--- /dev/null
+++ b/id/server/idserverlib/src/test/java/at/gv/egovernment/moa/id/process/spring/test/DummyTransactionStorage.java
@@ -0,0 +1,135 @@
+package at.gv.egovernment.moa.id.process.spring.test;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.Iterator;
+import java.util.List;
+
+import javax.sql.DataSource;
+
+import at.gv.egovernment.moa.id.auth.exception.AuthenticationException;
+import at.gv.egovernment.moa.id.commons.db.ex.MOADatabaseException;
+import at.gv.egovernment.moa.id.storage.ITransactionStorage;
+import at.gv.egovernment.moa.logging.Logger;
+
+/**
+ * Dummy DataSource implementation for convenience in test cases where a
+ * database connection will never actually be acquired.
+ *
+ * @see DataSource
+ * @author Chris Beams
+ */
+public class DummyTransactionStorage implements ITransactionStorage {
+
+ public class DummyDBEntry{
+ public DummyDBEntry(String key, Object value){
+ this.obj =value;
+ this.key = key;
+ }
+ public String getKey() {
+ return key;
+ }
+ public void setKey(String key) {
+ this.key = key;
+ }
+ public Object getObj() {
+ return obj;
+ }
+ public void setObj(Object obj) {
+ this.obj = obj;
+ }
+ private String key;
+ private Object obj;
+ }
+
+ private ArrayList<DummyDBEntry> ds = new ArrayList<DummyDBEntry>();
+
+
+
+ @Override
+ public boolean containsKey(String key) {
+ // TODO Auto-generated method stub
+ Iterator<DummyDBEntry> it = ds.iterator();
+ while(it.hasNext()){
+ DummyDBEntry t = it.next();
+ if(t.getKey().equals(key))
+ return true;
+ }
+ return false;
+ }
+
+ @Override
+ public void put(String key, Object value, int timeout_ms)
+ throws MOADatabaseException {
+ // TODO Auto-generated method stub
+ this.remove(key);
+ this.ds.add(new DummyDBEntry(key, value));
+
+ }
+
+ @Override
+ public Object get(String key) throws MOADatabaseException {
+ // TODO Auto-generated method stub
+ Iterator<DummyDBEntry> it = ds.iterator();
+ while(it.hasNext()){
+ DummyDBEntry t = it.next();
+ if(t.getKey().equals(key))
+ return t;
+ }
+ return null;
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> clazz) throws MOADatabaseException {
+
+ DummyDBEntry o = (DummyDBEntry) get(key);
+ if(o == null)
+ return null;
+ try {
+ @SuppressWarnings("unchecked")
+ T test = (T) (clazz.cast(o.getObj()));
+ return test;
+
+ } catch (Exception e) {
+ Logger.warn("Sessioninformation Cast-Exception by using Artifact=" + key);
+ throw new MOADatabaseException("Sessioninformation Cast-Exception");
+
+ }
+ }
+
+ @Override
+ public <T> T get(String key, Class<T> clazz, long dataTimeOut)
+ throws MOADatabaseException, AuthenticationException {
+ // TODO Auto-generated method stub
+ return get(key,clazz);
+ }
+
+ @Override
+ public void changeKey(String oldKey, String newKey, Object value)
+ throws MOADatabaseException {
+ this.remove(oldKey);
+ this.put(newKey, value, -1);
+
+ }
+
+ @Override
+ public void remove(String key) {
+ Iterator<DummyDBEntry> it = ds.iterator();
+ while(it.hasNext()){
+ DummyDBEntry t = it.next();
+ if(t.getKey().equals(key)){
+ this.ds.remove(t);
+ return;
+ }
+ }
+
+ }
+
+ @Override
+ public List<String> clean(Date now, long dataTimeOut) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+
+} \ No newline at end of file