Search in sources :

Example 36 with RepositoryRequest

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

the class PurRepositoryUnitTest method testEtcIsNotThereInGetChildren.

@Test
public void testEtcIsNotThereInGetChildren() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockFile = mock(RepositoryFile.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String testFileId = "TEST_FILE_ID";
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockFile);
    when(mockFile.getPath()).thenReturn("/etc");
    when(mockFile.getId()).thenReturn(testFileId);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    List<RepositoryFile> rootChildren = new ArrayList<>(Collections.singletonList(mockFile));
    when(mockRepo.getChildren(argThat(IsInstanceOf.<RepositoryRequest>instanceOf(RepositoryRequest.class)))).thenReturn(rootChildren);
    // for Lazy Repo
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    // for Eager Repo
    RepositoryFileTree repositoryFileTree = mock(RepositoryFileTree.class);
    when(mockRepo.getTree("/", -1, null, true)).thenReturn(repositoryFileTree);
    when(repositoryFileTree.getFile()).thenReturn(mockRootFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    List<RepositoryDirectoryInterface> children = purRepository.getRootDir().getChildren();
    assertThat(children, empty());
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

Example 37 with RepositoryRequest

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

the class PurRepositoryUnitTest method testRevisionsEnabled.

@Test
public void testRevisionsEnabled() throws KettleException {
    PurRepository purRepository = new PurRepository();
    IUnifiedRepository mockRepo = mock(IUnifiedRepository.class);
    RepositoryConnectResult result = mock(RepositoryConnectResult.class);
    when(result.getUnifiedRepository()).thenReturn(mockRepo);
    IRepositoryConnector connector = mock(IRepositoryConnector.class);
    when(connector.connect(anyString(), anyString())).thenReturn(result);
    RepositoryServiceRegistry registry = mock(RepositoryServiceRegistry.class);
    UnifiedRepositoryLockService lockService = new UnifiedRepositoryLockService(mockRepo);
    when(registry.getService(ILockService.class)).thenReturn(lockService);
    when(result.repositoryServiceRegistry()).thenReturn(registry);
    PurRepositoryMeta mockMeta = mock(PurRepositoryMeta.class);
    purRepository.init(mockMeta);
    purRepository.setPurRepositoryConnector(connector);
    ObjectId objectId = mock(ObjectId.class);
    RepositoryFile mockFileVersioningEnabled = mock(RepositoryFile.class);
    RepositoryFile mockFileVersioningNotEnabled = mock(RepositoryFile.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningEnabled = mock(RepositoryFileTree.class);
    RepositoryFileTree mockRepositoryTreeChildVersioningNotEnabled = mock(RepositoryFileTree.class);
    RepositoryFile publicFolder = mock(RepositoryFile.class);
    RepositoryFileTree publicFolderTree = mock(RepositoryFileTree.class);
    RepositoryFile mockRootFolder = mock(RepositoryFile.class);
    RepositoryFileTree mockRepositoryTree = mock(RepositoryFileTree.class);
    String testId = "TEST_ID";
    String testFileId = "TEST_FILE_ID";
    List<RepositoryFileTree> children = Arrays.asList(mockRepositoryTreeChildVersioningEnabled, mockRepositoryTreeChildVersioningNotEnabled);
    when(objectId.getId()).thenReturn(testId);
    when(mockRepo.getFileById(testId)).thenReturn(mockFileVersioningEnabled);
    when(mockFileVersioningEnabled.getPath()).thenReturn("/public/path.ktr");
    when(mockFileVersioningEnabled.getId()).thenReturn(testFileId);
    when(mockFileVersioningEnabled.getName()).thenReturn("path.ktr");
    when(mockFileVersioningNotEnabled.getPath()).thenReturn("/public/path2.ktr");
    when(mockFileVersioningNotEnabled.getId()).thenReturn(testFileId + "2");
    when(mockFileVersioningNotEnabled.getName()).thenReturn("path2.ktr");
    when(publicFolder.getPath()).thenReturn("/public");
    when(publicFolder.getName()).thenReturn("public");
    when(publicFolder.getId()).thenReturn(testFileId + "3");
    when(publicFolder.isFolder()).thenReturn(true);
    when(publicFolderTree.getFile()).thenReturn(publicFolder);
    when(mockRepositoryTreeChildVersioningEnabled.getFile()).thenReturn(mockFileVersioningEnabled);
    when(mockRepositoryTreeChildVersioningEnabled.getVersionCommentEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningEnabled.getVersioningEnabled()).thenReturn(true);
    when(mockRepositoryTreeChildVersioningNotEnabled.getFile()).thenReturn(mockFileVersioningNotEnabled);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersionCommentEnabled()).thenReturn(false);
    when(mockRepositoryTreeChildVersioningNotEnabled.getVersioningEnabled()).thenReturn(false);
    when(mockRepo.getTree(anyString(), anyInt(), anyString(), anyBoolean())).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(any(RepositoryRequest.class))).thenReturn(mockRepositoryTree);
    when(mockRepo.getTree(argThat(new ArgumentMatcher<RepositoryRequest>() {

        @Override
        public boolean matches(Object argument) {
            return ((RepositoryRequest) argument).getPath().equals("/public");
        }
    }))).thenReturn(publicFolderTree);
    when(mockRepositoryTree.getFile()).thenReturn(mockRootFolder);
    when(mockRepositoryTree.getChildren()).thenReturn(new ArrayList<>(Collections.singletonList(publicFolderTree)));
    when(publicFolderTree.getChildren()).thenReturn(children);
    when(mockRootFolder.getId()).thenReturn("/");
    when(mockRootFolder.getPath()).thenReturn("/");
    when(mockRepo.getFile("/")).thenReturn(mockRootFolder);
    when(mockRepo.getFile("/public")).thenReturn(publicFolder);
    purRepository.connect("TEST_USER", "TEST_PASSWORD");
    List<RepositoryElementMetaInterface> repositoryObjects = purRepository.findDirectory("/public").getRepositoryObjects();
    assertThat(repositoryObjects.size(), is(2));
    // Test Enabled
    RepositoryElementMetaInterface element = repositoryObjects.get(0);
    assertThat(element, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement = (EERepositoryObject) element;
    assertThat(eeElement.getVersioningEnabled(), is(true));
    assertThat(eeElement.getVersionCommentEnabled(), is(true));
    // Test Not Enabled
    RepositoryElementMetaInterface element2 = repositoryObjects.get(1);
    assertThat(element2, is(instanceOf(EERepositoryObject.class)));
    EERepositoryObject eeElement2 = (EERepositoryObject) element;
    assertThat(eeElement2.getVersioningEnabled(), is(true));
    assertThat(eeElement2.getVersionCommentEnabled(), is(true));
}
Also used : EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) StringObjectId(org.pentaho.di.repository.StringObjectId) ObjectId(org.pentaho.di.repository.ObjectId) Matchers.anyString(org.mockito.Matchers.anyString) RepositoryFileTree(org.pentaho.platform.api.repository2.unified.RepositoryFileTree) ArgumentMatcher(org.mockito.ArgumentMatcher) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryRequest(org.pentaho.platform.api.repository2.unified.RepositoryRequest) EERepositoryObject(org.pentaho.di.repository.pur.model.EERepositoryObject) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) RepositoryElementMetaInterface(org.pentaho.di.repository.RepositoryElementMetaInterface) Test(org.junit.Test)

Aggregations

RepositoryRequest (org.pentaho.platform.api.repository2.unified.RepositoryRequest)31 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)19 RepositoryFileTree (org.pentaho.platform.api.repository2.unified.RepositoryFileTree)19 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)11 Matchers.anyString (org.mockito.Matchers.anyString)8 ITenant (org.pentaho.platform.api.mt.ITenant)7 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Collator (java.text.Collator)4 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)4 File (java.io.File)3 Serializable (java.io.Serializable)3 ObjectId (org.pentaho.di.repository.ObjectId)3 EERepositoryObject (org.pentaho.di.repository.pur.model.EERepositoryObject)3 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)3 RepositoryFileDto (org.pentaho.platform.repository2.unified.webservices.RepositoryFileDto)3 HashMap (java.util.HashMap)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)2