use of java.time.chrono.ChronoPeriod in project drools by kiegroup.
the class MinFunctionTest method invokeArrayOfChronoPeriods.
@Test
public void invokeArrayOfChronoPeriods() {
final ChronoPeriod p1Period = Period.parse("P1Y");
final ChronoPeriod p1Comparable = ComparablePeriod.parse("P1Y");
final ChronoPeriod p2Period = Period.parse("P1M");
final ChronoPeriod p2Comparable = ComparablePeriod.parse("P1M");
Predicate<ChronoPeriod> assertion = i -> i.get(ChronoUnit.YEARS) == 0 && i.get(ChronoUnit.MONTHS) == 1;
FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[] { p2Period }), ChronoPeriod.class, assertion);
FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[] { p2Comparable }), ChronoPeriod.class, assertion);
FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[] { p1Period, p2Period }), ChronoPeriod.class, assertion);
FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[] { p1Comparable, p2Period }), ChronoPeriod.class, assertion);
FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[] { p1Period, p2Comparable }), ChronoPeriod.class, assertion);
FunctionTestUtil.assertPredicateOnResult(minFunction.invoke(new Object[] { p1Comparable, p2Comparable }), ChronoPeriod.class, assertion);
}
use of java.time.chrono.ChronoPeriod in project drools by kiegroup.
the class DMNRuntimeTest method testYearsAndMonthsDuration.
@Test
public void testYearsAndMonthsDuration() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("yearMonthDuration.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_6eda1490-21ca-441e-8a26-ab3ca800e43c", "Drawing 1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final BuiltInType feelType = (BuiltInType) BuiltInType.determineTypeFromName("yearMonthDuration");
final ChronoPeriod period = (ChronoPeriod) feelType.fromString("P2Y1M");
final DMNContext context = runtime.newContext();
context.set("iDuration", period);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("How long"), is("Longer than a year"));
}
use of java.time.chrono.ChronoPeriod in project drools by kiegroup.
the class DMNRuntimeTest method testChronoPeriod.
@Test
public void testChronoPeriod() {
// DROOLS-3848 DMN Years and Months internals expect value is Comparable
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("ChronoPeriod.dmn", this.getClass());
final DMNModel dmnModel = getAndAssertModelNoErrors(runtime, "http://www.trisotech.com/definitions/_f6036734-c7b3-42d2-adde-d7db17953114", "Drawing 1");
final ChronoPeriod p1Period = Period.parse("P1Y");
final ChronoPeriod p1Comparable = ComparablePeriod.parse("P1Y");
final ChronoPeriod p2Period = Period.parse("P1M");
final ChronoPeriod p2Comparable = ComparablePeriod.parse("P1M");
checkChronoPeriodEvaluateAll(runtime, dmnModel, p1Period, p2Period);
checkChronoPeriodEvaluateAll(runtime, dmnModel, p1Comparable, p2Period);
checkChronoPeriodEvaluateAll(runtime, dmnModel, p1Period, p2Comparable);
checkChronoPeriodEvaluateAll(runtime, dmnModel, p1Comparable, p2Comparable);
checkChronoPeriodEvaluateDS(runtime, dmnModel, p1Period, p2Period);
checkChronoPeriodEvaluateDS(runtime, dmnModel, p1Comparable, p2Period);
checkChronoPeriodEvaluateDS(runtime, dmnModel, p1Period, p2Comparable);
checkChronoPeriodEvaluateDS(runtime, dmnModel, p1Comparable, p2Comparable);
}
use of java.time.chrono.ChronoPeriod in project jdk8u_jdk by JetBrains.
the class TCKJapaneseChronology method test_periodUntilDate.
//-----------------------------------------------------------------------
// PeriodUntil()
//-----------------------------------------------------------------------
@Test
public void test_periodUntilDate() {
JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
ChronoPeriod period = mdate1.until(mdate2);
assertEquals(period, JapaneseChronology.INSTANCE.period(1, 1, 1));
}
use of java.time.chrono.ChronoPeriod in project jdk8u_jdk by JetBrains.
the class TestUmmAlQuraChronology method test_until.
// Test to get the Period between two given dates
@Test(dataProvider = "datesForPeriod")
public void test_until(HijrahDate h1, HijrahDate h2, ChronoPeriod p) {
ChronoPeriod period = h1.until(h2);
assertEquals(period, p);
}
Aggregations