私はseamフレームワークを使用してWebサイトを開発しています。私は時間を開発するときに一つの問題を共有したい。私は、継ぎ目として1つのシームテストメソッドを持っています。Seamエンティティはデータベースを保持しません
カテゴリクラスは;アイテムの
@Entity
public class Category extends Item implements Serializable {
private static final long serialVersionUID = -1154500438874768209L;
private List<Item> children;
public Category() {
}
public Category(String name) {
this();
setName(name);
}
@OneToMany(targetEntity=Item.class, mappedBy = "parent",cascade = CascadeType.ALL)
public List<Item> getChildren() {
return children;
}
public void addChild(Item child) {
if (children == null) {
children = new ArrayList<Item>();
}
if (!children.contains(child)) {
child.setParent(this);
children.add(child);
}
}
public void setChildren(List<Item> children) {
this.children = children;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Category other = (Category) obj;
if (children == null) {
if (other.children != null)
return false;
} else if (!children.equals(other.children))
return false;
return true;
}
}
クラスです。
@Inheritance(strategy = InheritanceType.JOINED)
@Entity
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = "name") })
public class Item implements Serializable {
private static final long serialVersionUID = 8332532835833777840L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Long getId() {
return id;
}
/**
* Hold the item's parent.
*/
private Category parent;
/**
* Hold the item's name.
*/
private String name;
private Long id;
@Transient
public List<Item> getChildren() {
return null;
}
@ManyToOne(targetEntity=Category.class)
public Category getParent() {
return parent;
}
public void setParent(Category parent) {
this.parent = parent;
}
public void setId(Long id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
この方法に従うと、私がテストを実行すると、太字の行については例外が発生します。
FAILED: saveOneCategoryToRoot
java.lang.AssertionError: expected:<2> but was:<1>
at org.junit.Assert.fail(Assert.java:91)
at org.junit.Assert.failNotEquals(Assert.java:645)
at org.junit.Assert.assertEquals(Assert.java:126)
at org.junit.Assert.assertEquals(Assert.java:470)
at org.junit.Assert.assertEquals(Assert.java:454)
at com.galaksiya.kobar.test.itemtree.CategoryTest$2.invokeApplication(CategoryTest.java:105)
at org.jboss.seam.mock.AbstractSeamTest$Request.invokeApplicationPhase(AbstractSeamTest.java:656)
at org.jboss.seam.mock.AbstractSeamTest$Request.emulateJsfLifecycle(AbstractSeamTest.java:605)
at org.jboss.seam.mock.AbstractSeamTest$Request.access$100(AbstractSeamTest.java:177)
at org.jboss.seam.mock.AbstractSeamTest$Request$2.doFilter(AbstractSeamTest.java:505)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:206)
at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:60)
at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
at org.jboss.seam.mock.AbstractSeamTest$Request.run(AbstractSeamTest.java:499)
at org.jboss.seam.mock.AbstractSeamTest$FacesRequest.run(AbstractSeamTest.java:872)
at com.galaksiya.kobar.test.itemtree.CategoryTest.saveOneCategoryToRoot(CategoryTest.java:120)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:676)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:845)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1169)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.runWorkers(TestRunner.java:1182)
at org.testng.TestRunner.privateRun(TestRunner.java:761)
at org.testng.TestRunner.run(TestRunner.java:612)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:335)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:330)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:292)
at org.testng.SuiteRunner.run(SuiteRunner.java:241)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1169)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1094)
at org.testng.TestNG.run(TestNG.java:1006)
at org.testng.remote.RemoteTestNG.run(RemoteTestNG.java:107)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:199)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:170)
なぜ 'whiteGoods'のインスタンスがデータベースを保存しないのかわかりません。
事前に感謝..
カテゴリのソースコードを見るのは難しいでしょう。 –
あなたは正しいです。カテゴリと項目のクラスが追加されます。 – shafak