Search in sources :

Example 1 with AccessDateProvider

use of org.dbflute.hook.AccessContext.AccessDateProvider in project dbflute-core by dbflute.

the class AccessContextTest method test_getValue_whenAccessContextProvider_Tx.

public void test_getValue_whenAccessContextProvider_Tx() throws Exception {
    // ## Arrange ##
    AccessContext accessContext = new AccessContext();
    final String dateExp = "2013-02-02 12:34:56";
    accessContext.setAccessDateProvider(new AccessDateProvider() {

        public Date provideDate() {
            return toDate(dateExp);
        }
    });
    final String timestampExp = "2013-02-02 12:34:56";
    accessContext.setAccessTimestampProvider(new AccessTimestampProvider() {

        public Timestamp provideTimestamp() {
            return toTimestamp(timestampExp);
        }
    });
    accessContext.setAccessUserProvider(new AccessUserProvider() {

        public String provideUser() {
            return "foo";
        }
    });
    accessContext.setAccessProcessProvider(new AccessProcessProvider() {

        public String provideProcess() {
            return "bar";
        }
    });
    accessContext.setAccessModuleProvider(new AccessModuleProvider() {

        public String provideModule() {
            return "qux";
        }
    });
    AccessContext.setAccessContextOnThread(accessContext);
    // ## Act & Assert ##
    assertNotNull(dateExp, AccessContext.getAccessDateOnThread());
    assertNotNull(timestampExp, AccessContext.getAccessTimestampOnThread());
    assertEquals("foo", AccessContext.getAccessUserOnThread());
    assertEquals("bar", AccessContext.getAccessProcessOnThread());
    assertEquals("qux", AccessContext.getAccessModuleOnThread());
}
Also used : AccessTimestampProvider(org.dbflute.hook.AccessContext.AccessTimestampProvider) AccessModuleProvider(org.dbflute.hook.AccessContext.AccessModuleProvider) AccessDateProvider(org.dbflute.hook.AccessContext.AccessDateProvider) AccessUserProvider(org.dbflute.hook.AccessContext.AccessUserProvider) AccessProcessProvider(org.dbflute.hook.AccessContext.AccessProcessProvider) Timestamp(java.sql.Timestamp) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

Timestamp (java.sql.Timestamp)1 LocalDate (java.time.LocalDate)1 Date (java.util.Date)1 AccessDateProvider (org.dbflute.hook.AccessContext.AccessDateProvider)1 AccessModuleProvider (org.dbflute.hook.AccessContext.AccessModuleProvider)1 AccessProcessProvider (org.dbflute.hook.AccessContext.AccessProcessProvider)1 AccessTimestampProvider (org.dbflute.hook.AccessContext.AccessTimestampProvider)1 AccessUserProvider (org.dbflute.hook.AccessContext.AccessUserProvider)1