|
| 1 | +package org.hypertrace.core.documentstore.expression.impl; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +class PostgresDataTypeTest { |
| 8 | + |
| 9 | + @Test |
| 10 | + void testTextGetType() { |
| 11 | + assertEquals("text", PostgresDataType.TEXT.getType()); |
| 12 | + } |
| 13 | + |
| 14 | + @Test |
| 15 | + void testTextToString() { |
| 16 | + assertEquals("text", PostgresDataType.TEXT.toString()); |
| 17 | + } |
| 18 | + |
| 19 | + @Test |
| 20 | + void testIntegerGetType() { |
| 21 | + assertEquals("int4", PostgresDataType.INTEGER.getType()); |
| 22 | + } |
| 23 | + |
| 24 | + @Test |
| 25 | + void testIntegerToString() { |
| 26 | + assertEquals("int4", PostgresDataType.INTEGER.toString()); |
| 27 | + } |
| 28 | + |
| 29 | + @Test |
| 30 | + void testBigintGetType() { |
| 31 | + assertEquals("int8", PostgresDataType.BIGINT.getType()); |
| 32 | + } |
| 33 | + |
| 34 | + @Test |
| 35 | + void testBigintToString() { |
| 36 | + assertEquals("int8", PostgresDataType.BIGINT.toString()); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + void testSmallintGetType() { |
| 41 | + assertEquals("int2", PostgresDataType.SMALLINT.getType()); |
| 42 | + } |
| 43 | + |
| 44 | + @Test |
| 45 | + void testSmallintToString() { |
| 46 | + assertEquals("int2", PostgresDataType.SMALLINT.toString()); |
| 47 | + } |
| 48 | + |
| 49 | + @Test |
| 50 | + void testFloatGetType() { |
| 51 | + assertEquals("float4", PostgresDataType.FLOAT.getType()); |
| 52 | + } |
| 53 | + |
| 54 | + @Test |
| 55 | + void testFloatToString() { |
| 56 | + assertEquals("float4", PostgresDataType.FLOAT.toString()); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + void testDoubleGetType() { |
| 61 | + assertEquals("float8", PostgresDataType.DOUBLE.getType()); |
| 62 | + } |
| 63 | + |
| 64 | + @Test |
| 65 | + void testDoubleToString() { |
| 66 | + assertEquals("float8", PostgresDataType.DOUBLE.toString()); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + void testNumericGetType() { |
| 71 | + assertEquals("numeric", PostgresDataType.NUMERIC.getType()); |
| 72 | + } |
| 73 | + |
| 74 | + @Test |
| 75 | + void testNumericToString() { |
| 76 | + assertEquals("numeric", PostgresDataType.NUMERIC.toString()); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + void testBooleanGetType() { |
| 81 | + assertEquals("bool", PostgresDataType.BOOLEAN.getType()); |
| 82 | + } |
| 83 | + |
| 84 | + @Test |
| 85 | + void testBooleanToString() { |
| 86 | + assertEquals("bool", PostgresDataType.BOOLEAN.toString()); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + void testTimestampGetType() { |
| 91 | + assertEquals("timestamp", PostgresDataType.TIMESTAMP.getType()); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + void testTimestampToString() { |
| 96 | + assertEquals("timestamp", PostgresDataType.TIMESTAMP.toString()); |
| 97 | + } |
| 98 | + |
| 99 | + @Test |
| 100 | + void testTimestamptzGetType() { |
| 101 | + assertEquals("timestamptz", PostgresDataType.TIMESTAMPTZ.getType()); |
| 102 | + } |
| 103 | + |
| 104 | + @Test |
| 105 | + void testTimestamptzToString() { |
| 106 | + assertEquals("timestamptz", PostgresDataType.TIMESTAMPTZ.toString()); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + void testDateGetType() { |
| 111 | + assertEquals("date", PostgresDataType.DATE.getType()); |
| 112 | + } |
| 113 | + |
| 114 | + @Test |
| 115 | + void testDateToString() { |
| 116 | + assertEquals("date", PostgresDataType.DATE.toString()); |
| 117 | + } |
| 118 | + |
| 119 | + @Test |
| 120 | + void testUuidGetType() { |
| 121 | + assertEquals("uuid", PostgresDataType.UUID.getType()); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + void testUuidToString() { |
| 126 | + assertEquals("uuid", PostgresDataType.UUID.toString()); |
| 127 | + } |
| 128 | + |
| 129 | + @Test |
| 130 | + void testJsonbGetType() { |
| 131 | + assertEquals("jsonb", PostgresDataType.JSONB.getType()); |
| 132 | + } |
| 133 | + |
| 134 | + @Test |
| 135 | + void testJsonbToString() { |
| 136 | + assertEquals("jsonb", PostgresDataType.JSONB.toString()); |
| 137 | + } |
| 138 | + |
| 139 | + @Test |
| 140 | + void testByteaGetType() { |
| 141 | + assertEquals("bytea", PostgresDataType.BYTEA.getType()); |
| 142 | + } |
| 143 | + |
| 144 | + @Test |
| 145 | + void testByteaToString() { |
| 146 | + assertEquals("bytea", PostgresDataType.BYTEA.toString()); |
| 147 | + } |
| 148 | + |
| 149 | + @Test |
| 150 | + void testGetTypeAndToStringReturnSameValue() { |
| 151 | + // Verify that getType() and toString() always return the same value for all enum constants |
| 152 | + for (PostgresDataType type : PostgresDataType.values()) { |
| 153 | + assertEquals( |
| 154 | + type.getType(), |
| 155 | + type.toString(), |
| 156 | + "getType() and toString() should return the same value for " + type.name()); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + void testGetPgTypeNameMatchesGetType() { |
| 162 | + // Verify that getPgTypeName() returns the same as getType() |
| 163 | + for (PostgresDataType type : PostgresDataType.values()) { |
| 164 | + assertEquals( |
| 165 | + type.getType(), |
| 166 | + type.getPgTypeName(), |
| 167 | + "getPgTypeName() should match getType() for " + type.name()); |
| 168 | + } |
| 169 | + } |
| 170 | + |
| 171 | + @Test |
| 172 | + void testAllEnumValuesHaveNonNullType() { |
| 173 | + // Verify that all enum constants have non-null type names |
| 174 | + for (PostgresDataType type : PostgresDataType.values()) { |
| 175 | + assertEquals(type.getType() != null, true, "Type name should not be null for " + type.name()); |
| 176 | + } |
| 177 | + } |
| 178 | +} |
0 commit comments