From b5daedba5d62b130b1c25d6b2b7783fc9502a8fb Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 6 Jul 2023 14:54:01 +0200 Subject: [PATCH] Add an IT --- src/it/cd-plugin/.mvn/extensions.xml | 7 +++ src/it/cd-plugin/.mvn/maven.config | 3 ++ src/it/cd-plugin/invoker.properties | 2 + src/it/cd-plugin/pom.xml | 47 +++++++++++++++++++ src/it/cd-plugin/postbuild.groovy | 23 +++++++++ .../src/main/java/test/SampleRootAction.java | 28 +++++++++++ .../cd-plugin/src/main/resources/index.jelly | 2 + .../test/java/test/SampleRootActionTest.java | 25 ++++++++++ .../src/test/resources/test/expected.txt | 1 + 9 files changed, 138 insertions(+) create mode 100644 src/it/cd-plugin/.mvn/extensions.xml create mode 100644 src/it/cd-plugin/.mvn/maven.config create mode 100644 src/it/cd-plugin/invoker.properties create mode 100644 src/it/cd-plugin/pom.xml create mode 100644 src/it/cd-plugin/postbuild.groovy create mode 100644 src/it/cd-plugin/src/main/java/test/SampleRootAction.java create mode 100644 src/it/cd-plugin/src/main/resources/index.jelly create mode 100644 src/it/cd-plugin/src/test/java/test/SampleRootActionTest.java create mode 100644 src/it/cd-plugin/src/test/resources/test/expected.txt diff --git a/src/it/cd-plugin/.mvn/extensions.xml b/src/it/cd-plugin/.mvn/extensions.xml new file mode 100644 index 0000000000..90787cbb2d --- /dev/null +++ b/src/it/cd-plugin/.mvn/extensions.xml @@ -0,0 +1,7 @@ + + + io.jenkins.tools.incrementals + git-changelist-maven-extension + 1.6 + + diff --git a/src/it/cd-plugin/.mvn/maven.config b/src/it/cd-plugin/.mvn/maven.config new file mode 100644 index 0000000000..f7daf60d07 --- /dev/null +++ b/src/it/cd-plugin/.mvn/maven.config @@ -0,0 +1,3 @@ +-Pconsume-incrementals +-Pmight-produce-incrementals +-Dchangelist.format=%d.v%s diff --git a/src/it/cd-plugin/invoker.properties b/src/it/cd-plugin/invoker.properties new file mode 100644 index 0000000000..42e9017061 --- /dev/null +++ b/src/it/cd-plugin/invoker.properties @@ -0,0 +1,2 @@ +# Same options as in https://github.com/jenkins-infra/jenkins-maven-cd-action/blob/master/run.sh +invoker.goals=-Dstyle.color=always -Dset.changelist -Dchangelist=1234.deadbeef5678 -ntp -P-consume-incrementals -Pquick-build clean install diff --git a/src/it/cd-plugin/pom.xml b/src/it/cd-plugin/pom.xml new file mode 100644 index 0000000000..ab64c77d1a --- /dev/null +++ b/src/it/cd-plugin/pom.xml @@ -0,0 +1,47 @@ + + + 4.0.0 + + org.jenkins-ci.plugins + plugin + @project.version@ + + + org.jenkins-ci.plugins.its + cd-plugin + ${changelist} + hpi + CD plugin + CD description + + 999999-SNAPSHOT + false + + + + + org.jenkins-ci.plugins + structs + 1.5 + + + + + + org.jenkins-ci.plugins + structs + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + + + repo.jenkins-ci.org + https://repo.jenkins-ci.org/public/ + + + diff --git a/src/it/cd-plugin/postbuild.groovy b/src/it/cd-plugin/postbuild.groovy new file mode 100644 index 0000000000..0fce501e7e --- /dev/null +++ b/src/it/cd-plugin/postbuild.groovy @@ -0,0 +1,23 @@ +assert new File(basedir, 'target/cd-plugin.hpi').file +assert new File(basedir, 'target/cd-plugin.jar').file + +File installed = new File(basedir, '../../local-repo/org/jenkins-ci/plugins/its/cd-plugin/1234.deadbeef5678/') +assert new File(installed, 'cd-plugin-1234.deadbeef5678.hpi').file + +def targetPom = new File(basedir, 'target/cd-plugin-1234.deadbeef5678.pom') +assert targetPom.file + +def installedPom = new File(installed, 'cd-plugin-1234.deadbeef5678.pom') +assert installedPom.file + +assert installedPom.text.contains("") +assert installedPom.text.contains("") +assert installedPom.text.contains("") +assert installedPom.text.contains("") +assert installedPom.text.contains("") +assert !installedPom.text.contains("") +assert !installedPom.text.contains("") +assert !installedPom.text.contains("") +assert !installedPom.text.contains("") + +return true diff --git a/src/it/cd-plugin/src/main/java/test/SampleRootAction.java b/src/it/cd-plugin/src/main/java/test/SampleRootAction.java new file mode 100644 index 0000000000..66611bacbb --- /dev/null +++ b/src/it/cd-plugin/src/main/java/test/SampleRootAction.java @@ -0,0 +1,28 @@ +package test; + +import hudson.Extension; +import hudson.model.RootAction; +import org.kohsuke.stapler.HttpResponse; +import org.kohsuke.stapler.HttpResponses; + +@Extension +public class SampleRootAction implements RootAction { + @Override + public String getUrlName() { + return "sample"; + } + + @Override + public String getIconFileName() { + return null; + } + + @Override + public String getDisplayName() { + return null; + } + + public HttpResponse doIndex() { + return HttpResponses.plainText("sample served"); + } +} diff --git a/src/it/cd-plugin/src/main/resources/index.jelly b/src/it/cd-plugin/src/main/resources/index.jelly new file mode 100644 index 0000000000..2f655e510a --- /dev/null +++ b/src/it/cd-plugin/src/main/resources/index.jelly @@ -0,0 +1,2 @@ + +
diff --git a/src/it/cd-plugin/src/test/java/test/SampleRootActionTest.java b/src/it/cd-plugin/src/test/java/test/SampleRootActionTest.java new file mode 100644 index 0000000000..4e6ccea880 --- /dev/null +++ b/src/it/cd-plugin/src/test/java/test/SampleRootActionTest.java @@ -0,0 +1,25 @@ +package test; + +import static org.junit.Assert.*; + +import org.apache.commons.io.IOUtils; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; + +public class SampleRootActionTest { + + @Rule + public JenkinsRule r = new JenkinsRule(); + + @Test + public void smokes() throws Exception { + assertEquals( + IOUtils.toString(SampleRootActionTest.class.getResource("expected.txt")), + r.createWebClient() + .goTo("sample", "text/plain") + .getWebResponse() + .getContentAsString() + .trim()); + } +} diff --git a/src/it/cd-plugin/src/test/resources/test/expected.txt b/src/it/cd-plugin/src/test/resources/test/expected.txt new file mode 100644 index 0000000000..f18734ec4a --- /dev/null +++ b/src/it/cd-plugin/src/test/resources/test/expected.txt @@ -0,0 +1 @@ +sample served \ No newline at end of file