use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.
the class BatchLookupTest method testInternal.
private void testInternal(Class<? extends IFlowerLookupCall> callClazz, int expectedLocalInvocations, int expectedServerInvocations) throws Exception {
m_localInvocations = 0;
BatchLookupCall batchCall = new BatchLookupCall();
for (int i = 0; i < 1000; i++) {
IFlowerLookupCall call = callClazz.newInstance();
call.setKey((i / 100) + 1L);
call.setLatinId((i / 10) + 1L);
batchCall.addLookupCall((LookupCall) call);
}
//
List<ILookupCall<?>> callArray = batchCall.getCallBatch();
List<List<ILookupRow<?>>> resultArray = new BatchLookupService().getBatchDataByKey(batchCall);
assertEquals(resultArray.size(), callArray.size());
assertEquals(expectedLocalInvocations, m_localInvocations);
Mockito.verify(m_lookupService, Mockito.times(expectedServerInvocations)).getDataByKey(Mockito.<ILookupCall<Object>>any());
for (int i = 0; i < resultArray.size(); i++) {
assertEquals(1, resultArray.get(i).size());
assertEquals(callArray.get(i).getKey(), resultArray.get(i).get(0).getKey());
assertEquals(dumpCall(callArray.get(i)), resultArray.get(i).get(0).getText());
}
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.
the class BatchNormalizerTest method setUp.
@Before
public void setUp() throws Exception {
Answer answer = new Answer<List<ILookupRow<Object>>>() {
@Override
public List<ILookupRow<Object>> answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
ILookupCall<?> call = (ILookupCall<?>) args[0];
return createCallResult(call);
}
};
Mockito.doAnswer(answer).when(m_lookupService).getDataByKey(Mockito.<ILookupCall<Object>>any());
Mockito.doAnswer(answer).when(m_lookupService).getDataByAll(Mockito.<ILookupCall<Object>>any());
Mockito.doAnswer(answer).when(m_lookupService).getDataByText(Mockito.<ILookupCall<Object>>any());
Mockito.doAnswer(answer).when(m_lookupService).getDataByRec(Mockito.<ILookupCall<Object>>any());
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.
the class SmartFieldLookupTest method testSubtreeLookup_FilterResult.
@Test
public void testSubtreeLookup_FilterResult() {
ISmartField<Long> field = new AbstractSmartField<Long>() {
@Override
protected void execFilterRecLookupResult(ILookupCall<Long> call, List<ILookupRow<Long>> result) {
result.clear();
}
};
field.setLookupCall(new TestLookupCall());
List<? extends ILookupRow<Long>> rows2 = field.callSubTreeLookup(1L);
assertEquals(0, rows2.size());
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.
the class AbstractContentAssistField method newByKeyLookupRowProvider.
// ==== Lookup row fetching strategies ==== //
/**
* Creates a {@link ILookupRowProvider} to fetch a row by key.
*
* @see LookupCall#getDataByKey()
* @see LookupCall#getDataByAllInBackground(ILookupRowFetchedCallback)
*/
protected ILookupRowProvider<LOOKUP_KEY> newByKeyLookupRowProvider(final LOOKUP_KEY key) {
return new ILookupRowProvider<LOOKUP_KEY>() {
@Override
public void beforeProvide(ILookupCall<LOOKUP_KEY> lookupCall) {
prepareKeyLookup(lookupCall, key);
}
@Override
public void afterProvide(ILookupCall<LOOKUP_KEY> lookupCall, List<ILookupRow<LOOKUP_KEY>> result) {
interceptFilterLookupResult(lookupCall, result);
interceptFilterKeyLookupResult(lookupCall, result);
cleanupResultList(result);
}
@Override
public void provideSync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> callback) {
callback.onSuccess(provide(lookupCall));
}
@Override
public IFuture<Void> provideAsync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> callback, ClientRunContext clientRunContext) {
return lookupCall.getDataByKeyInBackground(clientRunContext, callback);
}
@SuppressWarnings("unchecked")
@Override
public List<ILookupRow<LOOKUP_KEY>> provide(ILookupCall<LOOKUP_KEY> lookupCall) {
return (List<ILookupRow<LOOKUP_KEY>>) lookupCall.getDataByKey();
}
@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this).attr("Key Lookup").attr("key", key);
return sb.toString();
}
};
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupCall in project scout.rt by eclipse.
the class AbstractContentAssistField method newByAllLookupRowProvider.
/**
* Creates a {@link ILookupRowProvider} to fetch all rows.
*
* @see LookupCall#getDataByAll()
* @see LookupCall#getDataByAllInBackground(ILookupRowFetchedCallback)
*/
protected ILookupRowProvider<LOOKUP_KEY> newByAllLookupRowProvider(final String browseHint, final TriState activeState) {
return new ILookupRowProvider<LOOKUP_KEY>() {
@Override
public void beforeProvide(ILookupCall<LOOKUP_KEY> lookupCall) {
prepareBrowseLookup(lookupCall, browseHint, activeState);
}
@Override
public void afterProvide(ILookupCall<LOOKUP_KEY> lookupCall, List<ILookupRow<LOOKUP_KEY>> result) {
interceptFilterLookupResult(lookupCall, result);
interceptFilterBrowseLookupResult(lookupCall, result);
cleanupResultList(result);
}
@Override
public void provideSync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> callback) {
callback.onSuccess(provide(lookupCall));
}
@Override
public IFuture<Void> provideAsync(ILookupCall<LOOKUP_KEY> lookupCall, ILookupRowFetchedCallback<LOOKUP_KEY> callback, ClientRunContext clientRunContext) {
return lookupCall.getDataByAllInBackground(clientRunContext, callback);
}
@SuppressWarnings("unchecked")
@Override
public List<ILookupRow<LOOKUP_KEY>> provide(ILookupCall<LOOKUP_KEY> lookupCall) {
return (List<ILookupRow<LOOKUP_KEY>>) lookupCall.getDataByAll();
}
@Override
public String toString() {
ToStringBuilder sb = new ToStringBuilder(this).attr("All Lookup").attr("browseHint", browseHint).attr("activeState", activeState);
return sb.toString();
}
};
}
Aggregations