Search in sources :

Example 1 with HubServerConfigValidator

use of com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator in project hub-alert by blackducksoftware.

the class GlobalHubConfigActionsTest method testValidConfig.

@Test
@Override
public void testValidConfig() throws Exception {
    final GlobalHubConfigActions configActions = new GlobalHubConfigActions(null, null, null);
    final String url = "https://www.google.com/";
    final String user = "User";
    final String password = "Password";
    HubServerConfigBuilder serverConfigBuilder = new HubServerConfigBuilder();
    serverConfigBuilder.setHubUrl(url);
    serverConfigBuilder.setUsername(user);
    serverConfigBuilder.setUsername(password);
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
        fail();
    } catch (final AlertFieldException e) {
        assertNotNull(e);
        assertEquals("There were issues with the configuration.", e.getMessage());
        assertTrue(!e.getFieldErrors().isEmpty());
    }
    final HubServerConfigValidator validator = Mockito.mock(HubServerConfigValidator.class);
    serverConfigBuilder = Mockito.spy(serverConfigBuilder);
    Mockito.when(serverConfigBuilder.createValidator()).thenReturn(validator);
    Mockito.when(validator.assertValid()).thenReturn(new ValidationResults());
    try {
        configActions.validateHubConfiguration(serverConfigBuilder);
    } catch (final AlertFieldException e) {
        fail();
    }
}
Also used : ValidationResults(com.blackducksoftware.integration.validator.ValidationResults) HubServerConfigBuilder(com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder) AlertFieldException(com.blackducksoftware.integration.hub.alert.exception.AlertFieldException) GlobalHubConfigActions(com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions) HubServerConfigValidator(com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator) Test(org.junit.Test) GlobalActionsTest(com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)

Aggregations

AlertFieldException (com.blackducksoftware.integration.hub.alert.exception.AlertFieldException)1 GlobalHubConfigActions (com.blackducksoftware.integration.hub.alert.hub.controller.global.GlobalHubConfigActions)1 GlobalActionsTest (com.blackducksoftware.integration.hub.alert.web.actions.global.GlobalActionsTest)1 HubServerConfigBuilder (com.blackducksoftware.integration.hub.configuration.HubServerConfigBuilder)1 HubServerConfigValidator (com.blackducksoftware.integration.hub.configuration.HubServerConfigValidator)1 ValidationResults (com.blackducksoftware.integration.validator.ValidationResults)1 Test (org.junit.Test)1