Search in sources :

Example 6 with SettingsProxyConfigAccessor

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

the class SettingsProxyTestActionTest method init.

@BeforeEach
void init() {
    UUID uuid = UUID.randomUUID();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(Optional.of(createSettingsProxyConfigurationEntity(uuid)));
    settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
}
Also used : NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) UUID(java.util.UUID) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 7 with SettingsProxyConfigAccessor

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

the class ProxySettingsEnvironmentHandlerFactoryTest method testProxySetInEnvironment.

@Test
void testProxySetInEnvironment() {
    Environment environment = Mockito.mock(Environment.class);
    SettingsProxyConfigAccessor configAccessor = Mockito.mock(SettingsProxyConfigAccessor.class);
    Mockito.when(configAccessor.getConfiguration()).thenReturn(Optional.empty());
    Set<String> expectedVariableNames = ProxySettingsEnvironmentHandlerFactory.PROXY_CONFIGURATION_KEYSET;
    String proxyHost = "https://proxyHostUrl";
    String proxyPort = "3128";
    String proxyUsername = "testUser";
    String proxyPassword = "testPassword";
    String nonProxyHosts = "https://nonProxyHostUrl";
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_HOST_KEY, proxyHost);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_PORT_KEY, proxyPort);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_USERNAME_KEY, proxyUsername);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_PASSWORD_KEY, proxyPassword);
    EnvironmentVariableMockingUtil.addEnvironmentVariableValueToMock(environment, (ignored) -> Boolean.TRUE, ProxySettingsEnvironmentHandlerFactory.PROXY_NON_PROXY_HOSTS_KEY, nonProxyHosts);
    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());
    assertEquals(expectedVariableNames, handler.getVariableNames());
    assertTrue(result.hasValues());
    assertEquals(proxyHost, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_HOST_KEY).orElse("Proxy host value is missing"));
    assertEquals(proxyPort, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_PORT_KEY).orElse("Proxy port value is missing"));
    assertEquals(proxyUsername, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_USERNAME_KEY).orElse("Proxy username value is missing"));
    assertEquals(AlertConstants.MASKED_VALUE, result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_PASSWORD_KEY).orElse("Proxy password value is missing"));
    assertEquals(List.of(nonProxyHosts).toString(), result.getVariableValue(ProxySettingsEnvironmentHandlerFactory.PROXY_NON_PROXY_HOSTS_KEY).orElse("Proxy non-proxy hosts value is missing"));
}
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)

Example 8 with SettingsProxyConfigAccessor

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

the class SettingsProxyCrudActionsTest method getOneTest.

@Test
public void getOneTest() {
    UUID uuid = UUID.randomUUID();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(Optional.of(createSettingsProxyConfigurationEntity(uuid)));
    SettingsProxyConfigAccessor settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions configActions = new SettingsProxyCrudActions(authorizationManager, settingsProxyConfigAccessor, settingsProxyValidator, settingsDescriptorKey);
    ActionResponse<SettingsProxyModel> actionResponse = configActions.getOne();
    assertTrue(actionResponse.isSuccessful());
    assertTrue(actionResponse.hasContent());
    assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
    assertModelObfuscated(actionResponse);
}
Also used : NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) UUID(java.util.UUID) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) Test(org.junit.jupiter.api.Test)

Example 9 with SettingsProxyConfigAccessor

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

the class SettingsProxyCrudActionsTest method createTestConfigAlreadyExists.

@Test
public void createTestConfigAlreadyExists() {
    UUID uuid = UUID.randomUUID();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    Mockito.when(settingsProxyConfigurationRepository.existsByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(true);
    SettingsProxyConfigAccessor settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions configActions = new SettingsProxyCrudActions(authorizationManager, settingsProxyConfigAccessor, settingsProxyValidator, settingsDescriptorKey);
    ActionResponse<SettingsProxyModel> actionResponse = configActions.create(createSettingsProxyModel());
    assertTrue(actionResponse.isError());
    assertFalse(actionResponse.hasContent());
    assertEquals(HttpStatus.BAD_REQUEST, actionResponse.getHttpStatus());
}
Also used : NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) UUID(java.util.UUID) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) Test(org.junit.jupiter.api.Test)

Example 10 with SettingsProxyConfigAccessor

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

the class SettingsProxyCrudActionsTest method updateTest.

@Test
public void updateTest() {
    UUID uuid = UUID.randomUUID();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    SettingsProxyConfigurationEntity entity = createSettingsProxyConfigurationEntity(uuid);
    Mockito.when(settingsProxyConfigurationRepository.findByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(Optional.of(entity));
    Mockito.when(settingsProxyConfigurationRepository.existsByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(true);
    Mockito.when(settingsProxyConfigurationRepository.save(Mockito.any())).thenReturn(entity);
    Mockito.when(settingsProxyConfigurationRepository.getOne(uuid)).thenReturn(entity);
    SettingsProxyConfigAccessor settingsProxyConfigAccessor = new SettingsProxyConfigAccessor(encryptionUtility, settingsProxyConfigurationRepository, nonProxyHostsConfigurationRepository);
    SettingsProxyCrudActions configActions = new SettingsProxyCrudActions(authorizationManager, settingsProxyConfigAccessor, settingsProxyValidator, settingsDescriptorKey);
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel();
    ActionResponse<SettingsProxyModel> actionResponse = configActions.update(settingsProxyModel);
    Mockito.verify(nonProxyHostsConfigurationRepository).saveAll(Mockito.any());
    assertTrue(actionResponse.isSuccessful());
    assertTrue(actionResponse.hasContent());
    assertEquals(HttpStatus.OK, actionResponse.getHttpStatus());
    assertModelObfuscated(actionResponse);
}
Also used : NonProxyHostsConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) SettingsProxyCrudActions(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions) SettingsProxyConfigAccessor(com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor) UUID(java.util.UUID) SettingsProxyConfigurationRepository(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository) SettingsProxyConfigurationEntity(com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity) 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