Search in sources :

Example 76 with ValidationResponseModel

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

the class SettingsProxyTestActionTestIT method testValidationFailureTest.

@Test
void testValidationFailureTest() {
    SettingsProxyModel settingsProxyModel = new SettingsProxyModel();
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck(validTargetUrl, settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 77 with ValidationResponseModel

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

the class SettingsProxyTestActionTestIT method malformedTargetUrlTest.

@Test
void malformedTargetUrlTest() {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck("Not a valid url", settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 78 with ValidationResponseModel

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

the class SettingsProxyTestActionTestIT method missingTargetUrlTest.

@Test
void missingTargetUrlTest() {
    SettingsProxyModel settingsProxyModel = createSettingsProxyModel(testProperties);
    AuthorizationManager authorizationManager = createAuthorizationManager(AuthenticationTestUtils.FULL_PERMISSIONS);
    settingsProxyTestAction = new SettingsProxyTestAction(authorizationManager, settingsProxyValidator, settingsDescriptorKey, proxyTestService, settingsProxyConfigAccessor);
    ActionResponse<ValidationResponseModel> testResult = settingsProxyTestAction.testWithPermissionCheck("", settingsProxyModel);
    assertTrue(testResult.isSuccessful());
    assertTrue(testResult.getContent().isPresent());
    ValidationResponseModel validationResponseModel = testResult.getContent().get();
    assertTrue(validationResponseModel.hasErrors());
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) SettingsProxyTestAction(com.synopsys.integration.alert.component.settings.proxy.action.SettingsProxyTestAction) SettingsProxyModel(com.synopsys.integration.alert.common.rest.model.SettingsProxyModel) AuthorizationManager(com.synopsys.integration.alert.common.security.authorization.AuthorizationManager) AlertIntegrationTest(com.synopsys.integration.alert.util.AlertIntegrationTest) Test(org.junit.jupiter.api.Test)

Example 79 with ValidationResponseModel

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

the class RoleActionsTest method validateDuplicatePermissionsTest.

@Test
public void validateDuplicatePermissionsTest() {
    PermissionModel permissionModel = createPermissionModel();
    PermissionModel permissionModelDuplicate = new PermissionModel(descriptorKey.getUniversalKey(), context, false, true, true, true, true, true, true, true);
    RolePermissionModel rolePermissionModel = new RolePermissionModel(null, roleName, Set.of(permissionModel, permissionModelDuplicate));
    Mockito.when(roleAccessor.doesRoleNameExist(Mockito.eq(roleName))).thenReturn(false);
    RoleActions roleActions = new RoleActions(userManagementDescriptorKey, roleAccessor, authorizationManager, descriptorMap);
    ValidationActionResponse validationActionResponse = roleActions.validate(rolePermissionModel);
    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 80 with ValidationResponseModel

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

the class ConfigurationManagerV2 method createGlobalConfiguration.

public <T extends Obfuscated<T>> Optional<T> createGlobalConfiguration(String apiConfigurationPath, T globalConfigModel, Class<T> modelType) {
    try {
        String requestBody = gson.toJson(globalConfigModel);
        String validationResponseString = alertRequestUtility.executePostRequest(String.format("%s/validate", apiConfigurationPath), requestBody, "Validating the global configuration failed.");
        ValidationResponseModel validationResponse = gson.fromJson(validationResponseString, ValidationResponseModel.class);
        if (validationResponse.hasErrors()) {
            intLogger.error(String.format("Could not validate global configuration model. Error: %s", validationResponse.getErrors()));
            return Optional.empty();
        }
        String testResponseString = alertRequestUtility.executePostRequest(String.format("%s/test", apiConfigurationPath), requestBody, "Testing the global configuration failed.");
        ValidationResponseModel testResponse = gson.fromJson(testResponseString, ValidationResponseModel.class);
        if (testResponse.hasErrors() && !ValidationResponseModel.VALIDATION_SUCCESS_MESSAGE.equals(validationResponse.getMessage())) {
            intLogger.error(String.format("Testing the global config model error message: %s", validationResponse.getMessage()));
            intLogger.error(String.format("Testing the global config model failed. Error: %s", validationResponse.getErrors()));
            return Optional.empty();
        }
        String globalConfigCreateResponse = alertRequestUtility.executePostRequest(apiConfigurationPath, requestBody, "Could not create the global configuration");
        JsonObject globalConfigSearchJsonObject = gson.fromJson(globalConfigCreateResponse, JsonObject.class);
        T savedGlobalConfig = gson.fromJson(globalConfigSearchJsonObject, modelType);
        return Optional.of(savedGlobalConfig);
    } catch (IntegrationException e) {
        intLogger.error("Unexpected error occurred while creating the global configuration.", e);
        return Optional.empty();
    }
}
Also used : ValidationResponseModel(com.synopsys.integration.alert.api.common.model.ValidationResponseModel) IntegrationException(com.synopsys.integration.exception.IntegrationException) JsonObject(com.google.gson.JsonObject)

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