Java Code Examples for java.time.LocalDate#minusYears()

The following examples show how to use java.time.LocalDate#minusYears() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: LocalDateVariableTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml")
void testGetLocalDateVariable() {
    LocalDate nowLocalDate = LocalDate.now();
    LocalDate oneYearBefore = nowLocalDate.minusYears(1);
    LocalDate oneYearLater = nowLocalDate.plusYears(1);
    ProcessInstance processInstance = runtimeService.createProcessInstanceBuilder()
            .processDefinitionKey("oneTaskProcess")
            .variable("nowLocalDate", nowLocalDate)
            .variable("oneYearBefore", oneYearBefore)
            .variable("oneYearLater", oneYearLater)
            .start();

    VariableInstance nowLocalDateVariableInstance = runtimeService.getVariableInstance(processInstance.getId(), "nowLocalDate");
    assertThat(nowLocalDateVariableInstance.getTypeName()).isEqualTo(LocalDateType.TYPE_NAME);
    assertThat(nowLocalDateVariableInstance.getValue()).isEqualTo(nowLocalDate);

    VariableInstance oneYearBeforeVariableInstance = runtimeService.getVariableInstance(processInstance.getId(), "oneYearBefore");
    assertThat(oneYearBeforeVariableInstance.getTypeName()).isEqualTo(LocalDateType.TYPE_NAME);
    assertThat(oneYearBeforeVariableInstance.getValue()).isEqualTo(oneYearBefore);

    VariableInstance oneYearLaterVariableInstance = runtimeService.getVariableInstance(processInstance.getId(), "oneYearLater");
    assertThat(oneYearLaterVariableInstance.getTypeName()).isEqualTo(LocalDateType.TYPE_NAME);
    assertThat(oneYearLaterVariableInstance.getValue()).isEqualTo(oneYearLater);

    assertThat(runtimeService.getVariables(processInstance.getId()))
            .containsOnly(
                    entry("nowLocalDate", nowLocalDate),
                    entry("oneYearBefore", oneYearBefore),
                    entry("oneYearLater", oneYearLater)
            );
}
 
Example 2
Source File: TCKLocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLarge() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 6, 1);
    test.minusYears(-1);
}
 
Example 3
Source File: TCKLocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLarge() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 6, 1);
    test.minusYears(-1);
}
 
Example 4
Source File: TCKLocalDate.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MIN_VALUE);
}
 
Example 5
Source File: TCKLocalDate.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MAX_VALUE);
}
 
Example 6
Source File: TCKLocalDate.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MIN_VALUE);
}
 
Example 7
Source File: TCKLocalDate.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MAX_VALUE);
}
 
Example 8
Source File: TCKLocalDate.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MAX_VALUE);
}
 
