Skip to content

Commit 3b6a706

Browse files
committed
Series sales form: validate url.
Fix #501
1 parent c773743 commit 3b6a706

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

src/main/java/ru/mystamps/web/controller/SeriesController.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030

3131
import javax.servlet.http.HttpServletRequest;
3232
import javax.servlet.http.HttpServletResponse;
33-
import javax.validation.Valid;
3433
import javax.validation.groups.Default;
3534

3635
import org.apache.commons.lang3.StringUtils;
@@ -419,7 +418,7 @@ public String removeFromCollection(
419418

420419
@PostMapping(Url.ADD_SERIES_ASK_PAGE)
421420
public String processAskForm(
422-
@Valid AddSeriesSalesForm form,
421+
@Validated({ Default.class, AddSeriesSalesForm.UrlChecks.class }) AddSeriesSalesForm form,
423422
BindingResult result,
424423
@PathVariable("id") Integer seriesId,
425424
Model model,

src/main/java/ru/mystamps/web/controller/dto/AddSeriesSalesForm.java

+16-1
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,12 @@
2020
import java.math.BigDecimal;
2121
import java.util.Date;
2222

23+
import javax.validation.GroupSequence;
2324
import javax.validation.constraints.NotNull;
2425
import javax.validation.constraints.Size;
2526

27+
import org.hibernate.validator.constraints.URL;
28+
2629
import org.springframework.format.annotation.DateTimeFormat;
2730

2831
import lombok.Getter;
@@ -42,7 +45,12 @@ public class AddSeriesSalesForm implements AddSeriesSalesDto {
4245
@NotNull
4346
private Integer sellerId;
4447

45-
@Size(max = ValidationRules.SERIES_SALES_URL_MAX_LENGTH, message = "{value.too-long}")
48+
@Size(
49+
max = ValidationRules.SERIES_SALES_URL_MAX_LENGTH,
50+
message = "{value.too-long}",
51+
groups = Group.Level1.class
52+
)
53+
@URL(groups = Group.Level2.class)
4654
private String url;
4755

4856
@NotNull
@@ -57,4 +65,11 @@ public class AddSeriesSalesForm implements AddSeriesSalesDto {
5765

5866
private Integer buyerId;
5967

68+
@GroupSequence({
69+
Group.Level1.class,
70+
Group.Level2.class,
71+
})
72+
public interface UrlChecks {
73+
}
74+
6075
}

src/test/robotframework/series/sales/validation.robot

+6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ Create series sales with too long url
1414
Submit Form id=add-series-sales-form
1515
Element Text Should Be id=url.errors Value is greater than allowable maximum of 255 characters
1616

17+
Create series sales with invalid url
18+
[Documentation] Verify validation of invalid url
19+
Input Text id=url invalid-url
20+
Submit Form id=add-series-sales-form
21+
Element Text Should Be id=url.errors Value must be a valid URL
22+
1723
*** Keywords ***
1824
Before Test Suite
1925
[Documentation] Login as admin and open a page with series

0 commit comments

Comments
 (0)