diff --git a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/audit/Auditor.java b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/audit/Auditor.java index 3b87ff3a128..b804356b38c 100644 --- a/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/audit/Auditor.java +++ b/elasticsearch/src/main/java/org/elasticsearch/xpack/prelert/job/audit/Auditor.java @@ -55,7 +55,7 @@ public class Auditor { } private void indexDoc(String type, ToXContent toXContent) { - client.prepareIndex(index, AuditActivity.TYPE.getPreferredName()) + client.prepareIndex(index, type) .setSource(toXContentBuilder(toXContent)) .execute(new ActionListener() { @Override diff --git a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/audit/AuditorTests.java b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/audit/AuditorTests.java index 6757a62d2ad..2dfd892bcdd 100644 --- a/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/audit/AuditorTests.java +++ b/elasticsearch/src/test/java/org/elasticsearch/xpack/prelert/job/audit/AuditorTests.java @@ -5,7 +5,6 @@ */ package org.elasticsearch.xpack.prelert.job.audit; -import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; import java.io.IOException; @@ -27,6 +26,7 @@ public class AuditorTests extends ESTestCase { private Client client; private ListenableActionFuture indexResponse; private ArgumentCaptor indexCaptor; + private ArgumentCaptor typeCaptor; private ArgumentCaptor jsonCaptor; @SuppressWarnings("unchecked") @@ -35,6 +35,7 @@ public class AuditorTests extends ESTestCase { client = Mockito.mock(Client.class); indexResponse = Mockito.mock(ListenableActionFuture.class); indexCaptor = ArgumentCaptor.forClass(String.class); + typeCaptor = ArgumentCaptor.forClass(String.class); jsonCaptor = ArgumentCaptor.forClass(XContentBuilder.class); } @@ -43,6 +44,7 @@ public class AuditorTests extends ESTestCase { Auditor auditor = new Auditor(client, "prelert-int", "foo"); auditor.info("Here is my info"); assertEquals("prelert-int", indexCaptor.getValue()); + assertEquals("audit_message", typeCaptor.getValue()); AuditMessage auditMessage = parseAuditMessage(); assertEquals("foo", auditMessage.getJobId()); assertEquals("Here is my info", auditMessage.getMessage()); @@ -54,6 +56,7 @@ public class AuditorTests extends ESTestCase { Auditor auditor = new Auditor(client, "someIndex", "bar"); auditor.warning("Here is my warning"); assertEquals("someIndex", indexCaptor.getValue()); + assertEquals("audit_message", typeCaptor.getValue()); AuditMessage auditMessage = parseAuditMessage(); assertEquals("bar", auditMessage.getJobId()); assertEquals("Here is my warning", auditMessage.getMessage()); @@ -65,6 +68,7 @@ public class AuditorTests extends ESTestCase { Auditor auditor = new Auditor(client, "someIndex", "foobar"); auditor.error("Here is my error"); assertEquals("someIndex", indexCaptor.getValue()); + assertEquals("audit_message", typeCaptor.getValue()); AuditMessage auditMessage = parseAuditMessage(); assertEquals("foobar", auditMessage.getJobId()); assertEquals("Here is my error", auditMessage.getMessage()); @@ -76,6 +80,7 @@ public class AuditorTests extends ESTestCase { Auditor auditor = new Auditor(client, "someIndex", ""); auditor.activity("Here is my activity"); assertEquals("someIndex", indexCaptor.getValue()); + assertEquals("audit_message", typeCaptor.getValue()); AuditMessage auditMessage = parseAuditMessage(); assertEquals("", auditMessage.getJobId()); assertEquals("Here is my activity", auditMessage.getMessage()); @@ -87,6 +92,7 @@ public class AuditorTests extends ESTestCase { Auditor auditor = new Auditor(client, "someIndex", ""); auditor.activity(10, 100, 5, 50); assertEquals("someIndex", indexCaptor.getValue()); + assertEquals("audit_activity", typeCaptor.getValue()); AuditActivity auditActivity = parseAuditActivity(); assertEquals(10, auditActivity.getTotalJobs()); assertEquals(100, auditActivity.getTotalDetectors()); @@ -98,9 +104,9 @@ public class AuditorTests extends ESTestCase { IndexRequestBuilder indexRequestBuilder = Mockito.mock(IndexRequestBuilder.class); when(indexRequestBuilder.setSource(jsonCaptor.capture())).thenReturn(indexRequestBuilder); when(indexRequestBuilder.execute()).thenReturn(indexResponse); - when(client.prepareIndex(indexCaptor.capture(), eq("audit_message"))) + when(client.prepareIndex(indexCaptor.capture(), typeCaptor.capture())) .thenReturn(indexRequestBuilder); - when(client.prepareIndex(indexCaptor.capture(), eq("audit_activity"))) + when(client.prepareIndex(indexCaptor.capture(), typeCaptor.capture())) .thenReturn(indexRequestBuilder); }