use of org.talend.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.
the class TreeViewerListener method treeExpanded.
@Override
public void treeExpanded(TreeExpansionEvent event) {
Object element = event.getElement();
if (element instanceof FolderRepositoryObject) {
FolderRepositoryObject fro = (FolderRepositoryObject) element;
String path = fro.getPath();
if (!path.isEmpty()) {
TreeItem item = getObject(viewer.getTree(), event.getElement());
if (item != null) {
item.setImage(ImageProvider.getImage(ECoreImage.FOLDER_OPEN_ICON));
}
}
}
}
use of org.talend.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.
the class ContainerCacheServiceTest method testRemoveContainer.
@Test
public void testRemoveContainer() {
// $NON-NLS-1$
String path = "/path";
// $NON-NLS-1$
String propId = "propertyId";
ERepositoryObjectType repObjType = IServerObjectRepositoryType.TYPE_DATAMODEL;
IRepositoryViewObject mockChildRpViewObj = PowerMockito.mock(IRepositoryViewObject.class);
Property mockProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockProperty.getId()).thenReturn(propId);
PowerMockito.when(mockChildRpViewObj.getId()).thenReturn(propId);
PowerMockito.when(mockChildRpViewObj.getProperty()).thenReturn(mockProperty);
ContainerCacheService.put(mockChildRpViewObj);
// container item
ItemState mockState = PowerMockito.mock(ItemState.class);
PowerMockito.when(mockState.getPath()).thenReturn(path);
ContainerItem mockContainerItem = PowerMockito.mock(ContainerItem.class);
PowerMockito.when(mockContainerItem.getState()).thenReturn(mockState);
PowerMockito.when(mockContainerItem.getRepObjType()).thenReturn(repObjType);
FolderRepositoryObject mockFolderRepoObj = PowerMockito.mock(FolderRepositoryObject.class);
List<IRepositoryViewObject> children = new ArrayList<IRepositoryViewObject>();
children.add(mockChildRpViewObj);
children = spy(children);
PowerMockito.when(mockFolderRepoObj.getChildren()).thenReturn(children);
Property mockFolderProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockFolderProperty.getItem()).thenReturn(mockContainerItem);
PowerMockito.when(mockFolderRepoObj.getProperty()).thenReturn(mockFolderProperty);
ContainerCacheService.putContainer(mockFolderRepoObj);
//
ContainerCacheService.removeContainer(repObjType, path);
assertNull(ContainerCacheService.get(repObjType, path));
assertNull(ContainerCacheService.get(mockProperty));
}
use of org.talend.mdm.repository.models.FolderRepositoryObject 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.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.
the class RepositoryResourceUtilTest method testCreateDeletedFolderViewObject.
@Test
public void testCreateDeletedFolderViewObject() throws Exception {
ERepositoryObjectType type = null;
String path = "mocked_path";
String folderName = "folderName";
List<IRepositoryViewObject> children = new ArrayList<IRepositoryViewObject>();
List<IRepositoryViewObject> spychildren = PowerMockito.spy(children);
StubFolderRepositoryObject mockParentFolderObject = mock(StubFolderRepositoryObject.class);
when(mockParentFolderObject.getChildren()).thenReturn(spychildren);
PowerMockito.mockStatic(ContainerCacheService.class);
PowerMockito.doNothing().when(ContainerCacheService.class, "putContainer", Mockito.any(IRepositoryViewObject.class));
FolderRepositoryObject deletedFolderViewObject = RepositoryResourceUtil.createDeletedFolderViewObject(type, path, folderName, mockParentFolderObject);
assertNotNull(deletedFolderViewObject);
}
use of org.talend.mdm.repository.models.FolderRepositoryObject in project tmdm-studio-se by Talend.
the class AbstractRemoveCommandStackAction method removeFolderObject.
private void removeFolderObject(FolderRepositoryObject viewObj) {
Project project = ProjectManager.getInstance().getCurrentProject();
ContainerItem containerItem = (ContainerItem) viewObj.getProperty().getItem();
String path = containerItem.getState().getPath();
ERepositoryObjectType repObjType = containerItem.getRepObjType();
// ContainerCacheService.removeContainer(repObjType, path);
for (IRepositoryViewObject childObj : viewObj.getChildren()) {
if (childObj instanceof FolderRepositoryObject) {
removeFolderObject((FolderRepositoryObject) childObj);
} else {
removeServerObject(childObj);
}
}
try {
factory.deleteFolder(project, repObjType, new Path(path), false);
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
}
}
Aggregations