From 8cc23cfd3338c682300e8a1489a7020038980e5e Mon Sep 17 00:00:00 2001 From: Christophe Duong Date: Wed, 9 Jun 2021 12:12:07 +0200 Subject: [PATCH] Fix webbackend api (#3986) * Fix webbackend api --- .../WebBackendConnectionsHandler.java | 11 ++++--- .../WebBackendConnectionsHandlerTest.java | 29 ++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java b/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java index 5ebb160dc3bb..10e2949f37c6 100644 --- a/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java +++ b/airbyte-server/src/main/java/io/airbyte/server/handlers/WebBackendConnectionsHandler.java @@ -321,13 +321,16 @@ protected static OperationUpdate toOperationUpdate(OperationCreateOrUpdate opera protected static ConnectionCreate toConnectionCreate(WebBackendConnectionCreate webBackendConnectionCreate, List operationIds) { ConnectionCreate connectionCreate = new ConnectionCreate(); + connectionCreate.name(webBackendConnectionCreate.getName()); connectionCreate.namespaceDefinition(webBackendConnectionCreate.getNamespaceDefinition()); connectionCreate.namespaceFormat(webBackendConnectionCreate.getNamespaceFormat()); connectionCreate.prefix(webBackendConnectionCreate.getPrefix()); + connectionCreate.sourceId(webBackendConnectionCreate.getSourceId()); + connectionCreate.destinationId(webBackendConnectionCreate.getDestinationId()); + connectionCreate.operationIds(operationIds); + connectionCreate.syncCatalog(webBackendConnectionCreate.getSyncCatalog()); connectionCreate.schedule(webBackendConnectionCreate.getSchedule()); connectionCreate.status(webBackendConnectionCreate.getStatus()); - connectionCreate.syncCatalog(webBackendConnectionCreate.getSyncCatalog()); - connectionCreate.operationIds(operationIds); return connectionCreate; } @@ -336,14 +339,14 @@ protected static ConnectionCreate toConnectionCreate(WebBackendConnectionCreate protected static ConnectionUpdate toConnectionUpdate(WebBackendConnectionUpdate webBackendConnectionUpdate, List operationIds) { ConnectionUpdate connectionUpdate = new ConnectionUpdate(); + connectionUpdate.connectionId(webBackendConnectionUpdate.getConnectionId()); connectionUpdate.namespaceDefinition(webBackendConnectionUpdate.getNamespaceDefinition()); connectionUpdate.namespaceFormat(webBackendConnectionUpdate.getNamespaceFormat()); connectionUpdate.prefix(webBackendConnectionUpdate.getPrefix()); - connectionUpdate.connectionId(webBackendConnectionUpdate.getConnectionId()); connectionUpdate.operationIds(operationIds); + connectionUpdate.syncCatalog(webBackendConnectionUpdate.getSyncCatalog()); connectionUpdate.schedule(webBackendConnectionUpdate.getSchedule()); connectionUpdate.status(webBackendConnectionUpdate.getStatus()); - connectionUpdate.syncCatalog(webBackendConnectionUpdate.getSyncCatalog()); return connectionUpdate; } diff --git a/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java b/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java index 80316fd59227..2113b4c64609 100644 --- a/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java +++ b/airbyte-server/src/test/java/io/airbyte/server/handlers/WebBackendConnectionsHandlerTest.java @@ -278,11 +278,16 @@ public void testToConnectionCreate() throws IOException { final ConnectionSchedule schedule = new ConnectionSchedule().units(1L).timeUnit(TimeUnitEnum.MINUTES); + final UUID newSourceId = UUID.randomUUID(); + final UUID newDestinationId = UUID.randomUUID(); final UUID newOperationId = UUID.randomUUID(); final WebBackendConnectionCreate input = new WebBackendConnectionCreate() + .name("testConnectionCreate") .namespaceDefinition(Enums.convertTo(standardSync.getNamespaceDefinition(), NamespaceDefinitionType.class)) .namespaceFormat(standardSync.getNamespaceFormat()) .prefix(standardSync.getPrefix()) + .sourceId(newSourceId) + .destinationId(newDestinationId) .operationIds(List.of(newOperationId)) .status(ConnectionStatus.INACTIVE) .schedule(schedule) @@ -291,9 +296,12 @@ public void testToConnectionCreate() throws IOException { final List operationIds = List.of(newOperationId); final ConnectionCreate expected = new ConnectionCreate() + .name("testConnectionCreate") .namespaceDefinition(Enums.convertTo(standardSync.getNamespaceDefinition(), NamespaceDefinitionType.class)) .namespaceFormat(standardSync.getNamespaceFormat()) .prefix(standardSync.getPrefix()) + .sourceId(newSourceId) + .destinationId(newDestinationId) .operationIds(operationIds) .status(ConnectionStatus.INACTIVE) .schedule(schedule) @@ -344,7 +352,26 @@ public void testToConnectionUpdate() throws IOException { } @Test - public void testForCompleteness() { + public void testForConnectionCreateCompleteness() { + final Set handledMethods = + Set.of("name", "namespaceDefinition", "namespaceFormat", "prefix", "sourceId", "destinationId", "operationIds", "syncCatalog", "schedule", + "status"); + + final Set methods = Arrays.stream(ConnectionCreate.class.getMethods()) + .filter(method -> method.getReturnType() == ConnectionCreate.class) + .map(Method::getName) + .collect(Collectors.toSet()); + + final String message = + "If this test is failing, it means you added a field to ConnectionCreate!\nCongratulations, but you're not done yet...\n" + + "\tYou should update WebBackendConnectionsHandler::toConnectionCreate\n" + + "\tand ensure that the field is tested in WebBackendConnectionsHandlerTest::testToConnectionCreate\n" + + "Then you can add the field name here to make this test pass. Cheers!"; + assertEquals(handledMethods, methods, message); + } + + @Test + public void testForConnectionUpdateCompleteness() { final Set handledMethods = Set.of("schedule", "connectionId", "syncCatalog", "namespaceDefinition", "namespaceFormat", "prefix", "status", "operationIds");