Skip to content

Commit

Permalink
Test for JENKINS-30386
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNielsen committed Sep 10, 2015
1 parent fe97369 commit 8671c16
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
3 changes: 3 additions & 0 deletions src/main/resources/index.jelly
@@ -0,0 +1,3 @@
<div>
A plugin that integrates with GrammaTech CodeSonar.
</div>
Expand Up @@ -5,15 +5,14 @@
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.model.queue.QueueTaskFuture;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import org.apache.commons.io.FileUtils;
import static org.junit.Assert.*;
import org.jenkinsci.plugins.codesonar.CodeSonarPublisher;
import org.jenkinsci.plugins.codesonar.conditions.Condition;
import org.jenkinsci.plugins.codesonar.conditions.PercentageOfWariningsIncreasedInCasesBellowCertainRankCondition;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
Expand Down Expand Up @@ -78,4 +77,33 @@ public void providedProjectNameIsEmpty_BuildFails() throws Exception {
// assert
assertEquals(EXPECTED_RESULT, build.getResult());
}

@Test
public void testLogging() throws Exception {
final Result EXPECTED_RESULT = Result.FAILURE;

final int RANK_OF_WARNINGS = 30;
final float WARNING_PERCENTAGE = 50.0f;
PercentageOfWariningsIncreasedInCasesBellowCertainRankCondition condition =
new PercentageOfWariningsIncreasedInCasesBellowCertainRankCondition(RANK_OF_WARNINGS, WARNING_PERCENTAGE);

final String VALID_HUB_ADDRESS = "10.10.10.10";
final String RANDOM_NAME = "projectNotThere";

FreeStyleProject project = jenkinsRule.createFreeStyleProject();

List<Condition> conditions = new ArrayList<Condition>();
project.getPublishersList().add(new CodeSonarPublisher(conditions, VALID_HUB_ADDRESS, RANDOM_NAME));

// act
QueueTaskFuture<FreeStyleBuild> queueTaskFuture = project.scheduleBuild2(0, new Cause.UserIdCause());
FreeStyleBuild build = queueTaskFuture.get();

// assert
assertEquals(EXPECTED_RESULT, build.getResult());

// assert that we have a message in the console log
String log = FileUtils.readFileToString(build.getLogFile());
assertTrue(log.contains("[CodeSonar] Request sent to http://10.10.10.10/index.xml"));
}
}

0 comments on commit 8671c16

Please sign in to comment.