Skip to content

Commit

Permalink
JENKINS-44165 Cover for non-existing owners
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysdk committed Jun 1, 2017
1 parent 34524a6 commit c66a9b4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,14 @@ public boolean contains(TopLevelItem item) {
return getItems().contains(item);
}

@Override
public ItemGroup<? extends TopLevelItem> getOwnerItemGroup() {
if (getOwner() == null) {
return null;
}
return super.getOwnerItemGroup();
}

@Override
protected void submit(StaplerRequest req) throws IOException, ServletException, Descriptor.FormException {
req.bindJSON(this, req.getSubmittedForm());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import static org.junit.Assert.assertTrue;

import org.jenkinsci.plugins.workflow.job.WorkflowJob;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.jvnet.hudson.test.WithoutJenkins;
import org.kohsuke.stapler.export.Exported;

import java.lang.annotation.Annotation;
Expand All @@ -32,34 +35,41 @@

public class ComponentTest {

@Rule
public JenkinsRule jenkins = new JenkinsRule();

@Test
@WithoutJenkins
public void shouldBeConsideredWorkflowComponent() {
assertTrue(new Component(null, null, null).isWorkflowComponent());
}

@Test
public void shouldProperlyFormatExpectedWorkflowUrl() {
final String expectedName = "JobName";
WorkflowJob workflowJob = new WorkflowJob(null, expectedName);
WorkflowJob workflowJob = new WorkflowJob(jenkins.jenkins, expectedName);
Component component = new Component("Workflow component", workflowJob, null);
assertThat(component.getWorkflowUrl(), is("job/" + expectedName + "/"));
}

@Test
@WithoutJenkins
public void shouldExposeWorkflowJob() {
final WorkflowJob workflowJob = new WorkflowJob(null, "Name");
Component component = new Component("Component", workflowJob, null);
assertThat(component.getWorkflowJob(), is(workflowJob));
}

@Test
@WithoutJenkins
public void shouldExposePipelines() {
final List<Pipeline> pipelines = new ArrayList<Pipeline>();
Component component = new Component("Component", null, pipelines);
assertThat(component.getPipelines(), is(pipelines));
}

@Test
@WithoutJenkins
public void shouldHaveProperToString() {
final String componentName = "Component Name";
Component component = new Component(componentName, null, Collections.<Pipeline>emptyList());
Expand All @@ -69,6 +79,7 @@ public void shouldHaveProperToString() {
}

@Test
@WithoutJenkins
public void shouldHaveExportedProperties() throws NoSuchMethodException {
assertTrue(methodHasExportedAnnoation("isWorkflowComponent"));
assertTrue(methodHasExportedAnnoation("getWorkflowUrl"));
Expand Down

0 comments on commit c66a9b4

Please sign in to comment.