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 */
}
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 */
}
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());
}
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);
}
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;
}
Aggregations