use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand in project tmdm-studio-se by Talend.
the class CommandManager method getDeployCommandsWithoutHistory.
public List<AbstractDeployCommand> getDeployCommandsWithoutHistory(List<IRepositoryViewObject> viewObjs) {
List<AbstractDeployCommand> cmds = new LinkedList<AbstractDeployCommand>();
for (IRepositoryViewObject viewObj : viewObjs) {
ICommand cmd = getNewCommand(viewObj, ICommand.CMD_MODIFY);
cmd.setVersion(viewObj.getVersion());
cmd.init(viewObj);
if (cmd instanceof AbstractDeployCommand) {
cmds.add((AbstractDeployCommand) cmd);
}
}
return cmds;
}
use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand in project tmdm-studio-se by Talend.
the class BatchDeployJobCommand method runDeleteCmds.
private void runDeleteCmds(Object params, IProgressMonitor monitor, MultiStatus ms) {
for (ICommand cmd : subDeleteCmds) {
if (cmd instanceof AbstractDeployCommand) {
AbstractDeployCommand removeCmd = (AbstractDeployCommand) cmd;
IStatus status = removeCmd.execute(params, monitor);
ms.add(status);
}
}
}
use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand in project tmdm-studio-se by Talend.
the class RepositoryViewObjectCheckedWidget method getSelectedCommands.
public List<AbstractDeployCommand> getSelectedCommands() {
List<AbstractDeployCommand> commands = new LinkedList<AbstractDeployCommand>();
CommandManager commandManager = CommandManager.getInstance();
for (Object obj : treeViewer.getCheckedElements()) {
if (obj instanceof FolderRepositoryObject) {
continue;
}
IRepositoryViewObject viewObject = (IRepositoryViewObject) obj;
String id = viewObject.getId();
AbstractDeployCommand e = cmdMap.get(id);
if (e == null) {
List<IRepositoryViewObject> objs = new ArrayList<IRepositoryViewObject>();
objs.add(viewObject);
List<AbstractDeployCommand> newCommands = commandManager.getDeployCommands(objs, ICommand.CMD_MODIFY);
if (!newCommands.isEmpty()) {
e = newCommands.get(0);
}
}
commands.add(e);
List<AbstractDeployCommand> associatedCommands = getAssociatedObjectCommand(viewObject, ICommand.CMD_MODIFY);
if (associatedCommands != null) {
commands.addAll(associatedCommands);
}
}
return commands;
}
use of org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand 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.deploy.AbstractDeployCommand 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);
}
}
Aggregations