<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 165, comments - 198, trackbacks - 0, articles - 1
      BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

    1. HttpUnit
    1>servlet可以脫離容器,容易把該測試寫入ant或maven腳本,讓測試進行。
    2>httpunit在測試servlet行為時,采用的是完全模擬瀏覽器,有時測試比較難寫。

    package?Cactus.test.support;

    import?junit.framework.TestCase;
    import?Cactus.HelloWorld;

    import?com.meterware.httpunit.GetMethodWebRequest;
    import?com.meterware.httpunit.WebRequest;
    import?com.meterware.httpunit.WebResponse;
    import?com.meterware.servletunit.InvocationContext;
    import?com.meterware.servletunit.ServletRunner;
    import?com.meterware.servletunit.ServletUnitClient;
    import?junit.framework.Assert;
    ?
    public?class?HttpUnitTestHelloWorld?extends?TestCase?{
    ?
    ?
    protected?void?setUp()?throws?Exception?{
    ??
    super.setUp();
    ?}
    ?
    ?
    protected?void?tearDown()?throws?Exception?{
    ??
    super.tearDown();
    ?}
    ?
    ?
    public?void?testHelloWorld()?{
    ??
    ??
    try?{

    ???
    //?創建Servlet的運行環境
    ???ServletRunner?sr?
    =?new?ServletRunner();
    ???
    //?向環境中注冊Servlet
    ???sr.registerServlet("HelloWorld",?HelloWorld.class.getName());
    ?
    ???
    //?創建訪問Servlet的客戶端
    ???ServletUnitClient?sc?
    =?sr.newClient();

    ???
    //?發送請求
    ???WebRequest?request?
    =?new?GetMethodWebRequest("http://localhost/HelloWorld");
    ???request.setParameter(
    "username",?"testuser");
    ???
    ???
    //用委托加載?is
    ???InvocationContext?ic?=?sc.newInvocation(request);
    ???HelloWorld?is?
    =?(HelloWorld)?ic.getServlet();
    ?
    ???
    //?測試servlet的某個方法
    ???Assert.assertTrue(is.authenticate());

    ???
    //?獲得模擬服務器的信息
    ???WebResponse?response?=?sc.getResponse(request);

    ???
    //?斷言
    ???Assert.assertTrue(response.getText().equals("testuser:Hello?World!"));

    ??}?
    catch?(Exception?e)?{

    ???e.printStackTrace();

    ??}

    ?}
    ?
    }


    Jetty
    package?Cactus.test.support;

    import?org.mortbay.jetty.Connector;
    import?org.mortbay.jetty.Server;
    import?org.mortbay.jetty.bio.SocketConnector;
    import?org.mortbay.jetty.servlet.ServletHandler;
    ?
    import?com.meterware.httpunit.WebConversation;
    import?com.meterware.httpunit.WebResponse;
    ?
    import?junit.framework.Assert;
    import?junit.framework.TestCase;
    ?
    public?class?JettySampleTest?extends?TestCase?{
    ?
    ?Server?server;
    ?
    protected?void?setUp()?throws?Exception?{
    ??????
    //通過代碼設置并啟動一個服務器,該服務器是servlet的測試容器
    ??????super.setUp();
    ??????server?
    =?new?Server();
    ??????Connector?connector
    =new?SocketConnector();
    ??????connector.setPort(
    80);
    ??????server.setConnectors(
    new?Connector[]{connector});
    ??????ServletHandler?handler
    =new?ServletHandler();
    ??????server.setHandler(handler);
    ??????handler.addServletWithMapping(
    "Cactus.HelloWorld",?"/");
    ??????server.start();
    ?}
    ?
    ?
    protected?void?tearDown()?throws?Exception?{
    ??
    super.tearDown();
    ??server.stop();
    ?}
    ?
    ?
    public?void?testHellWorld()?{
    ??
    try?{
    ???WebConversation?wc?
    =?new?WebConversation();
    ???WebResponse?web?
    =?wc.getResponse("http://127.0.0.1/HelloWorld");
    ???String?result
    =web.getText();
    ???Assert.assertEquals(result,
    "null:Hello?World!");
    ??
    ??}?
    catch?(Exception?e)?{
    ???e.printStackTrace();
    ??}
    ?}
    }

    posted @ 2007-10-31 11:11 G_G 閱讀(1091) | 評論 (2)編輯 收藏

    airlines 航空公司
    XX is one of the most well-known airlines in the world.

    square 廣場
    the are 4 statues,and fuontains,in the middle of Trafalgar square in Londen.

    understand 理解
    I wish he'd speak slower,I don't understand him.



    posted @ 2007-10-31 09:42 G_G 閱讀(205) | 評論 (0)編輯 收藏

    參考:http://caterpillar.onlyfun.net/GossipCN/JUnit/JUnitGossip.htm

    1. TestSuite
    ? public static Test suite() {
    ????
    TestSuite suite = new TestSuite(MathTool.class);
    ????
    suite.addTest(new MathToolTest("testGcd"));
    ? }

    2.全局屬性
    protected void setUp() throws Exception {
    super.setUp();
    arr = new ............;
    }

    protected void tearDown() throws Exception {
    super.tearDown();
    arr = null;
    }

    3. Cactus
    web設置

    http://caterpillar.onlyfun.net/GossipCN/JUnit/FirstCactusWithTomcat.htm
    http://caterpillar.onlyfun.net/GossipCN/JUnit/FirstCactusWithJetty.htm





    posted @ 2007-10-30 17:59 G_G 閱讀(294) | 評論 (0)編輯 收藏

    ??? ??? ??? ??? 我的編碼標準。(隨時間完善)
    1. 建立工作區
    ??? ?? -bin 編譯地點,-lib 包,-javadoc doc,
    ??? ?? -src 源碼區
    ??? ?? ?? |-設計功能包
    ??? ?? ?? ?? |-interface 功能描述接口
    ??? ?? ?? ?? |+com 功能實現包
    ??? ?? ? ??? |-test 測試區
    ??? ?? ?? ?? ??? |-support? 功能可行分析
    ??? ?? ?? ?? ??? |-unit ??? 單元測試
    ??? ?? ?? ?? ??? |-api ???? 使用文檔
    ??? ?? ? ??? |+設計代碼區
    ??? ?? ?? |+設計功能包
    ??? ?? ?? |+設計功能包
    ??? ?? ?? ?? .....
    初建立
    測試先行(迭帶開發)。原則上不手動建立類、接口。可以先命名后通過eclipes工具建立。
    (1)test.api 測試。也叫主功能測試。該測試主要目的是:
    ??? ??? 1>(接口級)功能描述,為再次使用提供幫助。
    ??? ?? ?? ? 結合javadoc和代碼本身描述 javadoc 使用??? ???
    ??? ??? 2>建立功能接口。
    ??? ?? ?? ? 在次步驟是:先Ctrl+C命名,再shift+ctrl+N選擇interface在package中去掉前面的test.api.
    (2)test.support 測試。也叫可行分析測試。該測試目的是(接口級)功能分為(方法級)功能并為各實現一個測試方法。
    (3)test.unit 測試。也叫單元測試。該測試目的是:
    ??? ??? 1>方法級功能設計提升為類級、抽象類級(設計實現類)。
    ??? ?? ??? 在次步驟是:先Ctrl+C命名,再shift+ctrl+N選擇class在package中換test.unit.為com
    ??? ??? 2>方法依賴描述,為再次使用提供幫助。 ????
    (4)重構。重構 eclips 快鍵

    建立中
    1.接口級功能添加。和初建立相同。
    2.抽象類、
    級功能添加。從 test.support 測試開始。

    開發包對應
    test.api <-> interface
    test.support 無
    test.unit <-> com

    ?? 在寫大量代碼時發現沒有個限定的標準是見可怕的事情。但我的
    動態面向對象數據庫操作這個我自己的小東西時在編碼很好用。不管是再次修改,直接copy到另個項目改改。都能很好的工作。而其他的小東西卻不行。這仔細的總結下。

    posted @ 2007-10-26 16:27 G_G 閱讀(1148) | 評論 (1)編輯 收藏

    eclipse中如何寫一個測試私有方法的junit?
    假設類Summer定義如下:
    public class Summer{
    ???private int methodone(String argsone){
    ??????//method code
    ??????.......
    ??????return?4;
    ???}
    }

    測試如下:
    public class SummerTest extends TestCase {
    ???public void testMethodone(){
    ??????Object rightResult = xxxxx;
    ??????Summer?example =?new Summer.newInstance();
    ??????Method m =?example .getClass().getDeclaredMethod("methodone",new Class[]{String.class});
    ??????m.setAccessible(true);
    ??????Object result = m.invoke(example ,new?Object[]?{new String(xxxx)});
    ??????m.setAccessible(false);
    ??????if (result.equals(rightResult)){
    ?????????//your code
    ?????????......
    ??????}
    ???}
    }

    posted @ 2007-10-23 11:11 G_G 閱讀(2280) | 評論 (1)編輯 收藏

    1.CollectionHelper 對List,Set,Map 包裝出不可修改的
    public?final?class?CollectionHelper?{
    ????
    public?static?final?List?EMPTY_LIST?=?Collections.unmodifiableList(?new?ArrayList(0)?);
    ????
    public?static?final?Collection?EMPTY_COLLECTION?=?Collections.unmodifiableCollection(?new?ArrayList(0)?);
    ????
    public?static?final?Map?EMPTY_MAP?=?Collections.unmodifiableMap(?new?HashMap(0)?);
    ????
    private?CollectionHelper()?{}
    }
    ??? 1.1 在Collections.unmodifiableList(...)是靜態內部類個構造方法
    ??? ?? 悟: 從上面看出是一個非常好的? 適配器 ?
    ???//1.Collections 中 new 出內部類
    ??? public static <T> Collection<T> unmodifiableCollection(Collection<? extends T> c) {
    ??? ??? return new UnmodifiableCollection<T>(c);
    ??? }



    ??? //2.
    內部類也繼承 Collection
    ??? static class UnmodifiableCollection<E> implements Collection<E>, Serializable {
    ??? private?static?final?long?serialVersionUID?=?1820017752578914078L;

    ????
    final?Collection<??extends?E>?c;
    ??? //3.很好適配 Collection 通過他把 add remove 等功能 封裝
    ????UnmodifiableCollection(Collection
    <??extends?E>?c)?{
    ????????????
    if?(c==null)
    ????????????????
    throw?new?NullPointerException();
    ????????????
    this.c?=?c;
    ????????}
    ??? ...............

    2.大量使用內部類枚矩 ?如:
    Mappings.PropertyReference?upr?=?(Mappings.PropertyReference)?iter.next();
    ////////////////////////////////////////////////
    Mappings中
    ????
    static?final?class?PropertyReference?implements?Serializable?{
    ????????String?referencedClass;
    ????????String?propertyName;
    ????????
    boolean?unique;
    ????}

    //感覺是可以更好的代碼編寫




    posted @ 2007-10-23 10:34 G_G 閱讀(545) | 評論 (0)編輯 收藏

    1. 接口里面的屬性在默認狀態下面都是public static

    2.????
    被聲明為final的變量必須在聲明時給定初值,而在以后的引用中只能讀取,不可修改。


    3.??
    匿名的內部類是沒有名字的內部類。不能extends(繼承) 其它類,但一個內部類可以作為一個接口,由另一個內部類實現。


    4.?
    靜態內部類(Inner Class)寫成這樣才可以 在內部 new 出 : static final public class XXXxx
    ??? ?? ?? ?
    1.創建一個static內部類的對象,不需要一個外部類對象
    ??? ??? ???
    2不能從一個static內部類的一個對象訪問一個外部類對象

    5.

    ??? ??? HashMap 類沒有分類或者排序。它允許一個 null 鍵和多個 null 值。

      Hashtable 類似于 HashMap,但是不允許 null 鍵和 null 值。它也比 HashMap 慢,因為它是同步的。


    6. GC

    ??? ??? System.gc()

    ??? ??? Runtime.getRuntime().gc()


    7.重寫Overriding和重載Overloading
    ??? 如果在子類中定義某方法與其父類有相同的名稱和參數,我們說該方法被重寫 (Overriding)

    ??? 如果在一個類中定義了多個同名的方法,它們或有不同的參數個數或有不同的參數類型,則稱為方法的重載(Overloading)Overloaded的方法是可以改變返回值的類型。


    8.抽象類是否可繼承實體類(concrete class)

    ??? ?? ?? 抽象類是否可繼承實體類,但前提是實體類必須有明確的構造函數


    9.try {}里有一個return語句,那么緊跟在這個try后的finally {}里的code會不會被執行,什么時候被執行,在return前還是后?

      會執行,在return前執行。

    ??? ??

    10.switchexpr1)中,expr1是一個整數表達式。因此傳遞給 switch case 語句的參數應該是 int short char 或者 bytelong,string 都不能作用于swtich


    posted @ 2007-10-22 18:34 G_G 閱讀(229) | 評論 (0)編輯 收藏

    1。項目中 ->Exprot.. -> @javadoc 就可以了
    2。javadoc 命令學習
    ??? @author 作者
    ??? @see 另請參見
    ??? ??? (1)、@see "string" 為"string"添加文本項,不產生鏈接。
    ??? ??? (2)、@see <a href="URL#Value">Label</a> 使用HTML標記產生鏈接
    ??? ??? (3)、@see package.class#member Label 使用Java語言的名字package.class #member產生鏈接。

    @version 版
    ??? @since 從以下版本開
    ??? @param 參數說明

    /** */中的開頭是注解

    ?? /**
    ?? */? 的就近原則 在那個上面就為那個注解

    參照:http://java.ccidnet.com/art/3743/20031203/519697_1.html

    /** class description
    */


    3、Variable Description:描述變量的意義和取值含義。
    /** var variable description
    */

    4、Method Description:標明每個方法的輸入、輸出參數和返回值類型,說明特殊變量取值的含義。相關類文檔鏈接。

    /** method description
    * @param var signification 方法參數說明
    * @exception exception class name throws 說明
    * @return return_value return signification return 說明
    */

    5、Association Description:關聯類文檔描述,在注釋當中需要參引其它文檔描述的地方,可在相應的注釋當中如下插入:
    /** method description

    * @param var signification
    * @exception exception class name
    * @return return_value return signification
    * @see package.class#member label
    */

    6、包描述文件:概括描述包的功能和設計概要。為每個包創建一個描述文件,命名為package.html,與包的java文件放在一起。



    ???

    posted @ 2007-10-22 16:47 G_G 閱讀(935) | 評論 (0)編輯 收藏

    如有錯誤大家多指教

    1.call(* *(..)) 和 execution(* *(..)) 區別
    ?
    call 和 execution 都為切面限定
    ? execution 進行切面添加只能在方法定義的開始和結束。如:
    ?? >>>AOP 添加
    ? ??? public String getName(){
    ? ??? ??? System.out.println("G_G");
    ??? ??? return this.name ;
    ??? }
    ?? >>>AOP 添加
    ? call進行切面添加沒有限定。如:
    ??? >>>AOP 添加
    ? ??? public String getName(){
    ????????? >>>AOP 添加
    ? ??? ??? System.out.println("G_G");
    ????????? >>>AOP 添加
    ??? ??? return this.name ;
    ??? }
    ?? >>>AOP 添加

    ???? 2.this within區別
    ?? 都為范圍限定作用,如: within(Demo) && execution( * *(..)) 在類Demo中的所有..
    ?? 區別是:this不能切靜態,within沒有

    ?3.cflow的作用

    ? 我們從 1>cflow( within(DD+) && execution( * *(..)) )

    ???????? 2>within(DD+) && execution( * *(..)) 的區別來看
    ? 1與2的對比是在2的切入點下再加 aj 文件的方法 進行添加切入點。

    4.方法添加
    ? 如:Introduction Example例中的 CloneablePoint.aj
    ???? Point類繼承Clonable 添加
    clone() 方法
    ???declare?parents:?Point?implements?Cloneable;

    ???
    public?Object?Point.clone() throws?CloneNotSupportedException?{
    ??????
    return?super.clone();
    ???}

    ?? point.clone()....




    ??


    posted @ 2007-10-18 18:16 G_G 閱讀(1600) | 評論 (3)編輯 收藏

    學習擁有連貫
    在我剛認識 讓 java 動態 這種動態編譯動態加載的幾天后
    對我一向不懂的 AOP 特別是 AspectJ 開竅了 (哈哈 那感覺好啊^_^)
    下面我寫出我剛對AOP的一些小練

    1。目的
    DAO中大量的 session的開和閉 不緊使代碼成倍加,還及容易出錯
    用 設計模式
    hibernate 包裝 下大家好象有點接受不了(@_@!)
    AOP就進入我的視線 但總沒個切入點

    2。原理
    其實 讓 java 動態 就是那點東西 但IBM 包出個好用的框架 來 。

    3。代碼說明
    //*******************Dao.java ****************************
    package
    ?tt;
    //為了簡單 session 看成是 真的session 哈 ^_^
    public?class?Dao?{
    ????
    public?String?session?=?"close"?;?
    ????
    ????
    public?void?testDao(){
    ????????System.out.println(?
    "testDao?in?function?:?"+?session);
    ????}
    ????
    ????
    static?public?void?main(String[]args){
    ????????Dao?dao?
    =?new?Dao()?;
    ????????dao.testDao();
    ????????System.out.println(
    "main?in?function?:?"?+??dao.session);
    ????}
    }

    //*****************List.aj ****************************
    package?tt;

    public?aspect?List?{
    ??? //切點? 范圍聲明? (Dao.testDao 歸 readOnly切點管? )
    ????pointcut?readOnly(Dao?dao):execution(
    *?*Dao.testDao*(..))&&this(dao);

    ????//掛載
    readOnly 開始方法
    ?????before(Dao?dao)?:??readOnly(dao)?{?????????
    ?????????????openSession(dao);
    ??????}
    ???? //掛載 readOnly 結束方法
    ?????after(Dao?dao)?returning()??:??readOnly(dao)?{
    ??????????close(dao);
    ?????}
    ????
    ????
    // readOnly 方法 運行代碼 (到這可以大膽的寫 java 代碼了 ) 。。。。
    ?????private?void?openSession(Dao?dao)?{
    ?????????
    if(dao.session.equals("close"))
    ?????????????dao.session?
    =?"Session?Open";
    ?????}
    ?????
    private?void?close(Dao?dao)?{
    ?????????dao.session?
    =?"close"?;
    ?????}
    }

    4。結果:
    testDao in function : Session Open
    main in function : close



    4。后續
    AspectJ 使 AOP 簡單
    可能還會統一標準
    能為我們的java 框架靈活 更上一層 (期待)


    posted @ 2007-10-15 16:57 G_G 閱讀(1170) | 評論 (0)編輯 收藏

    僅列出標題
    共16頁: First 上一頁 7 8 9 10 11 12 13 14 15 下一頁 Last 
    主站蜘蛛池模板: 久久亚洲国产精品五月天| 亚洲天堂一区在线| 日韩精品无码专区免费播放| 亚洲人成在线精品| 国产男女猛烈无遮挡免费网站| www一区二区www免费| 久久久久亚洲AV无码永不| 午夜dj免费在线观看| aa级女人大片喷水视频免费| 亚洲网站在线播放| 亚洲色偷偷狠狠综合网| 无码国产精品一区二区免费式直播 | 亚洲国产精品线在线观看| 久久不见久久见免费影院| 2022免费国产精品福利在线| 亚洲国产精品日韩在线观看 | 2020天堂在线亚洲精品专区| 国产精品亚洲综合专区片高清久久久| 最近免费中文字幕大全高清大全1| 亚洲aⅴ无码专区在线观看| 五月天网站亚洲小说| 日日操夜夜操免费视频| 精品熟女少妇av免费久久| 曰批全过程免费视频观看免费软件 | 亚洲成A人片777777| 国产精品免费播放| 国产h肉在线视频免费观看| 一级成人生活片免费看| 亚洲国产一区二区三区在线观看| 国产v亚洲v天堂无码网站| 免费a级黄色毛片| 在线观看日本免费a∨视频| 国产又黄又爽胸又大免费视频| 亚洲国产成人AV在线播放| 久久久亚洲AV波多野结衣 | 在线观看亚洲免费| 亚洲免费人成视频观看| 亚洲AV无码不卡在线播放| 免费大片在线观看网站| 99精品全国免费观看视频| 18pao国产成视频永久免费|