Search in sources :

Example 1 with BatchLookupService

use of org.eclipse.scout.rt.server.services.lookup.BatchLookupService in project scout.rt by eclipse.

the class BatchNormalizerTest method testInternal.

private void testInternal(BatchLookupCall batchCall, int expectedNormalizedSize, int expectedServerInvocations, int expectedNullArrayCount, int expectedTotalResultRowCount) throws Exception {
    // 
    BatchLookupNormalizer normalizer = new BatchLookupNormalizer();
    List<ILookupCall<?>> callArray = batchCall.getCallBatch();
    List<ILookupCall<?>> normCallArray = normalizer.normalizeCalls(callArray);
    List<List<ILookupRow<?>>> normResultArray = new BatchLookupService().getBatchDataByKey(new BatchLookupCall(normCallArray));
    List<List<ILookupRow<?>>> resultArray = normalizer.denormalizeResults(normResultArray);
    // 
    assertEquals(resultArray.size(), callArray.size());
    assertEquals(normResultArray.size(), normCallArray.size());
    assertEquals(expectedNormalizedSize, normResultArray.size());
    Mockito.verify(m_lookupService, Mockito.times(expectedServerInvocations)).getDataByKey(Mockito.<ILookupCall<Object>>any());
    int rowCount = 0;
    int nullArrayCount = 0;
    for (int i = 0; i < resultArray.size(); i++) {
        if (resultArray.get(i) == null) {
            nullArrayCount++;
        } else if (resultArray.get(i).size() == 1) {
            rowCount++;
            assertEquals(callArray.get(i).getKey(), resultArray.get(i).get(0).getKey());
            assertEquals(dumpCall(callArray.get(i)), resultArray.get(i).get(0).getText());
        } else if (resultArray.get(i).size() > 1) {
            fail("result length is expected to be 0 or 1");
        }
    }
    assertEquals(expectedNullArrayCount, nullArrayCount);
    assertEquals(expectedTotalResultRowCount, rowCount);
}
Also used : IBatchLookupService(org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService) BatchLookupService(org.eclipse.scout.rt.server.services.lookup.BatchLookupService) BatchLookupNormalizer(org.eclipse.scout.rt.shared.services.lookup.BatchLookupNormalizer) ArrayList(java.util.ArrayList) List(java.util.List) ILookupCall(org.eclipse.scout.rt.shared.services.lookup.ILookupCall) BatchLookupCall(org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 BatchLookupService (org.eclipse.scout.rt.server.services.lookup.BatchLookupService)1 BatchLookupCall (org.eclipse.scout.rt.shared.services.lookup.BatchLookupCall)1 BatchLookupNormalizer (org.eclipse.scout.rt.shared.services.lookup.BatchLookupNormalizer)1 IBatchLookupService (org.eclipse.scout.rt.shared.services.lookup.IBatchLookupService)1 ILookupCall (org.eclipse.scout.rt.shared.services.lookup.ILookupCall)1