From a797041e5d0365271a499e3e2bd210cbe3e94d33 Mon Sep 17 00:00:00 2001 From: Dongyeon Lee Date: Thu, 5 Sep 2024 00:00:52 +0900 Subject: [PATCH] [Improve][Test][Connector-V2][MongoDB] Add few test cases for BsonToRowDataConverters (#7579) --- .../serde/BsonToRowDataConvertersTest.java | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 seatunnel-connectors-v2/connector-mongodb/src/test/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConvertersTest.java diff --git a/seatunnel-connectors-v2/connector-mongodb/src/test/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConvertersTest.java b/seatunnel-connectors-v2/connector-mongodb/src/test/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConvertersTest.java new file mode 100644 index 00000000000..b47769c0aca --- /dev/null +++ b/seatunnel-connectors-v2/connector-mongodb/src/test/java/org/apache/seatunnel/connectors/seatunnel/mongodb/serde/BsonToRowDataConvertersTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.seatunnel.connectors.seatunnel.mongodb.serde; + +import org.apache.seatunnel.api.table.type.BasicType; + +import org.bson.BsonDouble; +import org.bson.BsonInt32; +import org.bson.BsonInt64; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class BsonToRowDataConvertersTest { + private final BsonToRowDataConverters converterFactory = new BsonToRowDataConverters(); + + @Test + public void testConvertAnyNumberToDouble() { + // It covered #6997 + BsonToRowDataConverters.BsonToRowDataConverter converter = + converterFactory.createConverter(BasicType.DOUBLE_TYPE); + + Assertions.assertEquals(1.0d, converter.convert(new BsonInt32(1))); + Assertions.assertEquals(1.0d, converter.convert(new BsonInt64(1L))); + + Assertions.assertEquals(4.0d, converter.convert(new BsonDouble(4.0d))); + Assertions.assertEquals(4.4d, converter.convert(new BsonDouble(4.4d))); + } + + @Test + public void testConvertBsonIntToBigInt() { + // It covered #7567 + BsonToRowDataConverters.BsonToRowDataConverter converter = + converterFactory.createConverter(BasicType.LONG_TYPE); + + Assertions.assertEquals(123456L, converter.convert(new BsonInt32(123456))); + + Assertions.assertEquals( + (long) Integer.MAX_VALUE, converter.convert(new BsonInt64(Integer.MAX_VALUE))); + } +}