Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Fix webbackend api (airbytehq#3986)
Browse files Browse the repository at this point in the history
* Fix webbackend api
  • Loading branch information
ChristopheDuong authored Jun 9, 2021
1 parent cb56180 commit 8cc23cf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -321,13 +321,16 @@ protected static OperationUpdate toOperationUpdate(OperationCreateOrUpdate opera
protected static ConnectionCreate toConnectionCreate(WebBackendConnectionCreate webBackendConnectionCreate, List<UUID> 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;
}
Expand All @@ -336,14 +339,14 @@ protected static ConnectionCreate toConnectionCreate(WebBackendConnectionCreate
protected static ConnectionUpdate toConnectionUpdate(WebBackendConnectionUpdate webBackendConnectionUpdate, List<UUID> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -291,9 +296,12 @@ public void testToConnectionCreate() throws IOException {
final List<UUID> 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)
Expand Down Expand Up @@ -344,7 +352,26 @@ public void testToConnectionUpdate() throws IOException {
}

@Test
public void testForCompleteness() {
public void testForConnectionCreateCompleteness() {
final Set<String> handledMethods =
Set.of("name", "namespaceDefinition", "namespaceFormat", "prefix", "sourceId", "destinationId", "operationIds", "syncCatalog", "schedule",
"status");

final Set<String> 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<String> handledMethods =
Set.of("schedule", "connectionId", "syncCatalog", "namespaceDefinition", "namespaceFormat", "prefix", "status", "operationIds");

Expand Down

0 comments on commit 8cc23cf

Please sign in to comment.