Search in sources :

Example 61 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails in project selenium_java by sergueik.

the class WhenSchedulingJob method testPlainJobShouldSaveNoParameters.

@Test
public void testPlainJobShouldSaveNoParameters() throws Exception {
    final FreeStyleProject project = createFreeStyleProject("PlainJob");
    // enable audit2db plugin
    final DbAuditPublisher plugin = getPlugin();
    project.getPublishersList().add((Publisher) plugin);
    // build now
    final Future<FreeStyleBuild> futureBuild = project.scheduleBuild2(0);
    final FreeStyleBuild build = futureBuild.get();
    Assert.assertNotNull(build);
    Assert.assertEquals("Unexpected build result", Result.SUCCESS, build.getResult());
    // check data persistence
    final BuildDetailsRepository repository = plugin.getRepository();
    final BuildDetails actual = repository.getBuildDetailsForBuild(build);
    final BuildDetails expected = new BuildDetailsImpl(build);
    Assert.assertEquals("Unexpected build details", expected, actual);
    Assert.assertNotNull("Unexpected null end date", actual.getEndDate());
    Assert.assertTrue("Unexpected duration", actual.getDuration() > 0L);
    Assert.assertEquals("Unexpected number of params", 0, actual.getParameters().size());
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) BuildDetailsRepository(org.jenkins.plugins.audit2db.data.BuildDetailsRepository) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) DbAuditPublisher(org.jenkins.plugins.audit2db.DbAuditPublisher) Test(org.junit.Test)

Example 62 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails in project selenium_java by sergueik.

the class Audit2DbExecutionTests method testRunAddsListenerWithValidBuildDetailsToStepContext.

@Test
public void testRunAddsListenerWithValidBuildDetailsToStepContext() throws Exception {
    Audit2DbStep step = new Audit2DbStep(JDBC_DRIVER, JDBC_URL, JDBC_USER, JDBC_PASS);
    final List<Audit2DbGraphListener> listeners = new ArrayList<Audit2DbGraphListener>();
    doReturn("/computer/(master)/").when(computer).getUrl();
    doReturn(node).when(computer).getNode();
    doReturn(computer).when(stepContext).get(Computer.class);
    doReturn("Full Display Name # -99").when(run).getFullDisplayName();
    doReturn(run).when(stepContext).get(Run.class);
    doReturn(flowExecution).when(stepContext).get(FlowExecution.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            listeners.add((Audit2DbGraphListener) invocation.getArguments()[0]);
            return null;
        }
    }).when(flowExecution).addListener(Mockito.any(GraphListener.class));
    Audit2DbExecution execution = new Audit2DbExecution(step, stepContext);
    execution.run();
    Audit2DbGraphListener listener = listeners.get(0);
    verify(flowExecution).addListener(listener);
    assertThat("No BuildDetails", listener, hasProperty("details", Matchers.isA(BuildDetails.class)));
    BuildDetails details = listener.getDetails();
    assertNotNull("Null BuildDetails", details);
    assertEquals("Mis-matched name", "Full Display Name # -99", details.getFullName());
    assertNotNull("Null BuildDetails.node", details.getNode());
    assertEquals("Mis-matched node url", "http://unconfigured-jenkins-server/computer/(master)/", details.getNode().getUrl());
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) GraphListener(org.jenkinsci.plugins.workflow.flow.GraphListener) Test(org.junit.Test)

Aggregations

BuildDetails (org.jenkins.plugins.audit2db.model.BuildDetails)62 Test (org.junit.Test)50 List (java.util.List)25 Calendar (java.util.Calendar)11 BuildParameter (org.jenkins.plugins.audit2db.model.BuildParameter)11 Date (java.util.Date)9 ArrayList (java.util.ArrayList)8 TransactionStatus (org.springframework.transaction.TransactionStatus)8 BuildDetailsHibernateRepository (org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository)5 BuildDetailsImpl (org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl)5 JobsByParamReportImpl (org.jenkins.plugins.audit2db.internal.reports.JobsByParamReportImpl)5 JobHistoryReport (org.jenkins.plugins.audit2db.reports.JobHistoryReport)5 JobsByParamReport (org.jenkins.plugins.audit2db.reports.JobsByParamReport)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 BuildNode (org.jenkins.plugins.audit2db.model.BuildNode)4 JobsByDateReport (org.jenkins.plugins.audit2db.reports.JobsByDateReport)4 HashMap (java.util.HashMap)3 Jenkins (jenkins.model.Jenkins)3 DetachedCriteria (org.hibernate.criterion.DetachedCriteria)3 BuildDetailsRepository (org.jenkins.plugins.audit2db.data.BuildDetailsRepository)3