Java Code Examples for org.jvnet.hudson.test.JenkinsRule#getLog()

The following examples show how to use org.jvnet.hudson.test.JenkinsRule#getLog() . 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: GerritReviewStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void gerritCommentStepInvokeNoAPITest() throws Exception {
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          "node {\n"
              + "  withEnv([\n"
              + "  ]) {\n"
              + "    gerritReview label: 'Verified', score: -1, message: 'Does not work'\n"
              + "  }\n"
              + "}",
          true));
  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  j.assertLogContains("Gerrit Review is disabled no API URL", run);
}
 
Example 2
Source File: GerritReviewStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void gerritCommentStepInvokeNoCredTest() throws Exception {
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          "node {\n"
              + "  withEnv([\n"
              + "    'GERRIT_API_URL=http://host/a/project',\n"
              + "  ]) {\n"
              + "    gerritReview label: 'Verified', score: -1, message: 'Does not work'\n"
              + "  }\n"
              + "}",
          true));
  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  j.assertLogContains("Gerrit Review requires authentication", run);
}
 
Example 3
Source File: GerritReviewStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 6 votes vote down vote up
@Test
public void gerritCommentStepInvokeMissingCredTest() throws Exception {
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          "node {\n"
              + "  withEnv([\n"
              + "    'GERRIT_API_URL=http://host/a/project',\n"
              + "    'GERRIT_CREDENTIALS_ID=cid',\n"
              + "  ]) {\n"
              + "    gerritReview label: 'Verified', score: -1, message: 'Does not work'\n"
              + "  }\n"
              + "}",
          true));
  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  j.assertLogContains("Gerrit Review requires authentication", run);
}
 
Example 4
Source File: MattermostSendStepIntegrationTest.java    From jenkins-mattermost-plugin with MIT License 6 votes vote down vote up
@Test
public void test_global_config_override() throws Exception {
  WorkflowJob job = jenkinsRule.jenkins.createProject(WorkflowJob.class, "workflow");
  // just define message
  job.setDefinition(
      new CpsFlowDefinition(
          "mattermostSend(message: 'message', endpoint: 'endpoint', icon: 'icon', channel: '#channel', color: 'good');",
          true));
  WorkflowRun run = jenkinsRule.assertBuildStatusSuccess(job.scheduleBuild2(0).get());
  // everything should come from step configuration
 //jenkinsRule.assertLogContains(
 String format = String.format(
          "Mattermost Send Pipeline step configured values from global config - connector: %s, icon: %s, channel: %s, color: %s",
	  false, false, false, false);
 String log = JenkinsRule.getLog(run);
 Assert.assertTrue(log.contains(format));
 //   run);
}
 
Example 5
Source File: IntegrationTest.java    From warnings-ng-plugin with MIT License 5 votes vote down vote up
/**
 * Returns the console log as a String.
 *
 * @param build
 *         the build to get the log for
 *
 * @return the console log
 */
protected String getConsoleLog(final Run<?, ?> build) {
    try {
        return JenkinsRule.getLog(build);
    }
    catch (IOException e) {
        throw new AssertionError(e);
    }
}
 
Example 6
Source File: GerritCommentStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void gerritCommentStepInvokeTest() throws Exception {
  int changeId = 4321;
  int revision = 1;
  String path = "/path/to/file";
  int line = 1;
  String message = "Invalid spacing";
  String branch = String.format("%02d/%d/%d", changeId % 100, changeId, revision);

  UsernamePasswordCredentialsImpl c =
      new UsernamePasswordCredentialsImpl(
          CredentialsScope.GLOBAL, "cid", "cid", "USERNAME", "PASSWORD");
  CredentialsProvider.lookupStores(j.jenkins)
      .iterator()
      .next()
      .addCredentials(Domain.global(), c);
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          String.format(
              ""
                  + "node {\n"
                  + "  withEnv([\n"
                  + "    'GERRIT_API_URL=https://%s:%s/a/project',\n"
                  + "    'GERRIT_API_INSECURE_HTTPS=true',\n"
                  + "    'GERRIT_CREDENTIALS_ID=cid',\n"
                  + "    'BRANCH_NAME=%s',\n"
                  + "  ]) {\n"
                  + "    gerritComment path: '%s', line: %s, message: '%s'\n"
                  + "  }\n"
                  + "}",
              g.getClient().remoteAddress().getHostString(),
              g.getClient().remoteAddress().getPort(),
              branch,
              path,
              line,
              message),
          true));

  DraftInput draftInput = new DraftInput();
  draftInput.path = path;
  draftInput.line = line;
  draftInput.message = message;
  g.getClient()
      .when(
          HttpRequest.request(
                  String.format(
                      "/a/project/a/changes/%s/revisions/%s/drafts", changeId, revision))
              .withMethod("PUT")
              .withBody(JsonBody.json(draftInput)))
      .respond(
          HttpResponse.response()
              .withStatusCode(200)
              .withBody(JsonBody.json(Collections.emptyMap())));

  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  g.getClient()
      .verify(
          HttpRequest.request(
              String.format("/a/project/a/changes/%s/revisions/%s/drafts", changeId, revision)),
          VerificationTimes.once());
}
 
