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

File PostgresTest.java

 

Code metrics

0
3
3
1
136
118
3
1
1
3
1

Classes

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