PageRenderTime 37ms CodeModel.GetById 1ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib-imola/cics-bc/jbi4cics/src/test/java/it/imolinfo/jbi4cics/test/mapping/coboltypes/CobolIntegerTypeMappingTest.java

https://bitbucket.org/pymma/openesb-components
Java | 451 lines | 282 code | 71 blank | 98 comment | 0 complexity | b439a9c589ae2238d00da3f79cab02e6 MD5 | raw file
  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. package it.imolinfo.jbi4cics.test.mapping.coboltypes;
  9. import it.imolinfo.jbi4cics.typemapping.cobol.CobolFieldFormatter;
  10. import it.imolinfo.jbi4cics.typemapping.cobol.CobolType;
  11. import it.imolinfo.jbi4cics.typemapping.cobol.CobolTypeDescriptor;
  12. import it.imolinfo.jbi4cics.typemapping.cobol.HexDump;
  13. import java.math.BigInteger;
  14. import java.util.Arrays;
  15. import junit.framework.TestCase;
  16. import org.apache.commons.logging.Log;
  17. import org.apache.commons.logging.LogFactory;
  18. public class CobolIntegerTypeMappingTest extends TestCase {
  19. private static Log log=LogFactory.getLog(CobolIntegerTypeMappingTest.class);
  20. public CobolIntegerTypeMappingTest(String arg0){
  21. super(arg0);
  22. }
  23. /**
  24. * testo un integer -- comp
  25. * la dichiarazione è
  26. * PIC 9(9) comp
  27. * valore 123456789
  28. *
  29. * PIC 9(1)-9(4) occupa due byte
  30. * PIC 9(5)-9(9) occupa 4 byte
  31. * PIC 9(10)-9(??) occupa 8 byte
  32. *
  33. * la differenza fra comp e comp-4 è che comp controlla che la reappresentazione in cifre non superi quello dichiarato
  34. */
  35. public void testInteger9_9(){
  36. try{
  37. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  38. cobolTypeDescriptor.setType(CobolType.INTEGER);
  39. cobolTypeDescriptor.setIntegerPartLength(9);
  40. cobolTypeDescriptor.setBigEndian(true);
  41. BigInteger value=BigInteger.valueOf(123456789L);
  42. //String value="pippo";
  43. byte[] buffer=new byte[4];
  44. byte[] expectedBuffer=value.toByteArray(); //cosi' semplice??
  45. //byte[] expectedBuffer=value.getBytes(); //cosi' semplice??
  46. long millis1=System.currentTimeMillis();
  47. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  48. long millis2=System.currentTimeMillis();
  49. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  50. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  51. log.debug("conversion time="+(millis2-millis1)+" millis");
  52. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  53. }
  54. catch(Exception e){
  55. e.printStackTrace();
  56. fail(e.getMessage());
  57. }
  58. }
  59. /**
  60. * testo un integer -- comp
  61. * la dichiarazione è
  62. * PIC s9(9) comp
  63. * valore 123456789
  64. *
  65. */
  66. public void testIntegersp9_9(){
  67. try{
  68. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  69. cobolTypeDescriptor.setType(CobolType.INTEGER);
  70. cobolTypeDescriptor.setIntegerPartLength(9);
  71. cobolTypeDescriptor.setBigEndian(true);
  72. cobolTypeDescriptor.setSigned(true);
  73. BigInteger value=BigInteger.valueOf(123456789L);
  74. byte[] buffer=new byte[4];
  75. byte[] expectedBuffer=value.toByteArray(); //cosi' semplice??
  76. long millis1=System.currentTimeMillis();
  77. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  78. long millis2=System.currentTimeMillis();
  79. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  80. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  81. log.debug("conversion time="+(millis2-millis1)+" millis");
  82. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  83. }
  84. catch(Exception e){
  85. e.printStackTrace();
  86. fail(e.getMessage());
  87. }
  88. }
  89. /**
  90. * testo un integer -- comp
  91. * la dichiarazione è
  92. * PIC s9(9) comp
  93. * valore -123456789
  94. *
  95. */
  96. public void testIntegersm9_9(){
  97. try{
  98. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  99. cobolTypeDescriptor.setType(CobolType.INTEGER);
  100. cobolTypeDescriptor.setIntegerPartLength(9);
  101. cobolTypeDescriptor.setBigEndian(true);
  102. cobolTypeDescriptor.setSigned(true);
  103. BigInteger value=BigInteger.valueOf(-123456789L);
  104. byte[] buffer=new byte[4];
  105. byte[] expectedBuffer=value.toByteArray(); //cosi' semplice??
  106. long millis1=System.currentTimeMillis();
  107. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  108. long millis2=System.currentTimeMillis();
  109. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  110. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  111. log.debug("conversion time="+(millis2-millis1)+" millis");
  112. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  113. }
  114. catch(Exception e){
  115. e.printStackTrace();
  116. fail(e.getMessage());
  117. }
  118. }
  119. /**
  120. * testo un integer -- comp
  121. * la dichiarazione è
  122. * PIC 9(4) comp
  123. * valore 1234
  124. *
  125. */
  126. public void testInteger9_4(){
  127. try{
  128. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  129. cobolTypeDescriptor.setType(CobolType.INTEGER);
  130. cobolTypeDescriptor.setIntegerPartLength(4);
  131. cobolTypeDescriptor.setBigEndian(true);
  132. BigInteger value=BigInteger.valueOf(1234L);
  133. byte[] buffer=new byte[2];
  134. byte[] expectedBuffer=value.toByteArray(); //cosi' semplice??
  135. long millis1=System.currentTimeMillis();
  136. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  137. long millis2=System.currentTimeMillis();
  138. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  139. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  140. log.debug("conversion time="+(millis2-millis1)+" millis");
  141. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  142. }
  143. catch(Exception e){
  144. e.printStackTrace();
  145. fail(e.getMessage());
  146. }
  147. }
  148. /**
  149. * testo un integer -- comp
  150. * la dichiarazione è
  151. * PIC s9(4) comp
  152. * valore 1234
  153. *
  154. */
  155. public void testIntegersp9_4(){
  156. try{
  157. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  158. cobolTypeDescriptor.setType(CobolType.INTEGER);
  159. cobolTypeDescriptor.setIntegerPartLength(4);
  160. cobolTypeDescriptor.setBigEndian(true);
  161. cobolTypeDescriptor.setSigned(true);
  162. BigInteger value=BigInteger.valueOf(1234L);
  163. byte[] buffer=new byte[2];
  164. byte[] expectedBuffer=value.toByteArray(); //cosi' semplice??
  165. long millis1=System.currentTimeMillis();
  166. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  167. long millis2=System.currentTimeMillis();
  168. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  169. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  170. log.debug("conversion time="+(millis2-millis1)+" millis");
  171. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  172. }
  173. catch(Exception e){
  174. e.printStackTrace();
  175. fail(e.getMessage());
  176. }
  177. }
  178. /**
  179. * testo un integer -- comp
  180. * la dichiarazione è
  181. * PIC s9(4) comp
  182. * valore -1234
  183. *
  184. */
  185. public void testIntegersm9_4(){
  186. try{
  187. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  188. cobolTypeDescriptor.setType(CobolType.INTEGER);
  189. cobolTypeDescriptor.setIntegerPartLength(4);
  190. cobolTypeDescriptor.setBigEndian(true);
  191. cobolTypeDescriptor.setSigned(true);
  192. BigInteger value=BigInteger.valueOf(-1234L);
  193. byte[] buffer=new byte[2];
  194. byte[] expectedBuffer=value.toByteArray(); //cosi' semplice??
  195. long millis1=System.currentTimeMillis();
  196. CobolFieldFormatter.format(value,buffer,cobolTypeDescriptor,0);
  197. long millis2=System.currentTimeMillis();
  198. log.debug("buffer dopo il format in esadecimale: ["+HexDump.toHex(buffer)+"]");
  199. log.debug("buffer expected in esadecimale: ["+HexDump.toHex(expectedBuffer)+"]");
  200. log.debug("conversion time="+(millis2-millis1)+" millis");
  201. assertTrue("conversione non corretta",Arrays.equals(expectedBuffer,buffer));
  202. }
  203. catch(Exception e){
  204. e.printStackTrace();
  205. fail(e.getMessage());
  206. }
  207. }
  208. /**
  209. * testo un integer -- comp
  210. * la dichiarazione è
  211. * PIC 9(9) comp
  212. * valore 123456789
  213. *
  214. */
  215. public void testUnformatInteger9_9(){
  216. try{
  217. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  218. cobolTypeDescriptor.setType(CobolType.INTEGER);
  219. cobolTypeDescriptor.setIntegerPartLength(9);
  220. cobolTypeDescriptor.setBigEndian(true);
  221. BigInteger value=BigInteger.valueOf(123456789L);
  222. byte[] buffer=value.toByteArray(); //cosi' semplice??
  223. long millis1=System.currentTimeMillis();
  224. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  225. long millis2=System.currentTimeMillis();
  226. log.debug("value ottenuto: ["+result.toString()+"]");
  227. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  228. log.debug("conversion time="+(millis2-millis1)+" millis");
  229. assertEquals("conversione non corretta",value,result);
  230. }
  231. catch(Exception e){
  232. e.printStackTrace();
  233. fail(e.getMessage());
  234. }
  235. }
  236. /**
  237. * testo un integer -- comp
  238. * la dichiarazione è
  239. * PIC s9(9) comp
  240. * valore 123456789
  241. *
  242. */
  243. public void testUnformatIntegersp9_9(){
  244. try{
  245. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  246. cobolTypeDescriptor.setType(CobolType.INTEGER);
  247. cobolTypeDescriptor.setIntegerPartLength(9);
  248. cobolTypeDescriptor.setBigEndian(true);
  249. cobolTypeDescriptor.setSigned(true);
  250. BigInteger value=BigInteger.valueOf(123456789L);
  251. byte[] buffer=value.toByteArray(); //cosi' semplice??
  252. long millis1=System.currentTimeMillis();
  253. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  254. long millis2=System.currentTimeMillis();
  255. log.debug("value ottenuto: ["+result.toString()+"]");
  256. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  257. log.debug("conversion time="+(millis2-millis1)+" millis");
  258. assertEquals("conversione non corretta",value,result);
  259. }
  260. catch(Exception e){
  261. e.printStackTrace();
  262. fail(e.getMessage());
  263. }
  264. }
  265. /**
  266. * testo un integer -- comp
  267. * la dichiarazione è
  268. * PIC s9(9) comp
  269. * valore -123456789
  270. *
  271. */
  272. public void testUnformatIntegersm9_9(){
  273. try{
  274. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  275. cobolTypeDescriptor.setType(CobolType.INTEGER);
  276. cobolTypeDescriptor.setIntegerPartLength(9);
  277. cobolTypeDescriptor.setBigEndian(true);
  278. cobolTypeDescriptor.setSigned(true);
  279. BigInteger value=BigInteger.valueOf(-123456789L);
  280. byte[] buffer=value.toByteArray(); //cosi' semplice??
  281. long millis1=System.currentTimeMillis();
  282. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  283. long millis2=System.currentTimeMillis();
  284. log.debug("value ottenuto: ["+result.toString()+"]");
  285. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  286. log.debug("conversion time="+(millis2-millis1)+" millis");
  287. assertEquals("conversione non corretta",value,result);
  288. }
  289. catch(Exception e){
  290. e.printStackTrace();
  291. fail(e.getMessage());
  292. }
  293. }
  294. /**
  295. * testo un integer -- comp
  296. * la dichiarazione è
  297. * PIC 9(4) comp
  298. * valore 1234
  299. *
  300. */
  301. public void testUnformatInteger9_4(){
  302. try{
  303. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  304. cobolTypeDescriptor.setType(CobolType.INTEGER);
  305. cobolTypeDescriptor.setIntegerPartLength(4);
  306. cobolTypeDescriptor.setBigEndian(true);
  307. BigInteger value=BigInteger.valueOf(1234L);
  308. byte[] buffer=value.toByteArray(); //cosi' semplice??
  309. long millis1=System.currentTimeMillis();
  310. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  311. long millis2=System.currentTimeMillis();
  312. log.debug("value ottenuto: ["+result.toString()+"]");
  313. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  314. log.debug("conversion time="+(millis2-millis1)+" millis");
  315. assertEquals("conversione non corretta",value,result);
  316. }
  317. catch(Exception e){
  318. e.printStackTrace();
  319. fail(e.getMessage());
  320. }
  321. }
  322. /**
  323. * testo un integer -- comp
  324. * la dichiarazione è
  325. * PIC s9(4) comp
  326. * valore 1234
  327. *
  328. */
  329. public void testUnformatIntegersp9_4(){
  330. try{
  331. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  332. cobolTypeDescriptor.setType(CobolType.INTEGER);
  333. cobolTypeDescriptor.setIntegerPartLength(4);
  334. cobolTypeDescriptor.setBigEndian(true);
  335. cobolTypeDescriptor.setSigned(true);
  336. BigInteger value=BigInteger.valueOf(1234L);
  337. byte[] buffer=value.toByteArray(); //cosi' semplice??
  338. long millis1=System.currentTimeMillis();
  339. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  340. long millis2=System.currentTimeMillis();
  341. log.debug("value ottenuto: ["+result.toString()+"]");
  342. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  343. log.debug("conversion time="+(millis2-millis1)+" millis");
  344. assertEquals("conversione non corretta",value,result);
  345. }
  346. catch(Exception e){
  347. e.printStackTrace();
  348. fail(e.getMessage());
  349. }
  350. }
  351. /**
  352. * testo un integer -- comp
  353. * la dichiarazione è
  354. * PIC s9(4) comp
  355. * valore -1234
  356. *
  357. */
  358. public void testUnformatIntegersm9_4(){
  359. try{
  360. CobolTypeDescriptor cobolTypeDescriptor=new CobolTypeDescriptor();
  361. cobolTypeDescriptor.setType(CobolType.INTEGER);
  362. cobolTypeDescriptor.setIntegerPartLength(4);
  363. cobolTypeDescriptor.setBigEndian(true);
  364. cobolTypeDescriptor.setSigned(true);
  365. BigInteger value=BigInteger.valueOf(-1234L);
  366. byte[] buffer=value.toByteArray(); //cosi' semplice??
  367. long millis1=System.currentTimeMillis();
  368. Object result=CobolFieldFormatter.unformat(buffer,cobolTypeDescriptor,0);
  369. long millis2=System.currentTimeMillis();
  370. log.debug("value ottenuto: ["+result.toString()+"]");
  371. log.debug("buffer esadecimale: ["+HexDump.toHex(buffer)+"]");
  372. log.debug("conversion time="+(millis2-millis1)+" millis");
  373. assertEquals("conversione non corretta",value,result);
  374. }
  375. catch(Exception e){
  376. e.printStackTrace();
  377. fail(e.getMessage());
  378. }
  379. }
  380. }