Example 7
Source File: GerritCheckStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void gerritCheckStepInvokeFailSSLValidationTest() throws Exception {
  int changeId = 4321;
  int revision = 1;
  String checkerUuid = "checker";
  String checkStatus = "SUCCESSFUL";
  String message = "Does not work";
  String branch = String.format("%02d/%d/%d", changeId % 100, changeId, revision);

  UsernamePasswordCredentialsImpl c =
      new UsernamePasswordCredentialsImpl(
          CredentialsScope.GLOBAL, "cid", "cid", "USERNAME", "PASSWORD");
  CredentialsProvider.lookupStores(j.jenkins)
      .iterator()
      .next()
      .addCredentials(Domain.global(), c);
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          String.format(
              ""
                  + "node {\n"
                  + "  withEnv([\n"
                  + "    'GERRIT_API_URL=https://%s:%s/a/project',\n"
                  + "    'GERRIT_CREDENTIALS_ID=cid',\n"
                  + "    'BRANCH_NAME=%s',\n"
                  + "  ]) {\n"
                  + "    gerritCheck checks: [%s: '%s'], message: '%s'\n"
                  + "  }\n"
                  + "}",
              g.getClient().remoteAddress().getHostString(),
              g.getClient().remoteAddress().getPort(),
              branch,
              checkerUuid,
              checkStatus,
              message),
          true));

  WorkflowRun run = j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  j.assertLogContains("javax.net.ssl.SSLHandshakeException", run);
}
 
Example 8
Source File: GerritCheckStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void gerritCheckStepInvokeTest() throws Exception {
  int changeId = 4321;
  int revision = 1;
  String checkerUuid = "checker";
  String checkStatus = "SUCCESSFUL";
  String message = "Does work";
  String branch = String.format("%02d/%d/%d", changeId % 100, changeId, revision);

  UsernamePasswordCredentialsImpl c =
      new UsernamePasswordCredentialsImpl(
          CredentialsScope.GLOBAL, "cid", "cid", "USERNAME", "PASSWORD");
  CredentialsProvider.lookupStores(j.jenkins)
      .iterator()
      .next()
      .addCredentials(Domain.global(), c);
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "q");
  p.setDefinition(
      new CpsFlowDefinition(
          String.format(
              ""
                  + "node {\n"
                  + "  withEnv([\n"
                  + "    'GERRIT_API_URL=https://%s:%s/a/project',\n"
                  + "    'GERRIT_API_INSECURE_HTTPS=true',\n"
                  + "    'GERRIT_CREDENTIALS_ID=cid',\n"
                  + "    'BRANCH_NAME=%s',\n"
                  + "  ]) {\n"
                  + "    gerritCheck checks: [%s: '%s'], message: '%s'\n"
                  + "  }\n"
                  + "}",
              g.getClient().remoteAddress().getHostString(),
              g.getClient().remoteAddress().getPort(),
              branch,
              checkerUuid,
              checkStatus,
              message),
          true));

  String expectedUrl = String.format("/a/changes/%s/revisions/%s/checks/", changeId, revision);

  CheckInput checkInput = new CheckInputForObjectMapper();
  checkInput.checkerUuid = checkerUuid;
  checkInput.state = CheckState.valueOf(checkStatus);
  checkInput.message = message;
  checkInput.url = j.getURL().toString() + p.getUrl() + "1/console";
  g.getClient()
      .when(
          HttpRequest.request(expectedUrl).withMethod("POST").withBody(JsonBody.json(checkInput)))
      .respond(
          HttpResponse.response()
              .withStatusCode(200)
              .withBody(JsonBody.json(Collections.emptyMap())));

  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  g.getClient().verify(HttpRequest.request(expectedUrl), VerificationTimes.once());
}
 
Example 9
Source File: GerritCheckStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void gerritCheckStepTestWithUrlSet() throws Exception {
  int changeId = 4321;
  int revision = 1;
  String checkerUuid = "checker";
  String checkStatus = "SUCCESSFUL";
  String url = "https://example.com/test";
  String branch = String.format("%02d/%d/%d", changeId % 100, changeId, revision);
  UsernamePasswordCredentialsImpl c =
      new UsernamePasswordCredentialsImpl(
          CredentialsScope.GLOBAL, "cid", "cid", "USERNAME", "PASSWORD");
  CredentialsProvider.lookupStores(j.jenkins)
      .iterator()
      .next()
      .addCredentials(Domain.global(), c);
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          String.format(
              ""
                  + "node {\n"
                  + "  withEnv([\n"
                  + "    'GERRIT_API_URL=https://%s:%s/a/project',\n"
                  + "    'GERRIT_API_INSECURE_HTTPS=true',\n"
                  + "    'GERRIT_CREDENTIALS_ID=cid',\n"
                  + "    'BRANCH_NAME=%s',\n"
                  + "  ]) {\n"
                  + "    gerritCheck checks: [%s: '%s'], url: '%s'\n"
                  + "  }\n"
                  + "}",
              g.getClient().remoteAddress().getHostString(),
              g.getClient().remoteAddress().getPort(),
              branch,
              checkerUuid,
              checkStatus,
              url),
          true));

  String expectedUrl = String.format("/a/changes/%s/revisions/%s/checks/", changeId, revision);

  CheckInput checkInput = new CheckInputForObjectMapper();
  checkInput.checkerUuid = checkerUuid;
  checkInput.state = CheckState.valueOf(checkStatus);
  checkInput.url = url;
  g.getClient()
      .when(
          HttpRequest.request(expectedUrl).withMethod("POST").withBody(JsonBody.json(checkInput)))
      .respond(
          HttpResponse.response()
              .withStatusCode(200)
              .withBody(JsonBody.json(Collections.emptyMap())));

  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  g.getClient().verify(HttpRequest.request(expectedUrl), VerificationTimes.once());
}
 
Example 10
Source File: GerritReviewStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void gerritReviewStepInvokeFailSSLValidationTest() throws Exception {
  int changeId = 4321;
  int revision = 1;
  String label = "Verfied";
  int score = -1;
  String message = "Does not work";
  String branch = String.format("%02d/%d/%d", changeId % 100, changeId, revision);

  UsernamePasswordCredentialsImpl c =
      new UsernamePasswordCredentialsImpl(
          CredentialsScope.GLOBAL, "cid", "cid", "USERNAME", "PASSWORD");
  CredentialsProvider.lookupStores(j.jenkins)
      .iterator()
      .next()
      .addCredentials(Domain.global(), c);
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          String.format(
              ""
                  + "node {\n"
                  + "  withEnv([\n"
                  + "    'GERRIT_API_URL=https://%s:%s/a/project',\n"
                  + "    'GERRIT_CREDENTIALS_ID=cid',\n"
                  + "    'BRANCH_NAME=%s',\n"
                  + "  ]) {\n"
                  + "    gerritReview label: '%s', score: %s, message: '%s'\n"
                  + "  }\n"
                  + "}",
              g.getClient().remoteAddress().getHostString(),
              g.getClient().remoteAddress().getPort(),
              branch,
              label,
              score,
              message),
          true));

  WorkflowRun run = j.assertBuildStatus(Result.FAILURE, p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  j.assertLogContains("javax.net.ssl.SSLHandshakeException", run);
}
 
