Michael Hanl | c8729b9 | 2015-09-02 12:37:36 +0200 | [diff] [blame^] | 1 | import de.ids_mannheim.korap.auditing.AuditRecord; |
| 2 | import de.ids_mannheim.korap.config.BeanConfiguration; |
| 3 | import de.ids_mannheim.korap.exceptions.StatusCodes; |
| 4 | import org.joda.time.LocalDate; |
| 5 | import org.junit.AfterClass; |
| 6 | import org.junit.BeforeClass; |
| 7 | import org.junit.Test; |
| 8 | |
| 9 | import java.io.File; |
| 10 | import java.util.Date; |
| 11 | |
| 12 | /** |
| 13 | * @author hanl |
| 14 | * @date 27/07/2015 |
| 15 | */ |
| 16 | //todo: test audit commit in thread and that no concurrency issue arrises |
| 17 | public class FileAuditingTest { |
| 18 | |
| 19 | @BeforeClass |
| 20 | public static void init() { |
| 21 | BeanConfiguration.loadClasspathContext(); |
| 22 | } |
| 23 | |
| 24 | @AfterClass |
| 25 | public static void finish() { |
| 26 | BeanConfiguration.closeApplication(); |
| 27 | File f = new File("logs/default_audit.log"); |
| 28 | assert f.length() > 0; |
| 29 | } |
| 30 | |
| 31 | @Test |
| 32 | public void testAdd() { |
| 33 | for (int i = 0; i < 20; i++) { |
| 34 | AuditRecord record = AuditRecord |
| 35 | .serviceRecord("MichaelHanl", StatusCodes.ILLEGAL_ARGUMENT, |
| 36 | String.valueOf(i), "string value"); |
| 37 | BeanConfiguration.getBeans().getAuditingProvider().audit(record); |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | @Test(expected = UnsupportedOperationException.class) |
| 42 | public void testRetrieval() { |
| 43 | BeanConfiguration.getBeans().getAuditingProvider() |
| 44 | .retrieveRecords(new LocalDate(new Date().getTime()), 10); |
| 45 | } |
| 46 | |
| 47 | } |