Search in sources :

Example 6 with FormValidation

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

the class NPMRegistryValidatorTest method test_server_url_that_contains_variable.

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

Example 7 with FormValidation

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

the class NPMRegistryValidatorTest method test_credentials_ok.

@Test
public void test_credentials_ok() throws Exception {
    String credentialsId = "secret";
    Credentials credentials = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialsId, "", "user", "password");
    Map<Domain, List<Credentials>> credentialsMap = new HashMap<>();
    credentialsMap.put(Domain.global(), Arrays.asList(credentials));
    SystemCredentialsProvider.getInstance().setDomainCredentialsMap(credentialsMap);
    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, credentialsId, serverURL);
    assertThat(result.kind, is(Kind.OK));
}
Also used : Item(hudson.model.Item) FormValidation(hudson.util.FormValidation) HashMap(java.util.HashMap) DescriptorImpl(jenkins.plugins.nodejs.configfiles.NPMRegistry.DescriptorImpl) Permission(hudson.security.Permission) List(java.util.List) UsernamePasswordCredentialsImpl(com.cloudbees.plugins.credentials.impl.UsernamePasswordCredentialsImpl) Domain(com.cloudbees.plugins.credentials.domains.Domain) FreeStyleProject(hudson.model.FreeStyleProject) Credentials(com.cloudbees.plugins.credentials.Credentials) Test(org.junit.Test)

Example 8 with FormValidation

use of hudson.util.FormValidation in project selenium_java by sergueik.

the class DbAuditPublisherDescriptorImpl method doGenerateDdl.

@Override
public FormValidation doGenerateDdl(@QueryParameter("audit2db.jdbcDriver") final String jdbcDriver, @QueryParameter("audit2db.jdbcUrl") final String jdbcUrl, @QueryParameter("audit2db.jdbcUser") final String username, @QueryParameter("audit2db.jdbcPassword") final String password) throws IOException, ServletException {
    LOGGER.log(Level.FINE, String.format("doGenerateDdl('%s','%s','%s','*****'", jdbcDriver, jdbcUrl, username));
    FormValidation retval;
    try {
        final String ddlText = HibernateUtil.getSchemaDdl(jdbcDriver, jdbcUrl, username, password);
        retval = FormValidation.ok(ddlText);
    } catch (final Exception e) {
        LOGGER.log(Level.SEVERE, e.getMessage(), e);
        retval = FormValidation.error(e.getMessage());
    }
    return retval;
}
Also used : FormValidation(hudson.util.FormValidation) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Example 9 with FormValidation

use of hudson.util.FormValidation in project selenium_java by sergueik.

the class WhenTestingDataSource method testInvalidJdbcDriverShouldFail.

@Test
public void testInvalidJdbcDriverShouldFail() throws Exception {
    final DbAuditPublisher publisher = new DbAuditPublisherImpl();
    final DbAuditPublisherDescriptor descriptor = (DbAuditPublisherDescriptor) publisher.getDescriptor();
    final FormValidation testResult = descriptor.doTestJdbcConnection("WrongDriver", jdbcUrl, jdbcUser, jdbcPassword);
    Assert.assertEquals("Unexpected successful connection.", FormValidation.Kind.ERROR, testResult.kind);
}
Also used : FormValidation(hudson.util.FormValidation) DbAuditPublisherImpl(org.jenkins.plugins.audit2db.internal.DbAuditPublisherImpl) DbAuditPublisher(org.jenkins.plugins.audit2db.DbAuditPublisher) DbAuditPublisherDescriptor(org.jenkins.plugins.audit2db.DbAuditPublisherDescriptor) Test(org.junit.Test)

Example 10 with FormValidation

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

the class BuildTriggerTest method smokes.

@Issue("JENKINS-28113")
@Test
public void smokes() throws Exception {
    BuildTrigger.DescriptorImpl d = r.jenkins.getDescriptorByType(BuildTrigger.DescriptorImpl.class);
    FreeStyleProject us = r.createProject(FreeStyleProject.class, "us");
    WorkflowJob ds = r.createProject(WorkflowJob.class, "ds");
    ds.setDefinition(new CpsFlowDefinition("", true));
    assertEquals(Collections.singletonList("ds"), d.doAutoCompleteChildProjects("d", us, r.jenkins).getValues());
    FormValidation validation = d.doCheck(us, "ds");
    assertEquals(validation.renderHtml(), FormValidation.Kind.OK, validation.kind);
    us.getPublishersList().add(new BuildTrigger("ds", Result.SUCCESS));
    r.jenkins.setQuietPeriod(0);
    FreeStyleBuild us1 = r.buildAndAssertSuccess(us);
    r.waitUntilNoActivity();
    WorkflowRun ds1 = ds.getLastBuild();
    assertNotNull("triggered", ds1);
    Cause.UpstreamCause cause = ds1.getCause(Cause.UpstreamCause.class);
    assertNotNull(cause);
    assertEquals(us1, cause.getUpstreamRun());
}
Also used : CpsFlowDefinition(org.jenkinsci.plugins.workflow.cps.CpsFlowDefinition) FormValidation(hudson.util.FormValidation) Cause(hudson.model.Cause) BuildTrigger(hudson.tasks.BuildTrigger) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) Issue(org.jvnet.hudson.test.Issue) 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