use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepositoryUnitTest method testRootIsNotVisible.
@Test
public void testRootIsNotVisible() 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);
RepositoryFile mockRootFolder = mock(RepositoryFile.class);
when(mockRootFolder.getId()).thenReturn("/");
when(mockRootFolder.getPath()).thenReturn("/");
// 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");
RepositoryDirectoryInterface rootDir = purRepository.getRootDir();
assertFalse(rootDir.isVisible());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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);
// purRepository.setTest( mockRepo );
ObjectId objectId = mock(ObjectId.class);
RepositoryFile mockFile = mock(RepositoryFile.class);
RepositoryFile mockRootFolder = mock(RepositoryFile.class);
RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
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());
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree 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);
// purRepository.setTest( mockRepo );
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);
RepositoryObjectType repositoryObjectType = RepositoryObjectType.TRANSFORMATION;
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<>(Arrays.asList(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));
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepository method initRepositoryDirectoryTree.
private RepositoryDirectoryInterface initRepositoryDirectoryTree(RepositoryFileTree repoTree) throws KettleException {
RepositoryFile rootFolder = repoTree.getFile();
RepositoryDirectory rootDir = new RepositoryDirectory();
rootDir.setObjectId(new StringObjectId(rootFolder.getId().toString()));
fillRepositoryDirectoryFromTree(rootDir, repoTree);
// Example: /etc
RepositoryDirectory etcDir = rootDir.findDirectory(ClientRepositoryPaths.getEtcFolderPath());
RepositoryDirectory newRoot = new RepositoryDirectory();
newRoot.setObjectId(rootDir.getObjectId());
newRoot.setVisible(false);
for (int i = 0; i < rootDir.getNrSubdirectories(); i++) {
RepositoryDirectory childDir = rootDir.getSubdirectory(i);
// Don't show /etc
boolean isEtcChild = childDir.equals(etcDir);
if (isEtcChild) {
continue;
}
newRoot.addSubdirectory(childDir);
}
return newRoot;
}
use of org.pentaho.platform.api.repository2.unified.RepositoryFileTree in project pentaho-kettle by pentaho.
the class PurRepository method loadRepositoryDirectoryTree.
@Override
public RepositoryDirectoryInterface loadRepositoryDirectoryTree(String path, String filter, int depth, boolean showHidden, boolean includeEmptyFolder, boolean includeAcls) throws KettleException {
// First check for possibility of speedy algorithm
if (filter == null && "/".equals(path) && includeEmptyFolder) {
return initRepositoryDirectoryTree(loadRepositoryFileTreeFolders("/", -1, includeAcls, showHidden));
}
// load count levels from root to destination path to load folder tree
int fromRootToDest = StringUtils.countMatches(path, "/");
// create new root directory "/"
RepositoryDirectory dir = new RepositoryDirectory();
// fetch folder tree from root "/" to destination path for populate folder
RepositoryFileTree rootDirTree = loadRepositoryFileTree("/", "*", fromRootToDest, showHidden, includeAcls, FILES_TYPE_FILTER.FOLDERS);
// populate directory by folder tree
fillRepositoryDirectoryFromTree(dir, rootDirTree);
RepositoryDirectoryInterface destinationDir = dir.findDirectory(path);
// search for goal path and filter
RepositoryFileTree repoTree = loadRepositoryFileTree(path, filter, depth, showHidden, includeAcls, FILES_TYPE_FILTER.FILES_FOLDERS);
// populate the directory with founded files and subdirectories with files
fillRepositoryDirectoryFromTree(destinationDir, repoTree);
if (includeEmptyFolder) {
RepositoryDirectoryInterface folders = initRepositoryDirectoryTree(loadRepositoryFileTree(path, null, depth, showHidden, includeAcls, FILES_TYPE_FILTER.FOLDERS));
return copyFrom(folders, destinationDir);
} else {
return destinationDir;
}
}
Aggregations