31
31
import io .airbyte .api .model .generated .PrivateDestinationDefinitionReadList ;
32
32
import io .airbyte .api .model .generated .ReleaseStage ;
33
33
import io .airbyte .api .model .generated .SupportLevel ;
34
+ import io .airbyte .api .model .generated .WorkspaceIdActorDefinitionRequestBody ;
34
35
import io .airbyte .api .model .generated .WorkspaceIdRequestBody ;
35
36
import io .airbyte .api .problems .throwable .generated .BadRequestProblem ;
36
37
import io .airbyte .commons .entitlements .Entitlement ;
@@ -308,7 +309,7 @@ void testListDestinationDefinitionsForWorkspace() throws IOException, URISyntaxE
308
309
.supportsDataActivation (destinationDefinitionVersion .getSupportsDataActivation ());
309
310
310
311
final DestinationDefinitionReadList actualDestinationDefinitionReadList = destinationDefinitionsHandler
311
- .listDestinationDefinitionsForWorkspace (new WorkspaceIdRequestBody ().workspaceId (workspaceId ));
312
+ .listDestinationDefinitionsForWorkspace (new WorkspaceIdActorDefinitionRequestBody ().workspaceId (workspaceId ));
312
313
313
314
assertEquals (
314
315
List .of (expectedDestinationDefinitionRead1 ),
@@ -334,7 +335,7 @@ void testListDestinationDefinitionsForWorkspaceWithUnentitledConnectors() throws
334
335
.thenReturn (Map .of (destinationDefinitionVersion .getActorDefinitionId (), destinationDefinitionVersion ));
335
336
336
337
final DestinationDefinitionReadList actualDestinationDefinitionReadList = destinationDefinitionsHandler
337
- .listDestinationDefinitionsForWorkspace (new WorkspaceIdRequestBody ().workspaceId (workspaceId ));
338
+ .listDestinationDefinitionsForWorkspace (new WorkspaceIdActorDefinitionRequestBody ().workspaceId (workspaceId ));
338
339
339
340
final List <UUID > expectedIds =
340
341
List .of (destinationDefinition .getDestinationDefinitionId ());
@@ -366,7 +367,7 @@ void testListDestinationDefinitionsForWorkspaceWithHiddenConnectors() throws IOE
366
367
.thenReturn (Map .of (destinationDefinitionVersion .getActorDefinitionId (), destinationDefinitionVersion ));
367
368
368
369
final DestinationDefinitionReadList actualDestinationDefinitionReadList = destinationDefinitionsHandler
369
- .listDestinationDefinitionsForWorkspace (new WorkspaceIdRequestBody ().workspaceId (workspaceId ));
370
+ .listDestinationDefinitionsForWorkspace (new WorkspaceIdActorDefinitionRequestBody ().workspaceId (workspaceId ));
370
371
371
372
final List <UUID > expectedIds =
372
373
List .of (destinationDefinition .getDestinationDefinitionId ());
@@ -376,6 +377,76 @@ void testListDestinationDefinitionsForWorkspaceWithHiddenConnectors() throws IOE
376
377
.map (DestinationDefinitionRead ::getDestinationDefinitionId ).toList ()));
377
378
}
378
379
380
+ @ Test
381
+ @ DisplayName ("listDestinationDefinitionsUsedByWorkspace should return the right list" )
382
+ void testListDestinationDefinitionsUsedByWorkspace () throws IOException , URISyntaxException , ConfigNotFoundException , JsonValidationException {
383
+ final StandardDestinationDefinition usedDestinationDefinition = generateDestinationDefinition ();
384
+ final ActorDefinitionVersion usedDestinationDefinitionVersion = generateVersionFromDestinationDefinition (usedDestinationDefinition );
385
+
386
+ when (destinationService .listDestinationDefinitionsForWorkspace (workspaceId , false )).thenReturn (List .of (usedDestinationDefinition ));
387
+ when (actorDefinitionVersionHelper .getDestinationVersions (List .of (usedDestinationDefinition ), workspaceId ))
388
+ .thenReturn (Map .of (usedDestinationDefinitionVersion .getActorDefinitionId (), usedDestinationDefinitionVersion ));
389
+
390
+ final DestinationDefinitionReadList actualDestinationDefinitionReadList = destinationDefinitionsHandler
391
+ .listDestinationDefinitionsForWorkspace (new WorkspaceIdActorDefinitionRequestBody ().workspaceId (workspaceId ).filterByUsed (true ));
392
+
393
+ final List <UUID > expectedIds =
394
+ List .of (usedDestinationDefinition .getDestinationDefinitionId ());
395
+
396
+ assertEquals (expectedIds .size (), actualDestinationDefinitionReadList .getDestinationDefinitions ().size ());
397
+ assertTrue (expectedIds .containsAll (actualDestinationDefinitionReadList .getDestinationDefinitions ().stream ()
398
+ .map (DestinationDefinitionRead ::getDestinationDefinitionId ).toList ()));
399
+ }
400
+
401
+ @ Test
402
+ @ DisplayName ("listDestinationDefinitionsUsedByWorkspace should return all definitions when filterByUsed is false" )
403
+ void testListDestinationDefinitionsUsedByWorkspaceWithFilterByUsedFalse () throws IOException , JsonValidationException , ConfigNotFoundException {
404
+ final StandardDestinationDefinition destinationDefinition2 = generateDestinationDefinition ();
405
+ final ActorDefinitionVersion destinationDefinitionVersion2 = generateVersionFromDestinationDefinition (destinationDefinition2 );
406
+
407
+ when (featureFlagClient .boolVariation (eq (HideActorDefinitionFromList .INSTANCE ), any ())).thenReturn (false );
408
+ when (destinationService .listPublicDestinationDefinitions (false )).thenReturn (List .of (destinationDefinition ));
409
+ when (destinationService .listGrantedDestinationDefinitions (workspaceId , false )).thenReturn (List .of (destinationDefinition2 ));
410
+ when (actorDefinitionVersionHelper .getDestinationVersions (List .of (destinationDefinition , destinationDefinition2 ), workspaceId ))
411
+ .thenReturn (
412
+ Map .of (
413
+ destinationDefinitionVersion .getActorDefinitionId (), destinationDefinitionVersion ,
414
+ destinationDefinitionVersion2 .getActorDefinitionId (), destinationDefinitionVersion2 ));
415
+ when (workspaceService .getStandardWorkspaceNoSecrets (workspaceId , true )).thenReturn (mock (StandardWorkspace .class ));
416
+ when (licenseEntitlementChecker .checkEntitlements (any (), eq (Entitlement .DESTINATION_CONNECTOR ),
417
+ eq (List .of (destinationDefinition .getDestinationDefinitionId ()))))
418
+ .thenReturn (Map .of (destinationDefinition .getDestinationDefinitionId (), true ));
419
+
420
+ final DestinationDefinitionReadList actualDestinationDefinitionReadList = destinationDefinitionsHandler
421
+ .listDestinationDefinitionsForWorkspace (new WorkspaceIdActorDefinitionRequestBody ().workspaceId (workspaceId ).filterByUsed (false ));
422
+
423
+ final List <UUID > expectedIds = List .of (destinationDefinition .getDestinationDefinitionId (), destinationDefinition2 .getDestinationDefinitionId ());
424
+ assertEquals (expectedIds .size (), actualDestinationDefinitionReadList .getDestinationDefinitions ().size ());
425
+ assertTrue (expectedIds .containsAll (actualDestinationDefinitionReadList .getDestinationDefinitions ().stream ()
426
+ .map (DestinationDefinitionRead ::getDestinationDefinitionId )
427
+ .toList ()));
428
+ }
429
+
430
+ @ Test
431
+ @ DisplayName ("listDestinationDefinitionsUsedByWorkspace should return only used definitions when filterByUsed is true" )
432
+ void testListDestinationDefinitionsUsedByWorkspaceWithFilterByUsedTrue () throws IOException , ConfigNotFoundException , JsonValidationException {
433
+ final StandardDestinationDefinition usedDestinationDefinition = generateDestinationDefinition ();
434
+ final ActorDefinitionVersion usedDestinationDefinitionVersion = generateVersionFromDestinationDefinition (usedDestinationDefinition );
435
+
436
+ when (destinationService .listDestinationDefinitionsForWorkspace (workspaceId , false )).thenReturn (List .of (usedDestinationDefinition ));
437
+ when (actorDefinitionVersionHelper .getDestinationVersions (List .of (usedDestinationDefinition ), workspaceId ))
438
+ .thenReturn (Map .of (usedDestinationDefinitionVersion .getActorDefinitionId (), usedDestinationDefinitionVersion ));
439
+
440
+ final DestinationDefinitionReadList actualDestinationDefinitionReadList = destinationDefinitionsHandler
441
+ .listDestinationDefinitionsForWorkspace (new WorkspaceIdActorDefinitionRequestBody ().workspaceId (workspaceId ).filterByUsed (true ));
442
+
443
+ final List <UUID > expectedIds = List .of (usedDestinationDefinition .getDestinationDefinitionId ());
444
+ assertEquals (expectedIds .size (), actualDestinationDefinitionReadList .getDestinationDefinitions ().size ());
445
+ assertTrue (expectedIds .containsAll (actualDestinationDefinitionReadList .getDestinationDefinitions ().stream ()
446
+ .map (DestinationDefinitionRead ::getDestinationDefinitionId )
447
+ .toList ()));
448
+ }
449
+
379
450
@ Test
380
451
@ DisplayName ("listPrivateDestinationDefinitions should return the right list" )
381
452
void testListPrivateDestinationDefinitions () throws IOException , URISyntaxException {
0 commit comments