Search in sources :

Example 11 with NonProxyHostConfigurationEntity

use of com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity in project hub-alert by blackducksoftware.

the class ProxyConfigurationModelSaveActionsTest method updateTest.

@Test
void updateTest() {
    AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(settingsProxyConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(settingsProxyConfigurationRepository.existsByName(Mockito.anyString())).thenAnswer(invocation -> savedEntity.get() != null);
    Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
        for (NonProxyHostConfigurationEntity entity : iterable) {
            savedNonProxyHostEntity.set(entity);
        }
        return List.of(savedNonProxyHostEntity.get());
    });
    SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
    ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
    String newHost = "updatedHost";
    String newPort = "1234";
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_HOST, newHost);
    updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_PORT, newPort);
    saveActions.updateConcreteModel(configurationModel);
    SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(newHost, actualEntity.getHost());
    assertEquals(Integer.valueOf(newPort), actualEntity.getPort());
    assertEquals(TEST_PROXY_USERNAME, actualEntity.getUsername());
    assertEquals(TEST_PROXY_PASSWORD, encryptionUtility.decrypt(actualEntity.getPassword()));
    NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
    assertNotNull(actualNonProxyHosts);
    assertEquals(TEST_PROXY_NON_PROXY_HOST, actualNonProxyHosts.getHostnamePattern());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 12 with NonProxyHostConfigurationEntity

use of com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity in project blackduck-alert by blackducksoftware.

the class SettingsProxyConfigAccessor method createConfiguration.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public SettingsProxyModel createConfiguration(SettingsProxyModel configuration) throws AlertConfigurationException {
    if (doesConfigurationExist()) {
        throw new AlertConfigurationException("A proxy config already exists.");
    }
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    UUID configurationId = UUID.randomUUID();
    configuration.setId(configurationId.toString());
    SettingsProxyConfigurationEntity configurationToSave = toEntity(configurationId, configuration, currentTime, currentTime);
    SettingsProxyConfigurationEntity savedProxyConfig = settingsProxyConfigurationRepository.save(configurationToSave);
    List<NonProxyHostConfigurationEntity> nonProxyHosts = toNonProxyHostEntityList(configurationId, configuration);
    nonProxyHostsConfigurationRepository.saveAll(nonProxyHosts);
    savedProxyConfig = settingsProxyConfigurationRepository.getOne(savedProxyConfig.getConfigurationId());
    return createConfigModel(savedProxyConfig);
}
Also used : NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) OffsetDateTime(java.time.OffsetDateTime) UUID(java.util.UUID) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with NonProxyHostConfigurationEntity

use of com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity in project blackduck-alert by blackducksoftware.

the class SettingsProxyConfigAccessor method updateConfiguration.

