Skip to content

Commit

Permalink
TEIID-3411 improving handling of null and empty results
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Jun 26, 2015
1 parent 006e367 commit 90b1812
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -344,28 +344,34 @@ private List<?> getRow(SearchResult result) throws TranslatorException, InvalidN

if (unwrapPos > -1) {
Object toUnwrap = row.get(unwrapPos);
if (toUnwrap == null) {
return row; //missing value
}
if (toUnwrap instanceof ArrayImpl) {
final Object[] val = ((ArrayImpl) toUnwrap).getValues();
final int pos = unwrapPos;
unwrapIterator = new Iterator<List<Object>>() {
int i = 0;
@Override
public boolean hasNext() {
return i < val.length;
}
@Override
public List<Object> next() {
List<Object> newRow = new ArrayList<Object>(row);
newRow.set(pos, val[i++]);
return newRow;
}
@Override
public void remove() {

if (val.length == 0) {
row.set(unwrapPos, null); //empty value
} else {
unwrapIterator = new Iterator<List<Object>>() {
int i = 0;
@Override
public boolean hasNext() {
return i < val.length;
}
@Override
public List<Object> next() {
List<Object> newRow = new ArrayList<Object>(row);
newRow.set(unwrapPos, val[i++]);
return newRow;
}
@Override
public void remove() {

}
};
if (unwrapIterator.hasNext()) {
return unwrapIterator.next();
}
};
if (unwrapIterator.hasNext()) {
return unwrapIterator.next();
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Iterator;
Expand Down Expand Up @@ -120,6 +121,31 @@ public T next() throws NamingException {
result = execution.next();
assertEquals(Arrays.asList("bar"), result);
assertNull(execution.next());

//missing attribute handling
Mockito.stub(attribs.get("objectClass")).toReturn(null);
enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
Mockito.stub(ctx.search((String)Mockito.any(), (String)Mockito.any(), (SearchControls)Mockito.any())).toReturn(enumeration);

execution = (LDAPSyncQueryExecution)lef.createExecution(command, ec, rm, connection);
execution.execute();
result = execution.next();
assertEquals(Collections.singletonList(null), result);
assertNull(execution.next());

//empty attribute handling
attribValues = new SimpleNamingEnumeration(new ArrayList<Object>().iterator());
Mockito.stub(attrib.size()).toReturn(0);
Mockito.stub(attrib.getAll()).toReturn(attribValues);
Mockito.stub(attribs.get("objectClass")).toReturn(attrib);
enumeration = new SimpleNamingEnumeration(Arrays.asList(sr).iterator());
Mockito.stub(ctx.search((String)Mockito.any(), (String)Mockito.any(), (SearchControls)Mockito.any())).toReturn(enumeration);

execution = (LDAPSyncQueryExecution)lef.createExecution(command, ec, rm, connection);
execution.execute();
result = execution.next();
assertEquals(Collections.singletonList(null), result);
assertNull(execution.next());
}

@Test public void testUnwrapExtract() throws Exception {
Expand Down

0 comments on commit 90b1812

Please sign in to comment.