1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
|
22 |
|
|
23 |
|
|
24 |
|
|
25 |
|
|
26 |
|
|
27 |
|
|
28 |
|
|
29 |
|
|
30 |
|
|
31 |
|
|
32 |
|
|
33 |
|
|
34 |
|
package info.magnolia.rest; |
35 |
|
|
36 |
|
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR; |
37 |
|
import static org.junit.Assert.*; |
38 |
|
import static org.mockito.Mockito.when; |
39 |
|
|
40 |
|
import info.magnolia.jcr.RuntimeRepositoryException; |
41 |
|
|
42 |
|
import javax.jcr.RepositoryException; |
43 |
|
import javax.ws.rs.core.Response; |
44 |
|
import javax.ws.rs.ext.Providers; |
45 |
|
|
46 |
|
import org.junit.Before; |
47 |
|
import org.junit.Test; |
48 |
|
import org.mockito.InjectMocks; |
49 |
|
import org.mockito.Mock; |
50 |
|
import org.mockito.MockitoAnnotations; |
51 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 4 |
Complexity Density: 0.21 |
|
52 |
|
public class RuntimeRepositoryExceptionMapperTest { |
53 |
|
|
54 |
|
@InjectMocks |
55 |
|
private final RuntimeRepositoryExceptionMapper runtimeRepositoryExceptionMapper = new RuntimeRepositoryExceptionMapper(); |
56 |
|
|
57 |
|
@Mock |
58 |
|
private Providers providers; |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
60 |
2 |
@Before... |
61 |
|
public void setUp() { |
62 |
|
|
63 |
2 |
MockitoAnnotations.initMocks(this); |
64 |
2 |
RepositoryExceptionMapper repositoryExceptionMapper = new RepositoryExceptionMapper(); |
65 |
2 |
when(providers.getExceptionMapper(RepositoryException.class)).thenReturn(repositoryExceptionMapper); |
66 |
|
} |
67 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
68 |
1 |
@Test... |
69 |
|
public void runtimeRepositoryExceptionHasCause() { |
70 |
|
|
71 |
1 |
String errorMessage = "Repository exception"; |
72 |
1 |
RepositoryException repositoryException = new RepositoryException(errorMessage); |
73 |
1 |
RuntimeRepositoryException runtimeRepositoryException = new RuntimeRepositoryException(repositoryException); |
74 |
|
|
75 |
|
|
76 |
1 |
Response response = runtimeRepositoryExceptionMapper.toResponse(runtimeRepositoryException); |
77 |
|
|
78 |
|
|
79 |
1 |
assertErrorResponse(response, INTERNAL_SERVER_ERROR, errorMessage, "unknown"); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
82 |
1 |
@Test... |
83 |
|
public void runtimeRepositoryExceptionDoesNotHaveCause() { |
84 |
|
|
85 |
1 |
String errorMessage = "Runtime repository exception"; |
86 |
1 |
RuntimeRepositoryException runtimeRepositoryException = new RuntimeRepositoryException(errorMessage, null); |
87 |
|
|
88 |
|
|
89 |
1 |
Response response = runtimeRepositoryExceptionMapper.toResponse(runtimeRepositoryException); |
90 |
|
|
91 |
|
|
92 |
1 |
assertErrorResponse(response, INTERNAL_SERVER_ERROR, errorMessage, "unknown"); |
93 |
|
} |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
95 |
2 |
private void assertErrorResponse(Response response, Response.Status expectedStatusCode, String expectedErrorMessage, String expectedErrorCode) {... |
96 |
2 |
assertEquals(expectedStatusCode, response.getStatusInfo()); |
97 |
2 |
assertNotNull(response.getEntity()); |
98 |
2 |
assertTrue(response.getEntity() instanceof RestError); |
99 |
2 |
RestError restError = (RestError) response.getEntity(); |
100 |
2 |
assertNotNull(restError.getErrorContainer().getCode()); |
101 |
2 |
assertEquals(expectedErrorCode, restError.getErrorContainer().getCode()); |
102 |
2 |
assertEquals(expectedErrorMessage, restError.getErrorContainer().getMessage()); |
103 |
|
} |
104 |
|
} |