[ML] Improve error message when post-calendar-events-request is empty (elastic/x-pack-elasticsearch#3572)
Relates elastic/x-pack-elasticsearch#3016 Original commit: elastic/x-pack-elasticsearch@3d25ed4723
This commit is contained in:
parent
aff9a4a2ba
commit
6c6dcafd0e
|
@ -82,6 +82,10 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
|
||||||
public Request(String calendarId, List<ScheduledEvent> scheduledEvents) {
|
public Request(String calendarId, List<ScheduledEvent> scheduledEvents) {
|
||||||
this.calendarId = ExceptionsHelper.requireNonNull(calendarId, Calendar.ID.getPreferredName());
|
this.calendarId = ExceptionsHelper.requireNonNull(calendarId, Calendar.ID.getPreferredName());
|
||||||
this.scheduledEvents = ExceptionsHelper.requireNonNull(scheduledEvents, EVENTS.getPreferredName());
|
this.scheduledEvents = ExceptionsHelper.requireNonNull(scheduledEvents, EVENTS.getPreferredName());
|
||||||
|
|
||||||
|
if (scheduledEvents.isEmpty()) {
|
||||||
|
throw ExceptionsHelper.badRequestException("at least 1 event is required");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getCalendarId() {
|
public String getCalendarId() {
|
||||||
|
|
|
@ -584,3 +584,15 @@
|
||||||
- length: { events: 2 }
|
- length: { events: 2 }
|
||||||
- match: { events.0.description: ski }
|
- match: { events.0.description: ski }
|
||||||
- match: { events.1.description: snow }
|
- match: { events.1.description: snow }
|
||||||
|
|
||||||
|
---
|
||||||
|
"Test post calendar events given empty events":
|
||||||
|
|
||||||
|
- do:
|
||||||
|
catch: /at least 1 event is required/
|
||||||
|
xpack.ml.post_calendar_events:
|
||||||
|
calendar_id: "foo"
|
||||||
|
body: >
|
||||||
|
{
|
||||||
|
"events": []
|
||||||
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ integTestRunner {
|
||||||
// know whether to expect an authorization exception or a validation exception
|
// know whether to expect an authorization exception or a validation exception
|
||||||
'ml/calendar_crud/Test cannot create calendar with name _all',
|
'ml/calendar_crud/Test cannot create calendar with name _all',
|
||||||
'ml/calendar_crud/Test PageParams with ID is invalid',
|
'ml/calendar_crud/Test PageParams with ID is invalid',
|
||||||
|
'ml/calendar_crud/Test post calendar events given empty events',
|
||||||
'ml/custom_all_field/Test querying custom all field',
|
'ml/custom_all_field/Test querying custom all field',
|
||||||
'ml/datafeeds_crud/Test delete datafeed with missing id',
|
'ml/datafeeds_crud/Test delete datafeed with missing id',
|
||||||
'ml/datafeeds_crud/Test put datafeed referring to missing job_id',
|
'ml/datafeeds_crud/Test put datafeed referring to missing job_id',
|
||||||
|
|
Loading…
Reference in New Issue