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());
}
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());
}
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));
}
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;
}
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;
}
Aggregations