1 package ch.ige.edossier.web.server.dao.test;
2
3 import junit.framework.*;
4 import ch.ige.edossier.web.vo.*;
5 import ch.ige.edossier.web.server.dao.*;
6 import ch.ige.edossier.util.*;
7 import java.sql.*;
8 import java.util.*;
9 import java.text.SimpleDateFormat;
10 import java.text.*;
11
12
13
21 public class PriorityDAOTest extends TestCase
22 {
23 private PriorityVO insertVO = new PriorityVO();
24 private PriorityDAO dao = new PriorityDAO();
25 private PriorityVO vo = new PriorityVO();
26 private SimpleDateFormat sdf = new SimpleDateFormat( "dd.MM.yyyy" );
27
28 public PriorityDAOTest( String s )
29 {
30 super( s );
31 }
32
33
36 protected void setUp()
37 {
38 insertVO.setPriorityId( this.selectMaxPriorityId() );
39 insertVO.setDossierId( 999 );
40 try
41 {
42 insertVO.setPrioDat( new java.sql.Date( ( sdf.parse( "11.11.2001" ) ).getTime() ) );
43 }
44 catch( ParseException ex )
45 {
46 }
47 insertVO.setCountryCd( "DE" );
48 }
49
50
53 public void test1Insert()
54 {
55 System.out.println( "Test INSERT PriorityDAO" );
57 try
58 {
59 int lastId = this.selectMaxPriorityId();
60
61 dao.insert( insertVO );
63 insertVO.setPriorityId( this.selectMaxPriorityId() );
64
65 assertTrue( "PriorityVO eingefügt ", insertVO.getPriorityId() != lastId );
67 }
68 catch( Exception ex )
69 {
70 ex.printStackTrace();
71 fail( ex.toString() );
72 }
73 }
74
75
78 public void test2SelectPriority()
79 {
80 System.out.println( "Test SELECT PriorityDAO " );
82
83 try
84 {
85 List list = dao.select( insertVO.getDossierId());
87
88 if( list == null )
90 {
91 System.out.println( "SELECT: Datensatz existiert nicht" );
92 }
93 else
94 {
95 PriorityVO vo = (PriorityVO)list.get(0);
96
97 assertEquals( vo.getPriorityId(), insertVO.getPriorityId() );
98 assertEquals( vo.getDossierId(), insertVO.getDossierId() );
99 assertEquals( vo.getPrioDat(), insertVO.getPrioDat() );
100 assertEquals( vo.getCountryCd(), insertVO.getCountryCd() );
101 }
102 }
103 catch( Exception ex )
104 {
105 ex.printStackTrace();
106 fail( ex.toString() );
107 }
108 }
109
110
113 public void test3Update()
114 {
115 System.out.println( "Test UPDATE PriorityDAO " );
117
118 try
119 {
120 insertVO.setCountryCd( "FR" );
122 insertVO.setPrioDat( new java.sql.Date( sdf.parse( "12.11.2001" ).getTime() ) );
123
124 dao.update( insertVO );
125
126 List list = dao.select(insertVO.getDossierId() );
127
128 if( vo == null )
130 {
131 System.out.println( "SELECT: Datensatz existiert nicht" );
132 }
133 else
134 {
135 PriorityVO vo = (PriorityVO)list.get(0);
136
137 assertEquals( vo.getPriorityId(), insertVO.getPriorityId() );
138 assertEquals( vo.getCountryCd(), "FR" );
139 assertEquals( vo.getPrioDat(), new java.sql.Date( sdf.parse( "12.11.2001" ).getTime() ) );
140 }
141 }
142 catch( Exception ex )
143 {
144 ex.printStackTrace();
145 fail( ex.toString() );
146 }
147 }
148
149
152 public void test4Delete()
153 {
154 int ret = 0;
155
156 System.out.println( "Test DELETE PriorityDAO" );
158
159 try
160 {
161 ret = dao.delete( insertVO.getPriorityId() );
163
164 assertEquals( "Anzahl gelöschte Datensätze: ", ret, 1 );
166 }
167 catch( SQLException ex )
168 {
169 ex.printStackTrace();
170 fail( ex.toString() );
171 }
172 }
173
174
178 private int selectMaxPriorityId()
179 {
180 Connection con = null;
181 PreparedStatement ps = null;
182 ResultSet rs = null;
183 int maxValue = 0;
184
185 try
186 {
187 con = DBHelper.getInstance().getEsolutionConnection();
188
189 ps = con.prepareStatement( "SELECT MAX(priority_id) max_value from priority" );
190 rs = ps.executeQuery();
191
192 if( rs.next() )
193 {
194 maxValue = rs.getInt( "max_value" );
195 }
196 }
197 catch( Exception ex )
198 {
199 ex.printStackTrace();
200 fail( ex.toString() );
201 }
202 return maxValue;
203 }
204 }
205