use of com.enonic.xp.event.Event in project xp by enonic.
the class TaskEventsTest method finished.
@Test
public void finished() {
TaskInfo taskInfo = TaskInfo.create().id(TaskId.from("task1")).name("name1").description("Task1 description").application(ApplicationKey.from("com.enonic.myapp")).user(PrincipalKey.from("user:store:me")).startTime(Instant.parse("2017-10-01T09:00:00Z")).state(TaskState.FINISHED).build();
final Event event = TaskEvents.finished(taskInfo);
assertEquals(TaskEvents.TASK_FINISHED_EVENT, event.getType());
assertEquals("task1", event.getValueAs(String.class, "id").get());
assertEquals("name1", event.getValueAs(String.class, "name").get());
assertEquals("Task1 description", event.getValueAs(String.class, "description").get());
assertEquals("FINISHED", event.getValueAs(String.class, "state").get());
assertEquals("com.enonic.myapp", event.getValueAs(String.class, "application").get());
assertEquals("user:store:me", event.getValueAs(String.class, "user").get());
assertEquals("2017-10-01T09:00:00Z", event.getValueAs(String.class, "startTime").get());
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class ScriptEventListenerImplTest method notLocalOrigin.
@Test
public void notLocalOrigin() {
final Event event = Event.create("application").localOrigin(false).build();
this.listener.onEvent(event);
assertNull(this.event);
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class ScriptEventListenerImplTest method noMatch.
@Test
public void noMatch() {
final Event event = Event.create("other").localOrigin(true).build();
this.listener.onEvent(event);
assertNull(this.event);
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class ScriptEventListenerImplTest method testException.
@Test
public void testException() {
final Consumer<Object> consumer = o -> {
throw new RuntimeException();
};
this.listener = new ScriptEventListenerBuilder().typePattern("app*").listener(consumer).application(ApplicationKey.from("foo.bar")).build();
final Event event = Event.create("application").localOrigin(true).build();
this.listener.onEvent(event);
}
use of com.enonic.xp.event.Event in project xp by enonic.
the class ScriptEventManagerImplTest method testOnEvent.
@Test
public void testOnEvent() {
final ScriptEventListener listener1 = newListener("foo.bar");
final ScriptEventListener listener2 = newListener("foo.other");
this.manager.add(listener1);
this.manager.add(listener2);
final Event event = Event.create("myEvent").build();
this.manager.onEvent(event);
verify(listener1, Mockito.times(1)).onEvent(event);
verify(listener2, Mockito.times(1)).onEvent(event);
}
Aggregations