Skip to content
Permalink
Browse files
Merge pull request #3 from maselvaraj/master
[JENKINS-10544] Persist ShelveProject property whenever the job is updated
  • Loading branch information
benpatterson committed Mar 21, 2014
2 parents 2df406a + 634a524 commit ea6afb8d682ca8c0c78a7a8213e661fb73e5cf00
@@ -31,13 +31,14 @@ public void onLoaded()
@Override
public void onCreated( Item item )
{
if ( item instanceof AbstractProject )
{
AbstractProject project = (AbstractProject) item;
addShelveProjectProperty( project );
}
addShelveProjectPropertyIfAbstractProject(item);
}

@Override
public void onUpdated(Item item) {
addShelveProjectPropertyIfAbstractProject(item);
}

private void addShelveProjectProperty( AbstractProject<?, ?> project )
{
try
@@ -52,4 +53,11 @@ private void addShelveProjectProperty( AbstractProject<?, ?> project )
LOGGER.log( Level.SEVERE, "Failed to persist " + project, e );
}
}

private void addShelveProjectPropertyIfAbstractProject(Item item) {
if (item instanceof AbstractProject) {
AbstractProject project = (AbstractProject) item;
addShelveProjectProperty(project);
}
}
}
@@ -84,4 +84,16 @@ public void testOnCreate_shouldAddShelveProjectActionForNewProjects()
assertEquals( "Project should have had a ShelveProjectAction added.", 1,
freeStyleProject.getActions( ShelveProjectAction.class ).size() );
}

public void testOnUpdate_shouldAddShelveProjectActionForUpdatedProjects()
throws IOException
{
FreeStyleProject freeStyleProject = createFreeStyleProject( "Goofy Project" );

itemListener.onUpdated( freeStyleProject );

assertEquals( "Project should have been added just once.", 1, freeStyleProject.getActions().size() );
assertEquals( "Project should have had a ShelveProjectAction added.", 1,
freeStyleProject.getActions( ShelveProjectAction.class ).size() );
}
}

0 comments on commit ea6afb8

Please sign in to comment.