package com.tudou.test;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import java.util.TimeZone;
import javax.naming.Context;
import javax.naming.InitialContext;
import org.junit.BeforeClass;
import org.junit.Test;
import com.tudou.t1Test.Classes;
import com.tudou.t1Test.Student;
import com.tudou.t1Test.StudentDao;
public class TestStu {
private static StudentDao studentDao;
@BeforeClass
public static void setUpBeforeClass() throws Exception {
Properties p = new Properties();
// weblogic值为weblogic.jndi.WLInitialContextFactory
// JBOSS为org.jnp.interfaces.NamingContextFactory
p.setProperty(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
// Weblogic为 t3://localhost:7001
p.setProperty(Context.PROVIDER_URL, "localhost");
InitialContext init = new InitialContext(p);
// weblogic为LoginBean#后面是实现类的全路径,包括包名
// 此时接口中必须配置为:@Stateless(mappedName="LoginBean")
studentDao = (StudentDao) init.lookup("StudentDaoBean/remote");
}
@Test
public void loginTest() {
TimeZone timeZone = TimeZone.getTimeZone("Asia/Shanghai");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss");
sdf.setTimeZone(timeZone);
String times = sdf.format(new Date());
Classes c1 = new Classes();
c1.setClassName("1班");
Classes c2 = new Classes();
c2.setClassName("2班");
Classes c3 = new Classes();
c3.setClassName("3班");
Student s1 = new Student(c1, "scce005", "tudou", times);
Student s2 = new Student(c1, "scce002", "doudou", times);
Student s3 = new Student(c2, "scce003", "qq", times);
Student s4 = new Student(c3, "scce004", "yaerfeng", times);
boolean flag1 = studentDao.addStu(s1);
boolean flag2 = studentDao.addStu(s2);
boolean flag3 = studentDao.addStu(s3);
boolean flag4 = studentDao.addStu(s4);
if (flag1 == true) {
System.out.println("用户1添加成功!!!");
} else {
System.out.println("添加失败!!!");
}
if (flag2 == true) {
System.out.println("用户2添加成功!!!");
} else {
System.out.println("添加失败!!!");
}
if (flag3 == true) {
System.out.println("用户3添加成功!!!");
} else {
System.out.println("添加失败!!!");
}
if (flag4 == true) {
System.out.println("用户4添加成功!!!");
} else {
System.out.println("添加失败!!!");
}
List<Student> lists = studentDao.queryStudents();
if (lists != null) {
System.out.println("学号\t\t玫级\t\t姓名\t\t入学日期");
for (Student s : lists) {
System.out.println(s.getStuNo() + "\t"
+ s.getClasses().getClassName() + "\t" + s.getStuName()
+ "\t\t" + s.getCreateDate());
}
} else {
System.out.println("里面是空的");
}
}
}
weblogic/jboss使用ejb3.0远程调用
最新推荐文章于 2023-01-10 14:54:32 发布