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.UseCaseSprachen;
28  import org.fhw.cabaweb.ojb.dataobjects.Sprachen;
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 Sprachen
35   *
36   * @author  <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
37   * @version Version 1.0 12.04.2004
38   */
39  public class UseCaseSprachenTest extends TestCase
40  {
41      private PersistenceBroker broker;
42      private UseCase testCase;
43      private Sprachen test;
44  
45      public static void main(String[] args)
46      {
47          //      junit.swingui.TestRunner.run(UseCaseSprachenTest.class);
48          junit.textui.TestRunner.run(UseCaseSprachenTest.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 UseCaseSprachen(broker);
69          
70          test = new Sprachen();
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 Sprachen(new Integer(99999), "Spanisch", new Boolean(true));
93  
94          testCase.erzeugen(test);
95  
96          Sprachen test2 = new Sprachen(new Integer(99999), null, null);
97   
98          assertEquals(test.toString(), ((Sprachen) testCase.sucheObjekt(test2)).toString());
99  
100         test = new Sprachen();       
101 	}
102 
103 	public void testEditieren()
104 	{
105         test = new Sprachen(new Integer(99999), "Deutsch", new Boolean(false));
106 
107         testCase.editieren(test);
108 
109         Sprachen test2 = new Sprachen(new Integer(99999), null, null);
110  
111         assertEquals(test.toString(), ((Sprachen) testCase.sucheObjekt(test2)).toString());
112 
113         test = new Sprachen();       
114 	}
115     
116     public void testSucheObjekt()
117     {
118         test = new Sprachen(new Integer(99999), null, null);
119 
120         Sprachen objekt = (Sprachen) testCase.sucheObjekt(test);
121         
122         Sprachen test2 = new Sprachen(new Integer(99999), "Deutsch", new Boolean(false));
123  
124         assertEquals(test2.toString(), objekt.toString());
125 
126         test = new Sprachen();        
127     }
128     
129     public void testSucheObjekte()
130     {
131         test = new Sprachen(null, "Deutsch", 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() > 1);
143     }
144     
145     public void testSucheAlle()
146     {
147         Collection alleObjekte = testCase.sucheAlle(Sprachen.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 Sprachen(new Integer(99999), null, null);
162 
163         testCase.loeschen(test);
164 
165         Sprachen test2 = new Sprachen(new Integer(99999), null, null);
166  
167         assertNull(testCase.sucheObjekt(test2));
168 
169         test = new Sprachen();       
170     }
171 }