use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.
the class DeployServiceTest method testDeployAnotherVersion.
@Test
public void testDeployAnotherVersion() {
try {
MDMServerDef mockServerDef = PowerMockito.mock(MDMServerDef.class);
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
Property mockProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
List<IRepositoryViewObject> repositoryViewObjs = new ArrayList<IRepositoryViewObject>(Arrays.asList(mockViewObj));
PowerMockito.mockStatic(CommandManager.class);
CommandManager mockCommandManager = PowerMockito.mock(CommandManager.class);
PowerMockito.when(CommandManager.getInstance()).thenReturn(mockCommandManager);
List<AbstractDeployCommand> deployCommands = new ArrayList<AbstractDeployCommand>();
deployCommands.add(PowerMockito.mock(AbstractDeployCommand.class));
PowerMockito.when(mockCommandManager.getDeployCommandsWithoutHistory(anyListOf(IRepositoryViewObject.class))).thenReturn(deployCommands);
PowerMockito.mockStatic(ModelImpactAnalyseService.class);
DeployService mockDeployService = PowerMockito.mock(DeployService.class);
PowerMockito.when(mockDeployService.deployAnotherVersion(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class))).thenCallRealMethod();
// //
mockDeployService.deployAnotherVersion(mockServerDef, repositoryViewObjs);
// //
Mockito.verify(mockDeployService).runCommands(deployCommands, mockServerDef);
PowerMockito.verifyStatic();
ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class));
// ---------
Map<IRepositoryViewObject, ImpactOperation> analyzeModelImpact = new HashMap<IRepositoryViewObject, ModelImpactAnalyseService.ImpactOperation>();
ImpactOperation mockImpactOperation = PowerMockito.mock(ImpactOperation.class);
analyzeModelImpact.put(mockViewObj, mockImpactOperation);
PowerMockito.when(ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class))).thenReturn(analyzeModelImpact);
// //
mockDeployService.deployAnotherVersion(mockServerDef, repositoryViewObjs);
// //
Mockito.verify(mockDeployService, times(2)).runCommands(deployCommands, mockServerDef);
PowerMockito.verifyStatic(times(2));
ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class));
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.
the class DeployServiceTest method testDeploy4params.
@Test
public void testDeploy4params() {
MDMServerDef mockServerDef = PowerMockito.mock(MDMServerDef.class);
List<IRepositoryViewObject> viewObjs = new ArrayList<IRepositoryViewObject>();
int defaultCmdType = ICommand.CMD_MODIFY;
boolean removeLocked = true;
int selectedButton = IModelValidationService.BUTTON_CANCEL;
IModelValidateResult mockValidateResult = PowerMockito.mock(IModelValidateResult.class);
DeployService mockDeployService = PowerMockito.mock(DeployService.class);
PowerMockito.when(mockDeployService.deploy(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class), eq(defaultCmdType), eq(removeLocked))).thenCallRealMethod();
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
viewObjs.add(mockViewObj);
PowerMockito.mockStatic(RepositoryResourceUtil.class);
PowerMockito.mockStatic(ConsistencyService.class);
try {
// check selection of cancel for validating model
PowerMockito.when(mockValidateResult.getSelectedButton()).thenReturn(selectedButton);
PowerMockito.when(mockDeployService.validateModel(anyListOf(IRepositoryViewObject.class))).thenReturn(mockValidateResult);
IStatus deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
assertEquals(Status.CANCEL_STATUS, deployStatus);
verify(mockDeployService).validateModel(viewObjs);
// check selection of ok for validating model
selectedButton = IModelValidationService.BUTTON_OK;
List<IRepositoryViewObject> invalidViewObjs = new ArrayList<IRepositoryViewObject>();
IRepositoryViewObject mockInvalidViewObj = PowerMockito.mock(IRepositoryViewObject.class);
invalidViewObjs.add(mockInvalidViewObj);
PowerMockito.when(mockValidateResult.getSelectedButton()).thenReturn(selectedButton);
PowerMockito.when(mockValidateResult.getValidObjects(eq(selectedButton))).thenReturn(viewObjs);
PowerMockito.when(mockValidateResult.getInvalidObjects(eq(selectedButton))).thenReturn(invalidViewObjs);
PowerMockito.when(mockDeployService.validateModel(anyListOf(IRepositoryViewObject.class))).thenReturn(mockValidateResult);
// // check consistency null and cancel
PowerMockito.mockStatic(ConsistencyService.class);
ConsistencyService mockConsistencyService = PowerMockito.mock(ConsistencyService.class);
PowerMockito.when(ConsistencyService.getInstance()).thenReturn(mockConsistencyService);
//
ConsistencyCheckResult mockConsistencyCheckResult = null;
PowerMockito.when(mockConsistencyService.checkConsistency(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class))).thenReturn(mockConsistencyCheckResult);
deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
assertEquals(Status.CANCEL_STATUS, deployStatus);
//
mockConsistencyCheckResult = PowerMockito.mock(ConsistencyCheckResult.class);
PowerMockito.when(mockConsistencyCheckResult.isCanceled()).thenReturn(true);
PowerMockito.when(mockConsistencyService.checkConsistency(any(MDMServerDef.class), anyListOf(IRepositoryViewObject.class))).thenReturn(mockConsistencyCheckResult);
deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
assertEquals(Status.CANCEL_STATUS, deployStatus);
// // check without impact dialog
PowerMockito.when(mockConsistencyCheckResult.isCanceled()).thenReturn(false);
PowerMockito.when(mockConsistencyCheckResult.getToDeployObjects()).thenReturn(viewObjs);
List<AbstractDeployCommand> deployCommands = new ArrayList<AbstractDeployCommand>();
deployCommands.add(PowerMockito.mock(AbstractDeployCommand.class));
PowerMockito.when(mockDeployService.runCommands(anyListOf(AbstractDeployCommand.class), any(MDMServerDef.class))).thenReturn(Status.OK_STATUS);
PowerMockito.mockStatic(CommandManager.class);
CommandManager mockCommandManager = PowerMockito.mock(CommandManager.class);
PowerMockito.when(CommandManager.getInstance()).thenReturn(mockCommandManager);
PowerMockito.when(mockCommandManager.getDeployCommands(anyListOf(IRepositoryViewObject.class), anyInt())).thenReturn(deployCommands);
PowerMockito.mockStatic(UIUtil.class);
PowerMockito.when(UIUtil.isWorkInUI()).thenReturn(false);
deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
assertEquals(Status.OK_STATUS, deployStatus);
verify(mockDeployService, atLeastOnce()).runCommands(deployCommands, mockServerDef);
verify(mockDeployService, atLeastOnce()).updateServerConsistencyStatus(mockServerDef, Status.OK_STATUS);
verify(mockDeployService, atLeastOnce()).generateValidationFailedDeployStatus(Status.OK_STATUS, invalidViewObjs);
// // check with normal executed impact dialog
PowerMockito.when(UIUtil.isWorkInUI()).thenReturn(true);
PowerMockito.mockStatic(ModelImpactAnalyseService.class);
deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
assertEquals(Status.OK_STATUS, deployStatus);
PowerMockito.verifyStatic();
ModelImpactAnalyseService.analyzeCommandImpact(mockServerDef, deployCommands);
// // check with interrupted impact dialog
PowerMockito.when(ModelImpactAnalyseService.analyzeCommandImpact(any(MDMServerDef.class), anyListOf(AbstractDeployCommand.class))).thenThrow(new InterruptedException());
deployStatus = mockDeployService.deploy(mockServerDef, viewObjs, defaultCmdType, removeLocked);
assertEquals(Status.CANCEL_STATUS, deployStatus);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.
the class RepositoryViewObjectCheckedWidget method getAssociatedObjectCommand.
private List<AbstractDeployCommand> getAssociatedObjectCommand(IRepositoryViewObject viewObj, int cmdType) {
ERepositoryObjectType type = viewObj.getRepositoryObjectType();
CommandManager commandManager = CommandManager.getInstance();
if (type != null) {
IInteractiveHandler handler = InteractiveService.findHandler(type);
if (handler != null) {
List<IRepositoryViewObject> associatedObjects = handler.getAssociatedObjects(viewObj);
if (associatedObjects != null) {
return commandManager.getDeployCommands(associatedObjects, cmdType);
}
}
}
return null;
}
use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.
the class UpdateLastServerService method updateLastServerDefInfo.
public void updateLastServerDefInfo(Object serverDef, IRepositoryViewObject ViewObject) {
if (serverDef == null || ViewObject == null || !(serverDef instanceof MDMServerDef)) {
return;
}
CommandManager cmdManager = CommandManager.getInstance();
DeployService deployService = DeployService.getInstance();
ICommand deployCmd = cmdManager.getNewCommand(ICommand.CMD_MODIFY);
deployCmd.init(ViewObject);
// $NON-NLS-1$ //$NON-NLS-2$
MultiStatus mStatus = new MultiStatus("PLUGIN_ID", Status.OK, "", null);
// $NON-NLS-1$
DeployStatus deployStatus = DeployStatus.getOKStatus(deployCmd, "");
mStatus.add(deployStatus);
cmdManager.removeCommandStack(deployCmd, ICommand.PHASE_DEPLOY);
deployService.pushRestoreCommand(cmdManager, deployCmd, (MDMServerDef) serverDef);
deployService.updateLastServer(mStatus, new NullProgressMonitor());
}
use of org.talend.mdm.repository.core.command.CommandManager in project tmdm-studio-se by Talend.
the class RemoveFromServerAction method doRun.
protected void doRun() {
SelectServerDefDialog dialog = new SelectServerDefDialog(getShell());
if (dialog.open() == IDialogConstants.OK_ID) {
// save editors
LockedDirtyObjectDialog lockDirtyDialog = new LockedDirtyObjectDialog(getShell(), Messages.AbstractDeployAction_promptToSaveEditors, getSelectedRepositoryViewObject());
if (lockDirtyDialog.needShowDialog() && lockDirtyDialog.open() == IDialogConstants.CANCEL_ID) {
return;
}
lockDirtyDialog.saveDirtyObjects();
// remove
MDMServerDef serverDef = dialog.getSelectedServerDef();
List<AbstractDeployCommand> commands = new LinkedList<AbstractDeployCommand>();
CommandManager commandManager = CommandManager.getInstance();
for (Object obj : getSelectedObject()) {
IRepositoryViewObject viewObj = (IRepositoryViewObject) obj;
ICommand deleteCommand = commandManager.getNewCommand(ICommand.CMD_DELETE);
deleteCommand.init(viewObj);
commands.add((AbstractDeployCommand) deleteCommand);
}
//
IStatus status = DeployService.getInstance().runCommands(commands, serverDef);
if (status.isMultiStatus()) {
showDeployStatus(status);
}
}
}
Aggregations