@Test public void testString_normalize_to_lower_case() { String initialString = " First and last are whitespace "; FunctionArgumentAttributeValue attr1 = null; try { attr1 = new FunctionArgumentAttributeValue(DataTypes.DT_STRING.createAttributeValue(initialString)); } catch (Exception e) { fail("creating attribute e="+ e); } FunctionDefinitionStringNormalize fd = (FunctionDefinitionStringNormalize) StdFunctions.FD_STRING_NORMALIZE_TO_LOWER_CASE; assertEquals(XACML3.ID_FUNCTION_STRING_NORMALIZE_TO_LOWER_CASE, fd.getId()); assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeArgs().getId()); assertEquals(DataTypes.DT_STRING.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); assertEquals(new Integer(1), fd.getNumArgs()); arguments.add(attr1); ExpressionResult res = fd.evaluate(null, arguments); assertTrue(res.isOk()); String resValue = (String)res.getValue().getValue(); assertTrue(initialString.toLowerCase().equals(resValue)); }
@Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<String> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } ExpressionResult expressionResult = null; switch (operation) { case SPACE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).trim() ); break; case LOWER_CASE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).toLowerCase() ); break; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; }
FunctionDefinitionStringNormalize extends FunctionDefinitionHomogeneousSimple<String, String> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<String> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } ExpressionResult expressionResult = null; switch (operation) { case SPACE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).trim() ); break; case LOWER_CASE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).toLowerCase() ); break; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } }
FunctionDefinitionStringNormalize extends FunctionDefinitionHomogeneousSimple<String, String> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<String> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } ExpressionResult expressionResult = null; switch (operation) { case SPACE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).trim() ); break; case LOWER_CASE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).toLowerCase() ); break; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } FunctionDefinitionStringNormalize(Identifier idIn,  OPERATION op); }
FunctionDefinitionStringNormalize extends FunctionDefinitionHomogeneousSimple<String, String> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<String> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } ExpressionResult expressionResult = null; switch (operation) { case SPACE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).trim() ); break; case LOWER_CASE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).toLowerCase() ); break; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } FunctionDefinitionStringNormalize(Identifier idIn,  OPERATION op); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionStringNormalize extends FunctionDefinitionHomogeneousSimple<String, String> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { List<String> convertedArguments = new ArrayList<>(); Status status = this.validateArguments(arguments, convertedArguments); if (!status.getStatusCode().equals(StdStatusCode.STATUS_CODE_OK)) { return ExpressionResult.newError(getFunctionStatus(status)); } ExpressionResult expressionResult = null; switch (operation) { case SPACE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).trim() ); break; case LOWER_CASE: result = new StdAttributeValue<>(XACML.ID_DATATYPE_STRING, convertedArguments.get(0).toLowerCase() ); break; } expressionResult = ExpressionResult.newSingle(result); return expressionResult; } FunctionDefinitionStringNormalize(Identifier idIn,  OPERATION op); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }