1. Project Clover database Fri Jul 17 2026 06:10:26 UTC
  2. Package guru.mikelue.foxglove.vendor

File H2Test.java

 

Code metrics

0
3
3
1
117
98
3
1
1
3
1

Classes

Class Line # Actions
H2Test 20 3 0% 3 6
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    package guru.mikelue.foxglove.vendor;
2   
3    import java.io.IOException;
4    import java.time.*;
5   
6    import org.springframework.beans.factory.annotation.Autowired;
7    import org.springframework.context.ApplicationContext;
8    import org.springframework.jdbc.core.JdbcTemplate;
9    import org.springframework.transaction.annotation.Transactional;
10   
11    import org.junit.jupiter.api.*;
12   
13    import guru.mikelue.foxglove.TableFacet;
14    import guru.mikelue.foxglove.annotation.GenData;
15    import guru.mikelue.foxglove.annotation.TableFacetsSource;
16    import guru.mikelue.foxglove.jdbc.JdbcTableFacet;
17    import guru.mikelue.foxglove.test.AbstractVendorTestBase;
18   
19    @Tag("vendor-h2")
 
20    public class H2Test extends AbstractVendorTestBase {
21    private final static int RANDOM_ROWS = gen().ints().range(5, 10).get();
22   
 
23  0 toggle public H2Test() {}
24   
 
25  0 toggle @BeforeAll
26    static void beforeAllSetup(
27    @Autowired ApplicationContext appContext,
28    @Autowired JdbcTemplate jdbcTemplate
29    ) throws IOException {
30  0 dropTables(jdbcTemplate, "ap_types");
31   
32  0 build("classpath:h2-types.sql", appContext);
33    }
34   
35    @TableFacetsSource
36    TableFacet[] defaultData = new JdbcTableFacet[] {
37    // Uses java.time.Instant as value for temporal types of database
38    JdbcTableFacet.builder("ap_types")
39    .numberOfRows(RANDOM_ROWS)
40    .column("tp_color").fixed("green")
41    .column("tp_int_array").fixed(new Integer[] { 1, 2, 3 })
42    .column("tp_date").fixed(Instant.now())
43    .column("tp_time").fixed(Instant.now())
44    .column("tp_time_with_time_zone").fixed(Instant.now())
45    .column("tp_timestamp").fixed(Instant.now())
46    .column("tp_timestamp_with_time_zone").fixed(Instant.now())
47    .build(),
48    // Uses java.time.OffsetXXX as value for temporal types of database
49    JdbcTableFacet.builder("ap_types")
50    .numberOfRows(RANDOM_ROWS)
51    .column("tp_color").fixed("green")
52    .column("tp_int_array").fixed(new Integer[] { 1, 2, 3 })
53    .column("tp_date").fixed(OffsetDateTime.now())
54    .column("tp_time").fixed(OffsetTime.now())
55    .column("tp_time_with_time_zone").fixed(OffsetTime.now())
56    .column("tp_timestamp").fixed(OffsetDateTime.now())
57    .column("tp_timestamp_with_time_zone").fixed(OffsetDateTime.now())
58    .build(),
59    // Uses java.time.ZonedDateTime as value for temporal types of database
60    JdbcTableFacet.builder("ap_types")
61    .numberOfRows(RANDOM_ROWS)
62    .column("tp_color").fixed("green")
63    .column("tp_int_array").fixed(new Integer[] { 1, 2, 3 })
64    .column("tp_date").fixed(ZonedDateTime.now())
65    .column("tp_time").fixed(ZonedDateTime.now())
66    .column("tp_time_with_time_zone").fixed(ZonedDateTime.now())
67    .column("tp_timestamp").fixed(ZonedDateTime.now())
68    .column("tp_timestamp_with_time_zone").fixed(ZonedDateTime.now())
69    .build(),
70    // Uses time types in java.sql as value for temporal types of database
71    JdbcTableFacet.builder("ap_types")
72    .numberOfRows(RANDOM_ROWS)
73    .column("tp_color").fixed("green")
74    .column("tp_int_array").fixed(new Integer[] { 1, 2, 3 })
75    .column("tp_date").fixed(java.sql.Date.from(Instant.now()))
76    .column("tp_time").fixed(java.sql.Time.from(Instant.now()))
77    .column("tp_time_with_time_zone").fixed(java.sql.Time.from(Instant.now()))
78    .column("tp_timestamp").fixed(java.sql.Timestamp.from(Instant.now()))
79    .column("tp_timestamp_with_time_zone").fixed(java.sql.Timestamp.from(Instant.now()))
80    .build(),
81    // Uses java.time.LocalTime as value for temporal types of database
82    JdbcTableFacet.builder("ap_types")
83    .numberOfRows(RANDOM_ROWS)
84    .column("tp_color").fixed("green")
85    .column("tp_int_array").fixed(new Integer[] { 1, 2, 3 })
86    .column("tp_date").fixed(LocalDate.now())
87    .column("tp_time").fixed(LocalTime.now())
88    .column("tp_time_with_time_zone").fixed(LocalTime.now())
89    .column("tp_timestamp").fixed(LocalDateTime.now())
90    .column("tp_timestamp_with_time_zone").fixed(LocalDateTime.now())
91    .build(),
92    // Uses strings as values for temporal types of database
93    JdbcTableFacet.builder("ap_types")
94    .numberOfRows(RANDOM_ROWS)
95    .column("tp_color").fixed("green")
96    .column("tp_int_array").fixed(new Integer[] { 1, 2, 3 })
97    .column("tp_date").fixed("2026-07-16")
98    .column("tp_time").fixed("12:34:56")
99    .column("tp_time_with_time_zone").fixed("12:34:56+00:00")
100    .column("tp_timestamp").fixed("2026-07-16 12:34:56")
101    .column("tp_timestamp_with_time_zone").fixed("2026-07-16 12:34:56+00:00")
102    .build(),
103    };
104   
105    /**
106    * Tests the basic functionality on H2.
107    */
 
108  0 toggle @Test
109    @GenData @Transactional
110    void basic()
111    {
112  0 assertNumberOfRows(
113    "ap_types", "tp_color = 'green'"
114    )
115    .isEqualTo(RANDOM_ROWS * defaultData.length);
116    }
117    }