1
|
package eu.etaxonomy.taxeditor.session;
|
2
|
|
3
|
import java.util.HashSet;
|
4
|
import java.util.List;
|
5
|
import java.util.Map;
|
6
|
import java.util.Set;
|
7
|
|
8
|
import org.apache.log4j.Logger;
|
9
|
import org.junit.Assert;
|
10
|
|
11
|
import eu.etaxonomy.cdm.api.application.CdmChangeEvent;
|
12
|
import eu.etaxonomy.cdm.api.application.ICdmChangeListener;
|
13
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
14
|
|
15
|
public class MockSessionOwner<T extends CdmBase> implements ICdmEntitySessionEnabled, ICdmChangeListener {
|
16
|
|
17
|
private static final Logger logger = Logger.getLogger(MockSessionOwner.class);
|
18
|
|
19
|
private final List<T> rootEntities;
|
20
|
private Set<T> expectedUpdatedObjects;
|
21
|
private Set<? extends CdmBase> eventUpdatedObjects;
|
22
|
|
23
|
private ICdmEntitySession session;
|
24
|
|
25
|
public MockSessionOwner() {
|
26
|
this.rootEntities = null;
|
27
|
this.expectedUpdatedObjects = new HashSet<T>();
|
28
|
}
|
29
|
|
30
|
// public MockSessionOwner(Set<T> updatedObjects) {
|
31
|
// this.rootEntities = null;
|
32
|
// this.updatedObjects = updatedObjects;
|
33
|
// }
|
34
|
//
|
35
|
// public MockSessionOwner(List<T> rootEntities) {
|
36
|
// this.rootEntities = rootEntities;
|
37
|
// }
|
38
|
|
39
|
public void setExpectedUpdatedObjects(Set<T> updatedObjects) {
|
40
|
this.expectedUpdatedObjects = updatedObjects;
|
41
|
}
|
42
|
|
43
|
public void addExpectedUpdatedObject(T updatedObject) {
|
44
|
this.expectedUpdatedObjects.add(updatedObject);
|
45
|
}
|
46
|
|
47
|
/* (non-Javadoc)
|
48
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
|
49
|
*/
|
50
|
@Override
|
51
|
public ICdmEntitySession getCdmEntitySession() {
|
52
|
return session;
|
53
|
}
|
54
|
|
55
|
public void setCdmEntitySession(ICdmEntitySession session) {
|
56
|
this.session = session;;
|
57
|
}
|
58
|
|
59
|
/* (non-Javadoc)
|
60
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
61
|
*/
|
62
|
@Override
|
63
|
public List<T> getRootEntities() {
|
64
|
return rootEntities;
|
65
|
}
|
66
|
|
67
|
public void dispose() {
|
68
|
if(session != null) {
|
69
|
session.dispose();
|
70
|
logger.info("disposed of session from session owner : " + this);
|
71
|
}
|
72
|
}
|
73
|
|
74
|
public Set<? extends CdmBase> getEventUpdatedObjects() {
|
75
|
return eventUpdatedObjects;
|
76
|
}
|
77
|
/* (non-Javadoc)
|
78
|
* @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
|
79
|
*/
|
80
|
@Override
|
81
|
public void onChange(CdmChangeEvent event) {
|
82
|
eventUpdatedObjects = event.getChangedObjects();
|
83
|
if(expectedUpdatedObjects != null && !expectedUpdatedObjects.isEmpty()) {
|
84
|
for(CdmBase cb : expectedUpdatedObjects) {
|
85
|
Assert.assertTrue(event.getChangedObjects().contains(cb));
|
86
|
}
|
87
|
}
|
88
|
|
89
|
}
|
90
|
|
91
|
/* (non-Javadoc)
|
92
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
|
93
|
*/
|
94
|
@Override
|
95
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
96
|
// TODO Auto-generated method stub
|
97
|
return null;
|
98
|
}
|
99
|
|
100
|
}
|