亚洲好骚综合-亚洲黄色录像-亚洲黄色网址-亚洲黄色网址大全-99久久99久久-99久久99久久精品国产

您的位置:軟件測試 > 開源軟件測試 > 開源單元測試工具 >
插入式持久性提供者的承諾:Kodo、OpenJPA和Hibernate
作者:網絡轉載 發布時間:[ 2013/2/27 14:47:53 ] 推薦標簽:

因為我們使用了O-R映射注釋表示Message類的實例與數據庫表和列之間的映射關系(或者說是哪個域值能夠作為Message實例的主標識符),所以JPA依賴關系已經移入這個Java類中。這些映射信息可以移到一個單獨的orm.xml中,從而使這個類恢復Pure Old Java Object (POJO)狀態并完善這種不明確的更接近域對象模型的方法。
編碼前的測試

JUnit測試用例通過JNDI查找與服務進行交互并檢驗兩個服務方法返回的是否為預期的結果。

TestJPAService.java

01 package junit;
02
03 import java.util.Properties;
04
05 import javax.naming.Context;
06 import javax.naming.InitialContext;
07
08 import service.JPAService;
09 import service.Message;
10 import junit.framework.TestCase;
11
12 /**
13  * A JUnit test case to verify that a Session Bean is using the correct provider.
14  *
15  * The test must be invoked with two mandatory Java System Properties:
16  * <li>
                       
jndi.name : the JNDI name of the registered Session Bean.
17  * <li>
                       
persistence.provider: The 
                       
logical name of the
18  * persistence provider. Allowed values are 
                       
kodo or 
                       
hibernate.
19  *
                       


20  * The optional Java System Properties are:
21  * <li>
                       
weblogic.user : The authenticated user to contact Weblogic server. Defaults to 
                       
weblogic
22  * <li>
                       
weblogic.password : The valid password to contact Weblogic server. Defaults to 
                       
weblogic
23  * <li>
                       
weblogic.url : The URL where Weblogic Server is running. Defaults to 
                       
t3://localhost:7001
24  *
25   *
26  * @author ppoddar
27  *
28  */
29 public class TestJPAService extends TestCase {
30   private static final String USER = System.getProperty("weblogic.user",     "weblogic");
31   private static final String PWD  = System.getProperty("weblogic.password", "weblogic");
32   private static final String URL  = System.getProperty("weblogic.url",    "t3://localhost:7001");
33   private static final String JNDI_NAME = System.getProperty("jndi.name");
34   private static final String PERSISTENCE_PROVIDER = System.getProperty("persistence.provider");
35  
36   private static JPAService service;
37  
38   /**
39    * Sets up the test by contacting Weblogic Server and looking up in JNDI
40    * for the registered Session Bean.
41    *
42    */
43   @Override
44   public void setUp() throws Exception {
45     assertNotNull("Must specify JVM System property -Djndi.name=<jndi> to run this test", JNDI_NAME);
46     assertNotNull("Must specify JVM System property -Dpersistence.provider=[kodo|hibernate] to run this test", PERSISTENCE_PROVIDER);
47     if (service == null) {
48           Properties p = new Properties();
49           p.put(Context.INITIAL_CONTEXT_FACTORY,  "weblogic.jndi.WLInitialContextFactory");
50           p.put(Context.SECURITY_PRINCIPAL,       USER);
51           p.put(Context.SECURITY_CREDENTIALS,     PWD);
52           p.put(Context.PROVIDER_URL, URL);
53           System.out.println("Contacting server " + URL + " as " + USER + " for " + JNDI_NAME);
54           InitialContext ctx = new InitialContext(p);
55           service = (JPAService)ctx.lookup(JNDI_NAME);
56     }
57   }
58  
59   /**
60    * Asserts that the Persistence Provider class name contains the 
                       
logical
61    * name of the intended provider i.e. 
                       
kodo or 
                       
hibernate.
62    *
63    */
64   public void testProvider() {
65     String actual = service.getProvider();
66     System.err.println("Logical Persistence Provider is [" + PERSISTENCE_PROVIDER + "]");
67     System.err.println("Actual  Persistence Provider is [" + actual + "]");
68     assertTrue("*** ERROR: " + actual + " is not provided by " + PERSISTENCE_PROVIDER, actual.indexOf(PERSISTENCE_PROVIDER) != -1);
69   }
70  
71   /**
72    * Simply logs (persists) a message via the remote service.
73    * The service will affix a timestamp with the persisted message it returns.
74    * Verifies that the timestamp against the time when the message has been
75    * sent. 
76    *
77    */
78   public void testLog() {
79     long senderTime = System.currentTimeMillis();
80     String body = "A message sent for logging on " + senderTime;
81     Message message = service.log(body);
82     long createTime = message.getTimestamp().getTime();
83     long elapsedTime = createTime - senderTime;
84     System.err.println("Persisted Message [id:" + message.getId() + " timestamp:" +
85         message.getTimestamp().getTime() + " body:"+ message.getBody() + "]");
86     System.err.println("Time elapsed between the message to send and persisted is " + elapsedTime + "ms");
87     assertTrue(elapsedTime>=0);
88   }
89 }

上一頁123456下一頁
軟件測試工具 | 聯系我們 | 投訴建議 | 誠聘英才 | 申請使用列表 | 網站地圖
滬ICP備07036474 2003-2017 版權所有 上海澤眾軟件科技有限公司 Shanghai ZeZhong Software Co.,Ltd
主站蜘蛛池模板: 99精品欧美 | 黄色小视频在线观看 | 99精品久久久久久久免费看蜜月 | 国产成人精品男人的天堂538 | 在线黄色观看 | 黄色免费网址在线观看 | 亚洲一区免费在线 | 野花视频在线观看-高清中文 | 天天摸夜夜添夜夜添国产 | 大象焦伊人久久综合网色视 | 亚洲国产一区二区三区 | 亚洲精品天堂在线观看 | 国产gav成人免费播放视频 | 亚洲成人网在线播放 | 国产69精品久久久久9牛牛 | 国产三级福利 | 一级做a爰片性色毛片16美国 | www.香蕉视频.com | 成年视频在线观看免费 | 看欧美一级片 | 精品国产品欧美日产在线 | 羞羞色在线 | 国产99在线播放免费 | 亚洲一级毛片免费观看 | 欧美高清亚洲欧美一区h | 国产亚洲欧美久久久久 | 99精品视频不卡在线观看免费 | 夜夜爽一区二区三区精品 | 伊人激情网 | 91亚洲视频在线观看 | 国产精品莉莉欧美自在线线 | 中文字幕亚洲欧美 | 中文字幕成人免费高清在线视频 | 91精品国产三级在线观看 | 日韩欧美一区二区三区中文精品 | 欧美性猛交xxxx免费看蜜桃 | 天海翼一区二区三区四区 | 国产成人精品高清在线观看99 | 国内精品在线视频 | 亚洲日韩精品欧美一区二区一 | 久久精品国产波多野结衣 |