我必须处理一个项目,我尝试为服务层编写JUNIT测试。我必须检查相同的数据是否写入数据库(具有相同的方案和输入)。
首先,我计划手动从用户界面创建数据,然后将Hibernate POJO类转换为XML并将其保存为示例结果值。然后在使用JUnit进行测试时,我计划将其与我的示例XML结果进行比较。因此,如果JUnit结果数据与手动创建的样本数据相同,我可以理解Junit测试是否成功。
我的问题是:如何将hibernate注释和POJO类转换为XML?我研究了JAXB但我找不到将其转换为XML的方法。
我的模特课就是这样。
@Entity
@Table(name="USERSS")
public class User {
@Id
@GeneratedValue(strategy = GenerationType.AUTO, generator = "Seq_Gen")
@SequenceGenerator(name = "Seq_Gen", sequenceName = "S_")
@Basic(optional = false)
@Column(name="ID", unique = true, nullable = false)
private int id;
@Column(name="NAME", unique = true, nullable = false)
private String name;
@Column(name="SURNAME", unique = true, nullable = false)
private String surname;
@Column(name="MAIL", unique = true, nullable = false)
private String mail;
@Column(name="PASSWORD", unique = true, nullable = false)
private String password;
//private UserRoles UserRoles;
public User() {
// TODO Auto-generated constructor stub
}
public User(int id, String name, String surname, String mail,
String password) {
this.id = id;
this.name = name;
this.surname = surname;
this.mail = mail;
this.password = password;
}
public int getId() {
return id;
}
//@Column(name="NAME", unique = true, nullable = false)
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String htmlInputText) {
this.name = htmlInputText;
}
public String getSurname() {
return surname;
}
public void setSurname(String htmlInputText) {
this.surname = htmlInputText;
}
public String getMail() {
return mail;
}
public String getPassword() {
return password;
}
public void setMail(String htmlInputText) {
this.mail = htmlInputText;
}
public void setPassword(String password) {
this.password = password;
}
}