開始之前,您必須先完成練習 1.3:建立 Java 方法。
練習 1.4 會引導您建立 Java 測試類別來測試應用程式。在這個練習中,您將執行下列動作:
/* * 建立於 2004 年 10 月 4 日 * * TODO 如果要變更這個所產生的檔案之範本,請前往 * Window - 喜好設定 - Java - 程式碼樣式 - 程式碼範本 */ package sample.ims; import sample.ims.data.*; import com.ibm.connector2.ims.ico.IMSDFSMessageException; /** * @author ivyho * * TODO 如果要變更這個所產生的類型註解之範本,請前往 * Window - 喜好設定 - Java - 程式碼樣式 - 程式碼範本 */ public class TestInOutProxy { public static void main (String[] args) { try { // --------------------------------------------------- // 建立 formatHandler,然後從 formatHandler 建立輸入 // 訊息 Bean。 // --------------------------------------------------- INOUTMSG input = new INOUTMSG(); int sz = input.getSize(); System.out.println("\nInitial size of input message is: " + sz); // --------------------------------------------------- // 請先不要設定長度 (LL) 欄位... 等 // 輸入訊息已調整為只反映 // 實際傳送的陣列元素數目時再設定。 // --------------------------------------------------- input.setWs__zz((short) 0); input.setWs__trcd("SKS7 "); // --------------------------------------------------- // 建構陣列, // 並將要傳送至 IMS 應用程式的元素移入陣列中。在這個範例中, // 會傳送三個元素。 // --------------------------------------------------- Inoutmsg_ws__customer[] customers = new Inoutmsg_ws__customer[3]; Inoutmsg_ws__customer aCustomer1 = new Inoutmsg_ws__customer(); aCustomer1.setWs__cust__name("Cathy Tang"); aCustomer1.setWs__cust__number("CN001"); customers[0] = aCustomer1; Inoutmsg_ws__customer aCustomer2 = new Inoutmsg_ws__customer(); aCustomer2.setWs__cust__name("Haley Fung"); aCustomer2.setWs__cust__number("CN002"); customers[1] = aCustomer2; Inoutmsg_ws__customer aCustomer3 = new Inoutmsg_ws__customer(); aCustomer3.setWs__cust__name("Steve Kuo"); aCustomer3.setWs__cust__number("CN003"); customers[2] = aCustomer3; // --------------------------------------------------- // 設定輸入訊息上的陣列。 // --------------------------------------------------- input.setWs__customer(customers); input.setIndx((short) 3); System.out.println("\nInitial value of INDX is: " + input.getIndx()); // --------------------------------------------------- // 將緩衝區重新配置為實際大小 // --------------------------------------------------- byte[] bytes = input.getBytes(); int size = input.getSize(); byte[] newBytes = new byte[size]; System.arraycopy(bytes, 0, newBytes, 0, size); // --------------------------------------------------- // 將位元組設回格式處理常式中,並設定 // 輸入訊息的長度欄位,因為我們已經知道 // 實際大小了。 // --------------------------------------------------- input.setBytes(newBytes); input.setWs__ll((short) size); System.out.println("\nAdjusted size of input message is: " + size); System.out.println("\nAdjusted size of INDX is: " + input.getIndx()); // --------------------------------------------------- // 將輸入訊息調整好之後, // 請設定陣列後面的欄位。 // --------------------------------------------------- input.setWs__func__code("123456"); InOutImpl proxy = new InOutImpl(); INOUTMSG output = new sample.ims.data.INOUTMSG(); output = proxy.runInOut(input); short outndx = output.getIndx(); System.out.println("\nOutput value of INDX is: " + outndx); Inoutmsg_ws__customer outArray[] = output.getWs__customer(); for (int i = 0; i < outndx; i++) { System.out.println( "\n" + outArray[i].getWs__cust__name() + outArray[i].getWs__cust__number()); } } catch (Exception e) { if (e instanceof IMSDFSMessageException) { System.out.println( "\nIMS returned message: " + ((IMSDFSMessageException) e).getDFSMessage()); } else { System.out.println( "\nIMS Connector exception is: " + e); } } } }
恭喜!您已完成「輸入輸出陣列指導教學」。
請檢視摘要中的資料來完成您的指導教學。