Search in sources :

Example 26 with ChronoPeriod

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);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) Period(java.time.Period) BigDecimal(java.math.BigDecimal) Arrays(java.util.Arrays) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) InvalidParametersEvent(org.kie.dmn.feel.runtime.events.InvalidParametersEvent) Predicate(java.util.function.Predicate) ComparablePeriod(org.kie.dmn.feel.lang.types.impl.ComparablePeriod) Test(org.junit.Test) Collections(java.util.Collections) ChronoPeriod(java.time.chrono.ChronoPeriod) Before(org.junit.Before) Test(org.junit.Test)

Example 27 with ChronoPeriod

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"));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 28 with ChronoPeriod

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);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 29 with ChronoPeriod

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));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 30 with ChronoPeriod

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);
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) Test(org.testng.annotations.Test)

Aggregations

ChronoPeriod (java.time.chrono.ChronoPeriod)55 Test (org.testng.annotations.Test)26 Test (org.junit.Test)21 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)14 ChronoLocalDate (java.time.chrono.ChronoLocalDate)6 MinguoDate (java.time.chrono.MinguoDate)5 List (java.util.List)5 BigDecimal (java.math.BigDecimal)4 Period (java.time.Period)4 ChronoUnit (java.time.temporal.ChronoUnit)4 Temporal (java.time.temporal.Temporal)4 TemporalAccessor (java.time.temporal.TemporalAccessor)4 Arrays (java.util.Arrays)4 Collections (java.util.Collections)4 Predicate (java.util.function.Predicate)4 Before (org.junit.Before)4 ComparablePeriod (org.kie.dmn.feel.lang.types.impl.ComparablePeriod)4 Duration (java.time.Duration)3 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)3 TemporalUnit (java.time.temporal.TemporalUnit)3