Example 11
Source File: GerritReviewStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void gerritReviewStepInvokeTest() throws Exception {
  int changeId = 4321;
  int revision = 1;
  String label = "Verfied";
  int score = -1;
  String message = "Does not work";
  String branch = String.format("%02d/%d/%d", changeId % 100, changeId, revision);

  UsernamePasswordCredentialsImpl c =
      new UsernamePasswordCredentialsImpl(
          CredentialsScope.GLOBAL, "cid", "cid", "USERNAME", "PASSWORD");
  CredentialsProvider.lookupStores(j.jenkins)
      .iterator()
      .next()
      .addCredentials(Domain.global(), c);
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          String.format(
              ""
                  + "node {\n"
                  + "  withEnv([\n"
                  + "    'GERRIT_API_URL=https://%s:%s/a/project',\n"
                  + "    'GERRIT_API_INSECURE_HTTPS=true',\n"
                  + "    'GERRIT_CREDENTIALS_ID=cid',\n"
                  + "    'BRANCH_NAME=%s',\n"
                  + "  ]) {\n"
                  + "    gerritReview labels: ['%s': %s], message: '%s'\n"
                  + "  }\n"
                  + "}",
              g.getClient().remoteAddress().getHostString(),
              g.getClient().remoteAddress().getPort(),
              branch,
              label,
              score,
              message),
          true));

  ReviewInput reviewInput = new ReviewInputForObjectMapper().label(label, score).message(message);
  reviewInput.drafts = ReviewInput.DraftHandling.PUBLISH;
  reviewInput.tag = "autogenerated:jenkins";
  reviewInput.notify = NotifyHandling.OWNER;
  g.getClient()
      .when(
          HttpRequest.request(
                  String.format(
                      "/a/project/a/changes/%s/revisions/%s/review", changeId, revision))
              .withMethod("POST")
              .withBody(JsonBody.json(reviewInput)))
      .respond(
          HttpResponse.response()
              .withStatusCode(200)
              .withBody(JsonBody.json(Collections.emptyMap())));

  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  g.getClient()
      .verify(
          HttpRequest.request(
              String.format("/a/project/a/changes/%s/revisions/%s/review", changeId, revision)),
          VerificationTimes.once());
}
 
Example 12
Source File: GerritReviewStepTest.java    From gerrit-code-review-plugin with Apache License 2.0 4 votes vote down vote up
@Test
public void gerritReviewStepInvokeLabelsTest() throws Exception {
  int changeId = 4321;
  int revision = 1;
  String label1 = "Verfied";
  int score1 = -1;
  String label2 = "CI-Review";
  int score2 = -1;
  String message = "Does not work";
  String branch = String.format("%02d/%d/%d", changeId % 100, changeId, revision);

  UsernamePasswordCredentialsImpl c =
      new UsernamePasswordCredentialsImpl(
          CredentialsScope.GLOBAL, "cid", "cid", "USERNAME", "PASSWORD");
  CredentialsProvider.lookupStores(j.jenkins)
      .iterator()
      .next()
      .addCredentials(Domain.global(), c);
  WorkflowJob p = j.jenkins.createProject(WorkflowJob.class, "p");
  p.setDefinition(
      new CpsFlowDefinition(
          String.format(
              ""
                  + "node {\n"
                  + "  withEnv([\n"
                  + "    'GERRIT_API_URL=https://%s:%s/a/project',\n"
                  + "    'GERRIT_API_INSECURE_HTTPS=true',\n"
                  + "    'GERRIT_CREDENTIALS_ID=cid',\n"
                  + "    'BRANCH_NAME=%s',\n"
                  + "  ]) {\n"
                  + "    gerritReview labels: ['%s': %s, '%s': %s], message: '%s'\n"
                  + "  }\n"
                  + "}",
              g.getClient().remoteAddress().getHostString(),
              g.getClient().remoteAddress().getPort(),
              branch,
              label1,
              score1,
              label2,
              score2,
              message),
          true));

  ReviewInput reviewInput =
      new ReviewInputForObjectMapper()
          .label(label1, score1)
          .label(label2, score2)
          .message(message);
  reviewInput.drafts = ReviewInput.DraftHandling.PUBLISH;
  reviewInput.tag = "autogenerated:jenkins";
  reviewInput.notify = NotifyHandling.OWNER;
  g.getClient()
      .when(
          HttpRequest.request(
                  String.format(
                      "/a/project/a/changes/%s/revisions/%s/review", changeId, revision))
              .withMethod("POST")
              .withBody(JsonBody.json(reviewInput)))
      .respond(
          HttpResponse.response()
              .withStatusCode(200)
              .withBody(JsonBody.json(Collections.emptyMap())));

  WorkflowRun run = j.assertBuildStatusSuccess(p.scheduleBuild2(0));
  String log = JenkinsRule.getLog(run);

  g.getClient()
      .verify(
          HttpRequest.request(
              String.format("/a/project/a/changes/%s/revisions/%s/review", changeId, revision)),
          VerificationTimes.once());
}