Skip to content

Commit

Permalink
DBZ-5317 Fix ValidateSqlSeverDatabasesIT to test against correct API …
Browse files Browse the repository at this point in the history
…endpoint
  • Loading branch information
ani-sha committed Aug 4, 2022
1 parent 862f5d3 commit 77772a5
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
Expand Up @@ -5,22 +5,19 @@
*/
package io.debezium.configserver;

import com.fasterxml.jackson.databind.node.ObjectNode;
import io.debezium.configserver.rest.ConnectorURIs;
import io.debezium.configserver.util.Infrastructure;
import io.debezium.configserver.util.SqlServerInfrastructureTestProfile;
import io.debezium.testing.testcontainers.ConnectorConfigurationTestingHelper;
import io.debezium.testing.testcontainers.Connector;
import io.debezium.testing.testcontainers.ConnectorConfiguration;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.http.ContentType;

import org.junit.jupiter.api.Test;

import java.util.Map;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.hasItems;

@QuarkusTest
Expand All @@ -29,24 +26,19 @@ public class ValidateSqlSeverDatabasesIT {

@Test
public void testMultipleDatabases() {
ObjectNode config = ConnectorConfigurationTestingHelper.getConfig(
Infrastructure.getSqlServerConnectorConfiguration(1)
.with("database.hostname", "localhost")
.with("database.port", Infrastructure.getSqlServerContainer().getMappedPort(1433))
.with("database.names", "testdb,testdb2")
);
ConnectorConfiguration config = Infrastructure.getSqlServerConnectorConfiguration(1)
.with("database.names", "testDB,testDB2");

Connector connector = Connector.from("custom-sqlserver-connector", config);

given().when().contentType(ContentType.JSON).accept(ContentType.JSON).body(config.toString())
.post(ConnectorURIs.API_PREFIX + ConnectorURIs.FILTERS_VALIDATION_ENDPOINT, "sqlserver")
given().when().contentType(ContentType.JSON).accept(ContentType.JSON).body(connector.toJson())
.post(ConnectorURIs.API_PREFIX + ConnectorURIs.CREATE_CONNECTOR_ENDPOINT, 1, "sqlserver")
.then().log().all()
.statusCode(200)
.assertThat().body("status", equalTo("VALID"))
.body("propertyValidationResults.size()", is(0))
.body("matchedCollections.size()", is(2))
.body("matchedCollections",
hasItems(
Map.of("names", "testdb"),
Map.of("names", "testdb2")
));
.assertThat().body("name", equalTo("custom-sqlserver-connector"))
.and().rootPath("config")
.body("['connector.class']", equalTo("io.debezium.connector.sqlserver.SqlServerConnector"))
.body("['database.names']", equalTo("testDB,testDB2"))
.and().body("['database.hostname']", equalTo(Infrastructure.getSqlServerContainer().getContainerInfo().getConfig().getHostName()));
}
}
18 changes: 18 additions & 0 deletions backend/src/test/resources/initialize-sqlserver-database.sql
@@ -1,5 +1,23 @@
CREATE DATABASE testDB
CREATE DATABASE testDB2
USE testDB2

EXEC sys.sp_cdc_enable_db

CREATE SCHEMA inventory

CREATE TABLE inventory.products (id INTEGER IDENTITY(101,1) NOT NULL PRIMARY KEY, name VARCHAR(255) NOT NULL, description VARCHAR(512), weight FLOAT)
INSERT INTO inventory.products(name,description,weight) VALUES ('scooter','Small 2-wheel scooter',3.14)
INSERT INTO inventory.products(name,description,weight) VALUES ('car battery','12V car battery',8.1)
INSERT INTO inventory.products(name,description,weight) VALUES ('12-pack drill bits','12-pack of drill bits with sizes ranging from #40 to #3',0.8)
INSERT INTO inventory.products(name,description,weight) VALUES ('hammer','12oz carpenter''s hammer',0.75)
INSERT INTO inventory.products(name,description,weight) VALUES ('hammer','14oz carpenter''s hammer',0.875)
INSERT INTO inventory.products(name,description,weight) VALUES ('hammer','16oz carpenter''s hammer',1.0)
INSERT INTO inventory.products(name,description,weight) VALUES ('rocks','box of assorted rocks',5.3)
INSERT INTO inventory.products(name,description,weight) VALUES ('jacket','water resistent black wind breaker',0.1)
INSERT INTO inventory.products(name,description,weight) VALUES ('spare tire','24 inch spare tire',22.2)
EXEC sys.sp_cdc_enable_table @source_schema = 'inventory', @source_name = 'products', @role_name = NULL, @supports_net_changes = 0

USE testDB

EXEC sys.sp_cdc_enable_db
Expand Down

0 comments on commit 77772a5

Please sign in to comment.