Search in sources :

Example 6 with AbstractDeployCommand

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

Example 7 with AbstractDeployCommand

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);
        }
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) ICommand(org.talend.mdm.repository.core.command.ICommand) AbstractDeployCommand(org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)

Example 8 with AbstractDeployCommand

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

Example 9 with AbstractDeployCommand

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);
    }
}
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 10 with AbstractDeployCommand

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);
    }
}
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)

Aggregations

AbstractDeployCommand (org.talend.mdm.repository.core.command.deploy.AbstractDeployCommand)21 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 CommandManager (org.talend.mdm.repository.core.command.CommandManager)8 IStatus (org.eclipse.core.runtime.IStatus)7 MDMServerDef (org.talend.mdm.repository.model.mdmmetadata.MDMServerDef)7 ArrayList (java.util.ArrayList)6 LinkedList (java.util.LinkedList)6 ICommand (org.talend.mdm.repository.core.command.ICommand)6 ICommandParameter (org.talend.mdm.repository.core.command.param.ICommandParameter)5 ImpactOperation (org.talend.mdm.repository.core.service.ModelImpactAnalyseService.ImpactOperation)4 Test (org.junit.Test)3 ConsistencyCheckResult (org.talend.mdm.repository.core.service.ConsistencyService.ConsistencyCheckResult)3 IModelValidateResult (org.talend.mdm.repository.core.service.IModelValidationService.IModelValidateResult)3 XtentisException (com.amalto.workbench.utils.XtentisException)2 HashSet (java.util.HashSet)2 WebServiceException (javax.xml.ws.WebServiceException)2 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 Property (org.talend.core.model.properties.Property)2 CommandStack (org.talend.mdm.repository.core.command.CommandStack)2