Search in sources :

Example 51 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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 52 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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 53 with IUnifiedRepository

use of org.pentaho.platform.api.repository2.unified.IUnifiedRepository 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)

Example 54 with IUnifiedRepository

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

the class UnifiedRepositoryPurgeServiceTest method getPurgeService.

// create the necessary mocks for running a full Purge Utility job
private static UnifiedRepositoryPurgeService getPurgeService(IUnifiedRepository mockRepo) {
    UnifiedRepositoryPurgeService purgeService = new UnifiedRepositoryPurgeService(mockRepo);
    DefaultUnifiedRepositoryWebService mockRepoWs = mock(DefaultUnifiedRepositoryWebService.class);
    UnifiedRepositoryPurgeService.repoWs = mockRepoWs;
    // Create a mocked tree to be returned
    JAXBContext jc;
    RepositoryFileTreeDto tree = null;
    try {
        jc = JAXBContext.newInstance(RepositoryFileTreeDto.class);
        Unmarshaller unmarshaller = jc.createUnmarshaller();
        ByteArrayInputStream xml = new ByteArrayInputStream(treeResponse.getBytes());
        tree = (RepositoryFileTreeDto) unmarshaller.unmarshal(xml);
    } catch (JAXBException e) {
        e.printStackTrace();
        fail("Test class has invalid xml representation of tree");
    }
    when(mockRepoWs.getTreeFromRequest(any(RepositoryRequest.class))).thenReturn(tree);
    return purgeService;
}
Also used : DefaultUnifiedRepositoryWebService(org.pentaho.platform.repository2.unified.webservices.DefaultUnifiedRepositoryWebService) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileTreeDto(org.pentaho.platform.repository2.unified.webservices.RepositoryFileTreeDto) JAXBException(javax.xml.bind.JAXBException) JAXBContext(javax.xml.bind.JAXBContext) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) Unmarshaller(javax.xml.bind.Unmarshaller)

Example 55 with IUnifiedRepository

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

the class UnifiedRepositoryPurgeServiceTest method verifyVersionCountDeletion.

private static void verifyVersionCountDeletion(HashMap<String, List<VersionSummary>> versionListMap, IUnifiedRepository mockRepo, String fileId, int versionCount) {
    List<VersionSummary> list = versionListMap.get(fileId);
    int i = 1;
    for (VersionSummary sum : list) {
        if (i <= list.size() - versionCount) {
            verify(mockRepo, times(1)).deleteFileAtVersion(fileId, sum.getId());
        }
        i++;
    }
}
Also used : VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary)

Aggregations

IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)88 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)61 Test (org.junit.Test)51 Matchers.anyString (org.mockito.Matchers.anyString)37 ArrayList (java.util.ArrayList)18 List (java.util.List)10 StringObjectId (org.pentaho.di.repository.StringObjectId)10 Serializable (java.io.Serializable)9 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)7 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)7 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)7 InputStream (java.io.InputStream)6 JobMeta (org.pentaho.di.job.JobMeta)6 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)6 FileSystemBackedUnifiedRepository (org.pentaho.platform.repository2.unified.fs.FileSystemBackedUnifiedRepository)6 HashMap (java.util.HashMap)5 ObjectId (org.pentaho.di.repository.ObjectId)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 Properties (java.util.Properties)4 Log (org.apache.commons.logging.Log)4