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 * jndi.name : the JNDI name of the registered Session Bean.
17 * 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 * weblogic.user : The authenticated user to contact Weblogic server. Defaults to weblogic
22 * weblogic.password : The valid password to contact Weblogic server. Defaults to weblogic
23 * 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= 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");
文章来源于领测软件测试网 https://www.ltesting.net/