src/test/TestQuotaType.java

Code
Comments
Other
Rev Date Author Line
412 15 Apr 05 enell 1 /*
2306 22 May 06 jari 2   $Id$
412 15 Apr 05 enell 3
3675 16 Aug 07 jari 4   Copyright (C) 2005 Johan Enell, Nicklas Nordborg
4889 06 Apr 09 nicklas 5   Copyright (C) 2006 Jari Häkkinen
412 15 Apr 05 enell 6
2304 22 May 06 jari 7   This file is part of BASE - BioArray Software Environment.
2304 22 May 06 jari 8   Available at http://base.thep.lu.se/
412 15 Apr 05 enell 9
412 15 Apr 05 enell 10   BASE is free software; you can redistribute it and/or
412 15 Apr 05 enell 11   modify it under the terms of the GNU General Public License
4480 05 Sep 08 jari 12   as published by the Free Software Foundation; either version 3
412 15 Apr 05 enell 13   of the License, or (at your option) any later version.
412 15 Apr 05 enell 14
412 15 Apr 05 enell 15   BASE is distributed in the hope that it will be useful,
412 15 Apr 05 enell 16   but WITHOUT ANY WARRANTY; without even the implied warranty of
412 15 Apr 05 enell 17   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
412 15 Apr 05 enell 18   GNU General Public License for more details.
412 15 Apr 05 enell 19
412 15 Apr 05 enell 20   You should have received a copy of the GNU General Public License
4514 11 Sep 08 jari 21   along with BASE. If not, see <http://www.gnu.org/licenses/>.
412 15 Apr 05 enell 22 */
5340 10 May 10 nicklas 23 import java.util.Set;
5340 10 May 10 nicklas 24
412 15 Apr 05 enell 25 import net.sf.basedb.core.BaseException;
412 15 Apr 05 enell 26 import net.sf.basedb.core.DbControl;
5340 10 May 10 nicklas 27 import net.sf.basedb.core.ItemProxy;
412 15 Apr 05 enell 28 import net.sf.basedb.core.QuotaType;
1418 07 Oct 05 nicklas 29 import net.sf.basedb.core.ItemResultList;
412 15 Apr 05 enell 30
412 15 Apr 05 enell 31 public class TestQuotaType
412 15 Apr 05 enell 32 {
412 15 Apr 05 enell 33
412 15 Apr 05 enell 34   static boolean ok = true;
412 15 Apr 05 enell 35   public static void main(String[] args)
412 15 Apr 05 enell 36   {
412 15 Apr 05 enell 37     TestUtil.checkArgs(args);
412 15 Apr 05 enell 38     TestUtil.begin();
412 15 Apr 05 enell 39     ok = test_all();
412 15 Apr 05 enell 40     TestUtil.stop();
412 15 Apr 05 enell 41   }
412 15 Apr 05 enell 42
412 15 Apr 05 enell 43   static boolean test_all()
412 15 Apr 05 enell 44   {
412 15 Apr 05 enell 45     write("++Testing quota types");
412 15 Apr 05 enell 46     write_header();
412 15 Apr 05 enell 47
412 15 Apr 05 enell 48     // Standard tests: list
412 15 Apr 05 enell 49     test_list();
412 15 Apr 05 enell 50
412 15 Apr 05 enell 51     write("++Testing quota types "+(ok ? "OK" : "Failed")+"\n");
412 15 Apr 05 enell 52     return ok;
412 15 Apr 05 enell 53   }
412 15 Apr 05 enell 54   
412 15 Apr 05 enell 55   static void test_list()
412 15 Apr 05 enell 56   {
412 15 Apr 05 enell 57     DbControl dc = null;
412 15 Apr 05 enell 58     try
412 15 Apr 05 enell 59     {
412 15 Apr 05 enell 60       dc = TestUtil.getDbControl();
1418 07 Oct 05 nicklas 61       ItemResultList<QuotaType> l = QuotaType.getQuery().list(dc);
412 15 Apr 05 enell 62       for (int i = 0; i<l.size(); i++)
412 15 Apr 05 enell 63       {
6870 16 Apr 15 nicklas 64         write_item(i, l.get(i));
412 15 Apr 05 enell 65       }
412 15 Apr 05 enell 66       write("--List quota types OK ("+l.size()+")");
412 15 Apr 05 enell 67     }
816 23 Jun 05 nicklas 68     catch (Throwable ex)
412 15 Apr 05 enell 69     {
412 15 Apr 05 enell 70       write("--List quota types FAILED");
412 15 Apr 05 enell 71       ex.printStackTrace();
412 15 Apr 05 enell 72       ok = false;
412 15 Apr 05 enell 73     }
412 15 Apr 05 enell 74     finally
412 15 Apr 05 enell 75     {
412 15 Apr 05 enell 76       if (dc != null) dc.close();
412 15 Apr 05 enell 77     }
412 15 Apr 05 enell 78   }
412 15 Apr 05 enell 79   
412 15 Apr 05 enell 80   static void test_delete(int id)
412 15 Apr 05 enell 81   {
412 15 Apr 05 enell 82     if (id == 0) return;
412 15 Apr 05 enell 83     DbControl dc = null;
412 15 Apr 05 enell 84     try
412 15 Apr 05 enell 85     {
412 15 Apr 05 enell 86       dc = TestUtil.getDbControl();
412 15 Apr 05 enell 87       QuotaType q = QuotaType.getById(dc, id);
412 15 Apr 05 enell 88       dc.deleteItem(q);
5340 10 May 10 nicklas 89       Set<ItemProxy> using = q.getUsingItems();
5340 10 May 10 nicklas 90       if (using.size() > 0) 
5340 10 May 10 nicklas 91       {
5340 10 May 10 nicklas 92          throw new BaseException(q + " is used by " + using);
5340 10 May 10 nicklas 93       }
412 15 Apr 05 enell 94       dc.commit();
412 15 Apr 05 enell 95       write("--Delete quota type OK");
412 15 Apr 05 enell 96     }
412 15 Apr 05 enell 97     catch (Throwable ex)
412 15 Apr 05 enell 98     {
412 15 Apr 05 enell 99       write("--Delete quota type FAILED");
412 15 Apr 05 enell 100       ex.printStackTrace();
412 15 Apr 05 enell 101       ok = false;
412 15 Apr 05 enell 102     }
412 15 Apr 05 enell 103     finally
412 15 Apr 05 enell 104     {
412 15 Apr 05 enell 105       if (dc != null) dc.close();
412 15 Apr 05 enell 106     }
412 15 Apr 05 enell 107   }
412 15 Apr 05 enell 108
412 15 Apr 05 enell 109   static void write_header()
412 15 Apr 05 enell 110   {
412 15 Apr 05 enell 111     if (!TestUtil.getSilent())
412 15 Apr 05 enell 112     {
412 15 Apr 05 enell 113       write("   \tID \tName\tDescription");
412 15 Apr 05 enell 114       write("-- \t-- \t----\t-----------");
412 15 Apr 05 enell 115     }
412 15 Apr 05 enell 116   }
412 15 Apr 05 enell 117   static void write_item(int i, QuotaType qt)
412 15 Apr 05 enell 118     throws BaseException
412 15 Apr 05 enell 119   {
412 15 Apr 05 enell 120     if (!TestUtil.getSilent())
412 15 Apr 05 enell 121       System.out.println(i+":\t"+qt.getId()+"\t"+
412 15 Apr 05 enell 122         qt.getName()+"\t"+qt.getDescription()
412 15 Apr 05 enell 123         );
412 15 Apr 05 enell 124   }
412 15 Apr 05 enell 125   static void write(String message)
412 15 Apr 05 enell 126   {
412 15 Apr 05 enell 127     System.out.println(message);
412 15 Apr 05 enell 128   }
412 15 Apr 05 enell 129 }
412 15 Apr 05 enell 130