|
| 1 | +/* |
| 2 | + * Copyright (c) 2022 Airbyte, Inc., all rights reserved. |
| 3 | + */ |
| 4 | + |
| 5 | +package io.airbyte.integrations.debezium; |
| 6 | + |
| 7 | +import com.google.common.collect.Lists; |
| 8 | +import io.airbyte.protocol.models.AirbyteCatalog; |
| 9 | +import io.airbyte.protocol.models.CatalogHelpers; |
| 10 | +import io.airbyte.protocol.models.ConfiguredAirbyteCatalog; |
| 11 | +import io.airbyte.protocol.models.Field; |
| 12 | +import io.airbyte.protocol.models.JsonSchemaType; |
| 13 | +import io.airbyte.protocol.models.SyncMode; |
| 14 | +import java.util.List; |
| 15 | +import org.junit.jupiter.api.Assertions; |
| 16 | +import org.junit.jupiter.api.Test; |
| 17 | + |
| 18 | +public class AirbyteDebeziumHandlerTest { |
| 19 | + |
| 20 | + @Test |
| 21 | + public void shouldUseCdcTestShouldReturnTrue() { |
| 22 | + final AirbyteCatalog catalog = new AirbyteCatalog().withStreams(List.of( |
| 23 | + CatalogHelpers.createAirbyteStream( |
| 24 | + "MODELS_STREAM_NAME", |
| 25 | + "MODELS_SCHEMA", |
| 26 | + Field.of("COL_ID", JsonSchemaType.NUMBER), |
| 27 | + Field.of("COL_MAKE_ID", JsonSchemaType.NUMBER), |
| 28 | + Field.of("COL_MODEL", JsonSchemaType.STRING)) |
| 29 | + .withSupportedSyncModes(Lists.newArrayList(SyncMode.FULL_REFRESH, SyncMode.INCREMENTAL)) |
| 30 | + .withSourceDefinedPrimaryKey(List.of(List.of("COL_ID"))))); |
| 31 | + final ConfiguredAirbyteCatalog configuredCatalog = CatalogHelpers |
| 32 | + .toDefaultConfiguredCatalog(catalog); |
| 33 | + // set all streams to incremental. |
| 34 | + configuredCatalog.getStreams().forEach(s -> s.setSyncMode(SyncMode.INCREMENTAL)); |
| 35 | + |
| 36 | + Assertions.assertTrue(AirbyteDebeziumHandler.shouldUseCDC(configuredCatalog)); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void shouldUseCdcTestShouldReturnFalse() { |
| 41 | + final AirbyteCatalog catalog = new AirbyteCatalog().withStreams(List.of( |
| 42 | + CatalogHelpers.createAirbyteStream( |
| 43 | + "MODELS_STREAM_NAME", |
| 44 | + "MODELS_SCHEMA", |
| 45 | + Field.of("COL_ID", JsonSchemaType.NUMBER), |
| 46 | + Field.of("COL_MAKE_ID", JsonSchemaType.NUMBER), |
| 47 | + Field.of("COL_MODEL", JsonSchemaType.STRING)) |
| 48 | + .withSupportedSyncModes(Lists.newArrayList(SyncMode.FULL_REFRESH, SyncMode.INCREMENTAL)) |
| 49 | + .withSourceDefinedPrimaryKey(List.of(List.of("COL_ID"))))); |
| 50 | + final ConfiguredAirbyteCatalog configuredCatalog = CatalogHelpers |
| 51 | + .toDefaultConfiguredCatalog(catalog); |
| 52 | + |
| 53 | + Assertions.assertFalse(AirbyteDebeziumHandler.shouldUseCDC(configuredCatalog)); |
| 54 | + } |
| 55 | + |
| 56 | +} |
0 commit comments