use of org.eclipse.scout.rt.platform.IBeanInstanceProducer in project scout.rt by eclipse.
the class ClientSessionTest method testStopWithBlockingClientCallback.
@Test
public void testStopWithBlockingClientCallback() throws Exception {
TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
TestingUtility.registerBean(new BeanMetaData(JobCompletionDelayOnSessionShutdown.class).withProducer(new IBeanInstanceProducer<JobCompletionDelayOnSessionShutdown>() {
@Override
public JobCompletionDelayOnSessionShutdown produce(IBean<JobCompletionDelayOnSessionShutdown> bean) {
return new JobCompletionDelayOnSessionShutdown() {
@Override
protected Long getDefaultValue() {
return 1000L;
}
};
}
}));
session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
// request a geo location
Future<Coordinates> geo = ModelJobs.schedule(new Callable<Future<Coordinates>>() {
@Override
public Future<Coordinates> call() throws Exception {
return IDesktop.CURRENT.get().requestGeolocation();
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDoneAndGet();
assertFalse(geo.isDone());
// close from ui
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
session.getDesktop().getUIFacade().closeFromUI(true);
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDone();
assertTrue(geo.isCancelled());
}
use of org.eclipse.scout.rt.platform.IBeanInstanceProducer in project scout.rt by eclipse.
the class ClientSessionTest method testStopWithBlockingMessageBox.
@Test
public void testStopWithBlockingMessageBox() throws Exception {
TestingUtility.registerBean(new BeanMetaData(TestEnvironmentClientSession.class));
TestingUtility.registerBean(new BeanMetaData(JobCompletionDelayOnSessionShutdown.class).withProducer(new IBeanInstanceProducer<JobCompletionDelayOnSessionShutdown>() {
@Override
public JobCompletionDelayOnSessionShutdown produce(IBean<JobCompletionDelayOnSessionShutdown> bean) {
return new JobCompletionDelayOnSessionShutdown() {
@Override
protected Long getDefaultValue() {
return 1000L;
}
};
}
}));
session = BEANS.get(ClientSessionProvider.class).provide(ClientRunContexts.empty().withUserAgent(UserAgents.createDefault()));
// show a messagebox
IFuture<Integer> f = ModelJobs.schedule(new Callable<Integer>() {
@Override
public Integer call() throws Exception {
messageBox = MessageBoxes.createYesNo();
return messageBox.show();
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true)));
try {
f.awaitDoneAndGet(1, TimeUnit.SECONDS);
fail("must throw a " + TimedOutError.class.getName());
} catch (TimedOutError e) {
// nop
}
assertFalse(f.isDone());
// close from ui
ModelJobs.schedule(new IRunnable() {
@Override
public void run() throws Exception {
session.getDesktop().getUIFacade().closeFromUI(true);
}
}, ModelJobs.newInput(ClientRunContexts.empty().withSession(session, true))).awaitDone();
assertEquals(JobState.DONE, f.getState());
}
Aggregations