Search in sources :

Example 1 with VersionSummary

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

the class PurRepository_MoveAndRename_IT method rename_CreatesNewRevision.

private void rename_CreatesNewRevision(Assistant assistant) throws Exception {
    final String initial = "rename_CreatesNewRevision";
    final String renamed = initial + "_renamed";
    AbstractMeta meta = assistant.createNew();
    assistant.save(meta, initial, getPublicDir());
    List<VersionSummary> historyBefore = unifiedRepository.getVersionSummaries(meta.getObjectId().getId());
    long before = System.currentTimeMillis();
    assistant.rename(meta, renamed);
    long after = System.currentTimeMillis();
    List<VersionSummary> historyAfter = unifiedRepository.getVersionSummaries(meta.getObjectId().getId());
    assertEquals(historyBefore.size() + 1, historyAfter.size());
    long newRevisionTs = historyAfter.get(historyAfter.size() - 1).getDate().getTime();
    assertTrue(String.format("%d <= %d <= %d", before, newRevisionTs, after), (before <= newRevisionTs) && (newRevisionTs <= after));
}
Also used : AbstractMeta(org.pentaho.di.base.AbstractMeta) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary)

Example 2 with VersionSummary

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

the class PurRepository_Revisions_IT method testOnlyRevision_DateAndCommentAreSaved.

private void testOnlyRevision_DateAndCommentAreSaved(RepositoryElementInterface transOrJob) throws Exception {
    final String elementName = "onlyRevision_" + transOrJob.getRepositoryElementType();
    final String comment = "onlyRevision";
    final Calendar date = Calendar.getInstance();
    date.setTimeInMillis(0);
    transOrJob.setName(elementName);
    transOrJob.setRepositoryDirectory(purRepository.getDefaultSaveDirectory(transOrJob));
    purRepository.save(transOrJob, comment, date, null, false);
    assertCommentAndDate(transOrJob.getObjectRevision(), date, comment);
    List<VersionSummary> versions = assertExistsAndGetRevisions(transOrJob);
    assertEquals(1, versions.size());
    assertCommentAndDate(versions.get(0), date, comment);
}
Also used : Calendar(java.util.Calendar) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary)

Example 3 with VersionSummary

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

the class UnifiedRepositoryPurgeServiceTest method processVersionMap.

private HashMap<String, List<VersionSummary>> processVersionMap(IUnifiedRepository mockRepo) {
    // Build versionListMap
    final HashMap<String, List<VersionSummary>> versionListMap = new HashMap<String, List<VersionSummary>>();
    List<VersionSummary> mockVersionList = new ArrayList<VersionSummary>();
    Date d = null;
    String fileId = null;
    for (String[] values : versionData) {
        d = getDate(values[2]);
        if (!values[1].equals(fileId)) {
            if (fileId != null) {
                versionListMap.put(fileId, mockVersionList);
            }
            mockVersionList = new ArrayList<VersionSummary>();
        }
        fileId = values[1];
        VersionSummary versionSummary = new VersionSummary(values[0], fileId, false, d, values[3], values[4], Arrays.asList(new String[] { values[5] }));
        mockVersionList.add(versionSummary);
    }
    versionListMap.put(fileId, mockVersionList);
    final ArgumentCaptor<String> fileIdArgument = ArgumentCaptor.forClass(String.class);
    when(mockRepo.getVersionSummaries(fileIdArgument.capture())).thenAnswer(new Answer<List<VersionSummary>>() {

        public List<VersionSummary> answer(InvocationOnMock invocation) throws Throwable {
            return versionListMap.get(fileIdArgument.getValue());
        }
    });
    return versionListMap;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) InvocationOnMock(org.mockito.invocation.InvocationOnMock) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) ArrayList(java.util.ArrayList) List(java.util.List)

Example 4 with VersionSummary

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

the class UnifiedRepositoryPurgeServiceTest method deleteAllVersionsTest.

@Test
public void deleteAllVersionsTest() throws KettleException {
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    final HashMap<String, List<VersionSummary>> versionListMap = processVersionMap(mockRepo);
    UnifiedRepositoryPurgeService purgeService = new UnifiedRepositoryPurgeService(mockRepo);
    String fileId = "1";
    purgeService.deleteAllVersions(element1);
    verifyAllVersionsDeleted(versionListMap, mockRepo, "1");
    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 5 with VersionSummary

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

the class UnifiedRepositoryPurgeServiceTest method doPurgeUtilVersionCountTest.

@Test
public void doPurgeUtilVersionCountTest() throws PurgeDeletionException {
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    final HashMap<String, List<VersionSummary>> versionListMap = processVersionMap(mockRepo);
    UnifiedRepositoryPurgeService purgeService = getPurgeService(mockRepo);
    PurgeUtilitySpecification spec = new PurgeUtilitySpecification();
    spec.setVersionCount(3);
    spec.setPath("/");
    purgeService.doDeleteRevisions(spec);
    verifyVersionCountDeletion(versionListMap, mockRepo, "1", spec.getVersionCount());
    verifyVersionCountDeletion(versionListMap, mockRepo, "2", spec.getVersionCount());
}
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