/components/camel-debezium-mongodb/src/test/java/org/apache/camel/component/debezium/configuration/MongodbConnectorEmbeddedDebeziumConfigurationTest.java

https://github.com/apache/camel · Java · 91 lines · 60 code · 15 blank · 16 comment · 0 complexity · 39a8dc32dbf738747711885bfb8a5c50 MD5 · raw file

  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.camel.component.debezium.configuration;
  18. import io.debezium.config.CommonConnectorConfig;
  19. import io.debezium.config.Configuration;
  20. import io.debezium.connector.mongodb.MongoDbConnector;
  21. import io.debezium.connector.mongodb.MongoDbConnectorConfig;
  22. import io.debezium.embedded.EmbeddedEngine;
  23. import org.apache.camel.component.debezium.DebeziumConstants;
  24. import org.junit.jupiter.api.Test;
  25. import static org.junit.jupiter.api.Assertions.assertEquals;
  26. import static org.junit.jupiter.api.Assertions.assertFalse;
  27. import static org.junit.jupiter.api.Assertions.assertTrue;
  28. public class MongodbConnectorEmbeddedDebeziumConfigurationTest {
  29. @Test
  30. void testIfCreatesConfig() {
  31. final MongoDbConnectorEmbeddedDebeziumConfiguration configuration = new MongoDbConnectorEmbeddedDebeziumConfiguration();
  32. configuration.setName("test_config");
  33. configuration.setMongodbUser("test_user");
  34. configuration.setMaxQueueSize(1212);
  35. final Configuration dbzConfigurations = configuration.createDebeziumConfiguration();
  36. assertEquals("test_config", dbzConfigurations.getString(EmbeddedEngine.ENGINE_NAME));
  37. assertEquals("test_user", dbzConfigurations.getString(MongoDbConnectorConfig.USER));
  38. assertEquals(1212, dbzConfigurations.getInteger(CommonConnectorConfig.MAX_QUEUE_SIZE));
  39. assertEquals(MongoDbConnector.class.getName(), dbzConfigurations.getString(EmbeddedEngine.CONNECTOR_CLASS));
  40. assertEquals(DebeziumConstants.DEFAULT_OFFSET_STORAGE,
  41. dbzConfigurations.getString(EmbeddedEngine.OFFSET_STORAGE));
  42. }
  43. @Test
  44. void testIfValidatesConfigurationCorrectly() {
  45. final MongoDbConnectorEmbeddedDebeziumConfiguration configuration = new MongoDbConnectorEmbeddedDebeziumConfiguration();
  46. configuration.setName("test_config");
  47. configuration.setMongodbUser("test_db");
  48. configuration.setMongodbName("test_server");
  49. configuration.setOffsetStorageFileName("/offset/file");
  50. configuration.setDatabaseHistoryFileFilename("/database_history/file");
  51. assertFalse(configuration.validateConfiguration().isValid());
  52. configuration.setMongodbHosts("localhost");
  53. configuration.setMongodbPassword("test_pwd");
  54. assertTrue(configuration.validateConfiguration().isValid());
  55. }
  56. @Test
  57. void testValidateConfigurationsForAllRequiredFields() {
  58. final MongoDbConnectorEmbeddedDebeziumConfiguration configuration = new MongoDbConnectorEmbeddedDebeziumConfiguration();
  59. configuration.setName("test_config");
  60. configuration.setMongodbUser("test_db");
  61. configuration.setMongodbHosts("localhost");
  62. configuration.setMongodbPassword("test_pwd");
  63. configuration.setMongodbName("test_server");
  64. configuration.setOffsetStorageFileName("/offset/file");
  65. configuration.setDatabaseHistoryFileFilename("/database_history/file");
  66. final ConfigurationValidation validation = configuration.validateConfiguration();
  67. assertTrue(validation.isValid());
  68. assertEquals("test_config", configuration.getName());
  69. assertEquals("test_db", configuration.getMongodbUser());
  70. assertEquals("localhost", configuration.getMongodbHosts());
  71. assertEquals("test_pwd", configuration.getMongodbPassword());
  72. assertEquals("test_server", configuration.getMongodbName());
  73. assertEquals("/offset/file", configuration.getOffsetStorageFileName());
  74. assertEquals("/database_history/file", configuration.getDatabaseHistoryFileFilename());
  75. }
  76. }