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.UseCaseProjekte;
28  import org.fhw.cabaweb.ojb.UseCaseReporterzeugung;
29  import org.fhw.cabaweb.ojb.UseCaseReportnamen;
30  import org.fhw.cabaweb.ojb.UseCaseSprachen;
31  import org.fhw.cabaweb.ojb.dataobjects.Projekte;
32  import org.fhw.cabaweb.ojb.dataobjects.Reporterzeugung;
33  import org.fhw.cabaweb.ojb.dataobjects.Reportnamen;
34  import org.fhw.cabaweb.ojb.dataobjects.Sprachen;
35  import org.fhw.cabaweb.ojb.interfaces.UseCase;
36  
37  import junit.framework.TestCase;
38  
39  /***
40   * Klasse f&uuml;r den Test der Funktionen des UseCases Projektbeschreibungen
41   *
42   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
43   * @version 13.04.2004
44   */
45  public class UseCaseReporterzeugungTest extends TestCase
46  {
47      private PersistenceBroker broker;
48      private UseCase testCase;
49      private Reporterzeugung test;
50  
51      public static void main(String[] args)
52      {
53          //      junit.swingui.TestRunner.run(UseCaseReporterzeugungTest.class);
54          junit.textui.TestRunner.run(UseCaseReporterzeugungTest.class);
55      }
56  
57  	/*
58  	 * @see TestCase#setUp()
59  	 */
60  	protected void setUp() throws Exception
61  	{
62          super.setUp();
63  
64          broker = null;
65          try
66          {
67              broker = PersistenceBrokerFactory.defaultPersistenceBroker();
68  
69              testCase = (UseCase) new UseCaseReporterzeugung(broker);
70          
71              test = new Reporterzeugung();
72  
73              Projekte prj = new Projekte(new Integer(1), null, null, null);
74              UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
75  
76              prj = (Projekte) prjCase.sucheObjekt(prj);
77  
78              Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), "Test", "Unternehmen");
79              UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
80              rptnamenCase.erzeugen(rptnamen);
81          }
82          catch (Throwable t)
83          {
84              t.printStackTrace();
85          }
86  	}
87  
88  	/*
89  	 * @see TestCase#tearDown()
90  	 */
91  	protected void tearDown() throws Exception
92  	{
93          super.tearDown();
94          
95          try
96          {
97              Projekte prj = new Projekte(new Integer(1), null, null, null);
98              UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
99  
100             prj = (Projekte) prjCase.sucheObjekt(prj);
101 
102             Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), "Test", "Unternehmen");
103             UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
104 
105             rptnamenCase.loeschen(rptnamen);
106 
107             broker.close();
108         }
109         catch (Throwable t)
110         {
111             t.printStackTrace();
112         }
113 	}
114 
115     public void testErzeugen()
116     {
117         Projekte prj = new Projekte(new Integer(1), null, null, null);
118         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
119         
120         prj = (Projekte) prjCase.sucheObjekt(prj);
121 
122         Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), null, null);
123         UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
124         Sprachen spr = new Sprachen(new Integer(1), null, null);
125         UseCase sprCase = (UseCase) new UseCaseSprachen(broker);
126 
127         rptnamen = (Reportnamen) rptnamenCase.sucheObjekt(rptnamen);
128         spr = (Sprachen) sprCase.sucheObjekt(spr);
129         
130         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, "Testgruppierung 123", null, null, null, "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
131 
132         testCase.erzeugen(test);
133 
134         Reporterzeugung test2 = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
135  
136         assertEquals(test.toString(), ((Reporterzeugung) testCase.sucheObjekt(test2)).toString());
137 
138         test = new Reporterzeugung();       
139     }
140 
141     public void testEditieren()
142     {
143         Projekte prj = new Projekte(new Integer(1), null, null, null);
144         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
145         
146         prj = (Projekte) prjCase.sucheObjekt(prj);
147 
148         Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), null, null);
149         UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
150         Sprachen spr = new Sprachen(new Integer(1), null, null);
151         UseCase sprCase = (UseCase) new UseCaseSprachen(broker);
152 
153         rptnamen = (Reportnamen) rptnamenCase.sucheObjekt(rptnamen);
154         spr = (Sprachen) sprCase.sucheObjekt(spr);
155 
156         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, "Testgruppierung 123", null, null, null, "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
157         testCase.erzeugen(test);
158         
159         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, "Testfeld 123", "Test 123", "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
160 
161         testCase.editieren(test);
162 
163         Reporterzeugung test2 = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, "Testfeld 123", "Test 123", null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
164  
165         assertEquals(test.toString(), ((Reporterzeugung) testCase.sucheObjekt(test2)).toString());
166 
167         test = new Reporterzeugung();       
168     }
169 
170     public void testSucheObjekt()
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         Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), null, null);
178         UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
179         Sprachen spr = new Sprachen(new Integer(1), null, null);
180         UseCase sprCase = (UseCase) new UseCaseSprachen(broker);
181 
182         rptnamen = (Reportnamen) rptnamenCase.sucheObjekt(rptnamen);
183         spr = (Sprachen) sprCase.sucheObjekt(spr);
184 
185         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, "Testfeld 123", "Test 123", "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
186         testCase.erzeugen(test);      
187         
188         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
189 
190         Reporterzeugung objekt = (Reporterzeugung) testCase.sucheObjekt(test);
191         
192         Reporterzeugung test2 =  new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, "Testfeld 123", "Test 123", "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
193  
194         assertEquals(test2.toString(), objekt.toString());
195 
196         test = new Reporterzeugung();        
197     }
198 
199     public void testSucheObjekte()
200     {
201         Projekte prj = new Projekte(new Integer(1), null, null, null);
202         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
203         prj = (Projekte) prjCase.sucheObjekt(prj);
204         Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), null, null);
205         UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
206         Sprachen spr = new Sprachen(new Integer(1), null, null);
207         UseCase sprCase = (UseCase) new UseCaseSprachen(broker);
208         rptnamen = (Reportnamen) rptnamenCase.sucheObjekt(rptnamen);
209         spr = (Sprachen) sprCase.sucheObjekt(spr);
210         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, "Testfeld 123", "Test 123", "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
211         testCase.erzeugen(test);      
212 
213         test = new Reporterzeugung(null, null, null, null, null, null, null, "Test 123", "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
214 
215         Collection objekte = testCase.sucheObjekte(test);
216         
217         java.util.Iterator iter = objekte.iterator();
218         while (iter.hasNext())
219         {
220 //          System.out.println(iter.next());
221             iter.next();
222         }         
223 
224         assertEquals(true, objekte.size() == 1);
225     }
226 
227     public void testSucheAlle()
228     {
229         Projekte prj = new Projekte(new Integer(1), null, null, null);
230         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
231         prj = (Projekte) prjCase.sucheObjekt(prj);
232         Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), null, null);
233         UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
234         Sprachen spr = new Sprachen(new Integer(1), null, null);
235         UseCase sprCase = (UseCase) new UseCaseSprachen(broker);
236         rptnamen = (Reportnamen) rptnamenCase.sucheObjekt(rptnamen);
237         spr = (Sprachen) sprCase.sucheObjekt(spr);
238         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, null, "Test 123", "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
239         testCase.erzeugen(test);      
240 
241         Collection alleObjekte = testCase.sucheAlle(Reporterzeugung.class);
242         
243         java.util.Iterator iter = alleObjekte.iterator();
244         while (iter.hasNext())
245         {
246 //          System.out.println(iter.next());
247             iter.next();
248         }         
249 
250         assertEquals(true, alleObjekte.size() == 1);
251     }
252 
253     public void testLoeschen()
254     {
255         Projekte prj = new Projekte(new Integer(1), null, null, null);
256         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
257         
258         prj = (Projekte) prjCase.sucheObjekt(prj);
259 
260         Reportnamen rptnamen = new Reportnamen(prj, new Integer(1), null, null);
261         UseCase rptnamenCase = (UseCase) new UseCaseReportnamen(broker);
262         Sprachen spr = new Sprachen(new Integer(1), null, null);
263         UseCase sprCase = (UseCase) new UseCaseSprachen(broker);
264 
265         rptnamen = (Reportnamen) rptnamenCase.sucheObjekt(rptnamen);
266         spr = (Sprachen) sprCase.sucheObjekt(spr);
267 
268         test = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, null, null, "left", "normal", new Boolean(false), null, null, null, null, null, null, "right", "normal", "right", new Boolean(false), new Boolean(false), new Boolean(false), new Boolean(false));
269 
270         testCase.loeschen(test);
271 
272         Reporterzeugung test2 = new Reporterzeugung(rptnamen, new Integer(1), new Integer(1), spr, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);
273  
274         assertNull(testCase.sucheObjekt(test2));
275 
276         test = new Reporterzeugung();       
277     }
278 }