use of org.talend.core.model.repository.RepositoryNodeProviderRegistryReader in project tmdm-studio-se by Talend.
the class RepositoryResourceUtilTest method setUp.
@Before
public void setUp() throws Exception {
ResourceBundle rb = mock(ResourceBundle.class);
// $NON-NLS-1$
stub(method(ResourceBundle.class, "getBundle", String.class)).toReturn(rb);
PowerMockito.mockStatic(JFaceResources.class);
ImageRegistry registry = mock(ImageRegistry.class);
when(JFaceResources.getImageRegistry()).thenReturn(registry);
PowerMockito.mockStatic(DefaultMessagesImpl.class);
// $NON-NLS-1$
when(DefaultMessagesImpl.getString(anyString())).thenReturn("anyString()");
IRepositoryResourceUtilExAdapter mockAdapter = PowerMockito.mock(IRepositoryResourceUtilExAdapter.class);
PowerMockito.mockStatic(ExAdapterManager.class);
PowerMockito.when(ExAdapterManager.getAdapter(new RepositoryResourceUtil(), IRepositoryResourceUtilExAdapter.class)).thenReturn(mockAdapter);
PowerMockito.mockStatic(CoreRuntimePlugin.class);
CoreRuntimePlugin coreRuntimePlugin = mock(CoreRuntimePlugin.class);
when(CoreRuntimePlugin.getInstance()).thenReturn(coreRuntimePlugin);
PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
}
use of org.talend.core.model.repository.RepositoryNodeProviderRegistryReader in project tmdm-studio-se by Talend.
the class RemoveFromRepositoryActionTest method doRunTest.
@Test
public void doRunTest() throws Exception {
PowerMockito.mockStatic(MDMWorbenchPlugin.class);
when(MDMWorbenchPlugin.getImageDescriptor(anyString())).thenReturn(mock(ImageDescriptor.class));
RemoveFromRepositoryAction removeAction = new RemoveFromRepositoryAction();
RemoveFromRepositoryAction removeActionM = PowerMockito.spy(removeAction);
CommonViewer commonViewerM = mock(CommonViewer.class);
// $NON-NLS-1$
Whitebox.setInternalState(removeActionM, "commonViewer", commonViewerM);
// $NON-NLS-1$
PowerMockito.doReturn(true).when(removeActionM, "confirm", 2);
// $NON-NLS-1$
PowerMockito.doNothing().when(removeActionM, "warn");
// mock a mdm repositoryViewObject
IRepositoryViewObject objectRVO = mock(IRepositoryViewObject.class);
MDMServerObjectItem mdmItemM = mock(MDMServerObjectItem.class);
Property propertyM = mock(Property.class);
when(objectRVO.getProperty()).thenReturn(propertyM);
when(propertyM.getItem()).thenReturn(mdmItemM);
// mock a FolderRepositoryObject
FolderRepositoryObject folderRO = mock(FolderRepositoryObject.class);
Property foldePropertyM = mock(Property.class);
ContainerItem containerItem = mock(ContainerItem.class);
when(folderRO.getProperty()).thenReturn(foldePropertyM);
when(foldePropertyM.getItem()).thenReturn(containerItem);
ItemState itemState = mock(ItemState.class);
when(containerItem.getState()).thenReturn(itemState);
// $NON-NLS-1$
when(itemState.getPath()).thenReturn("");
PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
ERepositoryObjectType typeM = ERepositoryObjectType.PROCESS;
when(containerItem.getRepObjType()).thenReturn(typeM);
MDMServerObject mdmServerObjectM = mock(MDMServerObject.class);
when(mdmItemM.getMDMServerObject()).thenReturn(mdmServerObjectM);
Shell shellM = mock(Shell.class);
Control controlM = mock(Control.class);
when(commonViewerM.getControl()).thenReturn(controlM);
when(controlM.getShell()).thenReturn(shellM);
List<Object> selectedObjects = new ArrayList<Object>();
selectedObjects.add(objectRVO);
selectedObjects.add(folderRO);
when(removeActionM.getSelectedObject()).thenReturn(selectedObjects);
// $NON-NLS-1$
Whitebox.setInternalState(removeActionM, "lockedObjs", Collections.EMPTY_LIST);
PowerMockito.mockStatic(MessageDialog.class);
when(MessageDialog.openConfirm((Shell) anyObject(), anyString(), anyString())).thenReturn(true);
PowerMockito.mockStatic(RepositoryResourceUtil.class);
when(RepositoryResourceUtil.isOpenedInEditor((IRepositoryViewObject) anyObject())).thenReturn(null);
when(RepositoryResourceUtil.hasContainerItem(anyObject(), eq(FolderType.FOLDER_LITERAL))).thenReturn(true);
PowerMockito.mockStatic(ContainerCacheService.class);
FolderItem folderItemM = mock(FolderItem.class);
when(repositoryFactory.getFolderItem(eq(projectM), eq(typeM), (IPath) anyObject())).thenReturn(folderItemM);
when(folderItemM.getState()).thenReturn(itemState);
removeActionM.doRun();
}
use of org.talend.core.model.repository.RepositoryNodeProviderRegistryReader in project tmdm-studio-se by Talend.
the class RenameObjectActionTest method doRunTest.
@Test
public void doRunTest() throws Exception {
RenameObjectAction renameAction = new RenameObjectAction();
RenameObjectAction renameActionM = PowerMockito.spy(renameAction);
CommonViewer commonViewerM = mock(CommonViewer.class);
// $NON-NLS-1$
Whitebox.setInternalState(renameActionM, "commonViewer", commonViewerM);
// mock a mdm repositoryViewObject
IRepositoryViewObject objectRVO = mock(IRepositoryViewObject.class);
IRepositoryViewObject parentRVO = mock(IRepositoryViewObject.class);
MDMServerObjectItem mdmItemM = mock(MDMServerObjectItem.class);
ContainerItem parentItemM = mock(ContainerItem.class);
Property propertyM = mock(Property.class);
Property parentPropertyM = mock(Property.class);
// $NON-NLS-1$
String name = "mockName";
MDMServerObject mdmServerObjectM = mock(MDMServerObject.class);
when(mdmServerObjectM.getName()).thenReturn(name);
ItemState itemStateM = mock(ItemState.class);
//
when(objectRVO.getProperty()).thenReturn(propertyM);
when(propertyM.getItem()).thenReturn(mdmItemM);
when(mdmItemM.getMDMServerObject()).thenReturn(mdmServerObjectM);
when(mdmItemM.getState()).thenReturn(itemStateM);
// $NON-NLS-1$
when(itemStateM.getPath()).thenReturn("");
//
when(parentRVO.getProperty()).thenReturn(parentPropertyM);
when(parentPropertyM.getItem()).thenReturn(parentItemM);
//
PowerMockito.mockStatic(RepositoryNodeProviderRegistryReader.class);
RepositoryNodeProviderRegistryReader reader = mock(RepositoryNodeProviderRegistryReader.class);
PowerMockito.when(RepositoryNodeProviderRegistryReader.getInstance()).thenReturn(reader);
ERepositoryObjectType typeM = ERepositoryObjectType.PROCESS;
when(resourceProviderM.getRepositoryObjectType(mdmItemM)).thenReturn(typeM);
// $NON-NLS-1$ //$NON-NLS-2$
PowerMockito.doReturn("NewName").when(renameActionM, "showRenameDlg", typeM, parentItemM, name);
//
PowerMockito.mockStatic(ContainerCacheService.class);
// $NON-NLS-1$
when(ContainerCacheService.get(eq(typeM), eq(""))).thenReturn(parentRVO);
Shell shellM = mock(Shell.class);
Control controlM = mock(Control.class);
when(commonViewerM.getControl()).thenReturn(controlM);
when(controlM.getShell()).thenReturn(shellM);
List<Object> selectedObjects = new ArrayList<Object>();
selectedObjects.add(objectRVO);
//
when(renameActionM.getSelectedObject()).thenReturn(selectedObjects);
InputDialog inputDialogM = mock(InputDialog.class);
PowerMockito.whenNew(InputDialog.class).withArguments(eq(shellM), anyString(), anyString(), anyString(), anyObject()).thenReturn(inputDialogM);
when(inputDialogM.open()).thenReturn(IDialogConstants.OK_ID);
// $NON-NLS-1$
when(inputDialogM.getValue()).thenReturn("NewName");
renameActionM.doRun();
}
Aggregations