Search in sources :

Example 11 with SettingsProxyConfigAccessor

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

the class ProxyConfigurationModelSaveActionsTest method createTest.

@Test
void createTest() {
    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(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);
    saveActions.createConcreteModel(createDefaultConfigurationModel());
    SettingsProxyConfigurationEntity actualEntity = savedEntity.get();
    assertEquals(TEST_PROXY_HOST, actualEntity.getHost());
    assertEquals(Integer.valueOf(TEST_PROXY_PORT), 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 : NonProxyHostConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity) NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) AtomicReference(java.util.concurrent.atomic.AtomicReference) List(java.util.List) 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) Test(org.junit.jupiter.api.Test)

Example 12 with SettingsProxyConfigAccessor

use of com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor 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 13 with SettingsProxyConfigAccessor

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

the class ProxySettingsEnvironmentHandlerFactoryTest method testProxyMissingFromEnvironment.

@Test
void testProxyMissingFromEnvironment() {
    Environment environment = Mockito.mock(Environment.class);
    SettingsProxyConfigAccessor configAccessor = Mockito.mock(SettingsProxyConfigAccessor.class);
    Mockito.when(configAccessor.getConfiguration()).thenReturn(Optional.empty());
    EnvironmentVariableUtility environmentVariableUtility = new EnvironmentVariableUtility(environment);
    EnvironmentVariableHandlerFactory factory = new ProxySettingsEnvironmentHandlerFactory(configAccessor, environmentVariableUtility, validator);
    EnvironmentVariableHandler handler = factory.build();
    EnvironmentProcessingResult result = handler.updateFromEnvironment();
    assertEquals(ProxySettingsEnvironmentHandlerFactory.HANDLER_NAME, handler.getName());
    assertFalse(result.hasValues());
}
Also used : EnvironmentVariableHandlerFactory(com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory) EnvironmentVariableUtility(com.synopsys.integration.alert.environment.EnvironmentVariableUtility) Environment(org.springframework.core.env.Environment) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) EnvironmentVariableHandler(com.synopsys.integration.alert.environment.EnvironmentVariableHandler) EnvironmentProcessingResult(com.synopsys.integration.alert.environment.EnvironmentProcessingResult) Test(org.junit.jupiter.api.Test)

Aggregations

SettingsProxyConfigAccessor (com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor)13 Test (org.junit.jupiter.api.Test)12 NonProxyHostsConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository)11 SettingsProxyConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository)11 SettingsProxyCrudActions (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions)10 SettingsProxyConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity)7 UUID (java.util.UUID)6 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)5 NonProxyHostConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostConfigurationEntity)5 List (java.util.List)5 AtomicReference (java.util.concurrent.atomic.AtomicReference)5 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)4 EnvironmentProcessingResult (com.synopsys.integration.alert.environment.EnvironmentProcessingResult)2 EnvironmentVariableHandler (com.synopsys.integration.alert.environment.EnvironmentVariableHandler)2 EnvironmentVariableHandlerFactory (com.synopsys.integration.alert.environment.EnvironmentVariableHandlerFactory)2 EnvironmentVariableUtility (com.synopsys.integration.alert.environment.EnvironmentVariableUtility)2 Environment (org.springframework.core.env.Environment)2 BeforeEach (org.junit.jupiter.api.BeforeEach)1