Search in sources :

Example 21 with VersionSummary

use of org.pentaho.platform.api.repository2.unified.VersionSummary in project pentaho-kettle by pentaho.

the class UnifiedRepositoryPurgeServiceTest method deleteVersionsBeforeDate.

@Test
public void deleteVersionsBeforeDate() throws KettleException {
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    final HashMap<String, List<VersionSummary>> versionListMap = processVersionMap(mockRepo);
    UnifiedRepositoryPurgeService purgeService = new UnifiedRepositoryPurgeService(mockRepo);
    String fileId = "1";
    Date beforeDate = getDate("01/02/2006");
    purgeService.deleteVersionsBeforeDate(element1, beforeDate);
    verifyDateBeforeDeletion(versionListMap, mockRepo, fileId, beforeDate);
    verify(mockRepo, never()).deleteFileAtVersion(eq("2"), anyString());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 22 with VersionSummary

use of org.pentaho.platform.api.repository2.unified.VersionSummary in project pentaho-kettle by pentaho.

the class UnifiedRepositoryPurgeServiceTest method keepNumberOfVersions0Test.

@Test
public void keepNumberOfVersions0Test() throws KettleException {
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    final HashMap<String, List<VersionSummary>> versionListMap = processVersionMap(mockRepo);
    UnifiedRepositoryPurgeService purgeService = new UnifiedRepositoryPurgeService(mockRepo);
    String fileId = "1";
    int versionCount = 0;
    purgeService.keepNumberOfVersions(element1, versionCount);
    verifyVersionCountDeletion(versionListMap, mockRepo, fileId, versionCount);
    verify(mockRepo, never()).deleteFileAtVersion(eq("2"), anyString());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 23 with VersionSummary

use of org.pentaho.platform.api.repository2.unified.VersionSummary in project pentaho-kettle by pentaho.

the class UnifiedRepositoryPurgeServiceTest method doPurgeUtilSharedObjectsTest.

@Test
public void doPurgeUtilSharedObjectsTest() throws PurgeDeletionException {
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    final HashMap<String, List<VersionSummary>> versionListMap = processVersionMap(mockRepo);
    UnifiedRepositoryPurgeService purgeService = getPurgeService(mockRepo);
    PurgeUtilitySpecification spec = new PurgeUtilitySpecification();
    spec.purgeFiles = true;
    spec.setSharedObjects(true);
    purgeService.doDeleteRevisions(spec);
    // Since each tree call delivers the same mock tree, we expect the files to get deleted once per folder.
    String fileId = "1";
    String fileLastRevision = "105";
    List<VersionSummary> list = versionListMap.get(fileId);
    for (VersionSummary sum : list) {
        final int expectedTimes;
        if (!fileLastRevision.equals(sum.getId())) {
            expectedTimes = 4;
        } else {
            expectedTimes = 0;
        }
        verify(mockRepo, times(expectedTimes)).deleteFileAtVersion(fileId, sum.getId());
        verify(UnifiedRepositoryPurgeService.getRepoWs(), times(4)).deleteFileWithPermanentFlag(eq(fileId), eq(true), anyString());
    }
}
Also used : VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 24 with VersionSummary

use of org.pentaho.platform.api.repository2.unified.VersionSummary in project pentaho-kettle by pentaho.

the class UnifiedRepositoryPurgeServiceTest method verifyDateBeforeDeletion.

private static void verifyDateBeforeDeletion(HashMap<String, List<VersionSummary>> versionListMap, IUnifiedRepository mockRepo, String fileId, Date beforeDate) {
    int i = 0;
    List<VersionSummary> list = versionListMap.get(fileId);
    for (VersionSummary sum : list) {
        if (beforeDate.after(sum.getDate()) && !sum.getId().equals(list.get(list.size() - 1).getId())) {
            verify(mockRepo, times(1)).deleteFileAtVersion(fileId, sum.getId());
        } else {
            verify(mockRepo, never()).deleteFileAtVersion(fileId, sum.getId());
        }
    }
}
Also used : VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary)

Example 25 with VersionSummary

use of org.pentaho.platform.api.repository2.unified.VersionSummary in project pentaho-kettle by pentaho.

the class UnifiedRepositoryPurgeServiceTest method doPurgeUtilPurgeFileTest.

@Test
public void doPurgeUtilPurgeFileTest() throws PurgeDeletionException {
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    final HashMap<String, List<VersionSummary>> versionListMap = processVersionMap(mockRepo);
    UnifiedRepositoryPurgeService purgeService = getPurgeService(mockRepo);
    PurgeUtilitySpecification spec = new PurgeUtilitySpecification();
    spec.purgeFiles = true;
    spec.setPath("/");
    purgeService.doDeleteRevisions(spec);
    verifyAllVersionsDeleted(versionListMap, mockRepo, "1");
    verifyAllVersionsDeleted(versionListMap, mockRepo, "2");
    verify(UnifiedRepositoryPurgeService.getRepoWs(), times(1)).deleteFileWithPermanentFlag(eq("1"), eq(true), anyString());
    verify(UnifiedRepositoryPurgeService.getRepoWs(), times(1)).deleteFileWithPermanentFlag(eq("2"), eq(true), anyString());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyString(org.mockito.Matchers.anyString) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Aggregations

VersionSummary (org.pentaho.platform.api.repository2.unified.VersionSummary)32 ArrayList (java.util.ArrayList)21 Test (org.junit.Test)18 Matchers.anyString (org.mockito.Matchers.anyString)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 List (java.util.List)12 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)9 Date (java.util.Date)7 ITenant (org.pentaho.platform.api.mt.ITenant)7 ByteArrayInputStream (java.io.ByteArrayInputStream)5 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)5 Serializable (java.io.Serializable)4 KettleException (org.pentaho.di.core.exception.KettleException)4 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)4 SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)4 Calendar (java.util.Calendar)3 Node (javax.jcr.Node)3 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)3 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)3 KettleFileException (org.pentaho.di.core.exception.KettleFileException)3