Rationalize AuditEventRepository contract

Closes gh-11331
pull/11497/merge
Stephane Nicoll 7 years ago
parent 644925e9f0
commit 4b59d5f517

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -33,24 +33,6 @@ public interface AuditEventRepository {
*/
void add(AuditEvent event);
/**
* Find audit events since the time provided.
* @param after timestamp of earliest result required (or {@code null} if
* unrestricted)
* @return audit events
* @since 1.4.0
*/
List<AuditEvent> find(Date after);
/**
* Find audit events relating to the specified principal since the time provided.
* @param principal the principal name to search for (or {@code null} if unrestricted)
* @param after timestamp of earliest result required (or {@code null} if
* unrestricted)
* @return audit events relating to the principal
*/
List<AuditEvent> find(String principal, Date after);
/**
* Find audit events of specified type relating to the specified principal since the
* time provided.

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -69,16 +69,6 @@ public class InMemoryAuditEventRepository implements AuditEventRepository {
}
}
@Override
public List<AuditEvent> find(Date after) {
return find(null, after, null);
}
@Override
public List<AuditEvent> find(String principal, Date after) {
return find(principal, after, null);
}
@Override
public List<AuditEvent> find(String principal, Date after, String type) {
LinkedList<AuditEvent> events = new LinkedList<>();

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -45,7 +45,7 @@ public class InMemoryAuditEventRepositoryTests {
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
repository.add(new AuditEvent("dave", "a"));
repository.add(new AuditEvent("dave", "b"));
List<AuditEvent> events = repository.find("dave", null);
List<AuditEvent> events = repository.find("dave", null, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType()).isEqualTo("a");
assertThat(events.get(1).getType()).isEqualTo("b");
@ -57,7 +57,7 @@ public class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("dave", "a"));
repository.add(new AuditEvent("dave", "b"));
repository.add(new AuditEvent("dave", "c"));
List<AuditEvent> events = repository.find("dave", null);
List<AuditEvent> events = repository.find("dave", null, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType()).isEqualTo("b");
assertThat(events.get(1).getType()).isEqualTo("c");
@ -78,7 +78,7 @@ public class InMemoryAuditEventRepositoryTests {
repository.add(new AuditEvent("phil", "b"));
repository.add(new AuditEvent("dave", "c"));
repository.add(new AuditEvent("phil", "d"));
List<AuditEvent> events = repository.find("dave", null);
List<AuditEvent> events = repository.find("dave", null, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType()).isEqualTo("a");
assertThat(events.get(1).getType()).isEqualTo("c");
@ -113,11 +113,11 @@ public class InMemoryAuditEventRepositoryTests {
calendar.add(Calendar.DAY_OF_YEAR, 1);
repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data));
calendar.add(Calendar.DAY_OF_YEAR, 1);
List<AuditEvent> events = repository.find(after);
List<AuditEvent> events = repository.find(null, after, null);
assertThat(events.size()).isEqualTo(2);
assertThat(events.get(0).getType()).isEqualTo("c");
assertThat(events.get(1).getType()).isEqualTo("d");
events = repository.find("dave", after);
events = repository.find("dave", after, null);
assertThat(events.size()).isEqualTo(1);
assertThat(events.get(0).getType()).isEqualTo("c");
}

Loading…
Cancel
Save