Alerts : add alert serialization test

This test tests that an alert that is serialized in and out of json is the same alert.

Original commit: elastic/x-pack-elasticsearch@58cdc6d784
This commit is contained in:
Brian Murphy 2014-11-07 17:44:18 +00:00
parent a6468781f0
commit c9eae998b5
1 changed files with 42 additions and 0 deletions

View File

@ -0,0 +1,42 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
package org.elasticsearch.alerts;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.alerts.actions.AlertAction;
import org.elasticsearch.alerts.triggers.ScriptedTrigger;
import org.elasticsearch.common.joda.time.DateTime;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.test.ElasticsearchIntegrationTest;
import org.junit.Test;
import java.util.ArrayList;
public class TestAlertSerialization extends ElasticsearchIntegrationTest {
@Test
public void testAlertSerialization() throws Exception {
Alert alert = new Alert("test-serialization",
new SearchRequest(),
new ScriptedTrigger("return true", null, null),
new ArrayList<AlertAction>(), "0/5 * * * * ? *",
new DateTime(),
0,
false);
XContentBuilder jsonBuilder = XContentFactory.jsonBuilder();
alert.toXContent(jsonBuilder, ToXContent.EMPTY_PARAMS);
final AlertsStore alertsStore =
internalCluster().getInstance(AlertsStore.class, internalCluster().getMasterName());
Alert parsedAlert = alertsStore.parseAlert("test-serialization", jsonBuilder.bytes());
assertEquals(parsedAlert, alert);
}
}