use of org.jenkinsci.test.acceptance.update_center.PluginSpec in project acceptance-test-harness by jenkinsci.
the class WithPluginsTest method combine_WithPlugins_annotations.
@Test
public void combine_WithPlugins_annotations() throws Exception {
// TODO test annotation harvesting and test class inheritance
List<WithPlugins> annotations = Arrays.asList(FakeTestClass.class.getAnnotation(WithPlugins.class), FakeTestClass.class.getMethod("test").getAnnotation(WithPlugins.class));
List<PluginSpec> actual = WithPlugins.RuleImpl.combinePlugins(annotations);
List<PluginSpec> expected = Arrays.asList(new PluginSpec("keep"), new PluginSpec("keepv@1"), // any version specification is more strict then plugin presence requirement
new PluginSpec("specify@42"), // ditto
new PluginSpec("keepspecific@42"), // never version is the more specific one
new PluginSpec("override@2"), // ditto
new PluginSpec("donotoverride@2"), new PluginSpec("inherit"), new PluginSpec("add"));
assertThat(actual, equalTo(expected));
}
use of org.jenkinsci.test.acceptance.update_center.PluginSpec in project acceptance-test-harness by jenkinsci.
the class JobDslPluginTest method should_fail_on_missing_plugin.
/**
* Verifies whether the build will be marked as failed or unstable if a plugin must
* be installed to support all features used in the DSL script.
*/
@Test
public void should_fail_on_missing_plugin() {
assumeTrue("This test requires a restartable Jenkins", jenkins.canRestart());
// check if plugin is installed. if true, disable plugin
PluginSpec pluginSpec = new PluginSpec("chucknorris");
PluginManager pm = jenkins.getPluginManager();
if (pm.isInstalled(pluginSpec)) {
pm.enablePlugin(pluginSpec.getName(), false);
jenkins.restart();
}
FreeStyleJob seedJob = createSeedJob();
JobDslBuildStep jobDsl = seedJob.addBuildStep(JobDslBuildStep.class);
jobDsl.setScript("job('New_Job') {\n" + " publishers {\n" + " chucknorris()\n" + " }\n" + "}");
seedJob.save();
Build build = seedJob.scheduleBuild().shouldBeUnstable();
assertThat(build.getConsole(), containsString("Warning: (script, line 3) plugin 'chucknorris' needs to be installed"));
seedJob.configure(() -> jobDsl.setFailOnMissingPlugin(true));
build = seedJob.scheduleBuild().shouldFail();
assertThat(build.getConsole(), containsString("ERROR: (script, line 3) plugin 'chucknorris' needs to be installed"));
}
use of org.jenkinsci.test.acceptance.update_center.PluginSpec in project acceptance-test-harness by jenkinsci.
the class PluginManager method installPlugins.
/**
* Installs specified plugins.
*
* @deprecated Please be encouraged to use {@link WithPlugins} annotations to statically declare
* the required plugins you need. If you really do need to install plugins in the middle
* of a test, as opposed to be in the beginning, then this is the right method.
* <p/>
* The deprecation marker is to call attention to {@link WithPlugins}. This method
* is not really deprecated.
* @return Always false.
*/
@Deprecated
public boolean installPlugins(final PluginSpec... specs) throws UnableToResolveDependencies, IOException {
final Map<String, String> candidates = getMapShortNamesVersion(specs);
if (!updated) {
checkForUpdates();
}
if (uploadPlugins) {
LOGGER.warning("Installing plugins by direct upload. Better to use the default MockUpdateCenter.");
// First check to see whether we need to do anything.
// If not, do not consider transitive dependencies of the requested plugins,
// which might force updates (and thus restarts) even though we already have
// a sufficiently new version of the requested plugin.
boolean someChangeRequired = false;
for (PluginSpec spec : specs) {
if (installationStatus(spec) != InstallationStatus.UP_TO_DATE) {
someChangeRequired = true;
break;
}
}
if (!someChangeRequired) {
return false;
}
List<PluginMetadata> pluginToBeInstalled = ucmd.get(jenkins).transitiveDependenciesOf(jenkins, Arrays.asList(specs));
for (PluginMetadata newPlugin : pluginToBeInstalled) {
final String name = newPlugin.getName();
String requiredVersion = candidates.get(name);
String availableVersion = newPlugin.getVersion();
if (requiredVersion == null) {
// a dependency
requiredVersion = availableVersion;
}
final String currentSpec = StringUtils.isNotEmpty(requiredVersion) ? name + "@" + requiredVersion : name;
InstallationStatus status = installationStatus(currentSpec);
if (status != InstallationStatus.UP_TO_DATE) {
if (new VersionNumber(requiredVersion).compareTo(new VersionNumber(availableVersion)) > 0) {
throw new AssumptionViolatedException(name + " has version " + availableVersion + " but " + requiredVersion + " was requested");
}
try {
newPlugin.uploadTo(jenkins, injector, availableVersion);
} catch (ArtifactResolutionException x) {
throw new UnableToResolveDependencies(x);
}
}
}
} else {
visit("available");
final ArrayList<PluginSpec> update = new ArrayList<>();
for (final PluginSpec n : specs) {
switch(installationStatus(n)) {
case NOT_INSTALLED:
tickPluginToInstall(n);
break;
case OUTDATED:
update.add(n);
break;
case UP_TO_DATE:
// Nothing to do
break;
default:
assert false : "Unreachable";
}
}
clickButton("Install");
// Plugins that are already installed in older version will be updated
System.out.println("Plugins to be updated: " + update);
if (!update.isEmpty()) {
// Updates tab
visit("");
for (PluginSpec n : update) {
tickPluginToInstall(n);
}
clickButton("Download now and install after restart");
}
}
// Jenkins will be restarted if necessary
new UpdateCenter(jenkins).waitForInstallationToComplete(specs);
return false;
}
use of org.jenkinsci.test.acceptance.update_center.PluginSpec in project acceptance-test-harness by jenkinsci.
the class UpdateCenter method waitForInstallationToComplete.
/**
* Wait for the plugin installation is done.
*
* Wait for all UC jobs are completed. If some of them fail or require restart, Jenkins is restarted.
* If some of the plugins is not installed after that or the version is older than expected, the waiting is considered failed.
*
* @return true if Jenkins ware restarted to install plugins.
* @throws InstallationFailedException If the installation has failed.
*/
public boolean waitForInstallationToComplete(final PluginSpec... specs) throws InstallationFailedException {
open();
// Wait for all plugins to get installed
waitFor(driver, not(Matchers.hasElement(by.xpath("//*[@id='log']//*[contains(.,'Pending') or contains(.,'Installing')]"))), 300);
String uc = getPageContent(driver);
// "IOException: Failed to dynamically deploy this plugin" can be reported (by at least some Jenkins versions)
// in case update of plugin dependency is needed (and is in fact performed in sibling UC job). Restart should fix that.
boolean restartRequired = uc.contains("restarted") || uc.contains("Failure");
Jenkins jenkins = getJenkins();
if (restartRequired) {
assumeTrue("This test requires a restartable Jenkins", jenkins.canRestart());
System.out.println("Restarting Jenkins to finish plugin installation");
jenkins.restart();
}
for (PluginSpec spec : specs) {
Plugin plugin = jenkins.getPlugin(spec.getName());
if (plugin == null) {
throw new InstallationFailedException("Plugin " + spec.getName() + " not installed, restarted " + restartRequired);
}
if (spec.getVersionNumber() != null && plugin.getVersion().isOlderThan(spec.getVersionNumber())) {
throw new InstallationFailedException("Plugin " + spec + " not installed in required version, is " + plugin.getVersion() + ", restarted " + true);
}
}
return restartRequired;
}
Aggregations