@Test public void testDateTime_Equal() { Calendar calendar = Calendar.getInstance(); Date today = calendar.getTime(); Date longAgo = new Date(1234); if (calendar.get(Calendar.ZONE_OFFSET) > 3) { calendar.set(Calendar.ZONE_OFFSET, 3); } else { calendar.set(Calendar.ZONE_OFFSET, 5); } Date todayPlus = calendar.getTime(); FunctionArgumentAttributeValue attrToday = null; FunctionArgumentAttributeValue attrToday2 = null; FunctionArgumentAttributeValue attrLaterToday = null; FunctionArgumentAttributeValue attrYesterday = null; try { attrToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); attrToday2 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(today)); attrLaterToday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(todayPlus)); attrYesterday = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(longAgo)); } catch (Exception e) { fail("creating attribute e="+ e); } FunctionDefinitionEquality<?> fd = (FunctionDefinitionEquality<?>) StdFunctions.FD_DATETIME_EQUAL; assertEquals(XACML3.ID_FUNCTION_DATETIME_EQUAL, 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(attrToday); arguments.add(attrToday2); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); Boolean resValue = (Boolean)res.getValue().getValue(); assertTrue(resValue); arguments.clear(); arguments.add(attrToday); arguments.add(attrYesterday); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (Boolean)res.getValue().getValue(); assertFalse(resValue); arguments.clear(); arguments.add(attrToday); arguments.add(attrLaterToday); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); resValue = (Boolean)res.getValue().getValue(); assertFalse(resValue); arguments.clear(); arguments.add(stringAttr1); arguments.add(intAttr1); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); }
@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)); } if (this.isEqual(convertedArguments.get(0), convertedArguments.get(1))) { return ER_TRUE; } else { return ER_FALSE; } }
FunctionDefinitionEquality 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)); } if (this.isEqual(convertedArguments.get(0), convertedArguments.get(1))) { return ER_TRUE; } else { return ER_FALSE; } } }
FunctionDefinitionEquality 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)); } if (this.isEqual(convertedArguments.get(0), convertedArguments.get(1))) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionEquality(Identifier idIn, DataType<I> dataTypeArgsIn); }
FunctionDefinitionEquality 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)); } if (this.isEqual(convertedArguments.get(0), convertedArguments.get(1))) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionEquality(Identifier idIn, DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionEquality 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)); } if (this.isEqual(convertedArguments.get(0), convertedArguments.get(1))) { return ER_TRUE; } else { return ER_FALSE; } } FunctionDefinitionEquality(Identifier idIn, DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }