Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -179,29 +179,33 @@ private boolean hasIndexKeyCondition(
}

private boolean isPrimaryKeyCondition(JsonNode condition, String keyType) {
String operator = condition.get(Constants.CONDITION_OPERATOR).textValue().toUpperCase();
if (!operator.equals(Constants.OPERATOR_EQ)) {
return false;
}

String givenType = condition.get(Constants.CONDITION_VALUE).getNodeType().name();
if (!givenType.equalsIgnoreCase(keyType)) {
throw new ContractContextException(Constants.INVALID_KEY_TYPE + givenType);
}

return condition
.get(Constants.CONDITION_OPERATOR)
.textValue()
.equalsIgnoreCase(Constants.OPERATOR_EQ);
return true;
}

private boolean isIndexKeyCondition(JsonNode condition, String keyType) {
String operator = condition.get(Constants.CONDITION_OPERATOR).textValue().toUpperCase();
if (operator.equals(Constants.OPERATOR_IS_NULL)) {
return true;
} else if (!operator.equals(Constants.OPERATOR_EQ)) {
return false;
}

String givenType = condition.get(Constants.CONDITION_VALUE).getNodeType().name();
if (!givenType.equalsIgnoreCase(keyType)) {
throw new ContractContextException(Constants.INVALID_INDEX_KEY_TYPE + givenType);
}

return operator.equals(Constants.OPERATOR_EQ);
return true;
}

private JsonNode getKeyColumnCondition(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,52 @@ public void invoke_ArgumentsWithInvalidIndexKeyConditionGiven_ShouldThrowExcepti
verify(ledger).get(SOME_TABLE_ASSET_ID);
}

@Test
public void invoke_ArgumentsWithOnlyIsNullConditionForPrimaryKeyGiven_ShouldThrowException() {
// Arrange
ArrayNode conditions =
mapper
.createArrayNode()
.add(createCondition(SOME_PRIMARY_KEY_COLUMN, Constants.OPERATOR_IS_NULL));
JsonNode argument =
mapper
.createObjectNode()
.put(Constants.QUERY_TABLE, SOME_TABLE_NAME)
.set(Constants.QUERY_CONDITIONS, conditions);
Asset<JsonNode> table = createAsset(SOME_TABLE);
when(ledger.get(SOME_TABLE_ASSET_ID)).thenReturn(Optional.of(table));
prepareTableAssetId(SOME_TABLE_NAME);

// Act Assert
assertThatThrownBy(() -> scan.invoke(ledger, argument, null))
.isExactlyInstanceOf(ContractContextException.class)
.hasMessageContaining(Constants.INVALID_KEY_SPECIFICATION);
verify(ledger).get(SOME_TABLE_ASSET_ID);
}

@Test
public void invoke_ArgumentsWithOnlyIsNotNullConditionForIndexKeyGiven_ShouldThrowException() {
// Arrange
ArrayNode conditions =
mapper
.createArrayNode()
.add(createCondition(SOME_INDEX_KEY_COLUMN_1, Constants.OPERATOR_IS_NOT_NULL));
JsonNode argument =
mapper
.createObjectNode()
.put(Constants.QUERY_TABLE, SOME_TABLE_NAME)
.set(Constants.QUERY_CONDITIONS, conditions);
Asset<JsonNode> table = createAsset(SOME_TABLE);
when(ledger.get(SOME_TABLE_ASSET_ID)).thenReturn(Optional.of(table));
prepareTableAssetId(SOME_TABLE_NAME);

// Act Assert
assertThatThrownBy(() -> scan.invoke(ledger, argument, null))
.isExactlyInstanceOf(ContractContextException.class)
.hasMessageContaining(Constants.INVALID_KEY_SPECIFICATION);
verify(ledger).get(SOME_TABLE_ASSET_ID);
}

@Test
public void invoke_InvalidConditionsGiven_ShouldThrowException() {
// Arrange
Expand Down