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