Search in sources :

Example 1 with BuildDetailsHibernateRepository

use of org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository 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 2 with BuildDetailsHibernateRepository

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

the class WhenRunningJobsByDateReport method testShouldDisplaySomeRecordsForMatchingSelection.

@Test
public void testShouldDisplaySomeRecordsForMatchingSelection() {
    final JobsByDateReport report = TestUtils.getReportExtension(JobsByDateReport.class);
    final BuildDetailsHibernateRepository repository = (BuildDetailsHibernateRepository) report.getRepository();
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(DbAuditUtil.getHostName());
    // after each test run
    for (final List<BuildDetails> detailsList : dataset.values()) {
        repository.saveBuildDetailsList(detailsList);
    }
    // used for debugging
    String pageText = null;
    try {
        page.load();
        page.setStartDate(now);
        page.setEndDate(tomorrow);
        final HtmlPage resultPage = page.submit();
        pageText = resultPage.asText();
        WebAssert.assertElementPresent(resultPage, "reportResults");
    } catch (final Exception e) {
        // expecting successful run
        LOGGER.log(Level.SEVERE, pageText, e);
        fail("Unexpected error.");
    }
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) List(java.util.List) JobsByDateReport(org.jenkins.plugins.audit2db.reports.JobsByDateReport) BuildDetailsHibernateRepository(org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository) Test(org.junit.Test)

Example 3 with BuildDetailsHibernateRepository

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

the class WhenRunningJobsByDateReport method testShouldDisplayNoRecordsForNonMatchingSelection.

@Test
public void testShouldDisplayNoRecordsForNonMatchingSelection() {
    final JobsByDateReport report = TestUtils.getReportExtension(JobsByDateReport.class);
    final BuildDetailsHibernateRepository repository = (BuildDetailsHibernateRepository) report.getRepository();
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(DbAuditUtil.getHostName());
    // after each test run
    for (final List<BuildDetails> detailsList : dataset.values()) {
        repository.saveBuildDetailsList(detailsList);
    }
    // used for debugging
    String pageText = null;
    try {
        page.load();
        page.setStartDate(yesterday);
        page.setEndDate(yesterday);
        final HtmlPage resultPage = page.submit();
        pageText = resultPage.asText();
        WebAssert.assertElementPresent(resultPage, "noDataWarning");
    } catch (final Exception e) {
        // expecting successful run
        LOGGER.log(Level.SEVERE, pageText, e);
        fail("Unexpected error.");
    }
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) List(java.util.List) JobsByDateReport(org.jenkins.plugins.audit2db.reports.JobsByDateReport) BuildDetailsHibernateRepository(org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository) Test(org.junit.Test)

Example 4 with BuildDetailsHibernateRepository

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

the class WhenRunningJobsHistoryReport method testShouldDisplayNoRecordsForNonMatchingSelection.

@Test
public void testShouldDisplayNoRecordsForNonMatchingSelection() {
    final JobHistoryReport report = TestUtils.getReportExtension(JobHistoryReport.class);
    final BuildDetailsHibernateRepository repository = (BuildDetailsHibernateRepository) report.getRepository();
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(DbAuditUtil.getHostName());
    // after each test run
    for (final List<BuildDetails> detailsList : dataset.values()) {
        repository.saveBuildDetailsList(detailsList);
    }
    // used for debugging
    String pageText = null;
    try {
        page.load();
        page.setStartDate(yesterday);
        page.setEndDate(tomorrow);
        page.setJobName("A JOB THAT DOES NOT EXIST");
        final HtmlPage resultPage = page.submit();
        pageText = resultPage.asText();
        WebAssert.assertElementPresent(resultPage, "noDataWarning");
    } catch (final Exception e) {
        // expecting successful run
        LOGGER.log(Level.SEVERE, pageText, e);
        fail("Unexpected error.");
    }
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JobHistoryReport(org.jenkins.plugins.audit2db.reports.JobHistoryReport) List(java.util.List) BuildDetailsHibernateRepository(org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository) Test(org.junit.Test)

Example 5 with BuildDetailsHibernateRepository

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

the class WhenRunningJobsHistoryReport method testShouldDisplaySomeRecordsForMatchingSelection.

@Test
public void testShouldDisplaySomeRecordsForMatchingSelection() {
    final JobHistoryReport report = TestUtils.getReportExtension(JobHistoryReport.class);
    final BuildDetailsHibernateRepository repository = (BuildDetailsHibernateRepository) report.getRepository();
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(DbAuditUtil.getHostName());
    // after each test run
    for (final List<BuildDetails> detailsList : dataset.values()) {
        repository.saveBuildDetailsList(detailsList);
    }
    final String projectName = dataset.keySet().iterator().next();
    // used for debugging
    String pageText = null;
    try {
        page.load();
        page.setStartDate(now);
        page.setEndDate(tomorrow);
        // test wildcard
        page.setJobName(projectName + "%");
        final HtmlPage resultPage = page.submit();
        pageText = resultPage.asText();
        WebAssert.assertElementPresent(resultPage, "reportResults");
    } catch (final Exception e) {
        // expecting successful run
        LOGGER.log(Level.SEVERE, pageText, e);
        fail("Unexpected error.");
    }
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) HtmlPage(com.gargoylesoftware.htmlunit.html.HtmlPage) JobHistoryReport(org.jenkins.plugins.audit2db.reports.JobHistoryReport) List(java.util.List) BuildDetailsHibernateRepository(org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository) Test(org.junit.Test)

Aggregations

BuildDetailsHibernateRepository (org.jenkins.plugins.audit2db.internal.data.BuildDetailsHibernateRepository)5 BuildDetails (org.jenkins.plugins.audit2db.model.BuildDetails)5 HtmlPage (com.gargoylesoftware.htmlunit.html.HtmlPage)4 List (java.util.List)4 Test (org.junit.Test)4 JobHistoryReport (org.jenkins.plugins.audit2db.reports.JobHistoryReport)2 JobsByDateReport (org.jenkins.plugins.audit2db.reports.JobsByDateReport)2 Computer (hudson.model.Computer)1 Properties (java.util.Properties)1 SessionFactory (org.hibernate.SessionFactory)1 BuildDetailsRepository (org.jenkins.plugins.audit2db.data.BuildDetailsRepository)1 FlowExecution (org.jenkinsci.plugins.workflow.flow.FlowExecution)1 StepContext (org.jenkinsci.plugins.workflow.steps.StepContext)1