Example 9
Source File: ExecutionQueryTest.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testQueryLocalDateVariable() throws Exception {
    Map<String, Object> vars = new HashMap<>();
    LocalDate localDate = LocalDate.now();
    vars.put("localDateVar", localDate);

    ProcessInstance processInstance1 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);

    LocalDate localDate2 = localDate.plusDays(1);
    vars = new HashMap<>();
    vars.put("localDateVar", localDate);
    vars.put("localDateVar2", localDate2);
    ProcessInstance processInstance2 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);

    LocalDate nextYear = localDate.plusYears(1);
    vars = new HashMap<>();
    vars.put("localDateVar", nextYear);
    ProcessInstance processInstance3 = runtimeService.startProcessInstanceByKey("oneTaskProcess", vars);

    LocalDate nextMonth = localDate.plusMonths(1);

    LocalDate twoYearsLater = localDate.plusYears(2);

    LocalDate oneYearAgo = localDate.minusYears(1);

    // Query on single localDate variable, should result in 2 matches
    ExecutionQuery query = runtimeService.createExecutionQuery().variableValueEquals("localDateVar", localDate);
    List<Execution> executions = query.list();
    assertThat(executions).hasSize(2);

    // Query on two localDate variables, should result in single value
    query = runtimeService.createExecutionQuery().variableValueEquals("localDateVar", localDate).variableValueEquals("localDateVar2", localDate2);
    Execution execution = query.singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance2.getId());

    // Query with unexisting variable value
    execution = runtimeService.createExecutionQuery().variableValueEquals("localDateVar", localDate.minusDays(1)).singleResult();
    assertThat(execution).isNull();

    // Test NOT_EQUALS
    execution = runtimeService.createExecutionQuery().variableValueNotEquals("localDateVar", localDate).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());

    // Test GREATER_THAN
    execution = runtimeService.createExecutionQuery().variableValueGreaterThan("localDateVar", nextMonth).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());

    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("localDateVar", nextYear).count()).isZero();
    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThan("localDateVar", oneYearAgo).count()).isEqualTo(3);

    // Test GREATER_THAN_OR_EQUAL
    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("localDateVar", nextMonth).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());

    execution = runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("localDateVar", nextYear).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());

    assertThat(runtimeService.createExecutionQuery().variableValueGreaterThanOrEqual("localDateVar", oneYearAgo).count()).isEqualTo(3);

    // Test LESS_THAN
    executions = runtimeService.createExecutionQuery().variableValueLessThan("localDateVar", nextYear).list();
    assertThat(executions)
        .extracting(Execution::getId)
        .containsExactlyInAnyOrder(
            processInstance1.getId(),
            processInstance2.getId()
        );

    assertThat(runtimeService.createExecutionQuery().variableValueLessThan("localDateVar", localDate).count()).isZero();
    assertThat(runtimeService.createExecutionQuery().variableValueLessThan("localDateVar", twoYearsLater).count()).isEqualTo(3);

    // Test LESS_THAN_OR_EQUAL
    executions = runtimeService.createExecutionQuery().variableValueLessThanOrEqual("localDateVar", nextYear).list();
    assertThat(executions).hasSize(3);

    assertThat(runtimeService.createExecutionQuery().variableValueLessThanOrEqual("localDateVar", oneYearAgo).count()).isZero();

    // Test value-only matching
    execution = runtimeService.createExecutionQuery().variableValueEquals(nextYear).singleResult();
    assertThat(execution).isNotNull();
    assertThat(execution.getId()).isEqualTo(processInstance3.getId());

    executions = runtimeService.createExecutionQuery().variableValueEquals(localDate).list();
    assertThat(executions)
        .extracting(Execution::getId)
        .containsExactlyInAnyOrder(
            processInstance1.getId(),
            processInstance2.getId()
        );

    execution = runtimeService.createExecutionQuery().variableValueEquals(twoYearsLater).singleResult();
    assertThat(execution).isNull();
}
 
Example 10
Source File: TCKLocalDate.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MIN_VALUE);
}
 
Example 11
Source File: TCKLocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLarge() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 6, 1);
    test.minusYears(-1);
}
 
Example 12
Source File: TCKLocalDate.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLarge() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 6, 1);
    test.minusYears(-1);
}
 
Example 13
Source File: TCKLocalDate.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MIN_VALUE);
}
 
Example 14
Source File: TCKLocalDate.java    From j2objc with Apache License 2.0 4 votes vote down vote up
@Test(expected=DateTimeException.class)
public void test_minusYears_long_invalidTooLarge() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 6, 1);
    test.minusYears(-1);
}
 
Example 15
Source File: TCKLocalDate.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MIN_VALUE);
}
 
Example 16
Source File: TCKLocalDate.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MAX_VALUE);
}
 
Example 17
Source File: TCKLocalDate.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLarge() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 6, 1);
    test.minusYears(-1);
}
 
Example 18
Source File: TCKLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MIN_VALUE);
}
 
Example 19
Source File: TCKLocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLargeMaxAddMax() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.minusYears(Long.MAX_VALUE);
}
 
Example 20
Source File: TCKLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
@Test(expectedExceptions=DateTimeException.class)
public void test_minusYears_long_invalidTooLarge() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 6, 1);
    test.minusYears(-1);
}