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.*; |
37 |
|
import static org.junit.Assert.*; |
38 |
|
|
39 |
|
import javax.jcr.AccessDeniedException; |
40 |
|
import javax.jcr.PathNotFoundException; |
41 |
|
import javax.jcr.RepositoryException; |
42 |
|
import javax.jcr.query.InvalidQueryException; |
43 |
|
import javax.ws.rs.core.Response; |
44 |
|
|
45 |
|
import org.junit.Test; |
46 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (28) |
Complexity: 5 |
Complexity Density: 0.22 |
|
47 |
|
public class RepositoryExceptionMapperTest { |
48 |
|
|
49 |
|
private final RepositoryExceptionMapper repositoryExceptionMapper = new RepositoryExceptionMapper(); |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
51 |
1 |
@Test... |
52 |
|
public void accessDeniedException() { |
53 |
|
|
54 |
1 |
String message = "Access denied"; |
55 |
1 |
RepositoryException exception = new AccessDeniedException(message); |
56 |
|
|
57 |
|
|
58 |
1 |
Response response = repositoryExceptionMapper.toResponse(exception); |
59 |
|
|
60 |
|
|
61 |
1 |
assertEquals(Response.Status.FORBIDDEN.getStatusCode(), response.getStatus()); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
64 |
1 |
@Test... |
65 |
|
public void pathNotFoundException() { |
66 |
|
|
67 |
1 |
String errorMessage = "Path not found"; |
68 |
1 |
RepositoryException exception = new PathNotFoundException(errorMessage); |
69 |
|
|
70 |
|
|
71 |
1 |
Response response = repositoryExceptionMapper.toResponse(exception); |
72 |
|
|
73 |
|
|
74 |
1 |
assertErrorResponse(response, NOT_FOUND, errorMessage, "pathNotFound"); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
77 |
3 |
private void assertErrorResponse(Response response, Response.Status expectedStatusCode, String expectedErrorMessage, String expectedErrorCode) {... |
78 |
3 |
assertEquals(expectedStatusCode, response.getStatusInfo()); |
79 |
3 |
assertNotNull(response.getEntity()); |
80 |
3 |
assertTrue(response.getEntity() instanceof RestError); |
81 |
3 |
RestError restError = (RestError) response.getEntity(); |
82 |
3 |
assertNotNull(restError.getErrorContainer().getCode()); |
83 |
3 |
assertEquals(expectedErrorCode, restError.getErrorContainer().getCode()); |
84 |
3 |
assertEquals(expectedErrorMessage, restError.getErrorContainer().getMessage()); |
85 |
|
} |
86 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
87 |
1 |
@Test... |
88 |
|
public void invalidQueryException() { |
89 |
|
|
90 |
1 |
String errorMessage = "SELECT * FROM [nt:base]"; |
91 |
1 |
RepositoryException exception = new InvalidQueryException(errorMessage); |
92 |
|
|
93 |
|
|
94 |
1 |
Response response = repositoryExceptionMapper.toResponse(exception); |
95 |
|
|
96 |
|
|
97 |
1 |
assertErrorResponse(response, BAD_REQUEST, "Invalid query", "invalidQuery"); |
98 |
|
} |
99 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
100 |
1 |
@Test... |
101 |
|
public void unknownRepositoryException() { |
102 |
|
|
103 |
1 |
String errorMessage = "Unknown"; |
104 |
1 |
RepositoryException exception = new RepositoryException(errorMessage); |
105 |
|
|
106 |
|
|
107 |
1 |
Response response = repositoryExceptionMapper.toResponse(exception); |
108 |
|
|
109 |
|
|
110 |
1 |
assertErrorResponse(response, INTERNAL_SERVER_ERROR, errorMessage, "unknown"); |
111 |
|
} |
112 |
|
} |