1 /*******************************************************************************
2 * Copyright (c) 2010, 2013 SAP AG and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html
9 * Mathias Kinzler (SAP AG) - initial implementation
10 *******************************************************************************/
11 package org
.eclipse
.egit
.ui
.test
.team
.actions
;
13 import static org
.junit
.Assert
.assertTrue
;
16 import java
.io
.IOException
;
18 import org
.eclipse
.egit
.ui
.common
.LocalRepositoryTestCase
;
19 import org
.eclipse
.egit
.ui
.internal
.UIText
;
20 import org
.eclipse
.egit
.ui
.test
.ContextMenuHelper
;
21 import org
.eclipse
.egit
.ui
.test
.TestUtil
;
22 import org
.eclipse
.jface
.dialogs
.IDialogConstants
;
23 import org
.eclipse
.jgit
.errors
.IncorrectObjectTypeException
;
24 import org
.eclipse
.jgit
.errors
.MissingObjectException
;
25 import org
.eclipse
.jgit
.lib
.Repository
;
26 import org
.eclipse
.jgit
.revwalk
.RevWalk
;
27 import org
.eclipse
.osgi
.util
.NLS
;
28 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
29 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCombo
;
30 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
31 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
32 import org
.junit
.Before
;
33 import org
.junit
.Test
;
34 import org
.junit
.runner
.RunWith
;
37 * Tests for the Team->Push action
39 @RunWith(SWTBotJunit4ClassRunner
.class)
40 public class PushActionTest
extends LocalRepositoryTestCase
{
41 private File repositoryFile
;
43 private File remoteRepositoryFile
;
46 public void setup() throws Exception
{
47 repositoryFile
= createProjectAndCommitToRepository();
48 remoteRepositoryFile
= createRemoteRepository(repositoryFile
);
53 public void testPushToBothDestination() throws Exception
{
55 pushTo("both", false);
59 public void testPushToPushDestination() throws Exception
{
61 pushTo("push", false);
64 private void pushTo(String destination
, boolean withConfirmPage
)
65 throws Exception
, MissingObjectException
,
66 IncorrectObjectTypeException
, IOException
{
67 Repository repo
= lookupRepository(remoteRepositoryFile
);
68 try (RevWalk rw
= new RevWalk(repo
)) {
69 String previous
= rw
.parseCommit(repo
.resolve("HEAD")).name();
71 SWTBotShell pushDialog
= openPushDialog();
73 SWTBotCombo destinationCombo
= pushDialog
.bot().comboBox();
74 String
[] items
= destinationCombo
.items();
75 for (int i
= 0; i
< items
.length
; i
++) {
76 if (items
[i
].startsWith(destination
))
77 destinationCombo
.setSelection(i
);
80 pushDialog
.bot().button(IDialogConstants
.NEXT_LABEL
).click();
82 pushDialog
.bot().button(IDialogConstants
.NEXT_LABEL
).click();
83 pushDialog
.bot().button(IDialogConstants
.FINISH_LABEL
).click();
84 SWTBotShell confirm
= bot
.shell(
85 NLS
.bind(UIText
.PushResultDialog_title
, destination
));
86 String result
= confirm
.bot().tree().getAllItems()[0].getText();
88 assertTrue("Wrong result",
89 result
.contains(previous
.substring(0, 7)));
93 pushDialog
= openPushDialog();
95 destinationCombo
= pushDialog
.bot().comboBox();
96 for (int i
= 0; i
< items
.length
; i
++) {
97 if (items
[i
].startsWith(destination
))
98 destinationCombo
.setSelection(i
);
101 pushDialog
.bot().button(IDialogConstants
.NEXT_LABEL
).click();
103 pushDialog
.bot().button(IDialogConstants
.NEXT_LABEL
).click();
104 pushDialog
.bot().button(IDialogConstants
.FINISH_LABEL
).click();
106 NLS
.bind(UIText
.PushResultDialog_title
, destination
));
107 result
= confirm
.bot().tree().getAllItems()[0].getText();
111 assertTrue("Wrong result",
112 result
.contains(UIText
.PushResultTable_statusUpToDate
));
116 private SWTBotShell
openPushDialog() throws Exception
{
117 SWTBotTree projectExplorerTree
= TestUtil
.getExplorerTree();
118 getProjectItem(projectExplorerTree
, PROJ1
).select();
119 String menuString
= util
.getPluginLocalizedValue("PushAction_label");
120 String submenuString
= util
121 .getPluginLocalizedValue("RemoteSubMenu.label");
122 ContextMenuHelper
.clickContextMenu(projectExplorerTree
, "Team",
123 submenuString
, menuString
);
124 SWTBotShell dialog
= bot
.shell(UIText
.PushWizard_windowTitleDefault
);