File tree Expand file tree Collapse file tree 5 files changed +68
-6
lines changed
main/java/org/seedstack/validation
test/java/org/seedstack/validation/internal Expand file tree Collapse file tree 5 files changed +68
-6
lines changed Original file line number Diff line number Diff line change 7676 <optional >true</optional >
7777 </dependency >
7878
79+ <dependency >
80+ <groupId >javax.ws.rs</groupId >
81+ <artifactId >javax.ws.rs-api</artifactId >
82+ <version >2.0.1</version >
83+ <scope >provided</scope >
84+ </dependency >
85+
86+ <!-- TESTS-->
7987 <dependency >
8088 <groupId >org.seedstack.seed</groupId >
8189 <artifactId >seed-testing</artifactId >
94102 <version >${javax-el.version} </version >
95103 <scope >test</scope >
96104 </dependency >
105+ <dependency >
106+ <groupId >org.glassfish.jersey.containers</groupId >
107+ <artifactId >jersey-container-servlet</artifactId >
108+ <version >2.22.1</version >
109+ <scope >test</scope >
110+ </dependency >
97111 <dependency >
98112 <groupId >ch.qos.logback</groupId >
99113 <artifactId >logback-classic</artifactId >
Original file line number Diff line number Diff line change 1919public class ValidationException extends SeedException {
2020 private static final long serialVersionUID = 1L ;
2121
22- protected ValidationException (ErrorCode errorCode ) {
22+ public ValidationException (ErrorCode errorCode ) {
2323 super (errorCode );
2424 }
2525}
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) 2013-2015, The SeedStack authors <http://seedstack.org>
3+ *
4+ * This Source Code Form is subject to the terms of the Mozilla Public
5+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+ */
8+ package org .seedstack .validation .internal ;
9+
10+ import org .seedstack .validation .ValidationException ;
11+
12+ import javax .ws .rs .core .Response ;
13+ import javax .ws .rs .ext .ExceptionMapper ;
14+ import javax .ws .rs .ext .Provider ;
15+
16+ @ Provider
17+ public class ValidationExceptionMapper implements ExceptionMapper <ValidationException > {
18+
19+ @ Override
20+ public Response toResponse (ValidationException exception ) {
21+ return Response .status (Response .Status .BAD_REQUEST ).build ();
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -30,13 +30,10 @@ public String name() {
3030
3131 @ Override
3232 public Object nativeUnitModule () {
33-
3433 if (validationModule == null ) {
3534 factory = Validation .buildDefaultValidatorFactory ();
36-
3735 validationModule = new ValidationModule (factory , validationService );
3836 }
39-
4037 return validationModule ;
4138 }
4239
@@ -51,10 +48,8 @@ public ValidationService getValidationService() {
5148
5249 @ Override
5350 public void stop () {
54-
5551 if (factory != null ) {
5652 factory .close ();
5753 }
58-
5954 }
6055}
Original file line number Diff line number Diff line change 1+ /**
2+ * Copyright (c) 2013-2015, The SeedStack authors <http://seedstack.org>
3+ *
4+ * This Source Code Form is subject to the terms of the Mozilla Public
5+ * License, v. 2.0. If a copy of the MPL was not distributed with this
6+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7+ */
8+ package org .seedstack .validation .internal ;
9+
10+ import org .assertj .core .api .Assertions ;
11+ import org .junit .Test ;
12+ import org .seedstack .validation .ValidationException ;
13+
14+ import javax .ws .rs .core .Response ;
15+ import javax .ws .rs .ext .Provider ;
16+
17+ public class ValidationExceptionMapperTest {
18+
19+ @ Test
20+ public void testIsProvider () {
21+ ValidationExceptionMapper .class .isAnnotationPresent (Provider .class );
22+ }
23+
24+ @ Test
25+ public void testReturnError400 () {
26+ Response response = new ValidationExceptionMapper ()
27+ .toResponse (new ValidationException (ValidationErrorCode .VALIDATION_ISSUE ));
28+ Assertions .assertThat (response .getStatus ()).isEqualTo (400 );
29+ }
30+ }
You can’t perform that action at this time.
0 commit comments