Search in sources :

Example 1 with RepositoryNodeProviderRegistryReader

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);
}
Also used : RepositoryNodeProviderRegistryReader(org.talend.core.model.repository.RepositoryNodeProviderRegistryReader) ImageRegistry(org.eclipse.jface.resource.ImageRegistry) ResourceBundle(java.util.ResourceBundle) CoreRuntimePlugin(org.talend.core.runtime.CoreRuntimePlugin) Before(org.junit.Before)

Example 2 with RepositoryNodeProviderRegistryReader

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();
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) CommonViewer(org.eclipse.ui.navigator.CommonViewer) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ArrayList(java.util.ArrayList) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) RepositoryNodeProviderRegistryReader(org.talend.core.model.repository.RepositoryNodeProviderRegistryReader) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) FolderItem(org.talend.core.model.properties.FolderItem) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) FolderRepositoryObject(org.talend.mdm.repository.models.FolderRepositoryObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with RepositoryNodeProviderRegistryReader

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();
}
Also used : ContainerItem(org.talend.mdm.repository.model.mdmproperties.ContainerItem) InputDialog(org.eclipse.jface.dialogs.InputDialog) CommonViewer(org.eclipse.ui.navigator.CommonViewer) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) ArrayList(java.util.ArrayList) RepositoryNodeProviderRegistryReader(org.talend.core.model.repository.RepositoryNodeProviderRegistryReader) Shell(org.eclipse.swt.widgets.Shell) Control(org.eclipse.swt.widgets.Control) ItemState(org.talend.core.model.properties.ItemState) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) MDMServerObject(org.talend.mdm.repository.model.mdmserverobject.MDMServerObject) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

RepositoryNodeProviderRegistryReader (org.talend.core.model.repository.RepositoryNodeProviderRegistryReader)3 ArrayList (java.util.ArrayList)2 Control (org.eclipse.swt.widgets.Control)2 Shell (org.eclipse.swt.widgets.Shell)2 CommonViewer (org.eclipse.ui.navigator.CommonViewer)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 ItemState (org.talend.core.model.properties.ItemState)2 Property (org.talend.core.model.properties.Property)2 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 ContainerItem (org.talend.mdm.repository.model.mdmproperties.ContainerItem)2 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)2 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)2 ResourceBundle (java.util.ResourceBundle)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)1 ImageRegistry (org.eclipse.jface.resource.ImageRegistry)1 Before (org.junit.Before)1 FolderItem (org.talend.core.model.properties.FolderItem)1