Search in sources :

Example 21 with ValidationResponseModel

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

the class JobConfigActionsTest method testWithProviderWarningsTest.

@Test
void testWithProviderWarningsTest() throws Exception {
    fieldModel.setId("testID");
    Mockito.when(mockedDescriptorProcessor.retrieveDescriptor(Mockito.any())).thenReturn(Optional.of(descriptor));
    Mockito.when(mockedFieldModelProcessor.createCustomMessageFieldModel(Mockito.any())).thenReturn(fieldModel);
    Mockito.when(mockedDescriptorProcessor.retrieveTestAction(Mockito.any())).thenReturn(Optional.of(createTestActionWithErrors()));
    Mockito.when(mockedConfigurationFieldModelConverter.convertToConfigurationFieldModelMap(Mockito.any())).thenReturn(Map.of(ChannelDescriptor.KEY_PROVIDER_TYPE, configurationFieldModel));
    Mockito.when(mockedDescriptorProcessor.retrieveTestAction(Mockito.any(), Mockito.any())).thenReturn(Optional.of(createTestActionWithErrors()));
    ValidationActionResponse validationActionResponse = defaultJobConfigActions.test(jobFieldModel);
    assertTrue(validationActionResponse.isSuccessful(), "Expected response to be successful");
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent(), "Expected response to have content");
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
    assertTrue(validationResponseModel.hasErrors(), "Expected response to have error content");
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 22 with ValidationResponseModel

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

the class JobConfigActionsTest method testTest.

@Test
void testTest() throws Exception {
    JobConfigActions jobConfigActionsForTest = new JobConfigActions(mockedAuthorizationManager, mockedDescriptorAccessor, mockedConfigurationModelConfigurationAccessor, mockedJobAccessor, mockedFieldModelProcessor, mockedDescriptorProcessor, mockedConfigurationFieldModelConverter, mockedGlobalConfigExistsValidator, mockedPkixErrorResponseFactory, descriptorMap, (id, list) -> {
    }, List.of(createChannelDistributionTestAction()), mockedJobModelExtractor);
    fieldModel.setId("testID");
    Mockito.when(mockedDescriptorProcessor.retrieveDescriptor(Mockito.any())).thenReturn(Optional.of(descriptor));
    Mockito.when(mockedFieldModelProcessor.createCustomMessageFieldModel(Mockito.any())).thenReturn(fieldModel);
    ValidationActionResponse validationActionResponse = jobConfigActionsForTest.test(jobFieldModel);
    assertTrue(validationActionResponse.isSuccessful(), "Validation response was not successful");
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent(), "Missing content");
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().orElseThrow(() -> new AlertRuntimeException("Missing validation response"));
    assertFalse(validationResponseModel.hasErrors(), "Validation response had errors");
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) AlertRuntimeException(com.synopsys.integration.alert.api.common.model.exception.AlertRuntimeException) Test(org.junit.jupiter.api.Test)

Example 23 with ValidationResponseModel

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

the class JobConfigActionsTest method testBadRequestTest.

@Test
void testBadRequestTest() {
    fieldModel.setId("testID");
    ValidationActionResponse validationActionResponse = defaultJobConfigActions.test(jobFieldModel);
    assertTrue(validationActionResponse.isError());
    assertEquals(HttpStatus.BAD_REQUEST, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent());
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 24 with ValidationResponseModel

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

the class JobConfigActionsTest method testExceptionTest.

@Test
void testExceptionTest() throws Exception {
    Mockito.when(mockedDescriptorProcessor.retrieveDescriptor(Mockito.any())).thenReturn(Optional.of(descriptor));
    Mockito.doThrow(new NullPointerException("RuntimeException for Alert test")).when(mockedFieldModelProcessor).createCustomMessageFieldModel(Mockito.any());
    ValidationActionResponse validationActionResponse = defaultJobConfigActions.test(jobFieldModel);
    assertTrue(validationActionResponse.isSuccessful());
    assertEquals(HttpStatus.OK, validationActionResponse.getHttpStatus());
    assertTrue(validationActionResponse.hasContent());
    ValidationResponseModel validationResponseModel = validationActionResponse.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) ValidationActionResponse(com.synopsys.integration.alert.common.action.ValidationActionResponse) Test(org.junit.jupiter.api.Test)

Example 25 with ValidationResponseModel

use of com.synopsys.integration.alert.api.common.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.api.common.model.ValidationResponseModel) ActionResponse(com.synopsys.integration.alert.common.action.ActionResponse)

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