@Test public void testDateTime_GT() { FunctionDefinitionComparison<?> fd = (FunctionDefinitionComparison<?>) StdFunctions.FD_DATETIME_GREATER_THAN; assertEquals(XACML3.ID_FUNCTION_DATETIME_GREATER_THAN, fd.getId()); assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeArgs().getId()); assertEquals(DataTypes.DT_BOOLEAN.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); assertEquals(new Integer(2), fd.getNumArgs()); arguments.add(attrDateTimeToday); arguments.add(attrDateTimeSameDay); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); Boolean resValue = (Boolean)res.getValue().getValue(); assertFalse(resValue); arguments.clear(); arguments.add(attrDateTimeToday); arguments.add(attrDateTimeTommorrow); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (Boolean)res.getValue().getValue(); assertFalse(resValue); arguments.clear(); arguments.add(attrDateTimeToday); arguments.add(attrDateTimeYesterday); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (Boolean)res.getValue().getValue(); assertTrue(resValue); arguments.clear(); arguments.add(stringAttr1); arguments.add(intAttr1); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); arguments.clear(); arguments.add(attrDateTimeWithTimeZone); arguments.add(attrDateTimeNoTimeZone); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-greater-than Cannot compare this ISO8601DateTime with non-time-zoned ISO8601DateTime", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); }
@Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } int compareResult; try { compareResult = ((I)convertedArguments.get(0)).compareTo((I)convertedArguments.get(1)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } switch (operation) { case GREATER_THAN: if (compareResult > 0) { return ER_TRUE; } else { return ER_FALSE; } case GREATER_THAN_EQUAL: if (compareResult > -1) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN: if (compareResult < 0) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN_EQUAL: if (compareResult < 1) { return ER_TRUE; } else { return ER_FALSE; } } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " ENUM did not cover case of " + operation)); }
FunctionDefinitionComparison extends FunctionDefinitionHomogeneousSimple<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } int compareResult; try { compareResult = ((I)convertedArguments.get(0)).compareTo((I)convertedArguments.get(1)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } switch (operation) { case GREATER_THAN: if (compareResult > 0) { return ER_TRUE; } else { return ER_FALSE; } case GREATER_THAN_EQUAL: if (compareResult > -1) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN: if (compareResult < 0) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN_EQUAL: if (compareResult < 1) { return ER_TRUE; } else { return ER_FALSE; } } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " ENUM did not cover case of " + operation)); } }
FunctionDefinitionComparison extends FunctionDefinitionHomogeneousSimple<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } int compareResult; try { compareResult = ((I)convertedArguments.get(0)).compareTo((I)convertedArguments.get(1)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } switch (operation) { case GREATER_THAN: if (compareResult > 0) { return ER_TRUE; } else { return ER_FALSE; } case GREATER_THAN_EQUAL: if (compareResult > -1) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN: if (compareResult < 0) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN_EQUAL: if (compareResult < 1) { return ER_TRUE; } else { return ER_FALSE; } } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " ENUM did not cover case of " + operation)); } FunctionDefinitionComparison(Identifier idIn, DataType<I> dataTypeArgsIn, OPERATION opIn); }
FunctionDefinitionComparison extends FunctionDefinitionHomogeneousSimple<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } int compareResult; try { compareResult = ((I)convertedArguments.get(0)).compareTo((I)convertedArguments.get(1)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } switch (operation) { case GREATER_THAN: if (compareResult > 0) { return ER_TRUE; } else { return ER_FALSE; } case GREATER_THAN_EQUAL: if (compareResult > -1) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN: if (compareResult < 0) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN_EQUAL: if (compareResult < 1) { return ER_TRUE; } else { return ER_FALSE; } } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " ENUM did not cover case of " + operation)); } FunctionDefinitionComparison(Identifier idIn, DataType<I> dataTypeArgsIn, OPERATION opIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionComparison extends FunctionDefinitionHomogeneousSimple<Boolean, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<I> convertedArguments = new ArrayList<I>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } int compareResult; try { compareResult = ((I)convertedArguments.get(0)).compareTo((I)convertedArguments.get(1)); } catch (Exception e) { String message = e.getMessage(); if (e.getCause() != null) { message = e.getCause().getMessage(); } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " " + message)); } switch (operation) { case GREATER_THAN: if (compareResult > 0) { return ER_TRUE; } else { return ER_FALSE; } case GREATER_THAN_EQUAL: if (compareResult > -1) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN: if (compareResult < 0) { return ER_TRUE; } else { return ER_FALSE; } case LESS_THAN_EQUAL: if (compareResult < 1) { return ER_TRUE; } else { return ER_FALSE; } } return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " ENUM did not cover case of " + operation)); } FunctionDefinitionComparison(Identifier idIn, DataType<I> dataTypeArgsIn, OPERATION opIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }