Search in sources :

Example 11 with ValidationResponseModel

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

the class JiraServerGlobalTestActionTest method testPermissionForbidden.

@Test
void testPermissionForbidden() {
    AuthorizationManager authorizationManager = createAuthorizationManager(0);
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerTestActionFactory jiraServerTestActionFactory = Mockito.mock(JiraServerTestActionFactory.class);
    JiraServerGlobalTestAction jiraServerGlobalTestAction = new JiraServerGlobalTestAction(authorizationManager, validator, jiraServerTestActionFactory);
    ActionResponse<ValidationResponseModel> validationResponseModel = jiraServerGlobalTestAction.testWithPermissionCheck(jiraServerGlobalConfigModel);
    assertTrue(validationResponseModel.isError());
    assertEquals(HttpStatus.FORBIDDEN, validationResponseModel.getHttpStatus());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigurationValidator(com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) Test(org.junit.jupiter.api.Test)

Example 12 with ValidationResponseModel

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

the class JiraServerInstallPluginAction method createBadRequestIntegrationException.

private ActionResponse<ValidationResponseModel> createBadRequestIntegrationException(IntegrationException error) {
    logger.error("There was an issue connecting to Jira server", error);
    ValidationResponseModel validationResponseModel = ValidationResponseModel.generalError("The following error occurred when connecting to Jira server: " + error.getMessage());
    return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResponseModel);
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

Example 13 with ValidationResponseModel

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

the class JiraServerGlobalConfigurationValidatorTest method verifyPasswordIsSavedAndMissingFromModel.

@Test
void verifyPasswordIsSavedAndMissingFromModel() {
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, null, Boolean.TRUE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(0, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 14 with ValidationResponseModel

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

the class JiraServerGlobalConfigurationValidatorTest method verifyEmptyConfig.

@Test
void verifyEmptyConfig() {
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel();
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(4, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
    for (AlertFieldStatus status : alertFieldStatuses) {
        assertEquals(ConfigurationFieldValidator.REQUIRED_FIELD_MISSING_MESSAGE, status.getFieldMessage(), "Validation had unexpected field message.");
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Example 15 with ValidationResponseModel

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

the class JiraServerGlobalConfigurationValidatorTest method verifyMalformedUrl.

@Test
void verifyMalformedUrl() {
    String badUrl = "notAValidUrl";
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator();
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, badUrl, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model);
    Collection<AlertFieldStatus> alertFieldStatuses = validationResponseModel.getErrors().values();
    assertEquals(1, alertFieldStatuses.size(), "There were errors in the configuration when none were expected.");
    for (AlertFieldStatus status : alertFieldStatuses) {
        assertEquals("url", status.getFieldName(), "Validation reported an error for an unexpected field.");
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.common.rest.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResponseModel (com.synopsys.integration.alert.common.rest.model.ValidationResponseModel)84 Test (org.junit.jupiter.api.Test)66 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)33 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)25 AlertFieldStatus (com.synopsys.integration.alert.common.descriptor.config.field.errors.AlertFieldStatus)23 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)18 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)15 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)13 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)9 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)9 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)7 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)7 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)7 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)7 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)7 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)7 IntegrationException (com.synopsys.integration.exception.IntegrationException)7 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)7 Map (java.util.Map)7 FieldModelTestAction (com.synopsys.integration.alert.common.action.FieldModelTestAction)6