Search in sources :

Example 36 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievalByMatchingDateRangeShouldReturnNonEmptyList.

@Test
public void retrievalByMatchingDateRangeShouldReturnNonEmptyList() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    build.setEndDate(new Date());
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final Calendar start = Calendar.getInstance();
    start.setTime(build.getStartDate());
    final Calendar end = Calendar.getInstance();
    end.setTime(build.getEndDate());
    List<BuildDetails> builds = repository.getBuildDetailsByDateRange(start.getTime(), end.getTime());
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertFalse("Unexpected empty list of builds", builds.isEmpty());
    Assert.assertEquals("Unexpected number of builds", 1, builds.size());
    Assert.assertEquals("Mismatching build details found", build, builds.get(0));
    start.setTime(new Date(build.getEndDate().getTime() - 10000));
    end.setTime(new Date(build.getEndDate().getTime() + 10000));
    builds = repository.getBuildDetailsByDateRange(start.getTime(), end.getTime());
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertFalse("Unexpected empty list of builds", builds.isEmpty());
    Assert.assertEquals("Unexpected number of builds", 1, builds.size());
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Calendar(java.util.Calendar) Date(java.util.Date) Test(org.junit.Test)

Example 37 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievalByNonMatchingDurationRangeShouldReturnEmptyList.

@Test
public void retrievalByNonMatchingDurationRangeShouldReturnEmptyList() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final long min = build.getDuration() + 10;
    final long max = min + 100;
    final List<BuildDetails> builds = repository.getBuildDetailsByDurationRange(min, max);
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertTrue("Unexpected non-empty list of builds", builds.isEmpty());
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Test(org.junit.Test)

Example 38 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievalByNonMatchingParamNameShouldReturnEmptyList.

@Test
public void retrievalByNonMatchingParamNameShouldReturnEmptyList() {
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(hostName);
    // ideally we should persist dataset in a transaction and roll it back
    // at the end of the test
    final TransactionStatus tx = txmgr.getTransaction(null);
    tx.setRollbackOnly();
    for (final List<BuildDetails> detailsList : dataset.values()) {
        repository.saveBuildDetailsList(detailsList);
    }
    final Calendar fromDate = Calendar.getInstance();
    fromDate.add(Calendar.YEAR, -1);
    final Calendar toDate = Calendar.getInstance();
    // get the first parameterised build details from the dataset
    BuildDetails expected = null;
    while (dataset.entrySet().iterator().hasNext()) {
        expected = dataset.entrySet().iterator().next().getValue().get(0);
        if (!expected.getParameters().isEmpty()) {
            break;
        }
    }
    final BuildParameter param = expected.getParameters().get(0);
    final List<BuildDetails> buildDetails = repository.getBuildDetailsByParams(hostName, param.getName() + "-WRONGNAME", param.getValue(), fromDate.getTime(), toDate.getTime());
    txmgr.rollback(tx);
    Assert.assertNotNull("Unexpected null list of project names", buildDetails);
    Assert.assertEquals("Unexpected non-empty list retrieved", 0, buildDetails.size());
}
Also used : BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Calendar(java.util.Calendar) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) Test(org.junit.Test)

Example 39 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievalByMatchingUserIdShouldReturnNonEmptyList.

@Test
public void retrievalByMatchingUserIdShouldReturnNonEmptyList() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final List<BuildDetails> builds = repository.getBuildDetailsByUserId(build.getUserId().toLowerCase());
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertFalse("Unexpected empty list of builds", builds.isEmpty());
    Assert.assertEquals("Unexpected number of builds", 1, builds.size());
    Assert.assertEquals("Mismatching build details found", build, builds.get(0));
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Test(org.junit.Test)

Example 40 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievalByNonMatchingParamValueShouldReturnEmptyList.

@Test
public void retrievalByNonMatchingParamValueShouldReturnEmptyList() {
    final Map<String, List<BuildDetails>> dataset = TestUtils.createRandomDataset(hostName);
    // ideally we should persist dataset in a transaction and roll it back
    // at the end of the test
    final TransactionStatus tx = txmgr.getTransaction(null);
    tx.setRollbackOnly();
    for (final List<BuildDetails> detailsList : dataset.values()) {
        repository.saveBuildDetailsList(detailsList);
    }
    final Calendar fromDate = Calendar.getInstance();
    fromDate.add(Calendar.YEAR, -1);
    final Calendar toDate = Calendar.getInstance();
    // get the first parameterised build details from the dataset
    BuildDetails expected = null;
    while (dataset.entrySet().iterator().hasNext()) {
        expected = dataset.entrySet().iterator().next().getValue().get(0);
        if (!expected.getParameters().isEmpty()) {
            break;
        }
    }
    final BuildParameter param = expected.getParameters().get(0);
    final List<BuildDetails> buildDetails = repository.getBuildDetailsByParams(hostName, param.getName(), param.getValue() + "-WRONGVALUE", fromDate.getTime(), toDate.getTime());
    txmgr.rollback(tx);
    Assert.assertNotNull("Unexpected null list of project names", buildDetails);
    Assert.assertEquals("Unexpected non-empty list retrieved", 0, buildDetails.size());
}
Also used : BuildParameter(org.jenkins.plugins.audit2db.model.BuildParameter) BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) Calendar(java.util.Calendar) TransactionStatus(org.springframework.transaction.TransactionStatus) List(java.util.List) Test(org.junit.Test)

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