refactor: simplify collection.toArray()
[egit/eclipse.git] / org.eclipse.egit.ui.test / src / org / eclipse / egit / ui / view / synchronize / SynchronizeViewPushTest.java
blob8021a1aa6eb66f8599347d9e394cbbdaf5a278fe
1 /*******************************************************************************
2 * Copyright (C) 2012, 2013 Robin Stocker <robin@nibor.org>
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License 2.0
6 * which accompanies this distribution, and is available at
7 * https://www.eclipse.org/legal/epl-2.0/
9 * SPDX-License-Identifier: EPL-2.0
10 *******************************************************************************/
11 package org.eclipse.egit.ui.view.synchronize;
13 import static org.hamcrest.Matchers.is;
14 import static org.junit.Assert.assertThat;
16 import java.util.concurrent.TimeUnit;
18 import org.eclipse.egit.core.op.FetchOperation;
19 import org.eclipse.egit.ui.JobFamilies;
20 import org.eclipse.egit.ui.internal.UIText;
21 import org.eclipse.egit.ui.test.JobJoiner;
22 import org.eclipse.egit.ui.test.TestUtil;
23 import org.eclipse.jgit.lib.ConfigConstants;
24 import org.eclipse.jgit.lib.Constants;
25 import org.eclipse.jgit.lib.ObjectId;
26 import org.eclipse.jgit.lib.Repository;
27 import org.eclipse.jgit.lib.StoredConfig;
28 import org.eclipse.jgit.transport.RefSpec;
29 import org.eclipse.jgit.transport.RemoteConfig;
30 import org.eclipse.jgit.transport.URIish;
31 import org.eclipse.osgi.util.NLS;
32 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
33 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
34 import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
35 import org.eclipse.team.ui.synchronize.ISynchronizeView;
36 import org.junit.Before;
37 import org.junit.Test;
39 /**
40 * Test for "Push" action in Synchronize view.
42 public class SynchronizeViewPushTest extends AbstractSynchronizeViewTest {
44 @Before
45 public void prepare() throws Exception {
46 Repository childRepository = lookupRepository(childRepositoryFile);
48 Repository repository = lookupRepository(repositoryFile);
49 StoredConfig config = repository.getConfig();
50 RemoteConfig remoteConfig = new RemoteConfig(config, "origin");
51 remoteConfig.addURI(new URIish(childRepository.getDirectory().getParentFile().toURI().toURL()));
52 remoteConfig.addFetchRefSpec(new RefSpec("+refs/heads/*:refs/remotes/origin/*"));
53 remoteConfig.update(config);
55 config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_REMOTE, "origin");
56 config.setString(ConfigConstants.CONFIG_BRANCH_SECTION, "master", ConfigConstants.CONFIG_KEY_MERGE, "refs/heads/master");
57 config.save();
59 FetchOperation fetchOperation = new FetchOperation(repository, remoteConfig, 60, false);
60 fetchOperation.run(null);
63 @Test
64 public void shouldUpdateTrackingBranchOnPush() throws Exception {
65 makeChangesAndCommit(PROJ1);
66 Repository repository = lookupRepository(repositoryFile);
67 ObjectId headId = repository.resolve(Constants.HEAD);
69 String trackingBranch = Constants.R_REMOTES + "origin/master";
70 launchSynchronization(Constants.HEAD, trackingBranch, false);
72 SWTBotView viewBot = bot.viewById(ISynchronizeView.VIEW_ID);
73 SWTBotToolbarButton pushButton = viewBot.toolbarButton(UIText.GitActionContributor_Push);
74 JobJoiner jobJoiner = JobJoiner.startListening(JobFamilies.PUSH, 30, TimeUnit.SECONDS);
75 pushButton.click();
76 TestUtil.openJobResultDialog(jobJoiner.join());
78 String destinationString = repositoryFile.getParentFile().getName() + " - " + "origin";
79 SWTBotShell resultDialog = bot.shell(NLS.bind(UIText.PushResultDialog_title, destinationString));
80 resultDialog.close();
82 Repository remoteRepository = lookupRepository(childRepositoryFile);
83 ObjectId masterOnRemote = remoteRepository.resolve("master");
84 assertThat("Expected push to update branch on remote repository", masterOnRemote, is(headId));
86 ObjectId trackingId = repository.resolve(trackingBranch);
87 assertThat("Expected tracking branch to be updated", trackingId, is(headId));