use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class IncrementalTreeBuilderTest method testCreatePaths_NonEmpty.
@Test
public void testCreatePaths_NonEmpty() {
@SuppressWarnings("unchecked") IKeyLookupProvider<Long> mockProvider = Mockito.mock(IKeyLookupProvider.class);
ITree tree = createTestTree();
IncrementalTreeBuilder<Long> builder = new IncrementalTreeBuilder<Long>(mockProvider);
ArrayList<ILookupRow<Long>> rows = new ArrayList<>();
rows.add(new LookupRow<Long>(1L, ""));
rows.add(new LookupRow<Long>(2L, "").withParentKey(1L));
List<List<ILookupRow<Long>>> paths = builder.createPaths(rows, tree);
assertTrue(paths.size() == 2);
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class IncrementalTreeBuilderTest method testCreatePaths_NullKeyLookupRow.
@Test
public void testCreatePaths_NullKeyLookupRow() {
final Map<Long, ILookupRow<Long>> lookupRowsMap = new HashMap<>();
lookupRowsMap.put(1L, new LookupRow<Long>(1L, "A"));
lookupRowsMap.put(2L, new LookupRow<Long>(2L, "A-B").withParentKey(1L));
lookupRowsMap.put(null, new LookupRow<Long>(null, "(none)"));
Collection<ILookupRow<Long>> rows = lookupRowsMap.values();
IKeyLookupProvider<Long> provider = new IKeyLookupProvider<Long>() {
@Override
public ILookupRow<Long> getLookupRow(Long key) {
return lookupRowsMap.get(key);
}
};
ITree tree = createTestTree();
IncrementalTreeBuilder<Long> builder = new IncrementalTreeBuilder<Long>(provider);
List<List<ILookupRow<Long>>> paths = builder.createPaths(rows, tree);
assertEquals(3, paths.size());
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class SmartFieldLookupTest method testTextLookupExceptions_InBackground.
@SuppressWarnings("unchecked")
@Test
public void testTextLookupExceptions_InBackground() throws InterruptedException {
m_field.setLookupCall(new TestLookupCall());
final String errorText = "lookup error";
when(m_mock_service.getDataByText(any(ILookupCall.class))).thenThrow(new PlatformException(errorText));
final IBlockingCondition bc = Jobs.newBlockingCondition(true);
ILookupRowFetchedCallback callback = new ILookupRowFetchedCallback<Long>() {
@Override
public void onSuccess(List<? extends ILookupRow<Long>> rows) {
Assert.fail("no exception thrown");
bc.setBlocking(false);
}
@Override
public void onFailure(RuntimeException exception) {
assertTrue(exception instanceof PlatformException);
assertEquals(errorText, exception.getMessage());
bc.setBlocking(false);
}
};
m_field.callTextLookupInBackground("", 10, callback);
bc.waitFor();
}
use of org.eclipse.scout.rt.shared.services.lookup.ILookupRow in project scout.rt by eclipse.
the class BatchLookupTest 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.ILookupRow in project scout.rt by eclipse.
the class BatchLookupServiceClientProxy method getBatchDataByKey.
@Override
public List<List<ILookupRow<?>>> getBatchDataByKey(BatchLookupCall batch) {
List<ILookupCall<?>> allCalls = batch.getCallBatch();
List<ILookupCall<?>> cleanCalls = new ArrayList<ILookupCall<?>>(allCalls.size());
// set calls with key==null to null
for (ILookupCall<?> call : allCalls) {
if (call != null && call.getKey() == null) {
cleanCalls.add(null);
} else {
cleanCalls.add(call);
}
}
BatchSplit split = new BatchSplit(cleanCalls);
if (split.getLocalCallCount() > 0) {
BatchLookupResultCache cache = new BatchLookupResultCache();
List<ILookupCall<?>> calls = split.getLocalCalls();
List<List<ILookupRow<?>>> result = new ArrayList<List<ILookupRow<?>>>();
for (ILookupCall<?> call : calls) {
result.add(cache.getDataByKey(call));
}
split.setLocalResults(result);
}
if (split.getRemoteCallCount() > 0) {
BatchLookupNormalizer normalizer = new BatchLookupNormalizer();
List<ILookupCall<?>> normCallArray = normalizer.normalizeCalls(split.getRemoteCalls());
List<List<ILookupRow<?>>> normResultArray = getTargetService().getBatchDataByKey(new BatchLookupCall(normCallArray));
List<List<ILookupRow<?>>> resultArray = normalizer.denormalizeResults(normResultArray);
split.setRemoteResults(resultArray);
}
List<List<ILookupRow<?>>> results = split.getCombinedResults();
// set null results to empty list
for (int i = 0; i < results.size(); i++) {
if (results.get(i) == null) {
List<ILookupRow<?>> emptyList = CollectionUtility.emptyArrayList();
results.set(i, emptyList);
}
}
return results;
}
Aggregations