Skip to content

Instantly share code, notes, and snippets.

@mschoch
Created May 24, 2012 18:32
Show Gist options
  • Save mschoch/2783344 to your computer and use it in GitHub Desktop.
Save mschoch/2783344 to your computer and use it in GitHub Desktop.
Integer Key Testcase
public void testIntegerKeyInView() {
String filesDir = getContext().getFilesDir().getAbsolutePath();
TDDatabase db = TDDatabase.createEmptyDBAtPath(filesDir + "/touch_couch_test.sqlite3");
List<String> testStringIntValues = new ArrayList<String>();
testStringIntValues.add("53");
testStringIntValues.add("35305");
testStringIntValues.add("2090");
testStringIntValues.add("22906");
int i=0;
for (String key : testStringIntValues) {
Map<String,Object> docProperties = new HashMap<String,Object>();
docProperties.put("_id", Integer.toString(i++));
docProperties.put("accountNumber", key);
putDoc(db, docProperties);
}
TDView view = db.getViewNamed("default/ints");
view.setMapReduceBlocks(new TDViewMapBlock() {
@Override
public void map(Map<String, Object> document, TDViewMapEmitBlock emitter) {
Object accountNumber = document.get("accountNumber");
String accountNumberString = accountNumber.toString();
Integer accountNumberInteger = Integer.getInteger(accountNumberString);
Integer accountNumberParsed = Integer.parseInt(accountNumberString);
Log.v(TAG, String.format("toString: %s, getInteger: %d, parseInt: %d", accountNumberString, accountNumberInteger, accountNumberParsed));
//emitter.emit(accountNumberInteger, null);
emitter.emit(accountNumberParsed, null);
}
}, null, "1.0");
TDStatus updated = view.updateIndex();
Assert.assertEquals(TDStatus.OK, updated.getCode());
TDQueryOptions options = new TDQueryOptions();
TDStatus status = new TDStatus();
List<Map<String,Object>> rows = view.queryWithOptions(options, status);
Assert.assertEquals(TDStatus.OK, status.getCode());
Log.v(TAG, rows.toString());
db.close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment