Search in sources :

Example 1 with SessionJobEventFilter

use of org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter in project scout.rt by eclipse.

the class SessionJobEventFilterTest method test.

@Test
public void test() {
    IServerSession session1 = mock(IServerSession.class);
    IServerSession session2 = mock(IServerSession.class);
    SessionJobEventFilter filter = new SessionJobEventFilter(session1);
    // Tests JobEvent of an event without a job associated
    JobEvent event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(null));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job without RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext without session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with correct session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty().withSession(session1)))));
    assertTrue(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with wrong session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ServerRunContexts.empty().withSession(session2)))));
    assertFalse(filter.accept(event));
    // Tests adaptable to the session
    assertSame(session1, filter.getAdapter(ISession.class));
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) SessionJobEventFilter(org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter) IServerSession(org.eclipse.scout.rt.server.IServerSession) IJobManager(org.eclipse.scout.rt.platform.job.IJobManager) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData) Test(org.junit.Test)

Example 2 with SessionJobEventFilter

use of org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter in project scout.rt by eclipse.

the class SessionJobEventFilterTest method test.

@Test
public void test() {
    IClientSession session1 = mock(IClientSession.class);
    IClientSession session2 = mock(IClientSession.class);
    SessionJobEventFilter filter = new SessionJobEventFilter(session1);
    // Tests JobEvent of an event without a job associated
    JobEvent event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(null));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job without RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput())));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with RunContext
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(RunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext without session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty()))));
    assertFalse(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with correct session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session1, false)))));
    assertTrue(filter.accept(event));
    // Tests JobEvent with job with ClientRunContext with wrong session
    event = new JobEvent(mock(IJobManager.class), JobEventType.JOB_STATE_CHANGED, new JobEventData().withFuture(Jobs.schedule(mock(IRunnable.class), Jobs.newInput().withRunContext(ClientRunContexts.empty().withSession(session2, false)))));
    assertFalse(filter.accept(event));
    // Tests adaptable to the session
    assertSame(session1, filter.getAdapter(ISession.class));
}
Also used : ISession(org.eclipse.scout.rt.shared.ISession) JobEvent(org.eclipse.scout.rt.platform.job.listener.JobEvent) SessionJobEventFilter(org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter) IClientSession(org.eclipse.scout.rt.client.IClientSession) IJobManager(org.eclipse.scout.rt.platform.job.IJobManager) JobEventData(org.eclipse.scout.rt.platform.job.listener.JobEventData) Test(org.junit.Test)

Aggregations

IJobManager (org.eclipse.scout.rt.platform.job.IJobManager)2 JobEvent (org.eclipse.scout.rt.platform.job.listener.JobEvent)2 JobEventData (org.eclipse.scout.rt.platform.job.listener.JobEventData)2 ISession (org.eclipse.scout.rt.shared.ISession)2 SessionJobEventFilter (org.eclipse.scout.rt.shared.job.filter.event.SessionJobEventFilter)2 Test (org.junit.Test)2 IClientSession (org.eclipse.scout.rt.client.IClientSession)1 IServerSession (org.eclipse.scout.rt.server.IServerSession)1