hudson.util.FormValidation.Kind Java Examples

The following examples show how to use hudson.util.FormValidation.Kind. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GroovyParser.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Validates this instance.
 *
 * @return {@code true} if this instance is valid, {@code false} otherwise
 */
public boolean isValid() {
    DescriptorImpl d = new DescriptorImpl(getJenkinsFacade());

    return d.doCheckScript(script).kind == Kind.OK
            && d.doCheckRegexp(regexp).kind == Kind.OK
            && d.validate(name, Messages.GroovyParser_Error_Name_isEmpty()).kind == Kind.OK;
}
 
Example #2
Source File: FormValidationAssert.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies that the kind of the {@link FormValidation} is {@link Kind#ERROR}.
 *
 * @return this assertion object.
 * @throws AssertionError
 *         if the kind of the {@link FormValidation} is not {@link Kind#ERROR}.
 */
public FormValidationAssert isError() {
    isNotNull();

    if (!Objects.equals(actual.kind, Kind.ERROR)) {
        failWithMessage(EXPECTED_BUT_WAS_MESSAGE, "kind", actual, "ERROR", "not an ERROR");
    }

    return this;
}
 
Example #3
Source File: FormValidationAssert.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies that the kind of the {@link FormValidation} is {@link Kind#OK}.
 *
 * @return this assertion object.
 * @throws AssertionError
 *         if the kind of the {@link FormValidation} is not {@link Kind#OK}.
 */
public FormValidationAssert isOk() {
    isNotNull();

    if (!Objects.equals(actual.kind, Kind.OK)) {
        failWithMessage(EXPECTED_BUT_WAS_MESSAGE, "kind", actual, "OK", "not OK");
    }

    return this;
}
 
Example #4
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies doCheckCredentialsId returns OK for credentials in the store 
 * @throws IOException 
 */
@Test
public void testDoCheckCredentialsFound() throws IOException {
    StandardUsernameCredentials user = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, testCredentials, "Description", testCredentialsUser, testCredentialsPassword);
    CredentialsProvider.lookupStores(j.getInstance()).iterator().next().addCredentials(Domain.global(), user);

    BuildStatusConfig instance = new BuildStatusConfig();
    assertEquals(Kind.OK, instance.doCheckCredentialsId(null, testCredentials).kind);
}
 
Example #5
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies doCheckCredentialsId returns ERROR for credentials not in the store 
 * @throws IOException 
 */
@Test
public void testDoCheckCredentialsNotFound() throws IOException {
    StandardUsernameCredentials user = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, testCredentials, "Description", testCredentialsUser, testCredentialsPassword);
    CredentialsProvider.lookupStores(j.getInstance()).iterator().next().addCredentials(Domain.global(), user);

    BuildStatusConfig instance = new BuildStatusConfig();
    assertEquals(Kind.ERROR, instance.doCheckCredentialsId(null, testInvalidCredentials).kind);
}
 
Example #6
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies doCheckHttpCredentialsId returns OK for credentials in the store
 * @throws IOException
 */
@Test
public void testDoCheckHttpCredentialsFound() throws IOException {
    StandardUsernameCredentials user = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, testCredentials, "Description", testCredentialsUser, testCredentialsPassword);
    CredentialsProvider.lookupStores(j.getInstance()).iterator().next().addCredentials(Domain.global(), user);

    BuildStatusConfig instance = new BuildStatusConfig();
    assertEquals(Kind.OK, instance.doCheckHttpCredentialsId(null, testCredentials).kind);
}
 
Example #7
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 5 votes vote down vote up
/**
 * Verifies doCheckHttpCredentialsId returns ERROR for credentials not in the store
 * @throws IOException
 */
@Test
public void testDoCheckHttpCredentialsNotFound() throws IOException {
    StandardUsernameCredentials user = new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, testCredentials, "Description", testCredentialsUser, testCredentialsPassword);
    CredentialsProvider.lookupStores(j.getInstance()).iterator().next().addCredentials(Domain.global(), user);

    BuildStatusConfig instance = new BuildStatusConfig();
    assertEquals(Kind.ERROR, instance.doCheckHttpCredentialsId(null, testInvalidCredentials).kind);
}
 
Example #8
Source File: Site.java    From jira-steps-plugin with Apache License 2.0 5 votes vote down vote up
public FormValidation doValidateCredentials(@QueryParameter String url,
                                            @QueryParameter String credentialsId,
                                            @QueryParameter Integer timeout,
                                            @QueryParameter Integer readTimeout) throws IOException {
  FormValidation validation = doCheckUrl(url);
  if (validation.kind != Kind.OK) {
    return FormValidation.error(Messages.Site_emptyURL());
  }

  validation = doCheckTimeout(timeout);
  if (validation.kind != Kind.OK) {
    return validation;
  }

  validation = doCheckReadTimeout(readTimeout);
  if (validation.kind != Kind.OK) {
    return validation;
  }

  Site site = new Site("test", new URL(url), LoginType.CREDENTIAL.name(), timeout);
  site.setCredentialsId(credentialsId);
  site.setReadTimeout(readTimeout);

  try {
    final JiraService service = new JiraService(site);
    final ResponseData<Map<String, Object>> response = service.getServerInfo();
    if (response.isSuccessful()) {
      Map<String, Object> data = response.getData();
      return FormValidation.ok(Messages.Site_testSuccess(data.get("serverTitle"), data.get("version")));
    } else {
      return FormValidation.error(response.getError());
    }
  } catch (Exception e) {
    log.log(Level.WARNING, Messages.Site_testFail(url), e);
  }
  return FormValidation.error(Messages.Site_testFail(url));
}
 
