Search in sources :

Example 46 with DomainMessage

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());
}
Also used : User(com.mercedesbenz.sechub.domain.administration.user.User) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 47 with DomainMessage

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());
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) AdministrationConfigMessage(com.mercedesbenz.sechub.sharedkernel.messaging.AdministrationConfigMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with DomainMessage

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());
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 49 with DomainMessage

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());
}
Also used : UserMessage(com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) Test(org.junit.Test)

Example 50 with DomainMessage

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);
}
Also used : JobMessage(com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage) DomainMessage(com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage) IsSendingAsyncMessage(com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)

Aggregations

DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)69 IsSendingAsyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingAsyncMessage)31 UserMessage (com.mercedesbenz.sechub.sharedkernel.messaging.UserMessage)21 Test (org.junit.Test)18 Test (org.junit.jupiter.api.Test)13 ProjectMessage (com.mercedesbenz.sechub.sharedkernel.messaging.ProjectMessage)10 DomainMessageSynchronousResult (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessageSynchronousResult)8 JobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.JobMessage)6 AdministrationConfigMessage (com.mercedesbenz.sechub.sharedkernel.messaging.AdministrationConfigMessage)5 BatchJobMessage (com.mercedesbenz.sechub.sharedkernel.messaging.BatchJobMessage)4 SecHubConfiguration (com.mercedesbenz.sechub.sharedkernel.configuration.SecHubConfiguration)3 IsSendingSyncMessage (com.mercedesbenz.sechub.sharedkernel.messaging.IsSendingSyncMessage)3 UUID (java.util.UUID)3 ScheduleSecHubJob (com.mercedesbenz.sechub.domain.schedule.job.ScheduleSecHubJob)2 SecHubExecutionException (com.mercedesbenz.sechub.sharedkernel.execution.SecHubExecutionException)2 SecHubRuntimeException (com.mercedesbenz.sechub.commons.model.SecHubRuntimeException)1 AdministrationAutoCleanupConfig (com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig)1 User (com.mercedesbenz.sechub.domain.administration.user.User)1 ScanMockData (com.mercedesbenz.sechub.domain.scan.project.ScanMockData)1 ScanProjectConfig (com.mercedesbenz.sechub.domain.scan.project.ScanProjectConfig)1