use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject 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();
}
use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.
the class Bean2EObjUtilTest method testWrapEObjWithTreeObject1Args.
/**
* test wrapEObjWithTreeObject with one input parameter
*/
@Test
public void testWrapEObjWithTreeObject1Args() {
EObject eobj = null;
Bean2EObjUtil util = Bean2EObjUtil.getInstance();
TreeObject treeObject = util.wrapEObjWithTreeObject(eobj);
assertNull(treeObject);
MDMServerObject mdmServerObject = PowerMockito.mock(MDMServerObject.class);
when(mdmServerObject.getName()).thenReturn("name");
when(mdmServerObject.getType()).thenReturn(2);
eobj = mdmServerObject;
treeObject = util.wrapEObjWithTreeObject(eobj);
assertNotNull(treeObject);
Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getName();
Mockito.verify(mdmServerObject, Mockito.atLeastOnce()).getType();
assertEquals("name", treeObject.getName());
assertEquals(2, treeObject.getType());
}
use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.
the class RenameProcessAction method renameProcessObject.
private void renameProcessObject(IRepositoryViewObject viewObj) {
MDMServerObjectItem item = (MDMServerObjectItem) viewObj.getProperty().getItem();
MDMServerObject serverObject = item.getMDMServerObject();
int type = getType(item);
if (serverObject != null) {
String oldName = serverObject.getName();
RenameProcessDialog dialog = getRenameDialog(getSite(), oldName, type, getInputValidator());
int returnCode = dialog.open();
if (returnCode == Window.OK) {
IProxyRepositoryFactory factory = getFactory();
String newName = dialog.getValue();
transformPath(viewObj, newName);
try {
if (factory.isEditableAndLockIfPossible(item)) {
serverObject.setName(newName);
viewObj.getProperty().setLabel(newName);
viewObj.getProperty().setDisplayName(newName);
factory.save(item, false);
MDMServerDef lastServerDef = RepositoryResourceUtil.getLastServerDef(item);
if (lastServerDef != null) {
CommandManager.getInstance().pushCommand(ICommand.CMD_RENAME, viewObj.getId(), new String[] { oldName, newName });
}
}
commonViewer.refresh(viewObj);
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
} finally {
try {
factory.unlock(item);
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
} catch (LoginException e) {
log.error(e.getMessage(), e);
}
}
}
}
}
use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.
the class XObjectEditor2 method saveResourceToRepository.
private boolean saveResourceToRepository() {
XObjectEditorInput2 editorInput = (XObjectEditorInput2) this.getEditorInput();
TreeObject xobject = (TreeObject) editorInput.getModel();
IRepositoryViewObject viewObject = editorInput.getViewObject();
IRepositoryViewObject refreshViewObject = RepositoryResourceUtil.assertViewObject(viewObject);
if (viewObject != refreshViewObject) {
editorInput.updateViewObject(refreshViewObject);
}
MDMServerObjectItem serverObjectItem = (MDMServerObjectItem) editorInput.getInputItem();
MDMServerObject serverObject = serverObjectItem.getMDMServerObject();
EObject eObj = Bean2EObjUtil.getInstance().convertFromBean2EObj(xobject.getWsObject(), serverObject);
if (eObj != null) {
IProxyRepositoryFactory factory = CoreRuntimePlugin.getInstance().getProxyRepositoryFactory();
try {
factory.save(serverObjectItem);
// TODO should call the following,but the page in editor has many call to remote webService ,it will
// search ServerRoot which cause a NPE
// xobject.fireEvent(IXObjectModelListener.SAVE, xobject.getParent(), xobject);
editorDirtyStateChanged();
refreshDirtyCue();
DeployService deployService = DeployService.getInstance();
if (deployService.isAutoDeploy()) {
autoDeployProcess(deployService);
} else {
MDMServerDef lastServerDef = RepositoryResourceUtil.getLastServerDef(serverObjectItem);
if (lastServerDef != null) {
CommandManager.getInstance().pushCommand(ICommand.CMD_MODIFY, editorInput.getViewObject());
}
}
return true;
} catch (PersistenceException e) {
log.error(e.getMessage(), e);
}
}
return false;
}
use of org.talend.mdm.repository.model.mdmserverobject.MDMServerObject in project tmdm-studio-se by Talend.
the class MDMServiceConfigrationMainPage method setForConfigureContent.
@Override
protected void setForConfigureContent(String serviceName) {
try {
if (serviceName != null && !"".equals(serviceName)) {
// $NON-NLS-1$
document = getServiceDocument(serviceName.trim());
XObjectEditorInput2 editorInput = (XObjectEditorInput2) getEditorInput();
MDMServerObjectItem serverObjectItem = (MDMServerObjectItem) editorInput.getInputItem();
MDMServerObject serverObject = serverObjectItem.getMDMServerObject();
String configContent = null;
if (serverObject instanceof WSServiceConfigurationE) {
WSServiceConfigurationE object = (WSServiceConfigurationE) serverObject;
for (WSServicePutConfigurationE config : object.getServicePutConfigurations()) {
if (config.getJndiName().equals(serviceName.trim())) {
configContent = config.getConfiguration();
}
}
}
serviceConfigurationsText.setText(configContent);
// $NON-NLS-1$
errorLabel.setText("");
}
} catch (WebServiceException e1) {
log.error(e1.getMessage(), e1);
}
}
Aggregations