Search in sources :

Example 6 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievingMatchingProjectNamePatternShouldReturnValidDataset.

@Test
public void retrievingMatchingProjectNamePatternShouldReturnValidDataset() {
    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();
    // let's try to find projects by matching the first one in the set
    final String projectName = dataset.keySet().iterator().next();
    // find partial match
    final String pattern = projectName.substring(0, projectName.length() / 2) + "%";
    final List<String> projectNames = repository.getProjectNames(hostName, pattern, fromDate.getTime(), toDate.getTime());
    txmgr.rollback(tx);
    Assert.assertNotNull("Unexpected null list of project names", projectNames);
    Assert.assertFalse("Unexpected empty list of project names", projectNames.isEmpty());
}
Also used : 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 7 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievingBuildNodeByValidUrlShouldSucceed.

@Test
public void retrievingBuildNodeByValidUrlShouldSucceed() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final BuildNode expected = build.getNode();
    final BuildNode actual = repository.getBuildNodeByUrl(expected.getUrl());
    Assert.assertNotNull("Unexppected null build node", actual);
    Assert.assertEquals("Unexpected build node", expected, actual);
}
Also used : BuildDetails(org.jenkins.plugins.audit2db.model.BuildDetails) BuildNode(org.jenkins.plugins.audit2db.model.BuildNode) Test(org.junit.Test)

Example 8 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievalByBlankParamNameShouldReturnNonEmptyList.

@Test
public void retrievalByBlankParamNameShouldReturnNonEmptyList() {
    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 non-parameterised build details from the dataset
    // this must appear in the returned list
    BuildDetails expected = null;
    for (final Entry<String, List<BuildDetails>> entry : dataset.entrySet()) {
        expected = entry.getValue().get(0);
        if (expected.getParameters().isEmpty()) {
            break;
        }
    }
    // get the first parameterised build details from the dataset
    // this one should not appear in the returned list
    BuildDetails unexpected = null;
    for (final Entry<String, List<BuildDetails>> entry : dataset.entrySet()) {
        unexpected = entry.getValue().get(0);
        if (!unexpected.getParameters().isEmpty()) {
            break;
        }
    }
    final List<BuildDetails> buildDetails = repository.getBuildDetailsByParams(hostName, "", "", fromDate.getTime(), toDate.getTime());
    txmgr.rollback(tx);
    Assert.assertNotNull("Unexpected null list of build details", buildDetails);
    Assert.assertFalse("Unexpected empty list of build details", buildDetails.isEmpty());
    Assert.assertTrue("The expected build details was not returned", buildDetails.contains(expected));
    Assert.assertTrue("The unexpected build details was returned", !buildDetails.contains(unexpected));
}
Also used : 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 9 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method retrievingMatchingProjectNameShouldReturnValidDataset.

@Test
public void retrievingMatchingProjectNameShouldReturnValidDataset() {
    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();
    // let's try to find projects by matching the first one in the set
    final String projectName = dataset.keySet().iterator().next();
    // find exact match
    final List<String> projectNames = repository.getProjectNames(hostName, projectName, fromDate.getTime(), toDate.getTime());
    txmgr.rollback(tx);
    Assert.assertNotNull("Unexpected null list of project names", projectNames);
    Assert.assertFalse("Unexpected empty list of project names", projectNames.isEmpty());
    Assert.assertEquals("Unexpected number of project names", 1, projectNames.size());
}
Also used : 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 10 with BuildDetails

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

the class BuildDetailsHibernateRepositoryTests method updatedBuildDetailsShouldBePersisted.

@Test
public void updatedBuildDetailsShouldBePersisted() {
    final BuildDetails build = TestUtils.createRandomBuildDetails();
    final Object buildId = repository.saveBuildDetails(build);
    Assert.assertNotNull("Unexpected null build id", buildId);
    final String oldName = build.getName();
    final String newName = oldName + "UPDATED";
    build.setName(newName);
    repository.updateBuildDetails(build);
    List<BuildDetails> builds = repository.getBuildDetailsByName(oldName);
    Assert.assertNotNull("Unexpected null list of builds", builds);
    Assert.assertTrue("Unexpected non-empty list of builds", builds.isEmpty());
    builds = repository.getBuildDetailsByName(newName);
    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)

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