Search in sources :

Example 6 with CommandManager

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);
    }
}
Also used : HashMap(java.util.HashMap) ImpactOperation(org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation) ArrayList(java.util.ArrayList) CommandManager(org.talend.mdm.repository.core.command.CommandManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) 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)

Example 7 with CommandManager

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);
    }
}
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 8 with CommandManager

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;
}
Also used : CommandManager(org.talend.mdm.repository.core.command.CommandManager) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IInteractiveHandler(org.talend.mdm.repository.core.service.IInteractiveHandler) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType)

Example 9 with CommandManager

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());
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) CommandManager(org.talend.mdm.repository.core.command.CommandManager) ICommand(org.talend.mdm.repository.core.command.ICommand) DeployStatus(org.talend.mdm.repository.core.service.DeployService.DeployStatus) MultiStatus(org.eclipse.core.runtime.MultiStatus) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)

Example 10 with CommandManager

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);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) CommandManager(org.talend.mdm.repository.core.command.CommandManager) ICommand(org.talend.mdm.repository.core.command.ICommand) LockedDirtyObjectDialog(org.talend.mdm.repository.ui.dialogs.lock.LockedDirtyObjectDialog) SelectServerDefDialog(org.talend.mdm.workbench.serverexplorer.ui.dialogs.SelectServerDefDialog) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MDMServerDef(org.talend.mdm.repository.model.mdmmetadata.MDMServerDef) LinkedList(java.util.LinkedList)

Aggregations

CommandManager (org.talend.mdm.repository.core.command.CommandManager)15 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)8 ICommand (org.talend.mdm.repository.core.command.ICommand)8 AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)8 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)6 ArrayList (java.util.ArrayList)5 IStatus (org.eclipse.core.runtime.IStatus)5 LinkedList (java.util.LinkedList)4 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)3 ImpactOperation (org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 MultiStatus (org.eclipse.core.runtime.MultiStatus)2 Test (org.junit.Test)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CommandStack (org.talend.mdm.repository.core.command.CommandStack)2 ICommandParameter (org.talend.mdm.repository.core.command.param.ICommandParameter)2 ConsistencyCheckResult (org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult)2 IModelValidateResult (org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult)2 SelectServerDefDialog (org.talend.mdm.workbench.serverexplorer.ui.dialogs.SelectServerDefDialog)2