@Test public void testCreateFromEvent() throws Exception { new AuditLogEntryFactory(); EventLogEvent[] events = new EventLogEvent[]{ new SimpleEvent("SimpleEvent"), new ExperimentChangeEvent(Mockito.mock(Experiment.class), "Property", "before", "after"), new ExperimentCreateEvent(Mockito.mock(Experiment.class)), new BucketCreateEvent(Mockito.mock(Experiment.class), Mockito.mock(Bucket.class)) }; Field[] fields = AuditLogEntry.class.getFields(); for (Field field : fields) { field.setAccessible(true); } for (EventLogEvent event : events) { AuditLogEntry aleFactory = AuditLogEntryFactory.createFromEvent(event); AuditLogEntry aleManual = new AuditLogEntry( event.getTime(), event.getUser(), AuditLogAction.getActionForEvent(event), event instanceof ExperimentEvent ? ((ExperimentEvent) event).getExperiment() : null, event instanceof BucketEvent ? ((BucketEvent) event).getBucket().getLabel() : null, event instanceof ChangeEvent ? ((ChangeEvent) event).getPropertyName() : null, event instanceof ChangeEvent ? ((ChangeEvent) event).getBefore() : null, event instanceof ChangeEvent ? ((ChangeEvent) event).getAfter() : null ); for (Field field : fields) { Assert.assertEquals(field.get(aleManual), field.get(aleFactory)); } } }
public static AuditLogEntry createFromEvent(EventLogEvent event) { Calendar time = event.getTime(); UserInfo user = event.getUser(); Application.Name appName = null; if (event instanceof ApplicationEvent) { appName = ((ApplicationEvent) event).getApplicationName(); } Experiment.Label expLabel = null; Experiment.ID expId = null; if (event instanceof ExperimentEvent) { expLabel = ((ExperimentEvent) event).getExperiment().getLabel(); expId = ((ExperimentEvent) event).getExperiment().getID(); } Bucket.Label bucketLabel = null; if (event instanceof BucketEvent) { bucketLabel = ((BucketEvent) event).getBucket().getLabel(); } String property = null; String before = null; String after = null; if (event instanceof ChangeEvent) { property = ((ChangeEvent) event).getPropertyName(); before = ((ChangeEvent) event).getBefore(); after = ((ChangeEvent) event).getAfter(); } else if (event instanceof BucketCreateEvent) { property = "allocation"; after = String.valueOf(((BucketCreateEvent) event).getBucket().getAllocationPercent()); } return new AuditLogEntry(time, user, AuditLogAction.getActionForEvent(event), appName, expLabel, expId, bucketLabel, property, before, after); }
AuditLogEntryFactory { public static AuditLogEntry createFromEvent(EventLogEvent event) { Calendar time = event.getTime(); UserInfo user = event.getUser(); Application.Name appName = null; if (event instanceof ApplicationEvent) { appName = ((ApplicationEvent) event).getApplicationName(); } Experiment.Label expLabel = null; Experiment.ID expId = null; if (event instanceof ExperimentEvent) { expLabel = ((ExperimentEvent) event).getExperiment().getLabel(); expId = ((ExperimentEvent) event).getExperiment().getID(); } Bucket.Label bucketLabel = null; if (event instanceof BucketEvent) { bucketLabel = ((BucketEvent) event).getBucket().getLabel(); } String property = null; String before = null; String after = null; if (event instanceof ChangeEvent) { property = ((ChangeEvent) event).getPropertyName(); before = ((ChangeEvent) event).getBefore(); after = ((ChangeEvent) event).getAfter(); } else if (event instanceof BucketCreateEvent) { property = "allocation"; after = String.valueOf(((BucketCreateEvent) event).getBucket().getAllocationPercent()); } return new AuditLogEntry(time, user, AuditLogAction.getActionForEvent(event), appName, expLabel, expId, bucketLabel, property, before, after); } }
AuditLogEntryFactory { public static AuditLogEntry createFromEvent(EventLogEvent event) { Calendar time = event.getTime(); UserInfo user = event.getUser(); Application.Name appName = null; if (event instanceof ApplicationEvent) { appName = ((ApplicationEvent) event).getApplicationName(); } Experiment.Label expLabel = null; Experiment.ID expId = null; if (event instanceof ExperimentEvent) { expLabel = ((ExperimentEvent) event).getExperiment().getLabel(); expId = ((ExperimentEvent) event).getExperiment().getID(); } Bucket.Label bucketLabel = null; if (event instanceof BucketEvent) { bucketLabel = ((BucketEvent) event).getBucket().getLabel(); } String property = null; String before = null; String after = null; if (event instanceof ChangeEvent) { property = ((ChangeEvent) event).getPropertyName(); before = ((ChangeEvent) event).getBefore(); after = ((ChangeEvent) event).getAfter(); } else if (event instanceof BucketCreateEvent) { property = "allocation"; after = String.valueOf(((BucketCreateEvent) event).getBucket().getAllocationPercent()); } return new AuditLogEntry(time, user, AuditLogAction.getActionForEvent(event), appName, expLabel, expId, bucketLabel, property, before, after); } AuditLogEntryFactory(); }
AuditLogEntryFactory { public static AuditLogEntry createFromEvent(EventLogEvent event) { Calendar time = event.getTime(); UserInfo user = event.getUser(); Application.Name appName = null; if (event instanceof ApplicationEvent) { appName = ((ApplicationEvent) event).getApplicationName(); } Experiment.Label expLabel = null; Experiment.ID expId = null; if (event instanceof ExperimentEvent) { expLabel = ((ExperimentEvent) event).getExperiment().getLabel(); expId = ((ExperimentEvent) event).getExperiment().getID(); } Bucket.Label bucketLabel = null; if (event instanceof BucketEvent) { bucketLabel = ((BucketEvent) event).getBucket().getLabel(); } String property = null; String before = null; String after = null; if (event instanceof ChangeEvent) { property = ((ChangeEvent) event).getPropertyName(); before = ((ChangeEvent) event).getBefore(); after = ((ChangeEvent) event).getAfter(); } else if (event instanceof BucketCreateEvent) { property = "allocation"; after = String.valueOf(((BucketCreateEvent) event).getBucket().getAllocationPercent()); } return new AuditLogEntry(time, user, AuditLogAction.getActionForEvent(event), appName, expLabel, expId, bucketLabel, property, before, after); } AuditLogEntryFactory(); static AuditLogEntry createFromEvent(EventLogEvent event); }
AuditLogEntryFactory { public static AuditLogEntry createFromEvent(EventLogEvent event) { Calendar time = event.getTime(); UserInfo user = event.getUser(); Application.Name appName = null; if (event instanceof ApplicationEvent) { appName = ((ApplicationEvent) event).getApplicationName(); } Experiment.Label expLabel = null; Experiment.ID expId = null; if (event instanceof ExperimentEvent) { expLabel = ((ExperimentEvent) event).getExperiment().getLabel(); expId = ((ExperimentEvent) event).getExperiment().getID(); } Bucket.Label bucketLabel = null; if (event instanceof BucketEvent) { bucketLabel = ((BucketEvent) event).getBucket().getLabel(); } String property = null; String before = null; String after = null; if (event instanceof ChangeEvent) { property = ((ChangeEvent) event).getPropertyName(); before = ((ChangeEvent) event).getBefore(); after = ((ChangeEvent) event).getAfter(); } else if (event instanceof BucketCreateEvent) { property = "allocation"; after = String.valueOf(((BucketCreateEvent) event).getBucket().getAllocationPercent()); } return new AuditLogEntry(time, user, AuditLogAction.getActionForEvent(event), appName, expLabel, expId, bucketLabel, property, before, after); } AuditLogEntryFactory(); static AuditLogEntry createFromEvent(EventLogEvent event);  }