Example #9
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
/**
 * Verifies doCheckCredentialsId returns OK if empty 
 */
@Test
public void testDoCheckCredentialsIdEmpty() {
    BuildStatusConfig instance = new BuildStatusConfig();
    assertEquals(Kind.OK, instance.doCheckCredentialsId(null, "").kind);
}
 
Example #10
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
/**
 * Verifies doCheckHttpCredentialsId returns OK if empty
 */
@Test
public void testDoCheckHttpCredentialsIdEmpty() {
    BuildStatusConfig instance = new BuildStatusConfig();
    assertEquals(Kind.OK, instance.doCheckHttpCredentialsId(null, "").kind);
}
 
Example #11
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
@Test
public void testDoCheckHttpEndpointEmpty(){
    BuildStatusConfig instance = new BuildStatusConfig();
    FormValidation result = instance.doCheckHttpEndpoint(null, "");
    assertEquals(Kind.ERROR, result.kind);
}
 
Example #12
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
@Test
public void testDoCheckHttpEndpointValid(){
    BuildStatusConfig instance = new BuildStatusConfig();
    FormValidation result = instance.doCheckHttpEndpoint(null, "https://mock.com:8443/api?token=1q2w3e");
    assertEquals(Kind.OK, result.kind);
}
 
Example #13
Source File: BuildStatusConfigTest.java    From github-autostatus-plugin with MIT License 4 votes vote down vote up
@Test
public void testDoCheckHttpEndpointInvalid(){
    BuildStatusConfig instance = new BuildStatusConfig();
    FormValidation result = instance.doCheckHttpEndpoint(null, "mock.com/api?token=1q2w3e");
    assertEquals(Kind.ERROR, result.kind);
}
 
Example #14
Source File: DingTalkRobotConfig.java    From dingtalk-plugin with MIT License 4 votes vote down vote up
/**
 * 测试配置信息
 *
 * @param id                      id
 * @param name                    名称
 * @param webhook                 webhook
 * @param securityPolicyConfigStr 安全策略
 * @return 机器人配置是否正确
 */
public FormValidation doTest(
    @QueryParameter("id") String id,
    @QueryParameter("name") String name,
    @QueryParameter("webhook") String webhook,
    @QueryParameter("securityPolicyConfigs") String securityPolicyConfigStr
) {
  CopyOnWriteArrayList<DingTalkSecurityPolicyConfig> securityPolicyConfigs = new CopyOnWriteArrayList<>();
  JSONArray array = (JSONArray) JSONSerializer.toJSON(securityPolicyConfigStr);
  for (Object item : array) {
    JSONObject json = (JSONObject) item;
    securityPolicyConfigs.add(
        new DingTalkSecurityPolicyConfig(
            (Boolean) json.get("checked"),
            (String) json.get("type"),
            (String) json.get("value"),
            ""
        )
    );
  }
  DingTalkRobotConfig robotConfig = new DingTalkRobotConfig(
      id,
      name,
      webhook,
      securityPolicyConfigs
  );
  DingTalkSender sender = new DingTalkSender(robotConfig);
  String rootUrl = Jenkins.get().getRootUrl();
  User user = User.current();
  if (user == null) {
    user = User.getUnknown();
  }
  String text = BuildJobModel
      .builder()
      .projectName("欢迎使用钉钉机器人插件~")
      .projectUrl(rootUrl)
      .jobName("系统配置")
      .jobUrl(rootUrl + "/configure")
      .statusType(BuildStatusEnum.SUCCESS)
      .duration("-")
      .executorName(user.getDisplayName())
      .executorMobile(user.getDescription())
      .build()
      .toMarkdown();
  MessageModel msg = MessageModel
      .builder()
      .type(MsgTypeEnum.MARKDOWN)
      .title("钉钉机器人测试成功")
      .text(text)
      .atAll(true)
      .build();
  String message = sender.sendMarkdown(msg);
  if (message == null) {
    return FormValidation
        .respond(
            Kind.OK,
            "<img src='"
                + rootUrl
                + "/images/16x16/accept.png'>"
                + "<span style='padding-left:4px;color:#52c41a;font-weight:bold;'>测试成功</span>"
        );
  }
  return FormValidation.error(message);
}