use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef 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.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class ServerExplorer method editServerDef.
private void editServerDef() {
IRepositoryViewObject viewObject = getCurSelectedViewObject();
if (viewObject != null) {
MDMServerDefItem mdmItem = getMDMItem(viewObject);
if (mdmItem != null) {
MDMServerDef serverDef = mdmItem.getServerDef();
ServerDefDialog dialog = new ServerDefDialog(getViewSite().getShell(), serverDef);
if (dialog.open() == IDialogConstants.OK_ID) {
String tempPasswd = serverDef.getTempPasswd();
ServerDefService.updateTempPassword(viewObject.getId(), tempPasswd);
boolean result = ServerDefService.saveServeDef(mdmItem);
if (result) {
refreshServerDefs();
}
}
}
}
}
use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class ServerExplorer method editServerDef.
private void editServerDef(IRepositoryViewObject viewObject) {
if (viewObject != null) {
MDMServerDefItem mdmItem = getMDMItem(viewObject);
if (mdmItem != null) {
MDMServerDef serverDef = mdmItem.getServerDef();
ServerDefDialog dialog = new ServerDefDialog(getViewSite().getShell(), serverDef);
if (dialog.open() == IDialogConstants.OK_ID) {
String tempPasswd = serverDef.getTempPasswd();
ServerDefService.updateTempPassword(viewObject.getId(), tempPasswd);
boolean result = ServerDefService.saveServeDef(mdmItem);
if (result) {
refreshServerDefs();
}
}
}
}
}
use of org.talend.mdm.repository.model.mdmmetadata.MDMServerDef 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.model.mdmmetadata.MDMServerDef in project tmdm-studio-se by Talend.
the class ConsistencyServiceTest method testUpdateDigestValue.
@Test
public void testUpdateDigestValue() {
PowerMockito.mockStatic(RepositoryResourceUtil.class);
IRepositoryViewObject mockViewObj = PowerMockito.mock(IRepositoryViewObject.class);
MDMServerObjectItem mockItem = PowerMockito.mock(MDMServerObjectItem.class);
Property mockProperty = PowerMockito.mock(Property.class);
PowerMockito.when(mockProperty.getItem()).thenReturn(mockItem);
PowerMockito.when(mockItem.getProperty()).thenReturn(mockProperty);
PowerMockito.when(mockViewObj.getProperty()).thenReturn(mockProperty);
PowerMockito.when(RepositoryResourceUtil.assertItem(mockItem)).thenReturn(mockItem);
PowerMockito.when(mockViewObj.getRepositoryObjectType()).thenReturn(IServerObjectRepositoryType.TYPE_DATAMODEL);
try {
TMDMService mockService = PowerMockito.mock(TMDMService.class);
MDMServerDef mockServerDef = PowerMockito.mock(MDMServerDef.class);
PowerMockito.mockStatic(RepositoryWebServiceAdapter.class);
PowerMockito.when(RepositoryWebServiceAdapter.getMDMService(mockServerDef)).thenReturn(mockService);
WSLong timeValue = new WSLong(11);
PowerMockito.when(mockService.updateDigest(any(WSDigest.class))).thenReturn(timeValue);
ConsistencyService mockCService = PowerMockito.mock(ConsistencyService.class);
// $NON-NLS-1$
PowerMockito.doNothing().when(mockCService, "updateLocalDigestValue", mockViewObj);
// $NON-NLS-1$
String label = "Product";
// $NON-NLS-1$
PowerMockito.when(mockCService, "getObjectName", mockViewObj).thenReturn(label);
PowerMockito.when(mockCService.getLocalDigestValue(mockItem)).thenReturn(label);
PowerMockito.when(mockCService, "updateDigestValue", any(MDMServerDef.class), any(IRepositoryViewObject.class)).thenCallRealMethod();
mockCService.updateDigestValue(mockServerDef, mockViewObj);
// check
Mockito.verify(mockCService, times(1)).updateLocalDigestValue(mockViewObj);
Mockito.verify(mockService, Mockito.times(1)).updateDigest(any(WSDigest.class));
PowerMockito.verifyStatic();
RepositoryResourceUtil.saveItem(mockItem);
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations