Skip to content

Commit

Permalink
Fail faster with invalid operation
Browse files Browse the repository at this point in the history
  • Loading branch information
aerospikerobertmarks committed Jun 24, 2019
1 parent 9c7ca02 commit 4864142
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ public class OperationConverter {

@SuppressWarnings("unchecked")
public static Operation convertMapToOperation(Map<String, Object>operationMap) {
/* Make sure that the user is not providing additional top level keys */
hasAllRequiredKeys(operationMap, OPERATION_FIELD_KEY, OP_VALUES_KEY);
onlyHasAllowedKeys(operationMap, OPERATION_FIELD_KEY, OP_VALUES_KEY);

String opName = (String) operationMap.get(OPERATION_FIELD_KEY);
if (opName == null) {
throw new InvalidOperationError("Operation must contain the \"operation\" field");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ public void testMissingOpValues() {
OperationConverter.convertMapToOperation(op);
}

/*
* If the user accidentally provides an extra key at the top level, we should error out.
*/
@Test(expected=InvalidOperationError.class)
public void testAdditionalTopLevelValue() {
Map<String, Object>opValues = new HashMap<>();
Map<String, Object>op = new HashMap<>();
op.put(AerospikeAPIConstants.OPERATION_FIELD, AerospikeAPIConstants.OPERATION_READ);
op.put("An Extra", "Field");
opValues.put("bin", "binname");
op.put(AerospikeAPIConstants.OPERATION_VALUES_FIELD, opValues);
OperationConverter.convertMapToOperation(op);
}

@Test(expected=InvalidOperationError.class)
public void testMissingValueInOpvalue() {
/*
Expand Down

0 comments on commit 4864142

Please sign in to comment.