Skip to content
Permalink
Browse files
[JENKINS-28881] - Add Folder ownership tests for Run components
  • Loading branch information
oleg-nenashev committed Jan 6, 2016
1 parent f5357c9 commit 1e3e70fb08a59ca70359fd22379c98f13c7b5745
Showing 2 changed files with 49 additions and 0 deletions.
@@ -24,6 +24,7 @@

package com.synopsys.arc.jenkins.plugins.ownership.wrappers;

import com.cloudbees.hudson.plugins.folder.Folder;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipPlugin;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipPluginConfiguration;
@@ -44,8 +45,11 @@
import hudson.tasks.Shell;
import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.concurrent.Future;
import static junit.framework.Assert.*;
import org.jenkinsci.plugins.ownership.folders.FolderOwnershipHelper;
import org.jenkinsci.plugins.ownership.test.util.OwnershipPluginConfigurer;
import org.jenkinsci.plugins.ownership.util.environment.EnvSetupOptions;
import org.jenkinsci.plugins.ownership.util.mail.MailOptions;
import org.junit.Rule;
@@ -130,6 +134,26 @@ public void initJenkinsInstance() throws Exception {
r.assertLogContains("JOB_COOWNERS="+PROJECT_OWNER_ID, build);
}

@Test
@Bug(28881)
public void shouldInjectInheritedOwnershipInfo() throws Exception {
initJenkinsInstance();
OwnershipPluginConfigurer.forJenkinsRule(r)
.withGlobalEnvSetupOptions(new EnvSetupOptions(true, true))
.configure();

// Init folder with a nested job
Folder folder = r.jenkins.createProject(Folder.class, "folder");
FolderOwnershipHelper.setOwnership(folder, new OwnershipDescription(true, PROJECT_OWNER_ID, Collections.<String>emptyList()));
FreeStyleProject prj = folder.createProject(FreeStyleProject.class, "projectInsideFolder");
prj.getBuildersList().add(new Shell("env"));

// Run test. We expect Ownership info to be inherited for the project
FreeStyleBuild build = testVarsPresense(false);
r.assertLogContains("NODE_COOWNERS="+NODE_OWNER_ID, build);
r.assertLogContains("JOB_COOWNERS="+PROJECT_OWNER_ID, build);
}

private FreeStyleBuild testVarsPresense(boolean failSCM) throws Exception {
project.setAssignedNode(node);
if (failSCM) {
@@ -23,6 +23,7 @@
*/
package org.jenkinsci.plugins.ownership.model.runs;

import com.cloudbees.hudson.plugins.folder.Folder;
import com.gargoylesoftware.htmlunit.html.HtmlDivision;
import com.gargoylesoftware.htmlunit.html.HtmlPage;
import com.synopsys.arc.jenkins.plugins.ownership.OwnershipDescription;
@@ -39,6 +40,9 @@

import static org.junit.Assert.assertThat;
import static org.hamcrest.Matchers.*;
import org.jenkinsci.plugins.ownership.folders.FolderOwnershipHelper;
import org.jenkinsci.plugins.ownership.model.OwnershipInfo;
import static org.junit.Assert.assertThat;
import org.jvnet.hudson.test.Bug;

/**
@@ -50,6 +54,27 @@ public class RunOwnershipActionTest {
@Rule
public JenkinsRule jenkinsRule = new JenkinsRule();

@Test
@Bug(28881)
public void shouldInheritOwnershipInfoFromFolders() throws Exception {
Folder folder = jenkinsRule.jenkins.createProject(Folder.class, "folder");
FreeStyleProject project = folder.createProject(FreeStyleProject.class, "projectInFolder");

// Set ownership via API
OwnershipDescription original = new OwnershipDescription(true, "ownerId",
Arrays.asList("coowner1, coowner2"));
FolderOwnershipHelper.setOwnership(folder, original);

// Run project
FreeStyleBuild build = jenkinsRule.buildAndAssertSuccess(project);

OwnershipInfo ownershipInfo = RunOwnershipHelper.getInstance().getOwnershipInfo(build);
assertThat("Folder ownership helper should return the inherited value after the reload",
ownershipInfo.getDescription(), equalTo(original));
assertThat("OwnershipInfo should return the right reference",
ownershipInfo.getSource().getItem(), equalTo((Object)jenkinsRule.jenkins.getItemByFullName("folder")));
}

@Test
public void shouldDisplayStubSummaryBoxIfNoOwnership() throws Exception {
FreeStyleProject project = jenkinsRule.createFreeStyleProject();

0 comments on commit 1e3e70f

Please sign in to comment.