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.UseCaseVoreinstellungenString;
28  import org.fhw.cabaweb.ojb.UseCaseProjekte;
29  import org.fhw.cabaweb.ojb.dataobjects.Projekte;
30  import org.fhw.cabaweb.ojb.dataobjects.Voreinstellungen_String;
31  import org.fhw.cabaweb.ojb.interfaces.UseCase;
32  
33  import junit.framework.TestCase;
34  
35  /***
36   * Klasse f&uuml;r den Test der Funktionen des UseCases Voreinstellungen_String
37   *
38   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
39   * @version 18.05.2004
40   */
41  public class UseCaseVoreinstellungenStringTest extends TestCase
42  {
43      private PersistenceBroker broker;
44      private UseCase testCase;
45      private Voreinstellungen_String test;
46  
47      public static void main(String[] args)
48      {
49          //      junit.swingui.TestRunner.run(UseCaseProjektbeschreibungenTest.class);
50          junit.textui.TestRunner.run(UseCaseVoreinstellungenStringTest.class);
51      }
52  
53  	/*
54  	 * @see TestCase#setUp()
55  	 */
56  	protected void setUp() throws Exception
57  	{
58          super.setUp();
59  
60          broker = null;
61          try
62          {
63              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
64          }
65          catch (Throwable t)
66          {
67              t.printStackTrace();
68          }
69  
70          testCase = (UseCase) new UseCaseVoreinstellungenString(broker);
71          
72          test = new Voreinstellungen_String();
73  	}
74  
75  	/*
76  	 * @see TestCase#tearDown()
77  	 */
78  	protected void tearDown() throws Exception
79  	{
80          super.tearDown();
81          
82          try
83          {
84              broker.close();
85          }
86          catch (Throwable t)
87          {
88              t.printStackTrace();
89          }
90  	}
91  
92      public void testErzeugen()
93      {
94          Projekte prj = new Projekte(new Integer(1), null, null, null);
95          UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
96          
97          prj = (Projekte) prjCase.sucheObjekt(prj);
98          
99          test = new Voreinstellungen_String(prj);
100         testCase.erzeugen(test);
101 
102         Voreinstellungen_String test2 = new Voreinstellungen_String(prj);
103  
104         assertEquals(test.toString(), ((Voreinstellungen_String) testCase.sucheObjekt(test2)).toString());
105 
106         test = new Voreinstellungen_String();       
107     }
108 
109     public void testEditieren()
110     {
111         Projekte prj = new Projekte(new Integer(1), null, null, null);
112         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
113         
114         prj = (Projekte) prjCase.sucheObjekt(prj);
115 
116         test = new Voreinstellungen_String(prj);
117         test.setString1("Test 1");
118         
119         testCase.editieren(test);
120 
121         Voreinstellungen_String test2 = new Voreinstellungen_String(prj);
122  
123         assertEquals(test.toString(), ((Voreinstellungen_String) testCase.sucheObjekt(test2)).toString());
124         assertEquals(test.getString1(), ((Voreinstellungen_String) testCase.sucheObjekt(test2)).getString1());
125 
126         test = new Voreinstellungen_String();       
127     }
128 
129     public void testSucheObjekt()
130     {
131         Projekte prj = new Projekte(new Integer(1), null, null, null);
132         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
133         
134         prj = (Projekte) prjCase.sucheObjekt(prj);
135         
136         test = new Voreinstellungen_String(prj);
137 
138         Voreinstellungen_String objekt = (Voreinstellungen_String) testCase.sucheObjekt(test);
139         
140         Voreinstellungen_String test2 = new Voreinstellungen_String(prj);
141         test2.setString1("Test 1");
142  
143         assertEquals(test2.toString(), objekt.toString());
144         assertEquals(test2.getString1(), objekt.getString1());
145 
146         test = new Voreinstellungen_String();        
147     }
148 
149     public void testSucheObjekte()
150     {
151         Projekte prj = new Projekte(new Integer(1), null, null, null);
152         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
153         
154         prj = (Projekte) prjCase.sucheObjekt(prj);
155 
156         test = new Voreinstellungen_String(prj);
157 
158         Collection objekte = testCase.sucheObjekte(test);
159         
160         java.util.Iterator iter = objekte.iterator();
161         while (iter.hasNext())
162         {
163 //          System.out.println(iter.next());
164             iter.next();
165         }         
166 
167         assertEquals(true, objekte.size() == 1);
168     }
169 
170     public void testSucheAlle()
171     {
172         Projekte prj = new Projekte(new Integer(1), null, null, null);
173         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
174         
175         prj = (Projekte) prjCase.sucheObjekt(prj);
176 
177         Collection alleObjekte = testCase.sucheAlle(Voreinstellungen_String.class);
178         
179         java.util.Iterator iter = alleObjekte.iterator();
180         while (iter.hasNext())
181         {
182 //          System.out.println(iter.next());
183             iter.next();
184         }         
185 
186         assertEquals(true, alleObjekte.size() == 1);
187     }
188 
189     public void testLoeschen()
190     {
191         Projekte prj = new Projekte(new Integer(1), null, null, null);
192         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
193         
194         prj = (Projekte) prjCase.sucheObjekt(prj);
195 
196         test = new Voreinstellungen_String(prj);
197 
198         testCase.loeschen(test);
199 
200         Voreinstellungen_String test2 = new Voreinstellungen_String(prj);
201  
202         assertNull(testCase.sucheObjekt(test2));
203 
204         test = new Voreinstellungen_String();       
205     }
206 }