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
|
import eu.etaxonomy.taxeditor.session.mock.MockCdmEntitySession;
|
12
|
|
13
|
public class MockSessionOwner<T extends CdmBase> implements ICdmEntitySessionEnabled {
|
14
|
|
15
|
List<T> rootEntities;
|
16
|
Set<T> updatedObjects;
|
17
|
|
18
|
public MockSessionOwner() {
|
19
|
this.rootEntities = null;
|
20
|
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
|
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 new MockCdmEntitySession();
|
46
|
}
|
47
|
|
48
|
/* (non-Javadoc)
|
49
|
* @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
|
50
|
*/
|
51
|
@Override
|
52
|
public List<T> getRootEntities() {
|
53
|
return rootEntities;
|
54
|
}
|
55
|
|
56
|
/* (non-Javadoc)
|
57
|
* @see eu.etaxonomy.cdm.api.application.ICdmChangeListener#onChange(eu.etaxonomy.cdm.api.application.CdmChangeEvent)
|
58
|
*/
|
59
|
@Override
|
60
|
public void onChange(CdmChangeEvent event) {
|
61
|
if(updatedObjects != null && !updatedObjects.isEmpty()) {
|
62
|
for(CdmBase cb : updatedObjects) {
|
63
|
Assert.assertTrue(event.getChangedObjects().contains(cb));
|
64
|
}
|
65
|
}
|
66
|
updatedObjects.clear();
|
67
|
}
|
68
|
|
69
|
}
|