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.util.Arrays; |
23 |
|
|
24 |
|
import org.junit.Test; |
25 |
|
import org.mockito.invocation.InvocationOnMock; |
26 |
|
import org.mockito.stubbing.Answer; |
27 |
|
import org.xwiki.job.DefaultRequest; |
28 |
|
import org.xwiki.job.DefaultJobStatus; |
29 |
|
import org.xwiki.job.event.status.JobStatus; |
30 |
|
import org.xwiki.job.event.status.QuestionAnsweredEvent; |
31 |
|
import org.xwiki.job.event.status.QuestionAskedEvent; |
32 |
|
import org.xwiki.logging.LoggerManager; |
33 |
|
import org.xwiki.observation.ObservationManager; |
34 |
|
import org.xwiki.observation.event.Event; |
35 |
|
|
36 |
|
import static org.junit.Assert.*; |
37 |
|
import static org.mockito.Mockito.*; |
38 |
|
|
39 |
|
|
40 |
|
@link |
41 |
|
|
42 |
|
@version |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (31) |
Complexity: 4 |
Complexity Density: 0.15 |
|
44 |
|
public class DefaultJobStatusTest |
45 |
|
{ |
46 |
|
private ObservationManager observationManager = mock(ObservationManager.class); |
47 |
|
|
48 |
|
private LoggerManager loggerManager = mock(LoggerManager.class); |
49 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (11) |
Complexity: 1 |
Complexity Density: 0.09 |
1PASS
|
|
50 |
1 |
@Test... |
51 |
|
public void subJobQuestionIsForwardedToParent() throws Exception |
52 |
|
{ |
53 |
1 |
JobStatus parentJobStatus = mock(JobStatus.class); |
54 |
1 |
org.xwiki.job.DefaultJobStatus<DefaultRequest> jobStatus = new org.xwiki.job.DefaultJobStatus<>( |
55 |
|
new DefaultRequest(), parentJobStatus, this.observationManager, this.loggerManager); |
56 |
|
|
57 |
1 |
String question = "What's up?"; |
58 |
1 |
jobStatus.ask(question); |
59 |
|
|
60 |
1 |
assertSame(question, jobStatus.getQuestion()); |
61 |
1 |
verify(parentJobStatus).ask(question); |
62 |
|
|
63 |
1 |
jobStatus.answered(); |
64 |
|
|
65 |
1 |
assertNull(jobStatus.getQuestion()); |
66 |
1 |
verify(parentJobStatus).answered(); |
67 |
|
|
68 |
|
|
69 |
1 |
verify(this.observationManager, never()).notify(any(Event.class), anyObject()); |
70 |
1 |
verify(this.observationManager, never()).notify(any(Event.class), anyObject(), anyObject()); |
71 |
|
} |
72 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
73 |
1 |
@Test... |
74 |
|
public void fireQuestionAnsweredOK() |
75 |
|
{ |
76 |
1 |
DefaultRequest request = new DefaultRequest(); |
77 |
1 |
request.setId(Arrays.asList("test", "answered")); |
78 |
|
|
79 |
1 |
DefaultJobStatus<DefaultRequest> jobStatus = |
80 |
|
new DefaultJobStatus<>(request, null, this.observationManager, this.loggerManager); |
81 |
|
|
82 |
1 |
jobStatus.answered(); |
83 |
|
|
84 |
|
|
85 |
1 |
verify(this.observationManager).notify(new QuestionAnsweredEvent(null, request.getId()), jobStatus); |
86 |
|
} |
87 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
88 |
1 |
@Test... |
89 |
|
public void fireQuestionAskedOK() throws Exception |
90 |
|
{ |
91 |
1 |
DefaultRequest request = new DefaultRequest(); |
92 |
1 |
request.setId(Arrays.asList("test", "asked")); |
93 |
|
|
94 |
1 |
DefaultJobStatus<DefaultRequest> jobStatus = |
95 |
|
new DefaultJobStatus<>(request, null, this.observationManager, this.loggerManager); |
96 |
|
|
97 |
1 |
QuestionAskedEvent questionAsked = new QuestionAskedEvent(String.class.getName(), request.getId()); |
98 |
1 |
doAnswer(new Answer<Void>() |
99 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
100 |
1 |
@Override... |
101 |
|
public Void answer(InvocationOnMock invocation) throws Throwable |
102 |
|
{ |
103 |
1 |
QuestionAskedEvent event = (QuestionAskedEvent) invocation.getArguments()[0]; |
104 |
1 |
event.answered(); |
105 |
1 |
return null; |
106 |
|
} |
107 |
|
}).when(this.observationManager).notify(questionAsked, jobStatus); |
108 |
|
|
109 |
1 |
jobStatus.ask("What's up?"); |
110 |
|
|
111 |
1 |
QuestionAnsweredEvent questionAnswered = new QuestionAnsweredEvent(String.class.getName(), request.getId()); |
112 |
1 |
verify(this.observationManager).notify(questionAnswered, jobStatus); |
113 |
|
} |
114 |
|
} |