1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.extension.job.history.internal; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.Date; |
25 |
|
|
26 |
|
import org.apache.commons.collections4.Predicate; |
27 |
|
import org.apache.commons.collections4.PredicateUtils; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.junit.rules.TemporaryFolder; |
31 |
|
import org.xwiki.extension.job.InstallRequest; |
32 |
|
import org.xwiki.extension.job.UninstallRequest; |
33 |
|
import org.xwiki.extension.job.history.ExtensionJobHistory; |
34 |
|
import org.xwiki.extension.job.history.ExtensionJobHistoryConfiguration; |
35 |
|
import org.xwiki.extension.job.history.ExtensionJobHistoryRecord; |
36 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
37 |
|
|
38 |
|
import static org.junit.Assert.*; |
39 |
|
import static org.mockito.Mockito.*; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 2 |
Complexity Density: 0.14 |
|
47 |
|
public class DefaultExtensionJobHistoryTest |
48 |
|
{ |
49 |
|
@Rule |
50 |
|
public MockitoComponentMockingRule<ExtensionJobHistory> mocker = |
51 |
|
new MockitoComponentMockingRule<ExtensionJobHistory>(DefaultExtensionJobHistory.class); |
52 |
|
|
53 |
|
@Rule |
54 |
|
public TemporaryFolder testFolder = new TemporaryFolder(); |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
56 |
1 |
@Test... |
57 |
|
public void addGetRecords() throws Exception |
58 |
|
{ |
59 |
1 |
ExtensionJobHistoryConfiguration config = this.mocker.getInstance(ExtensionJobHistoryConfiguration.class); |
60 |
1 |
when(config.getStorage()).thenReturn(testFolder.getRoot()); |
61 |
|
|
62 |
1 |
long now = new Date().getTime(); |
63 |
1 |
ExtensionJobHistoryRecord firstRecord = |
64 |
|
new ExtensionJobHistoryRecord("install", new InstallRequest(), null, null, new Date(now - 7000)); |
65 |
1 |
ExtensionJobHistoryRecord secondRecord = |
66 |
|
new ExtensionJobHistoryRecord("uninstall", new UninstallRequest(), null, null, new Date(now + 4000)); |
67 |
|
|
68 |
1 |
ExtensionJobHistory history = this.mocker.getComponentUnderTest(); |
69 |
1 |
history.addRecord(firstRecord); |
70 |
1 |
history.addRecord(secondRecord); |
71 |
|
|
72 |
|
|
73 |
1 |
Predicate<ExtensionJobHistoryRecord> all = |
74 |
|
PredicateUtils.allPredicate(Collections.<Predicate<ExtensionJobHistoryRecord>>emptyList()); |
75 |
1 |
assertEquals(Arrays.asList(secondRecord, firstRecord), history.getRecords(all, null, -1)); |
76 |
|
|
77 |
|
|
78 |
1 |
assertEquals(Arrays.asList(secondRecord), history.getRecords(all, null, 1)); |
79 |
|
|
80 |
|
|
81 |
1 |
assertEquals(Arrays.asList(firstRecord), history.getRecords(all, secondRecord.getId(), -1)); |
82 |
|
|
83 |
|
|
84 |
1 |
assertEquals(Arrays.asList(firstRecord), history.getRecords(new Predicate<ExtensionJobHistoryRecord>() |
85 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
86 |
2 |
@Override... |
87 |
|
public boolean evaluate(ExtensionJobHistoryRecord record) |
88 |
|
{ |
89 |
2 |
return "install".equals(record.getJobType()); |
90 |
|
} |
91 |
|
}, null, -1)); |
92 |
|
} |
93 |
|
} |