Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #353 from jenkinsci/JENKINS-41196
[JENKINS-41196] demonstrate that core component override plugin can work in ATH
- Loading branch information
Showing
4 changed files
with
121 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package plugins; | ||
|
||
import hudson.util.VersionNumber; | ||
import org.apache.commons.io.FileUtils; | ||
import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest; | ||
import org.jenkinsci.test.acceptance.junit.WithPlugins; | ||
import org.jenkinsci.test.acceptance.update_center.UpdateCenterMetadataProvider; | ||
import org.junit.Ignore; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.rules.TemporaryFolder; | ||
|
||
import javax.inject.Inject; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.util.jar.Attributes; | ||
import java.util.jar.JarFile; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* @author Kohsuke Kawaguchi | ||
*/ | ||
public class RemotingPluginTest extends AbstractJUnitTest { | ||
@Rule | ||
public TemporaryFolder tmp = new TemporaryFolder(); | ||
|
||
@Inject | ||
UpdateCenterMetadataProvider ucmp; | ||
|
||
/** | ||
* When installing a core component override plugin, we should see that plugin functioning. | ||
* | ||
* <p> | ||
* Run with environment variable: <tt>REMOTING_JPI=path/to/your-locally-build-remoting.hpi | ||
* <p> | ||
* We check this by: | ||
* <ol> | ||
* <li>Testing the version of the plugin as declared installed | ||
* <li>Making sure that the actual jar file in the system is replaced | ||
* </ol> | ||
*/ | ||
@Test | ||
@WithPlugins({"remoting"}) | ||
@Ignore // meant to be used to locally demonstrate JENKINS-41196 support | ||
public void test() throws IOException, InterruptedException { | ||
// expected version | ||
final String version = ucmp.get(jenkins).plugins.get("remoting").getVersion(); | ||
|
||
assertThat(trimSnapshot(jenkins.getPlugin("remoting").getVersion()), is(version)); | ||
|
||
File jar = tmp.newFile(); | ||
FileUtils.copyURLToFile(jenkins.url("jnlpJars/slave.jar"),jar); | ||
try (JarFile j = new JarFile(jar)) {// this is the copy of remoting jar | ||
Attributes main = j.getManifest().getMainAttributes(); | ||
assertThat(main.getValue("Version"),is(version)); | ||
} | ||
} | ||
|
||
/** | ||
* For version number like "1.0-SNAPSHOT (private-921e74fb-kohsuke)" trim off the whitespace and onward | ||
*/ | ||
private String trimSnapshot(VersionNumber v) { | ||
return v.toString().split(" ")[0]; | ||
} | ||
} |