Search in sources :

Example 11 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class SlackDistributionEventHandlerTest method createConnectionFactory.

private ChannelRestConnectionFactory createConnectionFactory() {
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    return new ChannelRestConnectionFactory(testAlertProperties, proxyManager, gson);
}
Also used : ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager)

Example 12 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class MsTeamsChannelTest method createConnectionFactory.

private ChannelRestConnectionFactory createConnectionFactory() {
    MockAlertProperties testAlertProperties = new MockAlertProperties();
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    return new ChannelRestConnectionFactory(testAlertProperties, proxyManager, gson);
}
Also used : ChannelRestConnectionFactory(com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager)

Example 13 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class BlackDuckSSOConfigRetrieverTest method createBlackDuckProperties.

private BlackDuckProperties createBlackDuckProperties() {
    TestProperties testProperties = new TestProperties();
    String blackDuckUrl = testProperties.getBlackDuckURL();
    String blackDuckApiKey = testProperties.getBlackDuckAPIToken();
    String blackDuckTimeout = testProperties.getOptionalProperty(TestPropertyKey.TEST_BLACKDUCK_PROVIDER_TIMEOUT).orElse("300");
    MockAlertProperties mockAlertProperties = new MockAlertProperties();
    ProxyManager mockProxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(mockProxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    ConfigurationModelMutable configurationModel = new ConfigurationModelMutable(0L, 0L, null, null, ConfigContextEnum.GLOBAL);
    configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_ENABLED, Boolean.TRUE.toString()));
    configurationModel.put(createConfigFieldModel(ProviderDescriptor.KEY_PROVIDER_CONFIG_NAME, BlackDuckSSOConfigRetrieverTest.class.getSimpleName()));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_URL, blackDuckUrl));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_API_KEY, blackDuckApiKey));
    configurationModel.put(createConfigFieldModel(BlackDuckDescriptor.KEY_BLACKDUCK_TIMEOUT, blackDuckTimeout));
    return new BlackDuckProperties(0L, new Gson(), BlackDuckServicesFactory.createDefaultObjectMapper(), mockAlertProperties, mockProxyManager, configurationModel);
}
Also used : TestProperties(com.synopsys.integration.alert.test.common.TestProperties) ConfigurationModelMutable(com.synopsys.integration.alert.common.persistence.model.mutable.ConfigurationModelMutable) BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) MockAlertProperties(com.synopsys.integration.alert.test.common.MockAlertProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) Gson(com.google.gson.Gson)

Example 14 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class SystemValidatorTest method testValidateHubValidProvider.

@Test
public void testValidateHubValidProvider() throws Exception {
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("https://alert.example.com:443/alert"));
    Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Test Api Key");
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(true);
    Mockito.when(blackDuckProperties.createBlackDuckServerConfig(Mockito.any(IntLogger.class))).thenReturn(serverConfig);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility, Mockito.times(0)).addSystemMessage(Mockito.anyString(), Mockito.any(SystemMessageSeverity.class), Mockito.any(SystemMessageType.class));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) SystemMessageSeverity(com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity) SystemMessageType(com.synopsys.integration.alert.common.enumeration.SystemMessageType) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Example 15 with ProxyManager

use of com.synopsys.integration.alert.common.rest.proxy.ProxyManager in project hub-alert by blackducksoftware.

the class SystemValidatorTest method testValidateHubInvalidProvider.

