use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.
the class ProjectDeleteServiceTest method when_a_project_is_found_2_events_will_be_triggered_first_project_deleted_second_owner_recalc.
@Test
public void when_a_project_is_found_2_events_will_be_triggered_first_project_deleted_second_owner_recalc() {
/* prepare */
ArgumentCaptor<DomainMessage> captorMessage = ArgumentCaptor.forClass(DomainMessage.class);
Project project1 = new Project();
project1.id = "project1";
User owner1 = mock(User.class);
when(owner1.getName()).thenReturn("owner1");
project1.owner = owner1;
when(projectRepository.findOrFailProject("project1")).thenReturn(project1);
/* execute */
serviceToTest.deleteProject("project1");
/* test */
verify(eventBusService, times(2)).sendAsynchron(captorMessage.capture());
List<DomainMessage> allMessages = captorMessage.getAllValues();
DomainMessage value1 = allMessages.get(0);
assertEquals(MessageID.PROJECT_DELETED, value1.getMessageId());
assertEquals("project1", value1.get(MessageDataKeys.PROJECT_DELETE_DATA).getProjectId());
DomainMessage value2 = allMessages.get(1);
assertEquals(MessageID.REQUEST_USER_ROLE_RECALCULATION, value2.getMessageId());
assertEquals("owner1", value2.get(MessageDataKeys.USER_ID_DATA).getUserId());
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.
the class AdministrationConfigServiceTest method auto_cleanup_configuration_change_does_result_in_auto_cleanup_change_event_with_correct_data.
@Test
void auto_cleanup_configuration_change_does_result_in_auto_cleanup_change_event_with_correct_data() {
/* prepare */
emulateExistingInitialAdministrationConfig();
long days = 42;
AdministrationAutoCleanupConfig autoCleanupConfiguration = new AdministrationAutoCleanupConfig();
when(calculator.calculateCleanupTimeInDays(eq(autoCleanupConfiguration))).thenReturn(days);
/* execute */
serviceToTest.updateAutoCleanupConfiguration(autoCleanupConfiguration);
/* test */
ArgumentCaptor<DomainMessage> captor = ArgumentCaptor.forClass(DomainMessage.class);
verify(domainMessageService).sendAsynchron(captor.capture());
DomainMessage message = captor.getValue();
AdministrationConfigMessage cleanupData = message.get(MessageDataKeys.AUTO_CLEANUP_CONFIG_CHANGE_DATA);
assertNotNull(cleanupData);
assertEquals(days, cleanupData.getAutoCleanupInDays());
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.
the class SignupCreateServiceTest method a_created_signup_sends_event_containing_userid_and_email.
@Test
public void a_created_signup_sends_event_containing_userid_and_email() {
/* prepare */
SignupJsonInput userSelfRegistrationInput = mock(SignupJsonInput.class);
when(userSelfRegistrationInput.getUserId()).thenReturn("schlaubi");
when(userSelfRegistrationInput.getEmailAdress()).thenReturn("schlaubi@schlumpfhausen.de");
/* execute */
serviceToTest.register(userSelfRegistrationInput);
/* test */
ArgumentCaptor<DomainMessage> domainMessageCaptor = ArgumentCaptor.forClass(DomainMessage.class);
verify(mockedEventBusService).sendAsynchron(domainMessageCaptor.capture());
DomainMessage messageSendByService = domainMessageCaptor.getValue();
assertNotNull("no message send!", messageSendByService);
UserMessage signupDataInMessage = messageSendByService.get(MessageDataKeys.USER_SIGNUP_DATA);
assertNotNull("no signup data inside message!", signupDataInMessage);
// check event contains expected data
assertEquals("schlaubi", signupDataInMessage.getUserId());
assertEquals("schlaubi@schlumpfhausen.de", signupDataInMessage.getEmailAdress());
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.
the class AnonymousUserRequestsNewApiTokenServiceTest method when_emailadress_found_a_new_async_event_is_sent_eventbus.
@Test
public void when_emailadress_found_a_new_async_event_is_sent_eventbus() throws Exception {
User user = new User();
user.emailAdress = "user@test.com";
user.name = "testuser";
/* prepare */
when(mockedUserRepository.findByEmailAdress("user@test.com")).thenReturn(Optional.of(user));
/* execute */
serviceToTest.anonymousRequestToGetNewApiTokenForUserMailAdress("user@test.com");
/* test */
ArgumentCaptor<DomainMessage> domainMessageCaptor = ArgumentCaptor.forClass(DomainMessage.class);
verify(mockedEventBusService).sendAsynchron(domainMessageCaptor.capture());
DomainMessage messageSendByService = domainMessageCaptor.getValue();
assertNotNull("no message send!", messageSendByService);
UserMessage refreshApiKeyMessage = messageSendByService.get(MessageDataKeys.USER_ONE_TIME_TOKEN_INFO);
assertNotNull("no refersh api key data inside message!", refreshApiKeyMessage);
// check event contains expected data
// user id not inside
assertNull(refreshApiKeyMessage.getUserId());
assertEquals("user@test.com", refreshApiKeyMessage.getEmailAdress());
}
use of com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage in project sechub by mercedes-benz.
the class SchedulerCancelJobService method sendJobCanceled.
@IsSendingAsyncMessage(MessageID.JOB_CANCELED)
private void sendJobCanceled(ScheduleSecHubJob secHubJob, String ownerEmailAddress) {
DomainMessage request = DomainMessageFactory.createEmptyRequest(MessageID.JOB_CANCELED);
JobMessage message = new JobMessage();
message.setJobUUID(secHubJob.getUUID());
message.setProjectId(secHubJob.getProjectId());
message.setOwner(secHubJob.getOwner());
message.setOwnerEmailAddress(ownerEmailAddress);
request.set(MessageDataKeys.JOB_CANCEL_DATA, message);
eventBus.sendAsynchron(request);
}
Aggregations