-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2347 from eclipse/CHE-2336
CHE-2336: add an action for downloading all projects from the ws
- Loading branch information
Showing
4 changed files
with
190 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
ide/che-core-ide-app/src/main/java/org/eclipse/che/ide/actions/DownloadWsAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.actions; | ||
|
||
import com.google.inject.Inject; | ||
import com.google.inject.Singleton; | ||
|
||
import org.eclipse.che.ide.CoreLocalizationConstant; | ||
import org.eclipse.che.ide.Resources; | ||
import org.eclipse.che.ide.api.action.AbstractPerspectiveAction; | ||
import org.eclipse.che.ide.api.action.ActionEvent; | ||
import org.eclipse.che.ide.api.app.AppContext; | ||
import org.eclipse.che.ide.api.resources.Project; | ||
import org.eclipse.che.ide.download.DownloadContainer; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import static java.util.Collections.singletonList; | ||
import static org.eclipse.che.ide.workspace.perspectives.project.ProjectPerspective.PROJECT_PERSPECTIVE_ID; | ||
|
||
/** | ||
* Download all projects from the workspace. | ||
* | ||
* @author Valeriy Svydenko | ||
*/ | ||
@Singleton | ||
public class DownloadWsAction extends AbstractPerspectiveAction { | ||
|
||
private final AppContext appContext; | ||
private final DownloadContainer downloadContainer; | ||
|
||
@Inject | ||
public DownloadWsAction(AppContext appContext, | ||
CoreLocalizationConstant locale, | ||
Resources resources, | ||
DownloadContainer downloadContainer) { | ||
super(singletonList(PROJECT_PERSPECTIVE_ID), | ||
locale.downloadProjectAsZipName(), | ||
locale.downloadProjectAsZipDescription(), | ||
null, | ||
resources.downloadZip()); | ||
this.appContext = appContext; | ||
this.downloadContainer = downloadContainer; | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public void actionPerformed(ActionEvent e) { | ||
downloadContainer.setUrl(appContext.getDevMachine().getWsAgentBaseUrl() + "/project/export/"); | ||
} | ||
|
||
/** {@inheritDoc} */ | ||
@Override | ||
public void updateInPerspective(@NotNull ActionEvent e) { | ||
final Project[] projects = appContext.getProjects(); | ||
e.getPresentation().setVisible(true); | ||
e.getPresentation().setEnabled(projects != null && projects.length > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
111 changes: 111 additions & 0 deletions
111
ide/che-core-ide-app/src/test/java/org/eclipse/che/ide/actions/DownloadWsActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2012-2016 Codenvy, S.A. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Codenvy, S.A. - initial API and implementation | ||
*******************************************************************************/ | ||
package org.eclipse.che.ide.actions; | ||
|
||
import com.google.gwtmockito.GwtMockitoTestRunner; | ||
|
||
import org.eclipse.che.ide.CoreLocalizationConstant; | ||
import org.eclipse.che.ide.Resources; | ||
import org.eclipse.che.ide.api.action.ActionEvent; | ||
import org.eclipse.che.ide.api.action.Presentation; | ||
import org.eclipse.che.ide.api.app.AppContext; | ||
import org.eclipse.che.ide.api.machine.DevMachine; | ||
import org.eclipse.che.ide.api.resources.Project; | ||
import org.eclipse.che.ide.download.DownloadContainer; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
|
||
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
/** | ||
* @author Valeriy Svydenko | ||
*/ | ||
@RunWith(GwtMockitoTestRunner.class) | ||
public class DownloadWsActionTest { | ||
@Mock | ||
private AppContext appContext; | ||
@Mock | ||
private DownloadContainer downloadContainer; | ||
@Mock | ||
private CoreLocalizationConstant locale; | ||
@Mock | ||
private Resources resources; | ||
@Mock | ||
private ActionEvent actionEvent; | ||
@Mock | ||
private Presentation presentation; | ||
|
||
@InjectMocks | ||
private DownloadWsAction action; | ||
|
||
@Test | ||
public void actionShouldBeInitialized() throws Exception { | ||
verify(locale).downloadProjectAsZipName(); | ||
verify(locale).downloadProjectAsZipDescription(); | ||
verify(resources).downloadZip(); | ||
} | ||
|
||
@Test | ||
public void actionShouldBePerformed() throws Exception { | ||
String baseUrl = "baseUrl"; | ||
|
||
DevMachine devMachine = mock(DevMachine.class); | ||
when(appContext.getDevMachine()).thenReturn(devMachine); | ||
when(devMachine.getWsAgentBaseUrl()).thenReturn(baseUrl); | ||
|
||
action.actionPerformed(actionEvent); | ||
|
||
verify(downloadContainer).setUrl(eq("baseUrl/project/export/")); | ||
} | ||
|
||
@Test | ||
public void actionShouldBeEnable() throws Exception { | ||
Project project = mock(Project.class); | ||
|
||
when(actionEvent.getPresentation()).thenReturn(presentation); | ||
Project[] projects = new Project[1]; | ||
projects[0] = project; | ||
when(appContext.getProjects()).thenReturn(projects); | ||
|
||
action.updateInPerspective(actionEvent); | ||
|
||
verify(presentation).setVisible(true); | ||
verify(presentation).setEnabled(true); | ||
} | ||
|
||
@Test | ||
public void actionShouldNotBeEnabledIfWsIsEmpty() throws Exception { | ||
when(actionEvent.getPresentation()).thenReturn(presentation); | ||
Project[] projects = new Project[0]; | ||
when(appContext.getProjects()).thenReturn(projects); | ||
|
||
action.updateInPerspective(actionEvent); | ||
|
||
verify(presentation).setVisible(true); | ||
verify(presentation).setEnabled(false); | ||
} | ||
|
||
@Test | ||
public void actionShouldNotBeEnabledIfListOfProjectsIsNull() throws Exception { | ||
when(actionEvent.getPresentation()).thenReturn(presentation); | ||
when(appContext.getProjects()).thenReturn(null); | ||
|
||
action.updateInPerspective(actionEvent); | ||
|
||
verify(presentation).setVisible(true); | ||
verify(presentation).setEnabled(false); | ||
} | ||
} |