@Test
public void testValidateHubInvalidProvider() throws Exception {
    long configId = 1L;
    ProxyManager proxyManager = Mockito.mock(ProxyManager.class);
    Mockito.when(proxyManager.createProxyInfoForHost(Mockito.anyString())).thenReturn(ProxyInfo.NO_PROXY_INFO);
    BlackDuckProperties blackDuckProperties = Mockito.mock(BlackDuckProperties.class);
    Mockito.when(blackDuckProperties.getBlackDuckUrl()).thenReturn(Optional.of("https://localhost:443/alert"));
    Mockito.when(blackDuckProperties.getApiToken()).thenReturn("Test Api Key");
    Mockito.when(blackDuckProperties.getBlackDuckTimeout()).thenReturn(BlackDuckProperties.DEFAULT_TIMEOUT);
    Mockito.when(blackDuckProperties.getConfigName()).thenReturn(DEFAULT_CONFIG_NAME);
    Mockito.when(blackDuckProperties.getConfigId()).thenReturn(configId);
    BlackDuckServerConfig serverConfig = Mockito.mock(BlackDuckServerConfig.class);
    Mockito.when(serverConfig.canConnect(Mockito.any(IntLogger.class))).thenReturn(false);
    Mockito.when(blackDuckProperties.createBlackDuckServerConfig(Mockito.any(IntLogger.class))).thenReturn(serverConfig);
    DefaultSystemMessageAccessor defaultSystemMessageUtility = Mockito.mock(DefaultSystemMessageAccessor.class);
    StatefulProvider statefulProvider = Mockito.mock(StatefulProvider.class);
    BlackDuckProvider provider = Mockito.mock(BlackDuckProvider.class);
    Mockito.when(provider.createStatefulProvider(Mockito.any())).thenReturn(statefulProvider);
    Mockito.when(statefulProvider.getProperties()).thenReturn(blackDuckProperties);
    String localhostMessageType = BlackDuckSystemValidator.createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_LOCALHOST);
    String connectivityMessageType = BlackDuckSystemValidator.createProviderSystemMessageType(blackDuckProperties, SystemMessageType.BLACKDUCK_PROVIDER_CONNECTIVITY);
    BlackDuckSystemValidator blackDuckSystemValidator = new BlackDuckSystemValidator(defaultSystemMessageUtility);
    blackDuckSystemValidator.validate(blackDuckProperties);
    Mockito.verify(defaultSystemMessageUtility).addSystemMessage(Mockito.eq(String.format(BlackDuckSystemValidator.BLACKDUCK_LOCALHOST_ERROR_FORMAT, DEFAULT_CONFIG_NAME)), Mockito.eq(SystemMessageSeverity.WARNING), Mockito.eq(localhostMessageType));
    Mockito.verify(defaultSystemMessageUtility).addSystemMessage(Mockito.eq(String.format("Can not connect to the Black Duck server with the configuration '%s'.", DEFAULT_CONFIG_NAME)), Mockito.eq(SystemMessageSeverity.WARNING), Mockito.eq(connectivityMessageType));
}
Also used : BlackDuckProperties(com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties) ProxyManager(com.synopsys.integration.alert.common.rest.proxy.ProxyManager) IntLogger(com.synopsys.integration.log.IntLogger) BlackDuckSystemValidator(com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator) DefaultSystemMessageAccessor(com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor) BlackDuckProvider(com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider) BlackDuckServerConfig(com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig) StatefulProvider(com.synopsys.integration.alert.api.provider.state.StatefulProvider) Test(org.junit.jupiter.api.Test)

Aggregations

ProxyManager (com.synopsys.integration.alert.common.rest.proxy.ProxyManager)16 Test (org.junit.jupiter.api.Test)9 MockAlertProperties (com.synopsys.integration.alert.test.common.MockAlertProperties)7 BlackDuckProperties (com.synopsys.integration.alert.provider.blackduck.BlackDuckProperties)6 Gson (com.google.gson.Gson)4 StatefulProvider (com.synopsys.integration.alert.api.provider.state.StatefulProvider)4 DefaultSystemMessageAccessor (com.synopsys.integration.alert.database.system.DefaultSystemMessageAccessor)4 BlackDuckProvider (com.synopsys.integration.alert.provider.blackduck.BlackDuckProvider)4 BlackDuckSystemValidator (com.synopsys.integration.alert.provider.blackduck.validator.BlackDuckSystemValidator)4 BlackDuckServerConfig (com.synopsys.integration.blackduck.configuration.BlackDuckServerConfig)4 IntLogger (com.synopsys.integration.log.IntLogger)4 ChannelRestConnectionFactory (com.synopsys.integration.alert.api.channel.rest.ChannelRestConnectionFactory)3 ProxyInfo (com.synopsys.integration.rest.proxy.ProxyInfo)3 AlertProperties (com.synopsys.integration.alert.common.AlertProperties)2 SystemMessageSeverity (com.synopsys.integration.alert.common.enumeration.SystemMessageSeverity)2 SystemMessageType (com.synopsys.integration.alert.common.enumeration.SystemMessageType)2 JobAccessor (com.synopsys.integration.alert.common.persistence.accessor.JobAccessor)2 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)2 Credentials (com.synopsys.integration.rest.credentials.Credentials)2 CredentialsBuilder (com.synopsys.integration.rest.credentials.CredentialsBuilder)2