|
| 1 | + |
| 2 | +/* |
| 3 | + * Copyright © 2024 Cask Data, Inc. |
| 4 | + * |
| 5 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 6 | + * use this file except in compliance with the License. You may obtain a copy of |
| 7 | + * 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, WITHOUT |
| 13 | + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 14 | + * License for the specific language governing permissions and limitations under |
| 15 | + * the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package io.cdap.plugin.mysql; |
| 19 | + |
| 20 | +import org.junit.Test; |
| 21 | + |
| 22 | +import java.sql.Types; |
| 23 | +import java.util.HashMap; |
| 24 | +import java.util.Map; |
| 25 | + |
| 26 | +import static org.junit.Assert.assertFalse; |
| 27 | +import static org.junit.Assert.assertTrue; |
| 28 | + |
| 29 | +public class MysqlUtilUnitTest { |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testIsZeroDateTimeToNull() { |
| 33 | + Map<String, String> connArgsMap = new HashMap<>(1); |
| 34 | + |
| 35 | + connArgsMap.put("zeroDateTimeBehavior", ""); |
| 36 | + assertFalse(MysqlUtil.isZeroDateTimeToNull(connArgsMap)); |
| 37 | + |
| 38 | + connArgsMap.put("zeroDateTimeBehavior", "ROUND"); |
| 39 | + assertFalse(MysqlUtil.isZeroDateTimeToNull(connArgsMap)); |
| 40 | + |
| 41 | + connArgsMap.put("zeroDateTimeBehavior", "CONVERT_TO_NULL"); |
| 42 | + assertTrue(MysqlUtil.isZeroDateTimeToNull(connArgsMap)); |
| 43 | + |
| 44 | + connArgsMap.put("zeroDateTimeBehavior", "convertToNull"); |
| 45 | + assertTrue(MysqlUtil.isZeroDateTimeToNull(connArgsMap)); |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testIsDateTimeLikeType() { |
| 50 | + int dateType = Types.DATE; |
| 51 | + int timestampType = Types.TIMESTAMP; |
| 52 | + int timestampWithTimezoneType = Types.TIMESTAMP_WITH_TIMEZONE; |
| 53 | + int timeType = Types.TIME; |
| 54 | + int stringType = Types.VARCHAR; |
| 55 | + |
| 56 | + assertTrue(MysqlUtil.isDateTimeLikeType(dateType)); |
| 57 | + assertTrue(MysqlUtil.isDateTimeLikeType(timestampType)); |
| 58 | + assertTrue(MysqlUtil.isDateTimeLikeType(timestampWithTimezoneType)); |
| 59 | + assertFalse(MysqlUtil.isDateTimeLikeType(timeType)); |
| 60 | + assertFalse(MysqlUtil.isDateTimeLikeType(stringType)); |
| 61 | + } |
| 62 | +} |
0 commit comments