use of org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEETransformation in project pentaho-kettle by pentaho.
the class RepositoryLockControllerTest method testBlockLock.
@Test
public void testBlockLock() throws Exception {
RepositoryLockController repositoryLockController = new RepositoryLockController();
List<UIRepositoryObject> selectedRepoObjects = new ArrayList<>();
UIEETransformation lockObject = Mockito.mock(UIEETransformation.class);
selectedRepoObjects.add(lockObject);
Mockito.when(lockObject.isLocked()).thenReturn(true);
ObjectId objectId = Mockito.mock(ObjectId.class);
Mockito.when(lockObject.getObjectId()).thenReturn(objectId);
XulMenuitem lockFileMenuItem = Mockito.mock(XulMenuitem.class);
Field lockFileMenuItemField = repositoryLockController.getClass().getDeclaredField("lockFileMenuItem");
lockFileMenuItemField.setAccessible(true);
lockFileMenuItemField.set(repositoryLockController, lockFileMenuItem);
XulMenuitem deleteFileMenuItem = Mockito.mock(XulMenuitem.class);
Field deleteFileMenuItemField = repositoryLockController.getClass().getDeclaredField("deleteFileMenuItem");
deleteFileMenuItemField.setAccessible(true);
deleteFileMenuItemField.set(repositoryLockController, deleteFileMenuItem);
XulMenuitem renameFileMenuItem = Mockito.mock(XulMenuitem.class);
Field renameFileMenuItemField = repositoryLockController.getClass().getDeclaredField("renameFileMenuItem");
renameFileMenuItemField.setAccessible(true);
renameFileMenuItemField.set(repositoryLockController, renameFileMenuItem);
Repository repository = Mockito.mock(Repository.class);
PurRepositoryMeta repositoryMeta = Mockito.mock(PurRepositoryMeta.class);
Mockito.when(repository.getRepositoryMeta()).thenReturn(repositoryMeta);
Field repositoryField = repositoryLockController.getClass().getDeclaredField("repository");
repositoryField.setAccessible(true);
repositoryField.set(repositoryLockController, repository);
ILockService service = Mockito.mock(ILockService.class);
Mockito.when(service.canUnlockFileById(objectId)).thenReturn(true);
Field serviceField = repositoryLockController.getClass().getDeclaredField("service");
serviceField.setAccessible(true);
serviceField.set(repositoryLockController, service);
repositoryLockController.setMenuItemEnabledState(selectedRepoObjects);
Assert.assertFalse(lockFileMenuItem.isDisabled());
Mockito.verify(lockFileMenuItem).setDisabled(false);
}
Aggregations