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> expectedUpdatedObjects;
|
16
|
private Set<? extends CdmBase> eventUpdatedObjects;
|
17
|
|
18
|
private ICdmEntitySession session;
|
19
|
|
20
|
public MockSessionOwner() {
|
21
|
this.rootEntities = null;
|
22
|
this.expectedUpdatedObjects = new HashSet<T>();
|
23
|
}
|
24
|
|
25
|
// public MockSessionOwner(Set<T> updatedObjects) {
|
26
|
// this.rootEntities = null;
|
27
|
// this.updatedObjects = updatedObjects;
|
28
|
// }
|
29
|
//
|
30
|
// public MockSessionOwner(List<T> rootEntities) {
|
31
|
// this.rootEntities = rootEntities;
|
32
|
// }
|
33
|
|
34
|
public void setExpectedUpdatedObjects(Set<T> updatedObjects) {
|
35
|
this.expectedUpdatedObjects = updatedObjects;
|
36
|
}
|
37
|
|
38
|
public void addExpectedUpdatedObject(T updatedObject) {
|
39
|
this.expectedUpdatedObjects.add(updatedObject);
|
40
|
}
|
41
|
|
42
|
/* (non-Javadoc)
|
43
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
|
44
|
*/
|
45
|
@Override
|
46
|
public ICdmEntitySession getCdmEntitySession() {
|
47
|
return session;
|
48
|
}
|
49
|
|
50
|
public void setCdmEntitySession(ICdmEntitySession session) {
|
51
|
this.session = session;;
|
52
|
}
|
53
|
|
54
|
/* (non-Javadoc)
|
55
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
56
|
*/
|
57
|
@Override
|
58
|
public List<T> getRootEntities() {
|
59
|
return rootEntities;
|
60
|
}
|
61
|
|
62
|
public void dispose() {
|
63
|
if(session != null) {
|
64
|
session.dispose();
|
65
|
}
|
66
|
}
|
67
|
|
68
|
public Set<? extends CdmBase> getEventUpdatedObjects() {
|
69
|
return eventUpdatedObjects;
|
70
|
}
|
71
|
/* (non-Javadoc)
|
72
|
* @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
|
73
|
*/
|
74
|
@Override
|
75
|
public void onChange(CdmChangeEvent event) {
|
76
|
eventUpdatedObjects = event.getChangedObjects();
|
77
|
if(expectedUpdatedObjects != null && !expectedUpdatedObjects.isEmpty()) {
|
78
|
for(CdmBase cb : expectedUpdatedObjects) {
|
79
|
Assert.assertTrue(event.getChangedObjects().contains(cb));
|
80
|
}
|
81
|
}
|
82
|
|
83
|
}
|
84
|
|
85
|
}
|