Search in sources :

Example 6 with AdministrationAutoCleanupConfig

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

the class ConfigAdministrationRestControllerRestDocTest method restdoc_admin_fetches_auto_cleanup_configuration.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminFetchesAutoCleanupConfiguration.class)
public void restdoc_admin_fetches_auto_cleanup_configuration() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminFetchesAutoCleanupConfigurationUrl();
    Class<? extends Annotation> useCase = UseCaseAdminFetchesAutoCleanupConfiguration.class;
    AdministrationAutoCleanupConfig config = new AdministrationAutoCleanupConfig();
    when(configService.fetchAutoCleanupConfiguration()).thenReturn(config);
    /* execute + test @formatter:off */
    this.mockMvc.perform(get(apiEndpoint).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isOk()).andExpect(content().json(config.toJSON())).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document());
/* @formatter:on */
}
Also used : UseCaseAdminFetchesAutoCleanupConfiguration(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesAutoCleanupConfiguration) AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 7 with AdministrationAutoCleanupConfig

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

the class ConfigAdministrationRestControllerRestDocTest method restdoc_admin_updates_auto_cleanup_configuration.

@Test
@UseCaseRestDoc(useCase = UseCaseAdminUpdatesAutoCleanupConfiguration.class)
public void restdoc_admin_updates_auto_cleanup_configuration() throws Exception {
    /* prepare */
    String apiEndpoint = https(PORT_USED).buildAdminUpdatesAutoCleanupConfigurationUrl();
    Class<? extends Annotation> useCase = UseCaseAdminUpdatesAutoCleanupConfiguration.class;
    AdministrationAutoCleanupConfig config = new AdministrationAutoCleanupConfig();
    /* execute + test @formatter:off */
    this.mockMvc.perform(put(apiEndpoint).content(config.toJSON()).contentType(MediaType.APPLICATION_JSON_VALUE)).andExpect(status().isAccepted()).andDo(defineRestService().with().useCaseData(useCase).tag(RestDocFactory.extractTag(apiEndpoint)).and().document());
/* @formatter:on */
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) UseCaseAdminUpdatesAutoCleanupConfiguration(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminUpdatesAutoCleanupConfiguration) UseCaseRestDoc(com.mercedesbenz.sechub.sharedkernel.usecases.UseCaseRestDoc) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 8 with AdministrationAutoCleanupConfig

use of com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig 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 9 with AdministrationAutoCleanupConfig

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

the class AdministrationConfigServiceTest method a_not_existing_config_is_created_blank_and_then_updated_with_given_auto_cleanup_config.

@Test
void a_not_existing_config_is_created_blank_and_then_updated_with_given_auto_cleanup_config() {
    /* prepare */
    emulateMissingAdministrationConfigCreated();
    AdministrationAutoCleanupConfig newAutoCleanConfiguration = new AdministrationAutoCleanupConfig();
    newAutoCleanConfiguration.getCleanupTime().setAmount(1);
    newAutoCleanConfiguration.getCleanupTime().setUnit(CountableInDaysTimeUnit.MONTH);
    /* execute */
    serviceToTest.updateAutoCleanupConfiguration(newAutoCleanConfiguration);
    /* test */
    verify(repository).findById(0);
    ArgumentCaptor<AdministrationConfig> captor = ArgumentCaptor.forClass(AdministrationConfig.class);
    verify(transactionService, times(2)).saveConfigInOwnTransaction(captor.capture());
    List<AdministrationConfig> storedConfigs = captor.getAllValues();
    assertEquals(2, storedConfigs.size());
    AdministrationConfig firstStored = storedConfigs.get(0);
    AdministrationConfig secondStored = storedConfigs.get(1);
    assertNotNull(firstStored.autoCleanupConfiguration);
    assertNotNull(secondStored.autoCleanupConfiguration);
    assertEquals(newAutoCleanConfiguration.toJSON(), secondStored.autoCleanupConfiguration);
    assertEquals(new AdministrationAutoCleanupConfig().toJSON(), firstStored.autoCleanupConfiguration);
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 10 with AdministrationAutoCleanupConfig

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

the class AdministrationConfigService method fetchAutoCleanupConfiguration.

@UseCaseAdminFetchesAutoCleanupConfiguration(@Step(number = 2, name = "Fetches auto cleanup config", description = "Fetches auto cleanup configuration from database"))
public AdministrationAutoCleanupConfig fetchAutoCleanupConfiguration() {
    String cleanupConfigJson = getOrCreateConfig().autoCleanupConfiguration;
    AdministrationAutoCleanupConfig cleanupConfig = null;
    if (cleanupConfigJson == null) {
        cleanupConfig = new AdministrationAutoCleanupConfig();
    } else {
        cleanupConfig = AdministrationAutoCleanupConfig.fromString(cleanupConfigJson);
    }
    return cleanupConfig;
}
Also used : AdministrationAutoCleanupConfig(com.mercedesbenz.sechub.domain.administration.autocleanup.AdministrationAutoCleanupConfig) UseCaseAdminFetchesAutoCleanupConfiguration(com.mercedesbenz.sechub.sharedkernel.usecases.admin.config.UseCaseAdminFetchesAutoCleanupConfiguration)

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