-
Notifications
You must be signed in to change notification settings - Fork 27
/
FunctionalNestedSetTest.java
74 lines (65 loc) · 2.02 KB
/
FunctionalNestedSetTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/**
* LICENSE
*
* This source file is subject to the MIT license that is bundled
* with this package in the file MIT.txt.
* It is also available through the world-wide-web at this URL:
* http://www.opensource.org/licenses/mit-license.html
*/
package org.pkaboo.jpa.nestedset;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
public class FunctionalNestedSetTest {
protected EntityManagerFactory emFactory;
protected EntityManager em;
protected JpaNestedSetManager nsm;
@BeforeClass(alwaysRun=true)
protected void createEntityManagerFactory() {
try {
emFactory = Persistence.createEntityManagerFactory("TestPU");
} catch (Exception ex) {
ex.printStackTrace();
}
}
@BeforeMethod(alwaysRun=true)
protected void createEntityManager() {
em = emFactory.createEntityManager();
this.nsm = new JpaNestedSetManager(this.em);
}
@AfterMethod
protected void closeEntityManager() {
if (em != null) {
em.getTransaction().begin();
em.createQuery("delete from Category").executeUpdate();
em.getTransaction().commit();
em.close();
em = null;
}
this.nsm = null;
}
@AfterClass
protected void closeEntityManagerFactory() {
if (emFactory != null) {
emFactory.close();
}
}
protected void printTree(Node<?> node) {
printNode(node);
if (node.hasChildren()) {
for (Node<?> child : node.getChildren()) {
printTree(child);
}
}
}
protected void printNode(Node<?> node) {
for (int i = 0; i < node.getLevel(); ++i) {
System.out.print("--");
}
System.out.println(node.toString());
}
}