1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.job.internal; |
21 |
|
|
22 |
|
import java.io.File; |
23 |
|
import java.util.Arrays; |
24 |
|
import java.util.List; |
25 |
|
|
26 |
|
import org.apache.commons.io.FileUtils; |
27 |
|
import org.junit.Assert; |
28 |
|
import org.junit.Before; |
29 |
|
import org.junit.Rule; |
30 |
|
import org.junit.Test; |
31 |
|
import org.xwiki.cache.CacheManager; |
32 |
|
import org.xwiki.cache.internal.MapCache; |
33 |
|
import org.xwiki.component.manager.ComponentLookupException; |
34 |
|
import org.xwiki.component.util.ReflectionUtils; |
35 |
|
import org.xwiki.job.DefaultJobStatus; |
36 |
|
import org.xwiki.job.DefaultRequest; |
37 |
|
import org.xwiki.job.JobManagerConfiguration; |
38 |
|
import org.xwiki.job.event.status.JobStatus; |
39 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
40 |
|
|
41 |
|
import static org.junit.Assert.assertNull; |
42 |
|
import static org.mockito.ArgumentMatchers.any; |
43 |
|
import static org.mockito.Mockito.mock; |
44 |
|
import static org.mockito.Mockito.verifyNoMoreInteractions; |
45 |
|
import static org.mockito.Mockito.when; |
46 |
|
|
47 |
|
|
48 |
|
@link |
49 |
|
|
50 |
|
@version |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (52) |
Complexity: 8 |
Complexity Density: 0.18 |
|
52 |
|
public class DefaultJobStatusStoreTest |
53 |
|
{ |
54 |
|
@Rule |
55 |
|
public final MockitoComponentMockingRule<DefaultJobStatusStore> componentManager = |
56 |
|
new MockitoComponentMockingRule<>(DefaultJobStatusStore.class); |
57 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
58 |
7 |
@Before... |
59 |
|
public void before() throws Exception |
60 |
|
{ |
61 |
7 |
JobManagerConfiguration jobManagerConfiguration = |
62 |
|
this.componentManager.getInstance(JobManagerConfiguration.class); |
63 |
|
|
64 |
7 |
FileUtils.deleteDirectory(new File("target/test/jobs/")); |
65 |
7 |
FileUtils.copyDirectory(new File("src/test/resources/jobs/"), new File("target/test/jobs/")); |
66 |
|
|
67 |
7 |
when(jobManagerConfiguration.getStorage()).thenReturn(new File("target/test/jobs/status")); |
68 |
7 |
when(jobManagerConfiguration.getJobStatusCacheSize()).thenReturn(100); |
69 |
|
|
70 |
7 |
CacheManager cacheManagerMock = this.componentManager.getInstance(CacheManager.class); |
71 |
7 |
when(cacheManagerMock.createNewCache(any())).thenReturn(new MapCache<>()); |
72 |
|
} |
73 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
74 |
1 |
@Test... |
75 |
|
public void getJobStatusWithNullId() throws Exception |
76 |
|
{ |
77 |
1 |
JobStatus jobStatus = this.componentManager.getComponentUnderTest().getJobStatus((List<String>) null); |
78 |
|
|
79 |
1 |
Assert.assertNotNull(jobStatus); |
80 |
1 |
Assert.assertNull(jobStatus.getRequest().getId()); |
81 |
1 |
Assert.assertEquals(JobStatus.State.FINISHED, jobStatus.getState()); |
82 |
|
|
83 |
1 |
Assert.assertSame(jobStatus, this.componentManager.getComponentUnderTest().getJobStatus((List<String>) null)); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void getJobStatusWithMultipleId() throws Exception |
88 |
|
{ |
89 |
1 |
JobStatus jobStatus = this.componentManager.getComponentUnderTest().getJobStatus(Arrays.asList("id1", "id2")); |
90 |
|
|
91 |
1 |
Assert.assertNotNull(jobStatus); |
92 |
1 |
Assert.assertEquals(Arrays.asList("id1", "id2"), jobStatus.getRequest().getId()); |
93 |
1 |
Assert.assertEquals(JobStatus.State.FINISHED, jobStatus.getState()); |
94 |
|
|
95 |
1 |
Assert.assertSame(jobStatus, |
96 |
|
this.componentManager.getComponentUnderTest().getJobStatus(Arrays.asList("id1", "id2"))); |
97 |
|
} |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
99 |
1 |
@Test... |
100 |
|
public void getJobStatusInOldPlace() throws Exception |
101 |
|
{ |
102 |
1 |
JobStatus jobStatus = |
103 |
|
this.componentManager.getComponentUnderTest().getJobStatus(Arrays.asList("id1", "id2", "id3")); |
104 |
|
|
105 |
1 |
Assert.assertNotNull(jobStatus); |
106 |
1 |
Assert.assertEquals(Arrays.asList("id1", "id2", "id3"), jobStatus.getRequest().getId()); |
107 |
1 |
Assert.assertEquals(JobStatus.State.FINISHED, jobStatus.getState()); |
108 |
|
} |
109 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
1PASS
|
|
110 |
1 |
@Test... |
111 |
|
public void getJobStatusInWrongPlaceAndWithInvalidLogArgument() throws Exception |
112 |
|
{ |
113 |
1 |
JobStatus jobStatus = |
114 |
|
this.componentManager.getComponentUnderTest().getJobStatus(Arrays.asList("invalidlogargument")); |
115 |
|
|
116 |
1 |
Assert.assertEquals(3, jobStatus.getLog().size()); |
117 |
|
} |
118 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
119 |
1 |
@Test... |
120 |
|
public void getJobStatusThatDoesNotExist() throws Exception |
121 |
|
{ |
122 |
1 |
JobStatus jobStatus = this.componentManager.getComponentUnderTest().getJobStatus(Arrays.asList("nostatus")); |
123 |
|
|
124 |
1 |
assertNull(jobStatus); |
125 |
|
|
126 |
1 |
JobStatusSerializer mockSerializer = mock(JobStatusSerializer.class); |
127 |
1 |
ReflectionUtils.setFieldValue(this.componentManager.getComponentUnderTest(), "serializer", mockSerializer); |
128 |
|
|
129 |
1 |
jobStatus = this.componentManager.getComponentUnderTest().getJobStatus(Arrays.asList("nostatus")); |
130 |
1 |
assertNull(jobStatus); |
131 |
|
|
132 |
1 |
verifyNoMoreInteractions(mockSerializer); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
135 |
1 |
@Test... |
136 |
|
public void removeJobStatus() throws ComponentLookupException |
137 |
|
{ |
138 |
1 |
List<String> id = null; |
139 |
|
|
140 |
1 |
JobStatus jobStatus = this.componentManager.getComponentUnderTest().getJobStatus(id); |
141 |
|
|
142 |
1 |
Assert.assertNotNull(jobStatus); |
143 |
1 |
Assert.assertNull(jobStatus.getRequest().getId()); |
144 |
1 |
Assert.assertEquals(JobStatus.State.FINISHED, jobStatus.getState()); |
145 |
|
|
146 |
1 |
Assert.assertSame(jobStatus, this.componentManager.getComponentUnderTest().getJobStatus(id)); |
147 |
|
|
148 |
1 |
this.componentManager.getComponentUnderTest().remove(id); |
149 |
|
|
150 |
1 |
Assert.assertSame(null, this.componentManager.getComponentUnderTest().getJobStatus(id)); |
151 |
|
} |
152 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
153 |
1 |
@Test... |
154 |
|
public void storeJobStatus() throws ComponentLookupException |
155 |
|
{ |
156 |
1 |
List<String> id = Arrays.asList("newstatus"); |
157 |
|
|
158 |
1 |
DefaultRequest request = new DefaultRequest(); |
159 |
1 |
request.setId(id); |
160 |
1 |
JobStatus jobStatus = new DefaultJobStatus(request, null, null, null); |
161 |
|
|
162 |
1 |
this.componentManager.getComponentUnderTest().store(jobStatus); |
163 |
|
|
164 |
1 |
Assert.assertSame(jobStatus, this.componentManager.getComponentUnderTest().getJobStatus(id)); |
165 |
|
} |
166 |
|
} |