Search in sources :

Example 26 with ValidationResponseModel

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

the class JiraServerGlobalTestActionTest method testPermissionForbidden.

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

Example 27 with ValidationResponseModel

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

the class JiraServerGlobalTestActionTest method testPermissionOK.

@Test
void testPermissionOK() throws IntegrationException {
    AuthorizationManager authorizationManager = createAuthorizationManager(255);
    JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
    Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(Mockito.anyString())).thenReturn(Optional.empty());
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
    JiraServerTestActionFactory jiraServerTestActionFactory = Mockito.mock(JiraServerTestActionFactory.class);
    JiraServerGlobalTestActionWrapper testActionWrapper = Mockito.mock(JiraServerGlobalTestActionWrapper.class);
    JiraServerGlobalConfigAccessor configurationAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
    Mockito.when(jiraServerTestActionFactory.createTestActionWrapper(Mockito.any())).thenReturn(testActionWrapper);
    Mockito.when(testActionWrapper.canUserGetIssues()).thenReturn(true);
    Mockito.when(testActionWrapper.isAppCheckEnabled()).thenReturn(true);
    Mockito.when(testActionWrapper.isUserAdmin()).thenReturn(true);
    Mockito.when(testActionWrapper.isAppMissing()).thenReturn(true);
    JiraServerGlobalTestAction jiraServerGlobalTestAction = new JiraServerGlobalTestAction(authorizationManager, validator, jiraServerTestActionFactory, configurationAccessor);
    ActionResponse<ValidationResponseModel> validationResponseModel = jiraServerGlobalTestAction.testWithPermissionCheck(jiraServerGlobalConfigModel);
    assertTrue(validationResponseModel.isSuccessful());
    assertEquals(HttpStatus.OK, validationResponseModel.getHttpStatus());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) JiraServerGlobalConfigurationValidator(com.synopsys.integration.alert.channel.jira.server.validator.JiraServerGlobalConfigurationValidator) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) Test(org.junit.jupiter.api.Test)

Example 28 with ValidationResponseModel

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

the class JiraServerGlobalConfigurationValidatorTest method verifyValidConfig.

@Test
void verifyValidConfig() {
    JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
    Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(Mockito.anyString())).thenReturn(Optional.empty());
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model, null);
    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.api.common.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) Test(org.junit.jupiter.api.Test)

Example 29 with ValidationResponseModel

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

the class JiraServerGlobalConfigurationValidatorTest method nameNotUniqueInvalidTest.

@Test
void nameNotUniqueInvalidTest() {
    JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
    JiraServerGlobalConfigModel existingModel = new JiraServerGlobalConfigModel(UUID.randomUUID().toString(), NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
    Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(NAME)).thenReturn(Optional.of(existingModel));
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(null, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, PASSWORD, Boolean.FALSE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model, null);
    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("name", status.getFieldName(), "Validation reported an error for an unexpected field.");
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) Test(org.junit.jupiter.api.Test)

Example 30 with ValidationResponseModel

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

the class JiraServerGlobalConfigurationValidatorTest method verifyPasswordIsSavedAndMissingFromModel.

@Test
void verifyPasswordIsSavedAndMissingFromModel() {
    JiraServerGlobalConfigAccessor jiraServerGlobalConfigAccessor = Mockito.mock(JiraServerGlobalConfigAccessor.class);
    Mockito.when(jiraServerGlobalConfigAccessor.getConfigurationByName(Mockito.anyString())).thenReturn(Optional.empty());
    JiraServerGlobalConfigurationValidator validator = new JiraServerGlobalConfigurationValidator(jiraServerGlobalConfigAccessor);
    JiraServerGlobalConfigModel model = new JiraServerGlobalConfigModel(ID, NAME, CREATED_AT, LAST_UPDATED, URL, USER_NAME, null, Boolean.TRUE, Boolean.FALSE);
    ValidationResponseModel validationResponseModel = validator.validate(model, null);
    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.api.common.model.ValidationResponseModel) JiraServerGlobalConfigModel(com.synopsys.integration.alert.channel.jira.server.model.JiraServerGlobalConfigModel) AlertFieldStatus(com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus) JiraServerGlobalConfigAccessor(com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor) Test(org.junit.jupiter.api.Test)

Aggregations

ValidationResponseModel (com.synopsys.integration.alert.api.common.model.ValidationResponseModel)179 Test (org.junit.jupiter.api.Test)139 ValidationActionResponse (com.synopsys.integration.alert.common.action.ValidationActionResponse)66 AlertFieldStatus (com.synopsys.integration.alert.api.common.model.errors.AlertFieldStatus)54 AuthorizationManager (com.synopsys.integration.alert.common.security.authorization.AuthorizationManager)50 SettingsProxyModel (com.synopsys.integration.alert.common.rest.model.SettingsProxyModel)36 EmailGlobalConfigModel (com.synopsys.integration.alert.service.email.model.EmailGlobalConfigModel)29 DescriptorKey (com.synopsys.integration.alert.descriptor.api.model.DescriptorKey)26 JiraServerGlobalConfigAccessor (com.synopsys.integration.alert.channel.jira.server.database.accessor.JiraServerGlobalConfigAccessor)20 ActionResponse (com.synopsys.integration.alert.common.action.ActionResponse)18 SettingsProxyTestAction (com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction)18 IntegrationException (com.synopsys.integration.exception.IntegrationException)16 AlertException (com.synopsys.integration.alert.api.common.model.exception.AlertException)14 EmailGlobalConfigurationValidator (com.synopsys.integration.alert.channel.email.validator.EmailGlobalConfigurationValidator)14 ConfigContextEnum (com.synopsys.integration.alert.common.enumeration.ConfigContextEnum)14 AlertFieldException (com.synopsys.integration.alert.common.exception.AlertFieldException)14 PermissionKey (com.synopsys.integration.alert.common.persistence.model.PermissionKey)14 AlertIntegrationTest (com.synopsys.integration.alert.util.AlertIntegrationTest)14 IntegrationRestException (com.synopsys.integration.rest.exception.IntegrationRestException)14 AlertConfigurationException (com.synopsys.integration.alert.api.common.model.exception.AlertConfigurationException)12