1
|
package eu.etaxonomy.taxeditor.session;
|
2
|
|
3
|
import java.util.HashSet;
|
4
|
import java.util.List;
|
5
|
import java.util.Set;
|
6
|
|
7
|
import org.junit.Assert;
|
8
|
|
9
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
|
10
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
11
|
|
12
|
public class MockSessionOwner<T extends CdmBase> implements ICdmEntitySessionEnabled {
|
13
|
|
14
|
private final List<T> rootEntities;
|
15
|
private Set<T> updatedObjects;
|
16
|
private ICdmEntitySession session;
|
17
|
|
18
|
public MockSessionOwner() {
|
19
|
this.rootEntities = null;
|
20
|
this.updatedObjects = new HashSet<T>();
|
21
|
}
|
22
|
|
23
|
// public MockSessionOwner(Set<T> updatedObjects) {
|
24
|
// this.rootEntities = null;
|
25
|
// this.updatedObjects = updatedObjects;
|
26
|
// }
|
27
|
//
|
28
|
// public MockSessionOwner(List<T> rootEntities) {
|
29
|
// this.rootEntities = rootEntities;
|
30
|
// }
|
31
|
|
32
|
public void setUpdatedObjects(Set<T> updatedObjects) {
|
33
|
this.updatedObjects = updatedObjects;
|
34
|
}
|
35
|
|
36
|
public void addExpectedUpdatedObject(T updatedObject) {
|
37
|
this.updatedObjects.add(updatedObject);
|
38
|
}
|
39
|
|
40
|
/* (non-Javadoc)
|
41
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
|
42
|
*/
|
43
|
@Override
|
44
|
public ICdmEntitySession getCdmEntitySession() {
|
45
|
return session;
|
46
|
}
|
47
|
|
48
|
public void setCdmEntitySession(ICdmEntitySession session) {
|
49
|
this.session = session;;
|
50
|
}
|
51
|
|
52
|
/* (non-Javadoc)
|
53
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
54
|
*/
|
55
|
@Override
|
56
|
public List<T> getRootEntities() {
|
57
|
return rootEntities;
|
58
|
}
|
59
|
|
60
|
public void dispose() {
|
61
|
if(session != null) {
|
62
|
session.dispose();
|
63
|
}
|
64
|
}
|
65
|
|
66
|
/* (non-Javadoc)
|
67
|
* @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
|
68
|
*/
|
69
|
@Override
|
70
|
public void onChange(CdmChangeEvent event) {
|
71
|
|
72
|
if(updatedObjects != null && !updatedObjects.isEmpty()) {
|
73
|
for(CdmBase cb : updatedObjects) {
|
74
|
Assert.assertTrue(event.getChangedObjects().contains(cb));
|
75
|
}
|
76
|
}
|
77
|
|
78
|
}
|
79
|
|
80
|
}
|