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.UseCaseReportnamen;
28  import org.fhw.cabaweb.ojb.UseCaseProjekte;
29  import org.fhw.cabaweb.ojb.dataobjects.Reportnamen;
30  import org.fhw.cabaweb.ojb.dataobjects.Projekte;
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 Reportnamen
37   *
38   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
39   * @version 17.05.2004
40   */
41  public class UseCaseReportnamenTest extends TestCase
42  {
43      private PersistenceBroker broker;
44      private UseCase testCase;
45      private Reportnamen test;
46  
47      public static void main(String[] args)
48      {
49          //      junit.swingui.TestRunner.run(UseCaseProjektbeschreibungenTest.class);
50          junit.textui.TestRunner.run(UseCaseReportnamenTest.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 UseCaseReportnamen(broker);
71          
72          test = new Reportnamen();
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 Reportnamen(prj, new Integer(1), "Testreportname 1", "Unternehmen");
100 
101         testCase.erzeugen(test);
102 
103         Reportnamen test2 = new Reportnamen(prj, new Integer(1), null, null);
104  
105         assertEquals(test.toString(), ((Reportnamen) testCase.sucheObjekt(test2)).toString());
106 
107         test = new Reportnamen();       
108     }
109 
110     public void testEditieren()
111     {
112         Projekte prj = new Projekte(new Integer(1), null, null, null);
113         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
114         
115         prj = (Projekte) prjCase.sucheObjekt(prj);
116         
117         test = new Reportnamen(prj, new Integer(1), "Testreportname A", "Unternehmen");
118 
119         testCase.editieren(test);
120 
121         Reportnamen test2 = new Reportnamen(prj, new Integer(1), "Testreportname A", "Unternehmen");
122  
123         assertEquals(test.toString(), ((Reportnamen) testCase.sucheObjekt(test2)).toString());
124 
125         test = new Reportnamen();       
126     }
127 
128     public void testSucheObjekt()
129     {
130         Projekte prj = new Projekte(new Integer(1), null, null, null);
131         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
132         
133         prj = (Projekte) prjCase.sucheObjekt(prj);
134         
135         test = new Reportnamen(prj, new Integer(1), null, null);
136 
137         Reportnamen objekt = (Reportnamen) testCase.sucheObjekt(test);
138         
139         Reportnamen test2 = new Reportnamen(prj, new Integer(1), "Testreportname A", "Unternehmen");
140  
141         assertEquals(test2.toString(), objekt.toString());
142 
143         test = new Reportnamen();        
144     }
145 
146     public void testSucheObjekte()
147     {
148         test = new Reportnamen(null, null, "Testreportname A", "Unternehmen");
149 
150         Collection objekte = testCase.sucheObjekte(test);
151         
152         java.util.Iterator iter = objekte.iterator();
153         while (iter.hasNext())
154         {
155 //          System.out.println(iter.next());
156             iter.next();
157         }         
158 
159         assertEquals(true, objekte.size() == 1);
160     }
161 
162     public void testSucheAlle()
163     {
164         Collection alleObjekte = testCase.sucheAlle(Reportnamen.class);
165         
166         java.util.Iterator iter = alleObjekte.iterator();
167         while (iter.hasNext())
168         {
169 //          System.out.println(iter.next());
170             iter.next();
171         }         
172 
173         assertEquals(true, alleObjekte.size() == 1);
174     }
175 
176     public void testLoeschen()
177     {
178         Projekte prj = new Projekte(new Integer(1), null, null, null);
179         UseCase prjCase = (UseCase) new UseCaseProjekte(broker);
180         
181         prj = (Projekte) prjCase.sucheObjekt(prj);
182 
183         test = new Reportnamen(prj, new Integer(1), null, null);
184 
185         testCase.loeschen(test);
186 
187         Reportnamen test2 = new Reportnamen(prj, new Integer(1), null, null);
188  
189         assertNull(testCase.sucheObjekt(test2));
190 
191         test = new Reportnamen();       
192     }
193 }