Search in sources :

Example 21 with BuildDetails

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

the class JobsByParamReportTests method matchingParametersShouldReturnNonEmptyResults.

@Test
public void matchingParametersShouldReturnNonEmptyResults() {
    final JobsByParamReport report = new JobsByParamReportImpl();
    report.setRepository(TestUtils.getTestRepository());
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(DbAuditUtil.getHostName());
    // after each test run
    for (final List<BuildDetails> detailsList : dataset.values()) {
        TestUtils.getTestRepository().saveBuildDetailsList(detailsList);
    }
    final BuildParameter param = dataset.values().iterator().next().get(0).getParameters().get(0);
    final Map<String, List<BuildDetails>> results = report.getProjectExecutions(param.getName(), param.getValue(), TestUtils.NOW, TestUtils.NOW);
    Assert.assertFalse("Unexpected empty results", results.isEmpty());
}
Also used : BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) JobsByParamReportImpl(org.jenkins.plugins.audit2db.internal.reports.JobsByParamReportImpl) List(java.util.List) JobsByParamReport(org.jenkins.plugins.audit2db.reports.JobsByParamReport) Test(org.junit.Test)

Example 22 with BuildDetails

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

the class JobsByParamReportTests method invalidParamNameShouldReturnEmptyResults.

@Test
public void invalidParamNameShouldReturnEmptyResults() {
    final JobsByParamReport report = new JobsByParamReportImpl();
    report.setRepository(TestUtils.getTestRepository());
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(DbAuditUtil.getHostName());
    // after each test run
    for (final List<BuildDetails> detailsList : dataset.values()) {
        TestUtils.getTestRepository().saveBuildDetailsList(detailsList);
    }
    final BuildParameter param = dataset.values().iterator().next().get(0).getParameters().get(0);
    final Map<String, List<BuildDetails>> results = report.getProjectExecutions(param.getName() + " INVALID", param.getValue(), TestUtils.NOW, TestUtils.NOW);
    Assert.assertTrue("Unexpected results collection", results.isEmpty());
}
Also used : BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) JobsByParamReportImpl(org.jenkins.plugins.audit2db.internal.reports.JobsByParamReportImpl) List(java.util.List) JobsByParamReport(org.jenkins.plugins.audit2db.reports.JobsByParamReport) Test(org.junit.Test)

Example 23 with BuildDetails

use of org.jenkins.plugins.audit2db.model.BuildDetails 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 24 with BuildDetails

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

the class BuildDetailsHibernateRepository method getBuildDetailsByParams.

/**
 * @see org.jenkins.plugins.audit2db.data.BuildDetailsRepository#getBuildDetailsByParams(String, String, String, Date, Date)
 */
@SuppressWarnings("unchecked")
@Override
public List<BuildDetails> getBuildDetailsByParams(final String masterHostName, final String paramName, final String paramValue, final Date fromDate, final Date toDate) {
    // we need to specifically state >=startdate AND <=enddate
    // because the "between" semantics vary between database
    // implementations and we want to use an inclusive filter every time
    final DetachedCriteria criteria = DetachedCriteria.forClass(BuildDetails.class).createAlias("node", "node").add(Restrictions.eq("node.masterHostName", masterHostName)).add(Restrictions.and(Restrictions.ge("startDate", getInclusiveStartDate(fromDate)), Restrictions.le("endDate", getInclusiveEndDate(toDate)))).addOrder(Property.forName("startDate").asc());
    if ((null == paramName) || paramName.isEmpty()) {
        criteria.add(Restrictions.isEmpty("parameters"));
    } else {
        criteria.createAlias("parameters", "param").add(Restrictions.and(Restrictions.ilike("param.name", paramName), Restrictions.ilike("param.value", paramValue)));
    }
    final List<BuildDetails> retval = new ArrayList<BuildDetails>();
    try {
        final List<BuildDetails> buildDetails = getHibernateTemplate().findByCriteria(criteria);
        if ((buildDetails != null) && !buildDetails.isEmpty()) {
            retval.addAll(buildDetails);
        }
    } catch (final Throwable t) {
        LOGGER.log(Level.SEVERE, t.getMessage(), t);
    }
    return retval;
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) DetachedCriteria(org.hibernate.criterion.DetachedCriteria) ArrayList(java.util.ArrayList)

Example 25 with BuildDetails

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

the class JobHistoryReportImpl method getProjectExecutions.

@Override
public Map<String, List<BuildDetails>> getProjectExecutions(final String jobName, final String startDateString, final String endDateString) {
    final Jenkins jenkins = Jenkins.getInstance();
    if (jenkins != null) {
        // unit tests won't have a Jenkins instance
        jenkins.checkPermission(DbAuditPlugin.RUN);
    }
    final Map<String, List<BuildDetails>> retval = new HashMap<String, List<BuildDetails>>();
    final Date startDate = DbAuditReportUtils.stringToDate(startDateString);
    final Date endDate = DbAuditReportUtils.stringToDate(endDateString);
    final String jenkinsHost = getJenkinsHostname();
    final List<String> projectNames = getRepository().getProjectNames(jenkinsHost, jobName, startDate, endDate);
    for (final String projectName : projectNames) {
        final List<BuildDetails> buildDetails = getRepository().getBuildDetails(jenkinsHost, projectName, startDate, endDate);
        if (!buildDetails.isEmpty()) {
            retval.put(projectName, buildDetails);
        }
    }
    return retval;
}
Also used : Jenkins(jenkins.model.Jenkins) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HashMap(java.util.HashMap) List(java.util.List) Date(java.util.Date)

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