@Test public void testInteger() { BigInteger s1 = new BigInteger("123"); BigInteger s2 = new BigInteger("456"); FunctionArgumentAttributeValue attr1 = null; FunctionArgumentAttributeValue attr2 = null; try { attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s1)); attr2 = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(s2)); } catch (Exception e) { fail("creating attributes e="+e); } FunctionDefinitionBag<?> fd = (FunctionDefinitionBag<?>) StdFunctions.FD_INTEGER_BAG; assertEquals(XACML3.ID_FUNCTION_INTEGER_BAG, fd.getId()); assertEquals(DataTypes.DT_INTEGER.getId(), fd.getDataTypeId()); assertTrue(fd.returnsBag()); arguments.clear(); arguments.add(attr1); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); Bag bag = res.getBag(); assertNotNull(bag); Iterator<AttributeValue<?>> it = bag.getAttributeValues(); assertEquals(1, bag.size()); AttributeValue<?> attrValueObject = it.next(); assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); assertEquals(s1, attrValueObject.getValue()); arguments.clear(); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); assertEquals(0, bag.size()); arguments.clear(); arguments.add(null); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:integer-bag Got null argument", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrString); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:integer-bag Expected data type 'integer' saw 'string'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attr1); arguments.add(attr2); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(2, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); assertEquals(s1, attrValueObject.getValue()); attrValueObject = it.next(); assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); assertEquals(s2, attrValueObject.getValue()); arguments.clear(); arguments.add(attr1); arguments.add(attr2); arguments.add(attr1); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(3, bag.size()); attrValueObject = it.next(); assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); assertEquals(s1, attrValueObject.getValue()); attrValueObject = it.next(); assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); assertEquals(s2, attrValueObject.getValue()); attrValueObject = it.next(); assertEquals(DataTypes.DT_INTEGER.getId(), attrValueObject.getDataTypeId()); assertEquals(s1, attrValueObject.getValue()); arguments.clear(); for (int i = 0; i < 1000; i++) { arguments.add(attr1); } res = fd.evaluate(null, arguments); assertTrue(res.isOk()); bag = res.getBag(); assertNotNull(bag); it = bag.getAttributeValues(); assertEquals(1000, bag.size()); }
@Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { Bag elementBag = new Bag(); if (arguments != null && arguments.size() > 0) { for (FunctionArgument argument : arguments) { ConvertedArgument<I> convertedArgument = new ConvertedArgument<I>(argument, this.getDataTypeArgs(), false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } elementBag.add(argument.getValue()); } } return ExpressionResult.newBag(elementBag); }
FunctionDefinitionBag extends FunctionDefinitionBase<I, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { Bag elementBag = new Bag(); if (arguments != null && arguments.size() > 0) { for (FunctionArgument argument : arguments) { ConvertedArgument<I> convertedArgument = new ConvertedArgument<I>(argument, this.getDataTypeArgs(), false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } elementBag.add(argument.getValue()); } } return ExpressionResult.newBag(elementBag); } }
FunctionDefinitionBag extends FunctionDefinitionBase<I, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { Bag elementBag = new Bag(); if (arguments != null && arguments.size() > 0) { for (FunctionArgument argument : arguments) { ConvertedArgument<I> convertedArgument = new ConvertedArgument<I>(argument, this.getDataTypeArgs(), false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } elementBag.add(argument.getValue()); } } return ExpressionResult.newBag(elementBag); } FunctionDefinitionBag(Identifier idIn, DataType<I> dataTypeArgsIn); }
FunctionDefinitionBag extends FunctionDefinitionBase<I, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { Bag elementBag = new Bag(); if (arguments != null && arguments.size() > 0) { for (FunctionArgument argument : arguments) { ConvertedArgument<I> convertedArgument = new ConvertedArgument<I>(argument, this.getDataTypeArgs(), false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } elementBag.add(argument.getValue()); } } return ExpressionResult.newBag(elementBag); } FunctionDefinitionBag(Identifier idIn, DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionBag extends FunctionDefinitionBase<I, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { Bag elementBag = new Bag(); if (arguments != null && arguments.size() > 0) { for (FunctionArgument argument : arguments) { ConvertedArgument<I> convertedArgument = new ConvertedArgument<I>(argument, this.getDataTypeArgs(), false); if ( ! convertedArgument.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument.getStatus())); } elementBag.add(argument.getValue()); } } return ExpressionResult.newBag(elementBag); } FunctionDefinitionBag(Identifier idIn, DataType<I> dataTypeArgsIn); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }