Search in sources :

Example 1 with UIEETransformation

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);
}
Also used : UIRepositoryObject(org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject) Field(java.lang.reflect.Field) Repository(org.pentaho.di.repository.Repository) ObjectId(org.pentaho.di.repository.ObjectId) XulMenuitem(org.pentaho.ui.xul.components.XulMenuitem) ILockService(org.pentaho.di.ui.repository.pur.services.ILockService) ArrayList(java.util.ArrayList) PurRepositoryMeta(org.pentaho.di.repository.pur.PurRepositoryMeta) UIEETransformation(org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEETransformation) Test(org.junit.Test)

Aggregations

Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 ObjectId (org.pentaho.di.repository.ObjectId)1 Repository (org.pentaho.di.repository.Repository)1 PurRepositoryMeta (org.pentaho.di.repository.pur.PurRepositoryMeta)1 UIEETransformation (org.pentaho.di.ui.repository.pur.repositoryexplorer.model.UIEETransformation)1 ILockService (org.pentaho.di.ui.repository.pur.services.ILockService)1 UIRepositoryObject (org.pentaho.di.ui.repository.repositoryexplorer.model.UIRepositoryObject)1 XulMenuitem (org.pentaho.ui.xul.components.XulMenuitem)1