use of org.pentaho.platform.dataaccess.metadata.model.Operator in project data-access by pentaho.
the class OperatorTest method testFormatConditionForNonParameterizedMultipleValues.
@Test
public void testFormatConditionForNonParameterizedMultipleValues() {
String columnName = "column_name";
String paramName = "param_name";
String[] values = { "\"value1\"", "value2", "value3" };
Operator[] operatorsArray = { Operator.GREATER_THAN, Operator.LESS_THAN, Operator.EQUAL, Operator.GREATOR_OR_EQUAL, Operator.LESS_OR_EQUAL };
// check with different number of values passed as argument
for (Operator operator : operatorsArray) {
Assert.assertThat(operator.formatCondition(columnName, paramName, values, false), is(columnName + " " + operator.toString() + values[0]));
}
String valuesList = "";
for (int idx = 0; idx < values.length; idx++) {
if (idx > 0) {
valuesList += ";";
}
if (!values[idx].startsWith("\"") && !values[idx].endsWith("\"")) {
valuesList += "\"" + values[idx] + "\"";
} else {
valuesList += values[idx];
}
}
Assert.assertThat(Operator.EXACTLY_MATCHES.formatCondition(columnName, paramName, values, false), is("IN(" + columnName + "; " + valuesList + ")"));
Assert.assertThat(Operator.CONTAINS.formatCondition(columnName, paramName, values, false), is("CONTAINS(" + columnName + ";" + values[0] + ")"));
Assert.assertThat(Operator.DOES_NOT_CONTAIN.formatCondition(columnName, paramName, values, false), is("NOT(CONTAINS(" + columnName + ";" + values[0] + "))"));
Assert.assertThat(Operator.BEGINS_WITH.formatCondition(columnName, paramName, values, false), is("BEGINSWITH(" + columnName + ";" + values[0] + ")"));
Assert.assertThat(Operator.ENDS_WITH.formatCondition(columnName, paramName, values, false), is("ENDSWITH(" + columnName + ";" + values[0] + ")"));
Assert.assertThat(Operator.IS_NULL.formatCondition(columnName, paramName, values, false), is("ISNA(" + columnName + ")"));
Assert.assertThat(Operator.IS_NOT_NULL.formatCondition(columnName, paramName, values, false), is("NOT(ISNA(" + columnName + "))"));
}
use of org.pentaho.platform.dataaccess.metadata.model.Operator in project data-access by pentaho.
the class OperatorTest method testFormatConditionForNonParameterizedSingleValues.
@Test
public void testFormatConditionForNonParameterizedSingleValues() {
String columnName = "column_name";
String paramName = "param_name";
String[] values = { "value1" };
Operator[] operatorsArray = { Operator.GREATER_THAN, Operator.LESS_THAN, Operator.EQUAL, Operator.GREATOR_OR_EQUAL, Operator.LESS_OR_EQUAL };
// check with different number of values passed as argument
for (Operator operator : operatorsArray) {
Assert.assertThat(operator.formatCondition(columnName, paramName, values, false), is(columnName + " " + operator.toString() + values[0]));
}
Assert.assertThat(Operator.EXACTLY_MATCHES.formatCondition(columnName, paramName, values, false), is(columnName + " = " + values[0]));
Assert.assertThat(Operator.CONTAINS.formatCondition(columnName, paramName, values, false), is("CONTAINS(" + columnName + ";" + values[0] + ")"));
Assert.assertThat(Operator.DOES_NOT_CONTAIN.formatCondition(columnName, paramName, values, false), is("NOT(CONTAINS(" + columnName + ";" + values[0] + "))"));
Assert.assertThat(Operator.BEGINS_WITH.formatCondition(columnName, paramName, values, false), is("BEGINSWITH(" + columnName + ";" + values[0] + ")"));
Assert.assertThat(Operator.ENDS_WITH.formatCondition(columnName, paramName, values, false), is("ENDSWITH(" + columnName + ";" + values[0] + ")"));
Assert.assertThat(Operator.IS_NULL.formatCondition(columnName, paramName, values, false), is("ISNA(" + columnName + ")"));
Assert.assertThat(Operator.IS_NOT_NULL.formatCondition(columnName, paramName, values, false), is("NOT(ISNA(" + columnName + "))"));
}