Search in sources :

Example 31 with MDMServerDef

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);
    }
}
Also used : IModelValidateResult(org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult) IStatus(org.eclipse.core.runtime.IStatus) ArrayList(java.util.ArrayList) CommandManager(org.talend.mdm.repository.core.command.CommandManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ConsistencyCheckResult(org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 32 with MDMServerDef

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();
                }
            }
        }
    }
}
Also used : ServerDefDialog(org.talend.mdm.workbench.serverexplorer.ui.dialogs.ServerDefDialog) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 33 with MDMServerDef

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();
                }
            }
        }
    }
}
Also used : ServerDefDialog(org.talend.mdm.workbench.serverexplorer.ui.dialogs.ServerDefDialog) MDMServerDefItem(org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 34 with MDMServerDef

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);
    }
}
Also used : HashMap(java.util.HashMap) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ConsistencyCheckResult(org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) UIUtil(org.talend.mdm.repository.utils.UIUtil) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 35 with MDMServerDef

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);
    }
}
Also used : WSLong(com.amalto.workbench.webservices.WSLong) TMDMService(com.amalto.workbench.webservices.TMDMService) MDMServerObjectItem(org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) WSDigest(com.amalto.workbench.webservices.WSDigest) Property(org.talend.core.model.properties.Property) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)66 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)36 SelectServerDefDialog (org.talend.mdm.workbench.serverexplorer.ui.dialogs.SelectServerDefDialog)15 Item (org.talend.core.model.properties.Item)11 MDMServerDefItem (org.talend.mdm.repository.model.mdmproperties.MDMServerDefItem)10 MDMServerObjectItem (org.talend.mdm.repository.model.mdmproperties.MDMServerObjectItem)10 IStatus (org.eclipse.core.runtime.IStatus)8 MDMServerObject (org.talend.mdm.repository.model.mdmserverobject.MDMServerObject)8 PersistenceException (org.talend.commons.exception.PersistenceException)7 AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)7 TMDMService (com.amalto.workbench.webservices.TMDMService)6 CommandManager (org.talend.mdm.repository.core.command.CommandManager)6 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)6 TreeObject (com.amalto.workbench.models.TreeObject)5 XtentisException (com.amalto.workbench.utils.XtentisException)5 ArrayList (java.util.ArrayList)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 LinkedList (java.util.LinkedList)4