1 /*******************************************************************************
2 * Copyright (c) 2005, 2006 Imola Informatica.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the LGPL License v2.1
5 * which accompanies this distribution, and is available at
6 * http://www.gnu.org/licenses/lgpl.html
7 *******************************************************************************/
8 /**
9 *
10 */
11 package it.imolinfo.jbi4cics.test.connection.jdbc;
12
13 import junit.framework.TestCase;
14
15 /**
16 * @author raffaele
17 *
18 */
19 public class SimpleJdbcConnectionManagerTest extends TestCase {
20 /* private static Log log=LogFactory.getLog(SimpleJdbcConnectionManagerTest.class);
21 *//**
22 *
23 *//*
24 public SimpleJdbcConnectionManagerTest(String arg0) {
25 super(arg0);
26 // TODO Auto-generated constructor stu
27 }
28
29 public void setUp(){
30 try {
31 String baseDirectory="./main/test/etc";
32 if(JNDIUnitTestHelper.notInitialized()){
33 JNDIUnitTestHelper.init(baseDirectory+"/"+"jndi_unit_test_helper.properties");
34 }
35 }
36 catch(IOException e){
37 e.printStackTrace();
38 fail(e.getMessage());
39 }
40 catch(NamingException e){
41 e.printStackTrace();
42 fail(e.getMessage());
43 }
44 catch(ResourceException e){
45 e.printStackTrace();
46 fail(e.getMessage());
47 }
48 }
49
50 public void testStoredProcedureOutParameterResultSet(){
51 try{
52 //costruisco il parameter descriptor
53 JdbcParameterDescriptor storedProcedureParameter=new JdbcParameterDescriptor(JdbcParameterDescriptor.IN_OUT_PARAMETER);
54 storedProcedureParameter.setSqlType(Types.VARCHAR);
55
56 //costruisco lo statement decriptor
57 JdbcStatementDescriptor jdbcStatementDescriptor=new JdbcStatementDescriptor();
58 jdbcStatementDescriptor.addFieldMapping("storedProcedureParameter",new Integer(1),storedProcedureParameter);
59 jdbcStatementDescriptor.setStatementType(JdbcStatementDescriptor.CALLABLE_STATEMENT);
60 jdbcStatementDescriptor.setSqlType(JdbcStatementDescriptor.SELECT_SQL);
61 jdbcStatementDescriptor.setSql("{call jbi4cics.test_rs (?)}");
62 jdbcStatementDescriptor.setBeanClass(StoredProcedureBean.class);
63
64 // costrisco il result set mapping descriptor
65 ResultSetMappingDescriptor resultSetMappingDescriptor=new ResultSetMappingDescriptor();
66 resultSetMappingDescriptor.addFieldMapping("id","ID",null);
67 resultSetMappingDescriptor.addFieldMapping("inpuData","input_data",null);
68 resultSetMappingDescriptor.addFieldMapping("outputData","output_data",null);
69 resultSetMappingDescriptor.setBeanClass(ResultSetBean.class);
70
71 // costruisco il mapping descriptor
72 JdbcBeanMappingDescriptor jdbcBeanMappingDescriptor=new JdbcBeanMappingDescriptor();
73 jdbcBeanMappingDescriptor.setJdbcStatementDescriptor(jdbcStatementDescriptor);
74 jdbcBeanMappingDescriptor.setResultSetMappingDescriptor(resultSetMappingDescriptor);
75 jdbcBeanMappingDescriptor.setResultSetPropertyName("resultSet");
76
77 // costruisco l'input bean
78 StoredProcedureBean inputBean=new StoredProcedureBean();
79 inputBean.setStoredProcedureParameter("hello");
80
81 // costruisco il locator
82 SimpleLocation j2cLocation=new SimpleLocation();
83 j2cLocation.setConnectionType(ServiceLocation.JDBC);
84 j2cLocation.setLocationName("jdbc/jbi4cics");
85
86 //costruisco l'account
87 J2CAccount j2cAccount=new J2CAccount();
88 j2cAccount.setUsername("jbi4cics");
89 j2cAccount.setPassword("jbi4cics");
90
91 //costruisco il service context
92 //inizializzazione del service context
93 ServiceContext serviceContext=new ServiceContext();
94 serviceContext.setInputMappingDescriptor(jdbcStatementDescriptor);
95 serviceContext.setOutputMappingDescriptor(jdbcBeanMappingDescriptor);
96 serviceContext.setInputBean(inputBean);
97 serviceContext.setServiceLocation(j2cLocation);
98 serviceContext.setAccount(j2cAccount);
99
100
101 // costruisco il jdbc formatter
102 JdbcFormatter jdbcFormatter=new JdbcFormatter();
103
104 // eseguo la formattazione in andata
105 long millis1=System.currentTimeMillis();
106 jdbcFormatter.mapInputBeanToInputMessage(serviceContext);
107 DisconnectedPreparedStatement inputMessage=(DisconnectedPreparedStatement)serviceContext.getInputMessage();
108 long millis2=System.currentTimeMillis();
109 log.debug("input message: "+inputMessage);
110 log.debug("conversion time1="+(millis2-millis1)+" millis");
111
112 // costruisco il connection manager
113 JdbcConnectionManager jdbcConnectionManager=new JdbcConnectionManager();
114
115 // eseguo la chiamata
116 millis1=System.currentTimeMillis();
117 jdbcConnectionManager.handleCall(serviceContext);
118 millis2=System.currentTimeMillis();
119 log.debug("execution time="+(millis2-millis1)+" millis");
120
121 // eseguo la formattazione all'indietro
122
123 millis1=System.currentTimeMillis();
124 jdbcFormatter.mapOutputMessageToOutputBean(serviceContext);
125 StoredProcedureBean outputBean=(StoredProcedureBean)serviceContext.getOutputBean();
126 millis2=System.currentTimeMillis();
127
128 log.debug("output bean: "+outputBean);
129 log.debug("conversion time1="+(millis2-millis1)+" millis");
130
131
132 }
133 catch (Jbi4cicsException e){
134 e.printStackTrace();
135 fail(e.getMessage());
136 }
137 }
138
139 public static class StoredProcedureBean {
140 String storedProcedureParameter;
141 List resultSet;
142
143 *//**
144 * @return Returns the resultSet.
145 *//*
146 public List getResultSet() {
147 return resultSet;
148 }
149
150 *//**
151 * @param resultSet The resultSet to set.
152 *//*
153 public void setResultSet(List resultSet) {
154 this.resultSet = resultSet;
155 }
156
157 *//**
158 * @return Returns the storedProcedureParameter.
159 *//*
160 public String getStoredProcedureParameter() {
161 return storedProcedureParameter;
162 }
163
164 *//**
165 * @param storedProcedureParameter The storedProcedureParameter to set.
166 *//*
167 public void setStoredProcedureParameter(String storedProcedureParameter) {
168 this.storedProcedureParameter = storedProcedureParameter;
169 }
170
171 }
172
173 public static class ResultSetBean {
174 int id;
175 String inputData;
176 String outputData;
177 *//**
178 * @return Returns the id.
179 *//*
180 public int getId() {
181 return id;
182 }
183 *//**
184 * @param id The id to set.
185 *//*
186 public void setId(int id) {
187 this.id = id;
188 }
189 *//**
190 * @return Returns the inputData.
191 *//*
192 public String getInputData() {
193 return inputData;
194 }
195 *//**
196 * @param inputData The inputData to set.
197 *//*
198 public void setInputData(String inputData) {
199 this.inputData = inputData;
200 }
201 *//**
202 * @return Returns the outputData.
203 *//*
204 public String getOutputData() {
205 return outputData;
206 }
207 *//**
208 * @param outputData The outputData to set.
209 *//*
210 public void setOutputData(String outputData) {
211 this.outputData = outputData;
212 }
213
214 }
215 */
216 }