如何测试这个方法J2EE webservice

时间:2014-03-28 13:49:02

标签: java java-ee

我的webservice项目中有一个名为customers的Entity类,它是一个来自数据库表的JPA实体,它具有描述客户的属性,如用户名,密码等。

我有一个名为customermanagement的网络服务,它基本上可以为客户处理crud操作。

例如,createcustomer方法类似于:

public void createcustomer(customers customer)
{
  em.persist(customer)

}

现在的问题是,在客户端我有这个webservices的方法,但不知道如何传递客户的object参数。

public boolean CreateUser()
{
    this.username = "John";
    this.fullname = "Doe";
    this.password = "magic";

    webservice.createcustomer() #this has to take an object instead. So how may i do it ?
}

请原谅我的技能水平。我对面向对象编程不太熟悉。

1 个答案:

答案 0 :(得分:1)

你必须像这样创建实体类的对象:

Customers customer = new Customers("John", "Doe", "Magic");

并将Customer对象传递给您的方法:

webservice.createcustomer(customer);

有更短的方法:

webservice.createcustomer(new Customers("John", "Doe", "Magic"));