/* * Copyright 2017 Graz University of Technology EAAF-Core Components has been developed in a * cooperation between EGIZ, A-SIT Plus, A-SIT, and Graz University of Technology. * * Licensed under the EUPL, Version 1.2 or - as soon they will be approved by the European * Commission - subsequent versions of the EUPL (the "Licence"); You may not use this work except in * compliance with the Licence. You may obtain a copy of the Licence at: * https://joinup.ec.europa.eu/news/understanding-eupl-v12 * * Unless required by applicable law or agreed to in writing, software distributed under the Licence * is distributed on an "AS IS" basis, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express * or implied. See the Licence for the specific language governing permissions and limitations under * the Licence. * * This product combines work with different licenses. See the "NOTICE" text file for details on the * various modules and licenses. The "NOTICE" text file is part of the distribution. Any derivative * works that you distribute must include a readable copy of the "NOTICE" text file. */ package at.gv.egiz.eaaf.core.impl.idp.process.spring.test; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import javax.sql.DataSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import at.gv.egiz.eaaf.core.api.storage.ITransactionStorage; import at.gv.egiz.eaaf.core.exceptions.EaafException; /** * 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 { private static final Logger log = LoggerFactory.getLogger(DummyTransactionStorage.class); public class DummyDbEntry { public DummyDbEntry(final String key, final Object value) { this.obj = value; this.key = key; } public String getKey() { return key; } public void setKey(final String key) { this.key = key; } public Object getObj() { return obj; } public void setObj(final Object obj) { this.obj = obj; } private String key; private Object obj; } private final ArrayList ds = new ArrayList<>(); @Override public boolean containsKey(final String key) { // TODO Auto-generated method stub final Iterator it = ds.iterator(); while (it.hasNext()) { final DummyDbEntry t = it.next(); if (t.getKey().equals(key)) { return true; } } return false; } @Override public void put(final String key, final Object value, final int timeout) throws EaafException { // TODO Auto-generated method stub this.remove(key); this.ds.add(new DummyDbEntry(key, value)); } @Override public Object get(final String key) throws EaafException { // TODO Auto-generated method stub final Iterator it = ds.iterator(); while (it.hasNext()) { final DummyDbEntry t = it.next(); if (t.getKey().equals(key)) { return t; } } return null; } @Override public T get(final String key, final Class clazz) throws EaafException { final DummyDbEntry o = (DummyDbEntry) get(key); if (o == null) { return null; } try { @SuppressWarnings("unchecked") final T test = clazz.cast(o.getObj()); return test; } catch (final Exception e) { log.warn("Sessioninformation Cast-Exception by using Artifact=" + key); throw new EaafException("Sessioninformation Cast-Exception"); } } @Override public T get(final String key, final Class clazz, final long dataTimeOut) throws EaafException { // TODO Auto-generated method stub return get(key, clazz); } @Override public void changeKey(final String oldKey, final String newKey, final Object value) throws EaafException { this.remove(oldKey); this.put(newKey, value, -1); } @Override public void remove(final String key) { final Iterator it = ds.iterator(); while (it.hasNext()) { final DummyDbEntry t = it.next(); if (t.getKey().equals(key)) { this.ds.remove(t); return; } } } @Override public List clean(final Date now, final long dataTimeOut) { // TODO Auto-generated method stub return null; } @Override public Object getRaw(final String key) throws EaafException { // TODO Auto-generated method stub return null; } @Override public void putRaw(final String key, final Object element) throws EaafException { // TODO Auto-generated method stub } // @Override // public Object getAssertionStore(String key) throwsEAAFException { // // TODO Auto-generated method stub // return null; // } // // @Override // public void putAssertionStore(Object element) throws EAAFException { // // TODO Auto-generated method stub // // } }