Search in sources :

Example 1 with BuildDetailsImpl

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

the class DbAuditPublisherImpl method prebuild.

@Override
public boolean prebuild(final AbstractBuild<?, ?> build, final BuildListener listener) {
    LOGGER.log(Level.FINE, String.format("prebuild: %s;", build.getDisplayName()));
    Object id = null;
    final BuildDetails details = new BuildDetailsImpl(build);
    try {
        id = getRepository().saveBuildDetails(details);
        LOGGER.log(Level.FINE, "Saved build details with id=" + id);
    } catch (final Throwable t) {
        LOGGER.log(Level.SEVERE, t.getMessage(), t);
    }
    return ((super.prebuild(build, listener)) && (id != null));
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails)

Example 2 with BuildDetailsImpl

use of org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl 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 3 with BuildDetailsImpl

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

the class BuildDetailsImplTests method getBuildDetails.

private BuildDetails getBuildDetails() {
    final BuildDetails build = new BuildDetailsImpl();
    build.setDuration(Long.valueOf(60));
    build.setEndDate(new Date(build.getStartDate().getTime() + (build.getDuration() * 1000)));
    build.setFullName("BUILD FULL NAME");
    build.setId("BUILD ID");
    build.setName("BUILD NAME");
    build.setUserId("BUILD USER ID");
    build.setUserName("BUILD USER NAME");
    final List<BuildParameter> params = new ArrayList<BuildParameter>();
    params.add(new BuildParameterImpl("PARAM_ID", "PARAM NAME", "PARAM VALUE", build));
    build.setParameters(params);
    return build;
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ArrayList(java.util.ArrayList) BuildParameterImpl(org.jenkins.plugins.audit2db.internal.model.BuildParameterImpl) Date(java.util.Date)

Example 4 with BuildDetailsImpl

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

the class TestUtils method createRandomBuildDetails.

public static BuildDetails createRandomBuildDetails(final boolean withParams) {
    final long salt = System.nanoTime();
    final BuildDetails build = new BuildDetailsImpl();
    build.setDuration(Long.valueOf(60 + (long) (Math.random() * 60)));
    build.setEndDate(new Date(build.getStartDate().getTime() + (build.getDuration() * 1000)));
    build.setFullName("BUILD FULL NAME " + salt);
    build.setId("BUILD ID " + salt);
    build.setName("BUILD NAME " + salt);
    build.setUserId("BUILD USER ID " + salt);
    build.setUserName("BUILD USER NAME " + salt);
    if (withParams) {
        final List<BuildParameter> params = new ArrayList<BuildParameter>();
        params.add(new BuildParameterImpl("PARAM_ID 1 " + salt, "PARAM NAME 1 " + salt, "PARAM VALUE 1 " + salt, build));
        params.add(new BuildParameterImpl("PARAM_ID 2 " + salt, "PARAM NAME 2 " + salt, "PARAM VALUE 2 " + salt, build));
        build.setParameters(params);
    }
    final BuildNode node = new BuildNodeImpl("NODE ADDRESS", "NODE HOSTNAME", "NODE DISPLAYNAME", "NODE URL", "NODE NAME", "NODE DESCRIPTION", "NODE LABEL");
    build.setNode(node);
    return build;
}
Also used : BuildDetailsImpl(org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl) BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) BuildNodeImpl(org.jenkins.plugins.audit2db.internal.model.BuildNodeImpl) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) ArrayList(java.util.ArrayList) BuildParameterImpl(org.jenkins.plugins.audit2db.internal.model.BuildParameterImpl) Date(java.util.Date) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode)

Example 5 with BuildDetailsImpl

use of org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl 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

BuildDetailsImpl (org.jenkins.plugins.audit2db.internal.model.BuildDetailsImpl)6 BuildDetails (org.jenkins.plugins.audit2db.model.BuildDetails)5 Date (java.util.Date)3 FreeStyleBuild (hudson.model.FreeStyleBuild)2 FreeStyleProject (hudson.model.FreeStyleProject)2 ArrayList (java.util.ArrayList)2 DbAuditPublisher (org.jenkins.plugins.audit2db.DbAuditPublisher)2 BuildDetailsRepository (org.jenkins.plugins.audit2db.data.BuildDetailsRepository)2 BuildParameterImpl (org.jenkins.plugins.audit2db.internal.model.BuildParameterImpl)2 BuildParameter (org.jenkins.plugins.audit2db.model.BuildParameter)2 Test (org.junit.Test)2 BooleanParameterDefinition (hudson.model.BooleanParameterDefinition)1 ParameterDefinition (hudson.model.ParameterDefinition)1 ParametersDefinitionProperty (hudson.model.ParametersDefinitionProperty)1 StringParameterDefinition (hudson.model.StringParameterDefinition)1 IOException (java.io.IOException)1 UnknownHostException (java.net.UnknownHostException)1 BuildNodeImpl (org.jenkins.plugins.audit2db.internal.model.BuildNodeImpl)1 BuildNode (org.jenkins.plugins.audit2db.model.BuildNode)1