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.logging.log4j.LogManager;import org.apache.logging.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>
|
16
|
implements ICdmEntitySessionEnabled<T>, ICdmChangeListener {
|
17
|
|
18
|
private static final Logger logger = LogManager.getLogger(MockSessionOwner.class);
|
19
|
|
20
|
private final List<T> rootEntities;
|
21
|
private Set<T> expectedUpdatedObjects;
|
22
|
private Set<? extends CdmBase> eventUpdatedObjects;
|
23
|
|
24
|
private ICdmEntitySession session;
|
25
|
|
26
|
public MockSessionOwner() {
|
27
|
this.rootEntities = null;
|
28
|
this.expectedUpdatedObjects = new HashSet<>();
|
29
|
}
|
30
|
|
31
|
// public MockSessionOwner(Set<T> updatedObjects) {
|
32
|
// this.rootEntities = null;
|
33
|
// this.updatedObjects = updatedObjects;
|
34
|
// }
|
35
|
//
|
36
|
// public MockSessionOwner(List<T> rootEntities) {
|
37
|
// this.rootEntities = rootEntities;
|
38
|
// }
|
39
|
|
40
|
public void setExpectedUpdatedObjects(Set<T> updatedObjects) {
|
41
|
this.expectedUpdatedObjects = updatedObjects;
|
42
|
}
|
43
|
|
44
|
public void addExpectedUpdatedObject(T updatedObject) {
|
45
|
this.expectedUpdatedObjects.add(updatedObject);
|
46
|
}
|
47
|
|
48
|
@Override
|
49
|
public ICdmEntitySession getCdmEntitySession() {
|
50
|
return session;
|
51
|
}
|
52
|
|
53
|
public void setCdmEntitySession(ICdmEntitySession session) {
|
54
|
this.session = session;;
|
55
|
}
|
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
|
logger.info("disposed of session from session owner : " + this);
|
66
|
}
|
67
|
}
|
68
|
|
69
|
public Set<? extends CdmBase> getEventUpdatedObjects() {
|
70
|
return eventUpdatedObjects;
|
71
|
}
|
72
|
|
73
|
@Override
|
74
|
public void onChange(CdmChangeEvent event) {
|
75
|
eventUpdatedObjects = event.getChangedObjects();
|
76
|
if(expectedUpdatedObjects != null && !expectedUpdatedObjects.isEmpty()) {
|
77
|
for(CdmBase cb : expectedUpdatedObjects) {
|
78
|
Assert.assertTrue(event.getChangedObjects().contains(cb) );
|
79
|
}
|
80
|
}
|
81
|
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
86
|
// TODO Auto-generated method stub
|
87
|
return null;
|
88
|
}
|
89
|
}
|