From b97e04bf710f09af85f3875e30f9f4631cc30590 Mon Sep 17 00:00:00 2001 From: Amit Galitzky Date: Tue, 15 Mar 2022 12:25:58 -0700 Subject: [PATCH] changed default description to empty string instead of null (#438) Signed-off-by: Amit Galitzky (cherry picked from commit 124a26978ab56c75a6b252569d8904c7f39d36d5) --- .../org/opensearch/ad/model/AnomalyDetector.java | 2 +- .../opensearch/ad/model/AnomalyDetectorTests.java | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opensearch/ad/model/AnomalyDetector.java b/src/main/java/org/opensearch/ad/model/AnomalyDetector.java index 2a8eea4f3..2c069d703 100644 --- a/src/main/java/org/opensearch/ad/model/AnomalyDetector.java +++ b/src/main/java/org/opensearch/ad/model/AnomalyDetector.java @@ -420,7 +420,7 @@ public static AnomalyDetector parse( TimeValue defaultDetectionWindowDelay ) throws IOException { String name = null; - String description = null; + String description = ""; String timeField = null; List indices = new ArrayList(); QueryBuilder filterQuery = QueryBuilders.matchAllQuery(); diff --git a/src/test/java/org/opensearch/ad/model/AnomalyDetectorTests.java b/src/test/java/org/opensearch/ad/model/AnomalyDetectorTests.java index cefe4b31e..51a65351d 100644 --- a/src/test/java/org/opensearch/ad/model/AnomalyDetectorTests.java +++ b/src/test/java/org/opensearch/ad/model/AnomalyDetectorTests.java @@ -636,4 +636,16 @@ public void testValidateResultIndex() { errorMessage = AnomalyDetector.validateResultIndex(CUSTOM_RESULT_INDEX_PREFIX + "abc#"); assertEquals(INVALID_CHAR_IN_RESULT_INDEX_NAME, errorMessage); } + + public void testParseAnomalyDetectorWithNoDescription() throws IOException { + String detectorString = "{\"name\":\"todagtCMkwpcaedpyYUM\",\"time_field\":\"dJRwh\",\"indices\":[\"eIrgWMqAED\"]," + + "\"feature_attributes\":[{\"feature_id\":\"lxYRN\",\"feature_name\":\"eqSeU\",\"feature_enabled\"" + + ":true,\"aggregation_query\":{\"aa\":{\"value_count\":{\"field\":\"ok\"}}}}],\"detection_interval\":" + + "{\"period\":{\"interval\":425,\"unit\":\"Minutes\"}},\"window_delay\":{\"period\":{\"interval\":973," + + "\"unit\":\"Minutes\"}},\"shingle_size\":4,\"schema_version\":-1203962153,\"ui_metadata\":{\"JbAaV\":{\"feature_id\":" + + "\"rIFjS\",\"feature_name\":\"QXCmS\",\"feature_enabled\":false,\"aggregation_query\":{\"aa\":" + + "{\"value_count\":{\"field\":\"ok\"}}}}},\"last_update_time\":1568396089028}"; + AnomalyDetector parsedDetector = AnomalyDetector.parse(TestHelpers.parser(detectorString), "id", 1L, null, null); + assertEquals(parsedDetector.getDescription(), ""); + } }