[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:
Dimitris Athanasiou 2018-01-15 18:13:50 +00:00 committed by GitHub
parent aff9a4a2ba
commit 6c6dcafd0e
3 changed files with 17 additions and 0 deletions

View File

@ -82,6 +82,10 @@ public class PostCalendarEventsAction extends Action<PostCalendarEventsAction.Re
public Request(String calendarId, List<ScheduledEvent> scheduledEvents) {
this.calendarId = ExceptionsHelper.requireNonNull(calendarId, Calendar.ID.getPreferredName());
this.scheduledEvents = ExceptionsHelper.requireNonNull(scheduledEvents, EVENTS.getPreferredName());
if (scheduledEvents.isEmpty()) {
throw ExceptionsHelper.badRequestException("at least 1 event is required");
}
}
public String getCalendarId() {

View File

@ -584,3 +584,15 @@
- length: { events: 2 }
- match: { events.0.description: ski }
- 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": []
}

View File

@ -22,6 +22,7 @@ integTestRunner {
// 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 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/datafeeds_crud/Test delete datafeed with missing id',
'ml/datafeeds_crud/Test put datafeed referring to missing job_id',