use of org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult 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.service.ConsistencyService.ConsistencyCheckResult in project tmdm-studio-se by Talend.
the class ConsistencyServiceTest method testCheckConsistency.
@Test
public void testCheckConsistency() {
MDMServerDef serverDef = MdmmetadataFactory.eINSTANCE.createMDMServerDef();
serverDef.setAlgorithm(PasswordUtil.ALGORITHM_COMMON_V2);
// $NON-NLS-1$
String url = "http://localhost:8180/talendmdm/service/soap?wsdl";
serverDef.parse(url);
serverDef.setUrl(url);
// $NON-NLS-1$
serverDef.setName("MyServer");
// $NON-NLS-1$
serverDef.setUser("admin");
// $NON-NLS-1$
serverDef.setPasswd("talend");
Map<IRepositoryViewObject, Integer> viewObCmdOpjMap = new HashMap<IRepositoryViewObject, Integer>();
IRepositoryViewObject mockViewObj = Mockito.mock(IRepositoryViewObject.class);
int cmdType = 1;
viewObCmdOpjMap.put(mockViewObj, cmdType);
try {
// isWorkInUI=false
PowerMockito.mockStatic(UIUtil.class);
// $NON-NLS-1$
when(UIUtil.class, "isWorkInUI").thenReturn(false);
ConsistencyService mockCService = PowerMockito.mock(ConsistencyService.class);
PowerMockito.when(mockCService.checkConsistency(serverDef, viewObCmdOpjMap)).thenCallRealMethod();
ConsistencyCheckResult checkResult1 = mockCService.checkConsistency(serverDef, viewObCmdOpjMap);
assertEquals(1, checkResult1.getToDeployObjects().size());
assertEquals(0, checkResult1.getToSkipObjects().size());
assertEquals(mockViewObj, checkResult1.getToDeployObjects().get(0));
// isWorkInUI=true
// $NON-NLS-1$
when(UIUtil.class, "isWorkInUI").thenReturn(true);
// has no conflict
// $NON-NLS-1$
PowerMockito.when(mockCService, "getConflictCount", anyMap()).thenReturn(0);
ConsistencyCheckResult checkResult2 = mockCService.checkConsistency(serverDef, viewObCmdOpjMap);
assertEquals(1, checkResult2.getToDeployObjects().size());
assertEquals(0, checkResult2.getToSkipObjects().size());
assertEquals(mockViewObj, checkResult2.getToDeployObjects().get(0));
// has (one) conflict
// $NON-NLS-1$
PowerMockito.when(mockCService, "getConflictCount", anyMap()).thenReturn(1);
PowerMockito.when(mockCService.isWarnUserWhenConflict()).thenReturn(true);
ConsistencyCheckResult mockResult1 = PowerMockito.mock(ConsistencyCheckResult.class);
PowerMockito.when(mockCService, "warnUserWhenConflict", eq(viewObCmdOpjMap), anyMap(), anyInt()).thenReturn(// $NON-NLS-1$
mockResult1);
ConsistencyCheckResult checkResult3 = mockCService.checkConsistency(serverDef, viewObCmdOpjMap);
assertEquals(mockResult1, checkResult3);
// $NON-NLS-1$
PowerMockito.verifyPrivate(mockCService, times(1)).invoke("correctCheckResult", mockResult1);
PowerMockito.when(mockCService.isWarnUserWhenConflict()).thenReturn(false);
ConsistencyCheckResult mockResult2 = PowerMockito.mock(ConsistencyCheckResult.class);
// $NON-NLS-1$
PowerMockito.when(mockCService, "getCheckResultByStrategy", anyInt(), anyMap(), eq(viewObCmdOpjMap)).thenReturn(mockResult2);
ConsistencyCheckResult checkResult4 = mockCService.checkConsistency(serverDef, viewObCmdOpjMap);
assertEquals(mockResult2, checkResult4);
// $NON-NLS-1$
PowerMockito.verifyPrivate(mockCService, times(1)).invoke("correctCheckResult", mockResult2);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult in project tmdm-studio-se by Talend.
the class DeployAllAction method runWithType.
public void runWithType(ERepositoryObjectType type) {
DeployAllDialog dialog = new DeployAllDialog(getShell(), type);
if (dialog.open() == IDialogConstants.OK_ID) {
List<AbstractDeployCommand> selectededCommands = dialog.getSelectedCommands();
if (selectededCommands.size() >= 0) {
DeployService deployService = DeployService.getInstance();
deployViewObject = deployService.getDeployViewObject(selectededCommands);
// validate object
IModelValidateResult validateResult = deployService.validateModel(deployViewObject);
int selectedButton = validateResult.getSelectedButton();
if (selectedButton == IModelValidationService.BUTTON_CANCEL) {
return;
}
List<IRepositoryViewObject> validObjects = validateResult.getValidObjects(selectedButton);
List<IRepositoryViewObject> invalidObjects = validateResult.getInvalidObjects(selectedButton);
//
MDMServerDef serverDef = dialog.getServerDef();
try {
// consistency check
ConsistencyCheckResult consistencyCheckResult = deployService.checkConsistency(serverDef, validObjects, selectededCommands);
if (consistencyCheckResult.isCanceled()) {
return;
} else {
validObjects = consistencyCheckResult.getToDeployObjects();
}
deployService.removeInvalidCommands(invalidObjects, selectededCommands);
deployService.removeInvalidCommands(consistencyCheckResult.getToSkipObjects(), selectededCommands);
// save editors
LockedDirtyObjectDialog lockDirtyDialog = new LockedDirtyObjectDialog(getShell(), Messages.AbstractDeployAction_promptToSaveEditors, validObjects);
if (lockDirtyDialog.needShowDialog() && lockDirtyDialog.open() == IDialogConstants.CANCEL_ID) {
return;
}
lockDirtyDialog.saveDirtyObjects();
// insert impact dialog
List<AbstractDeployCommand> canceledCommandAfterImpactAnalysis = new LinkedList<AbstractDeployCommand>(selectededCommands);
try {
Map<IRepositoryViewObject, ImpactOperation> analyzeModelImpact = ModelImpactAnalyseService.analyzeCommandImpact(serverDef, selectededCommands);
Map<IRepositoryViewObject, ICommandParameter> paramMap = null;
if (analyzeModelImpact != null) {
ModelImpactAnalyseService.shrinkDeployCommands(analyzeModelImpact, selectededCommands);
paramMap = ModelImpactAnalyseService.convertToParameters(analyzeModelImpact);
CommandManager.getInstance().attachParameterToCommand(selectededCommands, paramMap);
}
canceledCommandAfterImpactAnalysis.removeAll(selectededCommands);
} catch (InterruptedException ex) {
return;
}
IStatus status = deployService.runCommands(selectededCommands, serverDef);
// update consistency value
try {
deployService.updateServerConsistencyStatus(serverDef, status);
} catch (XtentisException e) {
log.error(e.getMessage(), e);
} catch (WebServiceException e) {
log.error(e.getMessage(), e);
}
// add canceled object to status
deployService.generateValidationFailedDeployStatus(status, invalidObjects);
deployService.generateConsistencyCancelDeployStatus(status, consistencyCheckResult.getToSkipObjects().toArray(new IRepositoryViewObject[0]));
for (AbstractDeployCommand cmd : canceledCommandAfterImpactAnalysis) {
deployService.generateConsistencyCancelDeployStatus(status, cmd.getViewObject());
}
//
updateChangedStatus(status);
if (status.isMultiStatus()) {
showDeployStatus(status);
}
updateLastServer(status, new NullProgressMonitor());
} catch (Exception e) {
String url = // $NON-NLS-1$
serverDef.getProtocol() + serverDef.getHost() + ":" + serverDef.getPort() + serverDef.getPath();
String title = Messages.bind(Messages.Server_cannot_connected, url);
MessageDialog.openError(getShell(), title, Messages.AbstractDataClusterAction_ConnectFailed);
}
}
}
}
use of org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult in project tmdm-studio-se by Talend.
the class DeployService method deploy.
public IStatus deploy(MDMServerDef serverDef, List<IRepositoryViewObject> viewObjs, int defaultCmdType, boolean removeLocked) {
if (removeLocked) {
removeLockedViewObj(viewObjs);
}
IModelValidateResult validateResult = validateModel(viewObjs);
int selectedButton = validateResult.getSelectedButton();
if (selectedButton == IModelValidationService.BUTTON_CANCEL) {
return Status.CANCEL_STATUS;
}
List<IRepositoryViewObject> validObjects = validateResult.getValidObjects(selectedButton);
List<IRepositoryViewObject> invalidObjects = validateResult.getInvalidObjects(selectedButton);
try {
// consistency check
ConsistencyCheckResult consistencyCheckResult = ConsistencyService.getInstance().checkConsistency(serverDef, validObjects);
if (consistencyCheckResult == null || consistencyCheckResult.isCanceled()) {
return Status.CANCEL_STATUS;
}
validObjects = consistencyCheckResult.getToDeployObjects();
//
CommandManager manager = CommandManager.getInstance();
List<AbstractDeployCommand> commands = manager.getDeployCommands(validObjects, defaultCmdType);
// insert impact dialog
List<AbstractDeployCommand> canceledCommandAfterImpactAnalysis = new LinkedList<AbstractDeployCommand>(commands);
if (UIUtil.isWorkInUI()) {
try {
Map<IRepositoryViewObject, ImpactOperation> analyzeModelImpact = ModelImpactAnalyseService.analyzeCommandImpact(serverDef, commands);
Map<IRepositoryViewObject, ICommandParameter> paramMap = null;
if (analyzeModelImpact != null) {
ModelImpactAnalyseService.shrinkDeployCommands(analyzeModelImpact, commands);
paramMap = ModelImpactAnalyseService.convertToParameters(analyzeModelImpact);
manager.attachParameterToCommand(commands, paramMap);
}
canceledCommandAfterImpactAnalysis.removeAll(commands);
} catch (InterruptedException ex) {
return Status.CANCEL_STATUS;
}
}
IStatus mainStatus = runCommands(commands, serverDef);
// update consistency value
try {
updateServerConsistencyStatus(serverDef, mainStatus);
} catch (XtentisException e) {
log.error(e.getMessage(), e);
} catch (WebServiceException e) {
log.error(e.getMessage(), e);
}
//
generateValidationFailedDeployStatus(mainStatus, invalidObjects);
if (UIUtil.isWorkInUI()) {
generateConsistencyCancelDeployStatus(mainStatus, consistencyCheckResult.getToSkipObjects().toArray(new IRepositoryViewObject[0]));
for (AbstractDeployCommand cmd : canceledCommandAfterImpactAnalysis) {
generateConsistencyCancelDeployStatus(mainStatus, cmd.getViewObject());
}
}
return mainStatus;
} catch (Exception e) {
log.error(e.getMessage(), e);
String url = // $NON-NLS-1$
serverDef.getProtocol() + serverDef.getHost() + ":" + serverDef.getPort() + serverDef.getPath();
String title = Messages.bind(Messages.Server_cannot_connected, url);
MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), title, Messages.AbstractDataClusterAction_ConnectFailed);
return Status.CANCEL_STATUS;
}
}
Aggregations