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());
}
}
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());
}
}
}
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());
}
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;
}
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++;
}
}
Aggregations