@Test public void testDateTime_subtract_yearMonthDuration() { ISO8601DateTime dateTimeStdExample1 = new ISO8601DateTime(null, new ISO8601Date(2000, 1, 12), new ISO8601Time(12, 13, 14, 0)); ISO8601DateTime dateTimeMsecs = new ISO8601DateTime(null, new ISO8601Date(2000, 1, 12), new ISO8601Time(12, 13, 14, 777)); ISO8601DateTime dateTimeCrossover = new ISO8601DateTime(null, new ISO8601Date(2000, 1, 1), new ISO8601Time(23, 59, 30, 1)); ISO8601DateTime dateTimeBC = new ISO8601DateTime(null, new ISO8601Date(-2000, 1, 12), new ISO8601Time(12, 13, 14, 0)); ISO8601TimeZone timeZone0 = new ISO8601TimeZone(0); ISO8601TimeZone timeZone5 = new ISO8601TimeZone(5 * 60); ISO8601DateTime dateTimeTimeZone0 = new ISO8601DateTime(timeZone0, new ISO8601Date(timeZone0, 2000, 1, 12), new ISO8601Time(timeZone0, 12, 13, 14, 0)); ISO8601DateTime dateTimeTimeZone5 = new ISO8601DateTime(timeZone5, new ISO8601Date(timeZone5, 2000, 1, 12), new ISO8601Time(timeZone5, 12, 13, 14, 0)); XPathYearMonthDuration duration0 = new XPathYearMonthDuration(1, 0, 0); XPathYearMonthDuration durationStdExample1 = new XPathYearMonthDuration(1, 5, 7); XPathYearMonthDuration durationNStdExample1 = new XPathYearMonthDuration(-1, 5, 7); XPathYearMonthDuration durationMsecs = new XPathYearMonthDuration(1, 5, 7); XPathYearMonthDuration durationCrossover = new XPathYearMonthDuration(1, 0, 1); FunctionArgumentAttributeValue attrDateTimeStdExample1 = null; FunctionArgumentAttributeValue attrDateTimeMsecs = null; FunctionArgumentAttributeValue attrDateTimeCrossover = null; FunctionArgumentAttributeValue attrDateTimeBC = null; FunctionArgumentAttributeValue attrDateTimeTimeZone0 = null; FunctionArgumentAttributeValue attrDateTimeTimeZone5 = null; FunctionArgumentAttributeValue attrDuration0 = null; FunctionArgumentAttributeValue attrDurationStdExample1 = null; FunctionArgumentAttributeValue attrDurationNStdExample1 = null; FunctionArgumentAttributeValue attrDurationMsecs = null; FunctionArgumentAttributeValue attrDurationCrossover = null; FunctionArgumentAttributeValue attrNull = null; FunctionArgumentAttributeValue attrBlank = null; FunctionArgumentAttributeValue attrInteger = null; try { attrDateTimeStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeStdExample1)); attrDateTimeMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeMsecs)); attrDateTimeCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeCrossover)); attrDateTimeBC = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeBC)); attrDateTimeTimeZone0 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone0)); attrDateTimeTimeZone5 = new FunctionArgumentAttributeValue(DataTypes.DT_DATETIME.createAttributeValue(dateTimeTimeZone5)); attrDuration0 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(duration0)); attrDurationStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationStdExample1)); attrDurationNStdExample1 = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationNStdExample1)); attrDurationMsecs = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationMsecs)); attrDurationCrossover = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(durationCrossover)); attrBlank = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue("")); attrNull = new FunctionArgumentAttributeValue(DataTypes.DT_YEARMONTHDURATION.createAttributeValue(null)); attrInteger = new FunctionArgumentAttributeValue(DataTypes.DT_INTEGER.createAttributeValue(1234)); } catch (Exception e) { fail("creating attributes e="+ e); } FunctionDefinitionDateTimeArithmetic<?,?> fd = (FunctionDefinitionDateTimeArithmetic<?,?>) StdFunctions.FD_DATETIME_SUBTRACT_YEARMONTHDURATION; assertEquals(XACML3.ID_FUNCTION_DATETIME_SUBTRACT_YEARMONTHDURATION, fd.getId()); assertEquals(DataTypes.DT_DATETIME.getId(), fd.getDataTypeId()); assertFalse(fd.returnsBag()); arguments.clear(); arguments.add(attrDateTimeStdExample1); arguments.add(attrDuration0); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); ISO8601DateTime resValue = (ISO8601DateTime)res.getValue().getValue(); assertEquals(dateTimeStdExample1, resValue); arguments.clear(); arguments.add(attrDateTimeStdExample1); arguments.add(attrDurationStdExample1); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); resValue = (ISO8601DateTime)res.getValue().getValue(); ISO8601DateTime testResponse = new ISO8601DateTime( null, new ISO8601Date(1994, 6, 12), new ISO8601Time(12, 13, 14, 0) ); assertEquals(testResponse, resValue); arguments.clear(); arguments.add(attrDateTimeStdExample1); arguments.add(attrDurationNStdExample1); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); resValue = (ISO8601DateTime)res.getValue().getValue(); testResponse = new ISO8601DateTime( null, new ISO8601Date(2005, 8, 12), new ISO8601Time(12, 13, 14, 0) ); assertEquals(testResponse, resValue); arguments.clear(); arguments.add(attrDateTimeMsecs); arguments.add(attrDurationMsecs); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); resValue = (ISO8601DateTime)res.getValue().getValue(); testResponse = new ISO8601DateTime( null, new ISO8601Date(1994, 6, 12), new ISO8601Time(12, 13, 14, 777) ); assertEquals(testResponse, resValue); arguments.clear(); arguments.add(attrDateTimeCrossover); arguments.add(attrDurationCrossover); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); resValue = (ISO8601DateTime)res.getValue().getValue(); testResponse = new ISO8601DateTime( null, new ISO8601Date(1999, 12, 1), new ISO8601Time(23, 59, 30, 1) ); assertEquals(testResponse, resValue); arguments.clear(); arguments.add(attrDateTimeBC); arguments.add(attrDurationStdExample1); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); resValue = (ISO8601DateTime)res.getValue().getValue(); testResponse = new ISO8601DateTime( null, new ISO8601Date(-2006, 6, 12), new ISO8601Time(12, 13, 14, 0) ); assertEquals(testResponse, resValue); arguments.clear(); arguments.add(attrDateTimeTimeZone0); arguments.add(attrDurationStdExample1); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); resValue = (ISO8601DateTime)res.getValue().getValue(); testResponse = new ISO8601DateTime( timeZone0, new ISO8601Date(timeZone0, 1994, 6, 12), new ISO8601Time(timeZone0, 12, 13, 14, 0) ); assertEquals(testResponse, resValue); arguments.clear(); arguments.add(attrDateTimeTimeZone5); arguments.add(attrDurationStdExample1); res = fd.evaluate(null, arguments); assertTrue(res.isOk()); assertEquals(com.att.research.xacml.std.datatypes.ISO8601DateTime.class, res.getValue().getValue().getClass()); resValue = (ISO8601DateTime)res.getValue().getValue(); testResponse = new ISO8601DateTime( timeZone5, new ISO8601Date(timeZone5, 1994, 6, 12), new ISO8601Time(timeZone5, 12, 13, 14, 0) ); assertEquals(testResponse, resValue); arguments.clear(); arguments.add(attrBlank); arguments.add(attrDurationStdExample1); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrDateTimeStdExample1); arguments.add(attrBlank); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrBlank); arguments.add(attrBlank); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrNull); arguments.add(attrBlank); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrDateTimeStdExample1); arguments.add(attrNull); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrInteger); arguments.add(attrDurationStdExample1); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-subtract-yearMonthDuration Expected data type 'dateTime' saw 'integer'", res.getStatus().getStatusMessage()); assertEquals("urn:oasis:names:tc:xacml:1.0:status:processing-error", res.getStatus().getStatusCode().getStatusCodeValue().stringValue()); arguments.clear(); arguments.add(attrDateTimeStdExample1); arguments.add(attrNull); res = fd.evaluate(null, arguments); assertFalse(res.isOk()); assertEquals("function:dateTime-subtract-yearMonthDuration Got null attribute", 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) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<O> convertedArgument0 = new ConvertedArgument<O>(functionArgument, this.getDataType(), false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } O idateOrig = convertedArgument0.getValue(); functionArgument = arguments.get(1); ConvertedArgument<I> convertedArgument1 = new ConvertedArgument<I>(functionArgument, this.getDataTypeArgs(), false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } ISO8601Duration duration = convertedArgument1.getValue(); O idateResult = null; switch(this.operation) { case ADD: idateResult = idateOrig.add(duration); break; case SUBTRACT: idateResult = idateOrig.sub(duration); break; } ExpressionResult expressionResult = null; try { expressionResult = ExpressionResult.newSingle(this.getDataType().createAttributeValue(idateResult)); } catch (DataTypeException 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)); } return expressionResult; }
FunctionDefinitionDateTimeArithmetic extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<O> convertedArgument0 = new ConvertedArgument<O>(functionArgument, this.getDataType(), false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } O idateOrig = convertedArgument0.getValue(); functionArgument = arguments.get(1); ConvertedArgument<I> convertedArgument1 = new ConvertedArgument<I>(functionArgument, this.getDataTypeArgs(), false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } ISO8601Duration duration = convertedArgument1.getValue(); O idateResult = null; switch(this.operation) { case ADD: idateResult = idateOrig.add(duration); break; case SUBTRACT: idateResult = idateOrig.sub(duration); break; } ExpressionResult expressionResult = null; try { expressionResult = ExpressionResult.newSingle(this.getDataType().createAttributeValue(idateResult)); } catch (DataTypeException 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)); } return expressionResult; } }
FunctionDefinitionDateTimeArithmetic extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<O> convertedArgument0 = new ConvertedArgument<O>(functionArgument, this.getDataType(), false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } O idateOrig = convertedArgument0.getValue(); functionArgument = arguments.get(1); ConvertedArgument<I> convertedArgument1 = new ConvertedArgument<I>(functionArgument, this.getDataTypeArgs(), false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } ISO8601Duration duration = convertedArgument1.getValue(); O idateResult = null; switch(this.operation) { case ADD: idateResult = idateOrig.add(duration); break; case SUBTRACT: idateResult = idateOrig.sub(duration); break; } ExpressionResult expressionResult = null; try { expressionResult = ExpressionResult.newSingle(this.getDataType().createAttributeValue(idateResult)); } catch (DataTypeException 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)); } return expressionResult; } FunctionDefinitionDateTimeArithmetic(Identifier idIn, DataType<O> dataTypeIn, DataType<I> dataTypeArgsIn, OPERATION op); }
FunctionDefinitionDateTimeArithmetic extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<O> convertedArgument0 = new ConvertedArgument<O>(functionArgument, this.getDataType(), false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } O idateOrig = convertedArgument0.getValue(); functionArgument = arguments.get(1); ConvertedArgument<I> convertedArgument1 = new ConvertedArgument<I>(functionArgument, this.getDataTypeArgs(), false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } ISO8601Duration duration = convertedArgument1.getValue(); O idateResult = null; switch(this.operation) { case ADD: idateResult = idateOrig.add(duration); break; case SUBTRACT: idateResult = idateOrig.sub(duration); break; } ExpressionResult expressionResult = null; try { expressionResult = ExpressionResult.newSingle(this.getDataType().createAttributeValue(idateResult)); } catch (DataTypeException 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)); } return expressionResult; } FunctionDefinitionDateTimeArithmetic(Identifier idIn, DataType<O> dataTypeIn, DataType<I> dataTypeArgsIn, OPERATION op); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments); }
FunctionDefinitionDateTimeArithmetic extends FunctionDefinitionBase<O, I> { @Override public ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments) { if (arguments == null || arguments.size() != 2) { return ExpressionResult.newError(new StdStatus(StdStatusCode.STATUS_CODE_PROCESSING_ERROR, this.getShortFunctionId() + " Expected 2 arguments, got " + ((arguments == null) ? "null" : arguments.size()) )); } FunctionArgument functionArgument = arguments.get(0); ConvertedArgument<O> convertedArgument0 = new ConvertedArgument<O>(functionArgument, this.getDataType(), false); if ( ! convertedArgument0.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument0.getStatus())); } O idateOrig = convertedArgument0.getValue(); functionArgument = arguments.get(1); ConvertedArgument<I> convertedArgument1 = new ConvertedArgument<I>(functionArgument, this.getDataTypeArgs(), false); if ( ! convertedArgument1.isOk()) { return ExpressionResult.newError(getFunctionStatus(convertedArgument1.getStatus())); } ISO8601Duration duration = convertedArgument1.getValue(); O idateResult = null; switch(this.operation) { case ADD: idateResult = idateOrig.add(duration); break; case SUBTRACT: idateResult = idateOrig.sub(duration); break; } ExpressionResult expressionResult = null; try { expressionResult = ExpressionResult.newSingle(this.getDataType().createAttributeValue(idateResult)); } catch (DataTypeException 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)); } return expressionResult; } FunctionDefinitionDateTimeArithmetic(Identifier idIn, DataType<O> dataTypeIn, DataType<I> dataTypeArgsIn, OPERATION op); @Override ExpressionResult evaluate(EvaluationContext evaluationContext, List<FunctionArgument> arguments);  }