@Override
@Transactional(propagation = Propagation.REQUIRED)
public SettingsProxyModel updateConfiguration(SettingsProxyModel configuration) throws AlertConfigurationException {
    SettingsProxyConfigurationEntity configurationEntity = settingsProxyConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME).orElseThrow(() -> new AlertConfigurationException("Proxy config does not exist"));
    if (BooleanUtils.toBoolean(configuration.getIsProxyPasswordSet()) && configuration.getProxyPassword().isEmpty()) {
        String decryptedPassword = encryptionUtility.decrypt(configurationEntity.getPassword());
        configuration.setProxyPassword(decryptedPassword);
    }
    UUID configurationId = configurationEntity.getConfigurationId();
    OffsetDateTime currentTime = DateUtils.createCurrentDateTimestamp();
    SettingsProxyConfigurationEntity configurationToSave = toEntity(configurationId, configuration, configurationEntity.getCreatedAt(), currentTime);
    SettingsProxyConfigurationEntity savedProxyConfig = settingsProxyConfigurationRepository.save(configurationToSave);
    nonProxyHostsConfigurationRepository.bulkDeleteByConfigurationId(savedProxyConfig.getConfigurationId());
    List<NonProxyHostConfigurationEntity> nonProxyHosts = toNonProxyHostEntityList(configurationId, configuration);
    nonProxyHostsConfigurationRepository.saveAll(nonProxyHosts);
    savedProxyConfig = settingsProxyConfigurationRepository.getOne(savedProxyConfig.getConfigurationId());
    return createConfigModel(savedProxyConfig);
}
Also used : NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) OffsetDateTime(java.time.OffsetDateTime) UUID(java.util.UUID) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) AlertConfigurationException(com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with NonProxyHostConfigurationEntity

use of com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity in project blackduck-alert by blackducksoftware.

the class ProxyConfigurationModelSaveActionsTest method updateTest.

@Test
void updateTest() {
    AtomicReference<SettingsProxyConfigurationEntity> savedEntity = new AtomicReference<>();
    AtomicReference<NonProxyHostConfigurationEntity> savedNonProxyHostEntity = new AtomicReference<>();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any(SettingsProxyConfigurationEntity.class))).thenAnswer(invocation -> {
        savedEntity.set(invocation.getArgument(0));
        return savedEntity.get();
    });
    Mockito.when(settingsProxyConfigurationRepository.findByName(Mockito.anyString())).thenAnswer(invocation -> Optional.ofNullable(savedEntity.get()));
    Mockito.when(settingsProxyConfigurationRepository.existsByName(Mockito.anyString())).thenAnswer(invocation -> savedEntity.get() != null);
    Mockito.when(nonProxyHostsConfigurationRepository.saveAll(Mockito.any(List.class))).thenAnswer(invocation -> {
        Iterable<NonProxyHostConfigurationEntity> iterable = invocation.getArgument(0);
        for (NonProxyHostConfigurationEntity entity : iterable) {
            savedNonProxyHostEntity.set(entity);
        }
        return List.of(savedNonProxyHostEntity.get());
    });
    SettingsProxyConfigAccessor configurationAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions settingsProxyCrudActions = new SettingsProxyCrudActions(authorizationManager, configurationAccessor, validator, settingsDescriptorKey);
    ProxyConfigurationModelSaveActions saveActions = new ProxyConfigurationModelSaveActions(converter, settingsProxyCrudActions);
    String newHost = "updatedHost";
    String newPort = "1234";
    ConfigurationModel configurationModel = createDefaultConfigurationModel();
    saveActions.createConcreteModel(configurationModel);
    updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_HOST, newHost);
    updateField(configurationModel, ProxyConfigurationModelConverter.FIELD_KEY_PORT, newPort);
    saveActions.updateConcreteModel(configurationModel);
    SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(newHost, actualEntity.getHost());
    assertEquals(Integer.valueOf(newPort), actualEntity.getPort());
    assertEquals(TEST_PROXY_USERNAME, actualEntity.getUsername());
    assertEquals(TEST_PROXY_PASSWORD, encryptionUtility.decrypt(actualEntity.getPassword()));
    NonProxyHostConfigurationEntity actualNonProxyHosts = savedNonProxyHostEntity.get();
    assertNotNull(actualNonProxyHosts);
    assertEquals(TEST_PROXY_NON_PROXY_HOST, actualNonProxyHosts.getHostnamePattern());
}
Also used : ConfigurationModel(com.synopsys.integration.alert.common.persistence.model.ConfigurationModel) NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) AtomicReference(java.util.concurrent.atomic.AtomicReference) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) List(java.util.List) Test(org.junit.jupiter.api.Test)

Aggregations

NonProxyHostConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity)14 SettingsProxyConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity)14 SettingsProxyCrudActions (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions)10 SettingsProxyConfigAccessor (com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor)10 NonProxyHostsConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository)10 SettingsProxyConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository)10 List (java.util.List)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 Test (org.junit.jupiter.api.Test)10 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)8 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)4 OffsetDateTime (java.time.OffsetDateTime)4 UUID (java.util.UUID)4 Transactional (org.springframework.transaction.annotation.Transactional)4