1   ////////////////////////////////////////////////////////////////////////////////
2   //CabaWeb
3   //Copyright (C) 2004  Thomas Vogt <Thomas.Vogt@TVC-Software.com>
4   //
5   //This library is free software; you can redistribute it and/or
6   //modify it under the terms of the GNU Lesser General Public
7   //License as published by the Free Software Foundation; either
8   //version 2.1 of the License, or (at your option) any later version.
9   //
10  //This library is distributed in the hope that it will be useful,
11  //but WITHOUT ANY WARRANTY; without even the implied warranty of
12  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  //Lesser General Public License for more details.
14  //
15  //You should have received a copy of the GNU Lesser General Public
16  //License along with this library; if not, write to the Free Software
17  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  ////////////////////////////////////////////////////////////////////////////////
19  
20  package org.fhw.cabaweb.junittests;
21  
22  import java.util.Collection;
23  
24  import org.apache.ojb.broker.PersistenceBroker;
25  import org.apache.ojb.broker.PersistenceBrokerFactory;
26  
27  import org.fhw.cabaweb.ojb.UseCaseBenutzerrollen;
28  import org.fhw.cabaweb.ojb.dataobjects.Benutzerrollen;
29  import org.fhw.cabaweb.ojb.interfaces.UseCase;
30  
31  import junit.framework.TestCase;
32  
33  /***
34   * Klasse f&uuml;r den Test der Funktionen des UseCases Benutzerrollen
35   *
36   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a> 
37   * @version 16.05.2004
38   */
39  public class UseCaseBenutzerrollenTest extends TestCase
40  {
41      private PersistenceBroker broker;
42      private UseCase testCase;
43      private Benutzerrollen test;
44  
45      public static void main(String[] args)
46      {
47          //      junit.swingui.TestRunner.run(UseCaseProjekteTest.class);
48          junit.textui.TestRunner.run(UseCaseBenutzerrollenTest.class);
49      }
50  
51  	/*
52  	 * @see TestCase#setUp()
53  	 */
54  	protected void setUp() throws Exception
55  	{
56          super.setUp();
57  
58          broker = null;
59          try
60          {
61              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
62          }
63          catch (Throwable t)
64          {
65              t.printStackTrace();
66          }
67  
68          testCase = (UseCase) new UseCaseBenutzerrollen(broker);
69          
70          test = new Benutzerrollen();
71  	}
72  
73  	/*
74  	 * @see TestCase#tearDown()
75  	 */
76  	protected void tearDown() throws Exception
77  	{
78          super.tearDown();
79          
80          try
81          {
82              broker.close();
83          }
84          catch (Throwable t)
85          {
86              t.printStackTrace();
87          }
88  	}
89  
90      public void testErzeugen()
91      {
92          test = new Benutzerrollen(new Integer(99999), "Administrator", new Boolean(true), new Boolean(false), new Boolean(false));
93  
94          testCase.erzeugen(test);
95  
96          Benutzerrollen test2 = new Benutzerrollen(new Integer(99999), null, null, null, null);
97   
98          assertEquals(test.toString(), ((Benutzerrollen) testCase.sucheObjekt(test2)).toString());
99  
100         test = new Benutzerrollen();       
101     }
102 
103     public void testEditieren()
104     {
105         test = new Benutzerrollen(new Integer(99999), "Projektleiter", new Boolean(false), new Boolean(true), new Boolean(false));
106 
107         testCase.editieren(test);
108 
109         Benutzerrollen test2 = new Benutzerrollen(new Integer(99999), null, null, null, null);
110  
111         assertEquals(test.toString(), ((Benutzerrollen) testCase.sucheObjekt(test2)).toString());
112 
113         test = new Benutzerrollen();       
114     }
115     
116     public void testSucheObjekt()
117     {
118         test = new Benutzerrollen(new Integer(99999), null, null, null, null);
119 
120         Benutzerrollen objekt = (Benutzerrollen) testCase.sucheObjekt(test);
121         
122         Benutzerrollen test2 = new Benutzerrollen(new Integer(99999), "Projektleiter", new Boolean(false), new Boolean(true), new Boolean(false));
123  
124         assertEquals(test2.toString(), objekt.toString());
125 
126         test = new Benutzerrollen();        
127     }
128     
129     public void testSucheObjekte()
130     {
131         test = new Benutzerrollen(null, "Projektleiter", null, null, null);
132 
133         Collection objekte = testCase.sucheObjekte(test);
134         
135         java.util.Iterator iter = objekte.iterator();
136         while (iter.hasNext())
137         {
138 //          System.out.println(iter.next());
139             iter.next();
140         }         
141 
142         assertEquals(true, objekte.size() == 2);
143     }
144     
145     public void testSucheAlle()
146     {
147         Collection alleObjekte = testCase.sucheAlle(Benutzerrollen.class);
148          
149         java.util.Iterator iter = alleObjekte.iterator();
150         while (iter.hasNext())
151         {
152 //            System.out.println(iter.next());
153             iter.next();
154         }         
155 
156         assertEquals(true, alleObjekte.size() > 1);
157     }
158 
159     public void testLoeschen()
160     {
161         test = new Benutzerrollen(new Integer(99999), null, null, null, null);
162 
163         testCase.loeschen(test);
164 
165         Benutzerrollen test2 = new Benutzerrollen(new Integer(99999), null, null, null, null);
166  
167         assertNull(testCase.sucheObjekt(test2));
168 
169         test = new Benutzerrollen();       
170     }
171 }