Search in sources :

Example 11 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class SettingsProxyCrudActionsTest method deleteTest.

@Test
public void deleteTest() {
    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.delete();
    Mockito.verify(settingsProxyConfigurationRepository).deleteByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    assertTrue(actionResponse.isSuccessful());
    assertFalse(actionResponse.hasContent());
    assertEquals(HttpStatus.NO_CONTENT, 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 12 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class SettingsProxyCrudActionsTest method createTest.

@Test
public void createTest() {
    UUID uuid = UUID.randomUUID();
    SettingsProxyConfigurationRepository settingsProxyConfigurationRepository = Mockito.mock(SettingsProxyConfigurationRepository.class);
    NonProxyHostsConfigurationRepository nonProxyHostsConfigurationRepository = Mockito.mock(NonProxyHostsConfigurationRepository.class);
    SettingsProxyConfigurationEntity entity = createSettingsProxyConfigurationEntity(uuid);
    Mockito.when(settingsProxyConfigurationRepository.existsByName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME)).thenReturn(false);
    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);
    ActionResponse<SettingsProxyModel> actionResponse = configActions.create(createSettingsProxyModel());
    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)

Example 13 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class SettingsProxyValidatorTest method validateHostWithoutPortTest.

@Test
void validateHostWithoutPortTest() {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    settingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    settingsProxyModel.setProxyHost(HOST);
    ValidationResponseModel validationResponseModel = settingsProxyValidator.validate(settingsProxyModel);
    assertTrue(validationResponseModel.hasErrors());
    assertEquals(1, validationResponseModel.getErrors().size());
    assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_PORT_FIELD_NAME));
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) Test(org.junit.jupiter.api.Test)

Example 14 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class SettingsProxyValidatorTest method validatePortWithoutHostTest.

@Test
void validatePortWithoutHostTest() {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    settingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    settingsProxyModel.setProxyPort(PORT);
    ValidationResponseModel validationResponseModel = settingsProxyValidator.validate(settingsProxyModel);
    assertTrue(validationResponseModel.hasErrors());
    assertEquals(1, validationResponseModel.getErrors().size());
    assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_HOST_FIELD_NAME));
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) Test(org.junit.jupiter.api.Test)

Example 15 with SettingsProxyModel

use of com.synopsys.integration.alert.common.rest.model.SettingsProxyModel in project hub-alert by blackducksoftware.

the class SettingsProxyValidatorTest method validateUsernameWithoutPasswordTest.

@Test
void validateUsernameWithoutPasswordTest() {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    settingsProxyModel.setName(AlertRestConstants.DEFAULT_CONFIGURATION_NAME);
    settingsProxyModel.setProxyHost(HOST);
    settingsProxyModel.setProxyPort(PORT);
    settingsProxyModel.setProxyUsername(USERNAME);
    ValidationResponseModel validationResponseModel = settingsProxyValidator.validate(settingsProxyModel);
    assertTrue(validationResponseModel.hasErrors());
    assertEquals(1, validationResponseModel.getErrors().size());
    assertTrue(validationResponseModel.getErrors().containsKey(SettingsProxyValidator.PROXY_PASSWORD_FIELD_NAME));
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) Test(org.junit.jupiter.api.Test)

Aggregations

SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)44 Test (org.junit.jupiter.api.Test)32 ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)18 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)12 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)8 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)7 URI (java.net.URI)6 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 SettingsProxyCrudActions (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyCrudActions)5 SettingsProxyConfigAccessor (com.synopsys.integration.alert.component.settings.proxy.database.accessor.SettingsProxyConfigAccessor)5 NonProxyHostsConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.NonProxyHostsConfigurationRepository)5 SettingsProxyConfigurationRepository (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationRepository)5 UUID (java.util.UUID)5 WithMockUser (org.springframework.security.test.context.support.WithMockUser)5 ConfigurationModel (com.synopsys.integration.alert.common.persistence.model.ConfigurationModel)3 SettingsProxyConfigurationEntity (com.synopsys.integration.alert.database.settings.proxy.SettingsProxyConfigurationEntity)2 AssertionFailedError (org.opentest4j.AssertionFailedError)2 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)1 SettingsUtility (com.synopsys.integration.alert.common.descriptor.accessor.SettingsUtility)1 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)1