Search in sources :

Example 1 with IUnifiedRepository

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

the class PurRepository_GetObjectInformation_IT method getObjectInformation_InvalidRepositoryId_ExceptionIsHandled.

@Test
public void getObjectInformation_InvalidRepositoryId_ExceptionIsHandled() throws Exception {
    IUnifiedRepository unifiedRepository = mock(IUnifiedRepository.class);
    when(unifiedRepository.getFileById(any(Serializable.class))).thenThrow(new RuntimeException("unknown id"));
    purRepository.setTest(unifiedRepository);
    RepositoryObject information = purRepository.getObjectInformation(new StringObjectId("invalid id"), RepositoryObjectType.JOB);
    assertNull("Should return null if file was not found", information);
}
Also used : Serializable(java.io.Serializable) RepositoryObject(org.pentaho.di.repository.RepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 2 with IUnifiedRepository

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

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

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

Example 5 with IUnifiedRepository

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

the class UnifiedRepositoryPurgeServiceTest method doPurgeUtilDateBeforeTest.

@Test
public void doPurgeUtilDateBeforeTest() throws PurgeDeletionException {
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    final HashMap<String, List<VersionSummary>> versionListMap = processVersionMap(mockRepo);
    UnifiedRepositoryPurgeService purgeService = getPurgeService(mockRepo);
    PurgeUtilitySpecification spec = new PurgeUtilitySpecification();
    spec.setBeforeDate(getDate("01/02/2006"));
    spec.setPath("/");
    purgeService.doDeleteRevisions(spec);
    verifyDateBeforeDeletion(versionListMap, mockRepo, "1", spec.getBeforeDate());
    verifyDateBeforeDeletion(versionListMap, mockRepo, "2", spec.getBeforeDate());
}
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

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