Search in sources :

Example 21 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class TaskEventsTest method updated.

@Test
public void updated() {
    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.RUNNING).build();
    final Event event = TaskEvents.updated(taskInfo);
    assertEquals(TaskEvents.TASK_UPDATED_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("RUNNING", 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());
}
Also used : TaskInfo(com.enonic.xp.task.TaskInfo) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 22 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class WebsocketEventListenerTest method testEvent.

@Test
public void testEvent() throws Exception {
    final Event event = Event.create("application").distributed(false).value("applicationKey", "module").value("eventType", BundleEvent.INSTALLED).build();
    eventListener.onEvent(event);
    verify(this.webSocketManager, atLeastOnce()).sendToAll(anyString());
}
Also used : Event(com.enonic.xp.event.Event) BundleEvent(org.osgi.framework.BundleEvent) Test(org.junit.jupiter.api.Test)

Example 23 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class LocalTaskManagerImplTest method setup.

@BeforeEach
public void setup() {
    cleanupScheduler = new TaskManagerCleanupSchedulerMock();
    taskMan = new LocalTaskManagerImpl(Runnable::run, cleanupScheduler, event -> this.eventsPublished.add(event));
    taskMan.activate();
    this.eventsPublished = new ArrayList<>();
    final Bundle bundle = OsgiSupportMock.mockBundle();
    when(bundle.getSymbolicName()).thenReturn("some.app");
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) TaskState(com.enonic.xp.task.TaskState) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) RecurringJob(com.enonic.xp.core.internal.concurrent.RecurringJob) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Branch(com.enonic.xp.branch.Branch) TaskInfo(com.enonic.xp.task.TaskInfo) ArrayList(java.util.ArrayList) RepositoryId(com.enonic.xp.repository.RepositoryId) RunnableTask(com.enonic.xp.task.RunnableTask) Event(com.enonic.xp.event.Event) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Bundle(org.osgi.framework.Bundle) OsgiSupportMock(com.enonic.xp.core.internal.osgi.OsgiSupportMock) AuthenticationInfo(com.enonic.xp.security.auth.AuthenticationInfo) Mockito.when(org.mockito.Mockito.when) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) TaskId(com.enonic.xp.task.TaskId) Mockito.verify(org.mockito.Mockito.verify) Test(org.junit.jupiter.api.Test) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) TaskContext(com.enonic.xp.impl.task.distributed.TaskContext) ChronoUnit(java.time.temporal.ChronoUnit) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Clock(java.time.Clock) Mockito.mock(org.mockito.Mockito.mock) Bundle(org.osgi.framework.Bundle) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 24 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class ScriptEventManagerImplTest method testDeactivate.

@Test
public void testDeactivate() {
    final ScriptEventListener listener1 = newListener("foo.bar");
    this.manager.add(listener1);
    final Event event = Event.create("myEvent").build();
    this.manager.onEvent(event);
    this.manager.deactivate();
    this.manager.onEvent(event);
    verify(listener1, Mockito.times(1)).onEvent(event);
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener) Event(com.enonic.xp.event.Event) Test(org.junit.jupiter.api.Test)

Example 25 with Event

use of com.enonic.xp.event.Event in project xp by enonic.

the class ScriptEventManagerImplTest method testRejectedExecution.

@Test
public void testRejectedExecution() {
    final ScriptAsyncService scriptAsyncService = mock(ScriptAsyncService.class);
    when(scriptAsyncService.getAsyncExecutor(any())).thenReturn(c -> {
        throw new RejectedExecutionException();
    });
    this.manager = new ScriptEventManagerImpl(scriptAsyncService);
    final ScriptEventListener listener1 = newListener("foo.bar");
    this.manager.add(listener1);
    assertEquals(1, StreamSupport.stream(manager.spliterator(), false).count());
    final Event event = Event.create("myEvent").build();
    this.manager.onEvent(event);
    assertEquals(0, StreamSupport.stream(manager.spliterator(), false).count());
    verify(listener1, Mockito.never()).onEvent(event);
}
Also used : ScriptEventListener(com.enonic.xp.script.event.ScriptEventListener) ScriptAsyncService(com.enonic.xp.script.impl.async.ScriptAsyncService) Event(com.enonic.xp.event.Event) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Test(org.junit.jupiter.api.Test)

Aggregations

Event (com.enonic.xp.event.Event)48 Test (org.junit.jupiter.api.Test)46 Node (com.enonic.xp.node.Node)12 NodeId (com.enonic.xp.node.NodeId)7 NodePath (com.enonic.xp.node.NodePath)7 InternalContext (com.enonic.xp.repo.impl.InternalContext)7 EventListener (com.enonic.xp.event.EventListener)6 TaskInfo (com.enonic.xp.task.TaskInfo)6 NodeBranchEntry (com.enonic.xp.node.NodeBranchEntry)3 ScriptEventListener (com.enonic.xp.script.event.ScriptEventListener)3 Branch (com.enonic.xp.branch.Branch)2 PushNodeEntries (com.enonic.xp.node.PushNodeEntries)2 NodeMovedParams (com.enonic.xp.repo.impl.storage.NodeMovedParams)2 RepositoryId (com.enonic.xp.repository.RepositoryId)2 JsonMapGenerator (com.enonic.xp.script.serializer.JsonMapGenerator)2 MapSerializable (com.enonic.xp.script.serializer.MapSerializable)2 AuthenticationInfo (com.enonic.xp.security.auth.AuthenticationInfo)2 Member (com.hazelcast.core.Member)2 Message (com.hazelcast.core.Message)2 List (java.util.List)2