|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | +package org.apache.seata.sqlparser.struct; |
| 18 | + |
| 19 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertFalse; |
| 21 | +import static org.junit.jupiter.api.Assertions.assertNotEquals; |
| 22 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 23 | + |
| 24 | +import org.junit.jupiter.api.Test; |
| 25 | + |
| 26 | +public class ColumnMetaTest { |
| 27 | + |
| 28 | + @Test |
| 29 | + public void testEqualsAndHashCode() { |
| 30 | + // Create two instances with identical properties |
| 31 | + ColumnMeta column1 = new ColumnMeta(); |
| 32 | + ColumnMeta column2 = new ColumnMeta(); |
| 33 | + |
| 34 | + // Test equality for two newly created instances |
| 35 | + assertTrue(column1.equals(column2)); |
| 36 | + assertEquals(column1.hashCode(), column2.hashCode()); |
| 37 | + |
| 38 | + // Modify some properties of column1 |
| 39 | + column1.setTableName("table1"); |
| 40 | + column1.setColumnName("column1"); |
| 41 | + column1.setDataType(1); |
| 42 | + |
| 43 | + // Test inequality after modifying properties |
| 44 | + assertFalse(column1.equals(column2)); |
| 45 | + assertNotEquals(column1.hashCode(), column2.hashCode()); |
| 46 | + |
| 47 | + // Create a copy of column1 with the same properties |
| 48 | + ColumnMeta column3 = new ColumnMeta(); |
| 49 | + column3.setTableName("table1"); |
| 50 | + column3.setColumnName("column1"); |
| 51 | + column3.setDataType(1); |
| 52 | + |
| 53 | + // Test equality with the copy |
| 54 | + assertTrue(column1.equals(column3)); |
| 55 | + assertEquals(column1.hashCode(), column3.hashCode()); |
| 56 | + |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void testAutoincrement() { |
| 61 | + ColumnMeta column = new ColumnMeta(); |
| 62 | + |
| 63 | + // Test default value |
| 64 | + assertFalse(column.isAutoincrement()); |
| 65 | + |
| 66 | + // Set autoincrement to YES |
| 67 | + column.setIsAutoincrement("YES"); |
| 68 | + assertTrue(column.isAutoincrement()); |
| 69 | + |
| 70 | + // Set autoincrement to NO |
| 71 | + column.setIsAutoincrement("NO"); |
| 72 | + assertFalse(column.isAutoincrement()); |
| 73 | + } |
| 74 | + |
| 75 | + @Test |
| 76 | + public void testGetTableCat() { |
| 77 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 78 | + columnMeta.setTableCat("tableCat"); |
| 79 | + assertEquals(columnMeta.getTableCat(), "tableCat".trim()); |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void testSetGetColumnName() { |
| 84 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 85 | + columnMeta.setColumnName("columnName"); |
| 86 | + assertEquals("columnName".trim(), columnMeta.getColumnName()); |
| 87 | + } |
| 88 | + |
| 89 | + @Test |
| 90 | + public void testSetGetDataType() { |
| 91 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 92 | + columnMeta.setDataType(2); |
| 93 | + assertEquals(2, columnMeta.getDataType()); |
| 94 | + } |
| 95 | + |
| 96 | + @Test |
| 97 | + public void testSetGetDataTypeName() { |
| 98 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 99 | + columnMeta.setDataTypeName("dataTypeName"); |
| 100 | + assertEquals("dataTypeName".trim(), columnMeta.getDataTypeName()); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testSetGetColumnSize() { |
| 105 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 106 | + columnMeta.setColumnSize(2); |
| 107 | + assertEquals(2, columnMeta.getColumnSize()); |
| 108 | + } |
| 109 | + |
| 110 | + @Test |
| 111 | + public void testSetGetDemicalDigits() { |
| 112 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 113 | + columnMeta.setDecimalDigits(2); |
| 114 | + assertEquals(2, columnMeta.getDecimalDigits()); |
| 115 | + } |
| 116 | + |
| 117 | + @Test |
| 118 | + public void testSetGetNumPrecRadix() { |
| 119 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 120 | + columnMeta.setNumPrecRadix(10); |
| 121 | + assertEquals(10, columnMeta.getNumPrecRadix()); |
| 122 | + } |
| 123 | + |
| 124 | + @Test |
| 125 | + public void testSetGetNullAble() { |
| 126 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 127 | + columnMeta.setNullAble(5); |
| 128 | + assertEquals(5, columnMeta.getNullAble()); |
| 129 | + } |
| 130 | + |
| 131 | + @Test |
| 132 | + public void testSetGetRemarks() { |
| 133 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 134 | + columnMeta.setRemarks("remarks"); |
| 135 | + assertEquals("remarks".trim(), columnMeta.getRemarks()); |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void testSetGetColumnDef() { |
| 140 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 141 | + columnMeta.setColumnDef("columnDef"); |
| 142 | + assertEquals("columnDef", columnMeta.getColumnDef()); |
| 143 | + } |
| 144 | + |
| 145 | + @Test |
| 146 | + public void testSetGetSqlDataType() { |
| 147 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 148 | + columnMeta.setSqlDataType(1); |
| 149 | + assertEquals(1, columnMeta.getSqlDataType()); |
| 150 | + } |
| 151 | + |
| 152 | + @Test |
| 153 | + public void testSetGetSqlDatetimeSub() { |
| 154 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 155 | + columnMeta.setSqlDatetimeSub(2); |
| 156 | + assertEquals(2, columnMeta.getSqlDatetimeSub()); |
| 157 | + } |
| 158 | + |
| 159 | + @Test |
| 160 | + public void testSetGetCharOctetLength() { |
| 161 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 162 | + Object charOctetLength = 255; |
| 163 | + columnMeta.setCharOctetLength(charOctetLength); |
| 164 | + assertEquals(charOctetLength, columnMeta.getCharOctetLength()); |
| 165 | + } |
| 166 | + |
| 167 | + @Test |
| 168 | + public void testSetGetOrdinalPosition() { |
| 169 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 170 | + columnMeta.setOrdinalPosition(3); |
| 171 | + assertEquals(3, columnMeta.getOrdinalPosition()); |
| 172 | + } |
| 173 | + |
| 174 | + @Test |
| 175 | + public void testSetGetIsOnUpdate() { |
| 176 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 177 | + columnMeta.setOnUpdate(true); |
| 178 | + assertTrue(columnMeta.isOnUpdate()); |
| 179 | + } |
| 180 | + |
| 181 | + @Test |
| 182 | + public void testSetGetIsCaseSensitive() { |
| 183 | + ColumnMeta columnMeta = new ColumnMeta(); |
| 184 | + columnMeta.setCaseSensitive(true); |
| 185 | + assertTrue(columnMeta.isCaseSensitive()); |
| 186 | + } |
| 187 | + |
| 188 | +} |
0 commit comments