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 java.sql.*;
7 import java.util.*;
8 import ch.ige.edossier.util.*;
9
10
18 public class AnswerDAOTest extends TestCase
19 {
20 private AnswerVO insertVO = new AnswerVO();
21 private AnswerDAO dao = new AnswerDAO();
22 private AnswerVO vo = new AnswerVO();
23
24 public AnswerDAOTest( String s )
25 {
26 super( s );
27 }
28
29
32 protected void setUp()
33 {
34 insertVO.setAnswerId( selectMaxAnswerId());
35 insertVO.setInterceptionId( selectMaxInterceptionId() );
36 insertVO.setName( "Kern" );
37 insertVO.setEmail( "kern@ch");
38 insertVO.setTelNr("0041 31 333 22 11");
39 insertVO.setText( "Test" );
40 }
41
42
45 public void test1Insert()
46 {
47 System.out.println( "Test INSERT AnswerDAO" );
49 try
50 {
51 dao.insert( insertVO );
53
54 assertTrue( "AnswerDAO eingefügt ", 1 == 1 );
56 }
57 catch( Exception ex )
58 {
59 ex.printStackTrace();
60 fail( ex.toString() );
61 }
62 }
63
64
67 public void test2SelectAnswer()
68 {
69 System.out.println( "Test SELECT_BY_INTERCEPTION AnswerDAO " );
71
72 try
73 {
74 vo = dao.selectByInterception( insertVO.getInterceptionId() );
76
77 if( vo == null )
79 {
80 System.out.println( "SELECT: Datensatz existiert nicht" );
81 }
82 else
83 {
84 assertEquals( vo.getInterceptionId(), insertVO.getInterceptionId() );
85 assertEquals( vo.getName(), insertVO.getName() );
86 assertEquals( vo.getEmail(), insertVO.getEmail() );
87 assertEquals( vo.getTelNr(), insertVO.getTelNr() );
88 assertEquals( vo.getText(), insertVO.getText() );
89 }
90 }
91 catch( Exception ex )
92 {
93 ex.printStackTrace();
94 fail( ex.toString() );
95 }
96 }
97
98
101 public void test3Delete()
102 {
103 int ret = 0;
104
105 System.out.println( "Test DELETE AnswerDAO" );
107
108 try
109 {
110 ret = dao.delete( insertVO.getAnswerId() );
112
113 assertEquals( "Anzahl gelöschte Datensätze: ", 1, ret );
115 }
116 catch( SQLException ex )
117 {
118 ex.printStackTrace();
119 fail( ex.toString() );
120 }
121 }
122
123
127 private int selectMaxInterceptionId()
128 {
129 Connection con = null;
130 PreparedStatement ps = null;
131 ResultSet rs = null;
132 int maxValue = 0;
133
134 try
135 {
136 con = DBHelper.getInstance().getEsolutionConnection();
137
138 ps = con.prepareStatement( "SELECT MAX(interception_id) max_value from interception" );
139 rs = ps.executeQuery();
140
141 if( rs.next() )
142 {
143 maxValue = rs.getInt( "max_value" );
144 }
145 }
146 catch( Exception ex )
147 {
148 ex.printStackTrace();
149 fail( ex.toString() );
150 }
151 return maxValue;
152 }
153
154
158 private int selectMaxAnswerId()
159 {
160 Connection con = null;
161 PreparedStatement ps = null;
162 ResultSet rs = null;
163 int maxValue = 0;
164
165 try
166 {
167 con = DBHelper.getInstance().getEsolutionConnection();
168
169 ps = con.prepareStatement( "SELECT MAX(answer_id) max_value from answer" );
170 rs = ps.executeQuery();
171
172 if( rs.next() )
173 {
174 maxValue = rs.getInt( "max_value" );
175 }
176 }
177 catch( Exception ex )
178 {
179 ex.printStackTrace();
180 fail( ex.toString() );
181 }
182 return maxValue;
183 }
184
185 }
186