Search in sources :

Example 1 with AdministrationAutoCleanupConfig

use of com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig in project sechub by mercedes-benz.

the class AdministrationAutoCleanupDaysCalculatorTest method days_calculated_as_expected.

@CsvSource({ "5,weeks,35", "20,days,20", "1,day,1", "2,months,60", "1,month,30", "1,MONTH,30", "0,MONTH,0", "0,DAY,0" })
@ParameterizedTest
void days_calculated_as_expected(int amount, String unit, long expectedDays) {
    /* prepare */
    String json = "{ 'cleanupTime' : { 'unit':'" + unit + "', 'amount': " + amount + "}" + "}";
    AdministrationAutoCleanupConfig config = AdministrationAutoCleanupConfig.fromString(json);
    /* execute */
    long calculatedDays = calculatorToTest.calculateCleanupTimeInDays(config);
    /* test */
    assertEquals(expectedDays, calculatedDays);
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with AdministrationAutoCleanupConfig

use of com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig in project sechub by mercedes-benz.

the class AdministrationConfigServiceTest method when_calculator_calculates_a_positive_day_count_or_zero_no__exception_is_thrown_and_an_event_sent.

@ParameterizedTest
@CsvSource({ "0", "1", "100", "4711" })
void when_calculator_calculates_a_positive_day_count_or_zero_no__exception_is_thrown_and_an_event_sent(long calculatedDays) {
    /* prepare */
    emulateExistingInitialAdministrationConfig();
    AdministrationAutoCleanupConfig autoCleanupConfiguration = new AdministrationAutoCleanupConfig();
    when(calculator.calculateCleanupTimeInDays(autoCleanupConfiguration)).thenReturn(calculatedDays);
    /* execute */
    serviceToTest.updateAutoCleanupConfiguration(autoCleanupConfiguration);
    /* test */
    verify(domainMessageService).sendAsynchron(any());
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with AdministrationAutoCleanupConfig

use of com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig in project sechub by mercedes-benz.

the class AdministrationConfigServiceTest method an_existing_config_is_updated_with_null_throws_illegal_argument.

@Test
void an_existing_config_is_updated_with_null_throws_illegal_argument() {
    /* prepare */
    emulateExistingInitialAdministrationConfig();
    AdministrationAutoCleanupConfig autoCleanupConfiguration = null;
    /* execute + test */
    assertThrows(IllegalArgumentException.class, () -> serviceToTest.updateAutoCleanupConfiguration(autoCleanupConfiguration));
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with AdministrationAutoCleanupConfig

use of com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig in project sechub by mercedes-benz.

the class AdministrationConfigServiceTest method when_calculator_calculates_an_negative_days_count_a_non_acceptable_exception_is_thrown.

@ParameterizedTest
@CsvSource({ "-1", "-100", "-4711" })
void when_calculator_calculates_an_negative_days_count_a_non_acceptable_exception_is_thrown(long calculatedDays) {
    /* prepare */
    emulateExistingInitialAdministrationConfig();
    AdministrationAutoCleanupConfig autoCleanupConfiguration = new AdministrationAutoCleanupConfig();
    when(calculator.calculateCleanupTimeInDays(autoCleanupConfiguration)).thenReturn(calculatedDays);
    /* execute + test */
    assertThrows(NotAcceptableException.class, () -> serviceToTest.updateAutoCleanupConfiguration(autoCleanupConfiguration));
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) CsvSource(org.junit.jupiter.params.provider.CsvSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with AdministrationAutoCleanupConfig

use of com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig in project sechub by mercedes-benz.

the class AdministrationConfigServiceTest method an_existing_config_is_updated_with_given_auto_cleanup_config.

@Test
void an_existing_config_is_updated_with_given_auto_cleanup_config() {
    /* prepare */
    emulateExistingInitialAdministrationConfig();
    AdministrationAutoCleanupConfig autoCleanupConfiguration = new AdministrationAutoCleanupConfig();
    /* execute */
    serviceToTest.updateAutoCleanupConfiguration(autoCleanupConfiguration);
    /* test */
    verify(repository).findById(0);
    ArgumentCaptor<AdministrationConfig> captor = ArgumentCaptor.forClass(AdministrationConfig.class);
    verify(transactionService).saveConfigInOwnTransaction(captor.capture());
    AdministrationConfig storedConfig = captor.getValue();
    assertEquals(storedConfig.autoCleanupConfiguration, autoCleanupConfiguration.toJSON());
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

AdministrationAutoCleanupConfig (com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig)10 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)7 Test (org.junit.jupiter.api.Test)4 CsvSource (org.junit.jupiter.params.provider.CsvSource)3 UseCaseRestDoc (com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc)2 UseCaseAdminFetchesAutoCleanupConfiguration (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesAutoCleanupConfiguration)2 Test (org.junit.Test)2 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)2 AdministrationConfigMessage (com.mercedesbenz.sechub.sharedkernel.messaging.AdministrationConfigMessage)1 DomainMessage (com.mercedesbenz.sechub.sharedkernel.messaging.DomainMessage)1 UseCaseAdminUpdatesAutoCleanupConfiguration (com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUpdatesAutoCleanupConfiguration)1