Skip to content

Commit faa8627

Browse files
committed
Added PngAction tests
1 parent 93b57e9 commit faa8627

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.gitee.jenkins.webhook.status;
2+
3+
import hudson.model.FreeStyleProject;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
6+
import org.mockito.junit.jupiter.MockitoExtension;
7+
8+
/**
9+
* @author Robin Müller
10+
*/
11+
@WithJenkins
12+
@ExtendWith(MockitoExtension.class)
13+
class BranchStatusPngActionTest extends StatusPngActionTest {
14+
15+
@Override
16+
protected BuildStatusAction getBuildStatusAction(FreeStyleProject project) {
17+
return new BranchStatusPngAction(project, branch);
18+
}
19+
}
20+
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.gitee.jenkins.webhook.status;
2+
3+
import hudson.model.FreeStyleProject;
4+
import org.junit.jupiter.api.extension.ExtendWith;
5+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
6+
import org.mockito.junit.jupiter.MockitoExtension;
7+
8+
/**
9+
* @author Robin Müller
10+
*/
11+
@WithJenkins
12+
@ExtendWith(MockitoExtension.class)
13+
class CommitStatusPngActionTest extends StatusPngActionTest {
14+
15+
@Override
16+
protected BuildStatusAction getBuildStatusAction(FreeStyleProject project) {
17+
return new CommitStatusPngAction(project, commitSha1);
18+
}
19+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package com.gitee.jenkins.webhook.status;
2+
3+
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.core.Is.is;
5+
import static org.mockito.Mockito.verify;
6+
7+
import hudson.model.FreeStyleBuild;
8+
import java.io.ByteArrayOutputStream;
9+
import org.apache.commons.io.IOUtils;
10+
import org.junit.jupiter.api.extension.ExtendWith;
11+
import org.jvnet.hudson.test.junit.jupiter.WithJenkins;
12+
import org.kohsuke.stapler.StaplerResponse2;
13+
import org.mockito.junit.jupiter.MockitoExtension;
14+
15+
/**
16+
* @author Robin Müller
17+
*/
18+
@WithJenkins
19+
@ExtendWith(MockitoExtension.class)
20+
abstract class StatusPngActionTest extends BuildStatusActionTest {
21+
22+
@Override
23+
protected void assertSuccessfulBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse2 response)
24+
throws Exception {
25+
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
26+
verify(response).setHeader("Cache-Control", "no-cache, private");
27+
verify(response).setHeader("Content-Type", "image/png");
28+
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("success.png"))));
29+
}
30+
31+
@Override
32+
protected void assertFailedBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse2 response)
33+
throws Exception {
34+
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
35+
verify(response).setHeader("Cache-Control", "no-cache, private");
36+
verify(response).setHeader("Content-Type", "image/png");
37+
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("failed.png"))));
38+
}
39+
40+
@Override
41+
protected void assertRunningBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse2 response)
42+
throws Exception {
43+
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
44+
verify(response).setHeader("Cache-Control", "no-cache, private");
45+
verify(response).setHeader("Content-Type", "image/png");
46+
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("running.png"))));
47+
}
48+
49+
@Override
50+
protected void assertCanceledBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse2 response)
51+
throws Exception {
52+
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
53+
verify(response).setHeader("Cache-Control", "no-cache, private");
54+
verify(response).setHeader("Content-Type", "image/png");
55+
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("unknown.png"))));
56+
}
57+
58+
@Override
59+
protected void assertUnstableBuild(FreeStyleBuild build, ByteArrayOutputStream out, StaplerResponse2 response)
60+
throws Exception {
61+
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
62+
verify(response).setHeader("Cache-Control", "no-cache, private");
63+
verify(response).setHeader("Content-Type", "image/png");
64+
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("unstable.png"))));
65+
}
66+
67+
@Override
68+
protected void assertNotFoundBuild(ByteArrayOutputStream out, StaplerResponse2 response) throws Exception {
69+
verify(response).setHeader("Expires", "Fri, 01 Jan 1984 00:00:00 GMT");
70+
verify(response).setHeader("Cache-Control", "no-cache, private");
71+
verify(response).setHeader("Content-Type", "image/png");
72+
assertThat(out.toByteArray(), is(IOUtils.toByteArray(getClass().getResourceAsStream("unknown.png"))));
73+
}
74+
}

0 commit comments

Comments
 (0)