|
|
@ -22,7 +22,9 @@ import java.util.HashMap;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.Rule;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.Test;
|
|
|
|
|
|
|
|
import org.junit.rules.ExpectedException;
|
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
|
|
|
|
|
|
@ -31,9 +33,13 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author Dave Syer
|
|
|
|
* @author Dave Syer
|
|
|
|
* @author Phillip Webb
|
|
|
|
* @author Phillip Webb
|
|
|
|
|
|
|
|
* @author Vedran Pavic
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class InMemoryAuditEventRepositoryTests {
|
|
|
|
public class InMemoryAuditEventRepositoryTests {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Rule
|
|
|
|
|
|
|
|
public ExpectedException thrown = ExpectedException.none();
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void lessThanCapacity() throws Exception {
|
|
|
|
public void lessThanCapacity() throws Exception {
|
|
|
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
|
|
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
|
|
@ -43,7 +49,6 @@ public class InMemoryAuditEventRepositoryTests {
|
|
|
|
assertThat(events.size()).isEqualTo(2);
|
|
|
|
assertThat(events.size()).isEqualTo(2);
|
|
|
|
assertThat(events.get(0).getType()).isEqualTo("a");
|
|
|
|
assertThat(events.get(0).getType()).isEqualTo("a");
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("b");
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("b");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
@ -58,6 +63,14 @@ public class InMemoryAuditEventRepositoryTests {
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("c");
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("c");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void addNullAuditEvent() throws Exception {
|
|
|
|
|
|
|
|
this.thrown.expect(IllegalArgumentException.class);
|
|
|
|
|
|
|
|
this.thrown.expectMessage("AuditEvent must not be null");
|
|
|
|
|
|
|
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
|
|
|
|
|
|
|
repository.add(null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void findByPrincipal() throws Exception {
|
|
|
|
public void findByPrincipal() throws Exception {
|
|
|
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
|
|
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
|
|
@ -71,6 +84,19 @@ public class InMemoryAuditEventRepositoryTests {
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("c");
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("c");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
|
|
|
public void findByPrincipalAndType() throws Exception {
|
|
|
|
|
|
|
|
InMemoryAuditEventRepository repository = new InMemoryAuditEventRepository();
|
|
|
|
|
|
|
|
repository.add(new AuditEvent("dave", "a"));
|
|
|
|
|
|
|
|
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, "a");
|
|
|
|
|
|
|
|
assertThat(events.size()).isEqualTo(1);
|
|
|
|
|
|
|
|
assertThat(events.get(0).getPrincipal()).isEqualTo("dave");
|
|
|
|
|
|
|
|
assertThat(events.get(0).getType()).isEqualTo("a");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
@Test
|
|
|
|
public void findByDate() throws Exception {
|
|
|
|
public void findByDate() throws Exception {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
@ -87,7 +113,7 @@ public class InMemoryAuditEventRepositoryTests {
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data));
|
|
|
|
repository.add(new AuditEvent(calendar.getTime(), "phil", "d", data));
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
|
|
|
List<AuditEvent> events = repository.find(null, after);
|
|
|
|
List<AuditEvent> events = repository.find(after);
|
|
|
|
assertThat(events.size()).isEqualTo(2);
|
|
|
|
assertThat(events.size()).isEqualTo(2);
|
|
|
|
assertThat(events.get(0).getType()).isEqualTo("c");
|
|
|
|
assertThat(events.get(0).getType()).isEqualTo("c");
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("d");
|
|
|
|
assertThat(events.get(1).getType()).isEqualTo("d");
|
|
|
|