Search in sources :

Example 11 with FormValidation

use of hudson.util.FormValidation in project hudson-2.x by hudson.

the class MatrixProject method checkAxisNames.

/**
 * Verifies that Axis names are valid and unique.
 */
private void checkAxisNames(Iterable<Axis> newAxes) throws FormException {
    HashSet<String> axisNames = new HashSet<String>();
    for (Axis a : newAxes) {
        FormValidation fv = a.getDescriptor().doCheckName(a.getName());
        if (fv.kind != Kind.OK)
            throw new FormException(Messages.MatrixProject_DuplicateAxisName(), fv, "axis.name");
        if (axisNames.contains(a.getName()))
            throw new FormException(Messages.MatrixProject_DuplicateAxisName(), "axis.name");
        axisNames.add(a.getName());
    }
}
Also used : FormException(hudson.model.Descriptor.FormException) FormValidation(hudson.util.FormValidation) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 12 with FormValidation

use of hudson.util.FormValidation in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_scopes_with_at_in_name.

@Test
public void test_scopes_with_at_in_name() throws Exception {
    DescriptorImpl descriptor = new DescriptorImpl();
    FormValidation result = descriptor.doCheckScopes(true, "@scope1");
    assertThat(result.kind, is(Kind.WARNING));
    assertThat(result.getMessage(), is(Messages.NPMRegistry_DescriptorImpl_invalidCharInScopes()));
}
Also used : FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Test(org.junit.Test)

Example 13 with FormValidation

use of hudson.util.FormValidation in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_invalid_credentials.

@Test
public void test_invalid_credentials() throws Exception {
    FreeStyleProject prj = mock(FreeStyleProject.class);
    when(prj.hasPermission(isA(Permission.class))).thenReturn(true);
    DescriptorImpl descriptor = mock(DescriptorImpl.class);
    when(descriptor.doCheckCredentialsId(any(Item.class), (String) any(), anyString())).thenCallRealMethod();
    String credentialsId = "secret";
    String serverURL = "http://acme.com";
    FormValidation result = descriptor.doCheckCredentialsId(prj, credentialsId, serverURL);
    assertThat(result.kind, is(Kind.ERROR));
    assertThat(result.getMessage(), is(Messages.NPMRegistry_DescriptorImpl_invalidCredentialsId()));
    when(prj.hasPermission(isA(Permission.class))).thenReturn(false);
    result = descriptor.doCheckCredentialsId(prj, credentialsId, serverURL);
    assertThat(result.kind, is(Kind.OK));
}
Also used : Item(hudson.model.Item) FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Permission(hudson.security.Permission) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Example 14 with FormValidation

use of hudson.util.FormValidation in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_empty_server_url_is_ok.

@Test
public void test_empty_server_url_is_ok() throws Exception {
    DescriptorImpl descriptor = new DescriptorImpl();
    FormValidation result = descriptor.doCheckUrl("http://acme.com");
    assertThat(result.kind, is(Kind.OK));
}
Also used : FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Test(org.junit.Test)

Example 15 with FormValidation

use of hudson.util.FormValidation in project nodejs-plugin by jenkinsci.

the class NPMRegistryValidatorTest method test_empty_credentials.

@Test
public void test_empty_credentials() throws Exception {
    FreeStyleProject prj = mock(FreeStyleProject.class);
    when(prj.hasPermission(isA(Permission.class))).thenReturn(true);
    DescriptorImpl descriptor = mock(DescriptorImpl.class);
    when(descriptor.doCheckCredentialsId(any(Item.class), (String) any(), anyString())).thenCallRealMethod();
    String serverURL = "http://acme.com";
    FormValidation result = descriptor.doCheckCredentialsId(prj, "", serverURL);
    assertThat(result.kind, is(Kind.WARNING));
    assertThat(result.getMessage(), is(Messages.NPMRegistry_DescriptorImpl_emptyCredentialsId()));
    result = descriptor.doCheckCredentialsId(prj, null, serverURL);
    assertThat(result.kind, is(Kind.WARNING));
    assertThat(result.getMessage(), is(Messages.NPMRegistry_DescriptorImpl_emptyCredentialsId()));
}
Also used : Item(hudson.model.Item) FormValidation(hudson.util.FormValidation) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Permission(hudson.security.Permission) FreeStyleProject(hudson.model.FreeStyleProject) Test(org.junit.Test)

Aggregations

FormValidation (hudson.util.FormValidation)24 Test (org.junit.Test)21 DescriptorImpl (jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl)11 FreeStyleProject (hudson.model.FreeStyleProject)4 Item (hudson.model.Item)3 Permission (hudson.security.Permission)3 DbAuditPublisher (org.jenkins.plugins.audit2db.DbAuditPublisher)3 DbAuditPublisherDescriptor (org.jenkins.plugins.audit2db.DbAuditPublisherDescriptor)3 DbAuditPublisherImpl (org.jenkins.plugins.audit2db.internal.DbAuditPublisherImpl)3 IOException (java.io.IOException)2 ServletException (javax.servlet.ServletException)2 Credentials (com.cloudbees.plugins.credentials.Credentials)1 Domain (com.cloudbees.plugins.credentials.domains.Domain)1 UsernamePasswordCredentialsImpl (com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl)1 Cause (hudson.model.Cause)1 FormException (hudson.model.Descriptor.FormException)1 FreeStyleBuild (hudson.model.FreeStyleBuild)1 BuildTrigger (hudson.tasks.BuildTrigger)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1