Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
paullatzelsperger committed Jul 5, 2024
1 parent 26bb69a commit f2f0a11
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,30 @@ void setup(ServiceExtensionContext context) {
}

@Test
void initialize_verifySuperUser(ParticipantContextSeedExtension ext,
void start_verifySuperUser(ParticipantContextSeedExtension ext,
ServiceExtensionContext context) {

when(participantContextService.createParticipantContext(any())).thenReturn(ServiceResult.success("some-key"));

ext.initialize(context);

ext.start();
verify(participantContextService).createParticipantContext(any());
verifyNoMoreInteractions(participantContextService);
}

@Test
void initialize_failsToCreate(ParticipantContextSeedExtension ext, ServiceExtensionContext context) {
void start_failsToCreate(ParticipantContextSeedExtension ext, ServiceExtensionContext context) {

when(participantContextService.createParticipantContext(any()))
.thenReturn(ServiceResult.badRequest("test-message"));
assertThatThrownBy(() -> ext.initialize(context)).isInstanceOf(EdcException.class);
ext.initialize(context);
assertThatThrownBy(ext::start).isInstanceOf(EdcException.class);
verify(participantContextService).createParticipantContext(any());
verifyNoMoreInteractions(participantContextService);
}

@Test
void initialize_withApiKeyOverride(ParticipantContextSeedExtension ext,
void start_withApiKeyOverride(ParticipantContextSeedExtension ext,
ServiceExtensionContext context) {


Expand All @@ -88,14 +90,15 @@ void initialize_withApiKeyOverride(ParticipantContextSeedExtension ext,
.thenReturn(ServiceResult.success(superUserContext().build()));

ext.initialize(context);
ext.start();
verify(participantContextService).createParticipantContext(any());
verify(participantContextService).getParticipantContext(eq("super-user"));
verify(vault).storeSecret(eq("super-user-apikey"), eq(apiKeyOverride));
verifyNoMoreInteractions(participantContextService, vault);
}

@Test
void initialize_withInvalidKeyOverride(ParticipantContextSeedExtension ext,
void start_withInvalidKeyOverride(ParticipantContextSeedExtension ext,
ServiceExtensionContext context) {
when(vault.storeSecret(any(), any())).thenReturn(Result.success());

Expand All @@ -109,6 +112,7 @@ void initialize_withInvalidKeyOverride(ParticipantContextSeedExtension ext,
.thenReturn(ServiceResult.success(superUserContext().build()));

ext.initialize(context);
ext.start();
verify(participantContextService).createParticipantContext(any());
verify(participantContextService).getParticipantContext(eq("super-user"));
verify(vault).storeSecret(eq("super-user-apikey"), eq(apiKeyOverride));
Expand All @@ -117,7 +121,7 @@ void initialize_withInvalidKeyOverride(ParticipantContextSeedExtension ext,
}

@Test
void initialize_whenVaultReturnsFailure(ParticipantContextSeedExtension ext,
void start_whenVaultReturnsFailure(ParticipantContextSeedExtension ext,
ServiceExtensionContext context) {
when(vault.storeSecret(any(), any())).thenReturn(Result.failure("test-failure"));

Expand All @@ -131,6 +135,7 @@ void initialize_whenVaultReturnsFailure(ParticipantContextSeedExtension ext,
.thenReturn(ServiceResult.success(superUserContext().build()));

ext.initialize(context);
ext.start();
verify(participantContextService).createParticipantContext(any());
verify(participantContextService).getParticipantContext(eq("super-user"));
verify(vault).storeSecret(eq("super-user-apikey"), eq(apiKeyOverride));
Expand Down

0 comments on commit f2f0a11

Please sign in to comment.