Search in sources :

Example 1 with BuildDetailsRepository

use of org.jenkins.plugins.audit2db.data.BuildDetailsRepository in project selenium_java by sergueik.

the class WhenSchedulingJob method testParameterisedJobShouldSaveAllParameters.

@Test
public void testParameterisedJobShouldSaveAllParameters() throws Exception {
    final FreeStyleProject project = createFreeStyleProject("ParameterisedJob");
    // set parameters
    final ParameterDefinition param1 = new StringParameterDefinition("myStringParam", "myStringValue", "My String Parameter");
    final ParameterDefinition param2 = new BooleanParameterDefinition("myBooleanParam", false, "My Boolean Parameter");
    project.addProperty(new ParametersDefinitionProperty(param1, param2));
    // 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", 2, actual.getParameters().size());
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) StringParameterDefinition(hudson.model.StringParameterDefinition) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ParametersDefinitionProperty(hudson.model.ParametersDefinitionProperty) BuildDetailsRepository(org.jenkins.plugins.audit2db.data.BuildDetailsRepository) FreeStyleBuild(hudson.model.FreeStyleBuild) FreeStyleProject(hudson.model.FreeStyleProject) BooleanParameterDefinition(hudson.model.BooleanParameterDefinition) StringParameterDefinition(hudson.model.StringParameterDefinition) ParameterDefinition(hudson.model.ParameterDefinition) DbAuditPublisher(org.jenkins.plugins.audit2db.DbAuditPublisher) Test(org.junit.Test)

Example 2 with BuildDetailsRepository

use of org.jenkins.plugins.audit2db.data.BuildDetailsRepository in project selenium_java by sergueik.

the class Audit2DbExecution method run.

@Override
protected Void run() throws Exception {
    StepContext context = getContext();
    Run<?, ?> run = context.get(Run.class);
    LOGGER.fine("StepContext.Run: " + run);
    Properties props = HibernateUtil.getExtraProperties(step.getJdbcDriver(), step.getJdbcUrl(), step.getJdbcUsername(), step.getJdbcPassword());
    if (StringUtils.isNotBlank(step.getHibernateDialect())) {
        props.put("hibernate.dialect", step.getHibernateDialect());
    }
    LOGGER.fine("props: " + props);
    SessionFactory sessionFactory = HibernateUtil.getSessionFactory(props);
    LOGGER.fine("sessionFactory: " + sessionFactory);
    BuildDetailsRepository repository = new BuildDetailsHibernateRepository(sessionFactory);
    BuildDetails details = BuildDetailsResolver.resolveBuildDetails(run, context.get(Computer.class));
    Audit2DbGraphListener listener = new Audit2DbGraphListener(repository, details);
    context.get(FlowExecution.class).addListener(listener);
    return null;
}
Also used : SessionFactory(org.hibernate.SessionFactory) StepContext(org.jenkinsci.plugins.workflow.steps.StepContext) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) FlowExecution(org.jenkinsci.plugins.workflow.flow.FlowExecution) BuildDetailsRepository(org.jenkins.plugins.audit2db.data.BuildDetailsRepository) Computer(hudson.model.Computer) Properties(java.util.Properties) BuildDetailsHibernateRepository(org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository)

Example 3 with BuildDetailsRepository

use of org.jenkins.plugins.audit2db.data.BuildDetailsRepository 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)

Aggregations

BuildDetailsRepository (org.jenkins.plugins.audit2db.data.BuildDetailsRepository)3 BuildDetails (org.jenkins.plugins.audit2db.model.BuildDetails)3 FreeStyleBuild (hudson.model.FreeStyleBuild)2 FreeStyleProject (hudson.model.FreeStyleProject)2 DbAuditPublisher (org.jenkins.plugins.audit2db.DbAuditPublisher)2 BuildDetailsImpl (org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl)2 Test (org.junit.Test)2 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)1 Computer (hudson.model.Computer)1 ParameterDefinition (hudson.model.ParameterDefinition)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 StringParameterDefinition (hudson.model.StringParameterDefinition)1 Properties (java.util.Properties)1 SessionFactory (org.hibernate.SessionFactory)1 BuildDetailsHibernateRepository (org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository)1 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)1 StepContext (org.jenkinsci.plugins.workflow.steps.StepContext)1