9
9
import java.util.List;
11
11
import org.eclipse.core.resources.IFile;
12
import org.eclipse.core.resources.IProject;
13
12
import org.eclipse.core.resources.IResource;
14
13
import org.eclipse.core.runtime.NullProgressMonitor;
15
14
import org.eclipse.core.runtime.Path;
16
import org.junit.After;
17
import org.junit.Before;
18
15
import org.junit.Test;
19
16
import org.vcs.bazaar.client.BazaarStatusKind;
20
17
import org.vcs.bazaar.client.BazaarTreeStatus;
21
import org.vcs.bazaar.client.IBazaarClient;
22
18
import org.vcs.bazaar.client.commandline.commands.options.Option;
23
import org.vcs.bazaar.client.testUtils.ExpectedWorkingTree;
24
import org.vcs.bazaar.eclipse.AbstractCoreTestCase;
25
19
import org.vcs.bazaar.eclipse.BzrWorkspaceRoot;
26
import org.vcs.bazaar.eclipse.EclipseBazaarCore;
27
import org.vcs.bazaar.eclipse.WorkspaceUtil;
28
import org.vcs.bazaar.eclipse.core.commands.CommitCommand;
20
import org.vcs.bazaar.eclipse.TestCaseWithProject;
29
21
import org.vcs.bazaar.eclipse.core.model.local.IBzrLocalResource;
30
import org.vcs.bazaar.eclipse.core.repository.BazaarTeamProvider;
34
25
* @author Guillermo Gonzalez <guillo.gonzo@gmail.com>
37
public class CommitCommandTest extends AbstractCoreTestCase {
39
private IProject project;
40
private ExpectedWorkingTree wt;
41
private IBazaarClient client;
44
public void setUp() throws Exception {
45
client = EclipseBazaarCore.getDefault().createClient();
46
project = WorkspaceUtil.createProject("commit");
47
wt = createWorkingTree(project.getLocation());
48
project.refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
49
BazaarTeamProvider.map(project, BazaarTeamProvider.ID);
53
public void tearDown() throws Exception {
55
project.delete(true, true, new NullProgressMonitor());
28
public class CommitCommandTest extends TestCaseWithProject {
59
31
public final void testExecute() throws Exception {
60
32
final List<IBzrLocalResource> resources = new ArrayList<IBzrLocalResource>();
61
final IFile res = project.getFile(new Path("file_in_root.txt"));
33
final IFile res = getProject().getFile(new Path("file_in_root.txt"));
62
34
assertNotNull(res);
63
35
IBzrLocalResource bzrRes = BzrWorkspaceRoot.getBzrFileFor(res);
64
36
assertNotNull(bzrRes);
69
41
addContentToFile(aFile, textToAdd);
71
43
// change the expectedWorkingTree to the expected status
72
wt.setItemStatus(aFile.getName(), BazaarStatusKind.MODIFIED);
73
String currentContent = wt.getItemContent(aFile.getName());
74
wt.setItemContent(aFile.getName(), currentContent + textToAdd);
44
getWt().setItemStatus(aFile.getName(), BazaarStatusKind.MODIFIED);
45
String currentContent = getWt().getItemContent(aFile.getName());
46
getWt().setItemContent(aFile.getName(), currentContent + textToAdd);
76
48
// Check if status is ok
77
client.setWorkDir(project.getLocation().toFile());
78
BazaarTreeStatus treeStatus = client.status(new File[] { project.getLocation().toFile() });
79
wt.check(treeStatus.getStatusAsArray(), project.getLocation().toFile().getCanonicalPath());
49
getClient().setWorkDir(getProject().getLocation().toFile());
50
BazaarTreeStatus treeStatus = getClient().status(new File[] { getProject().getLocation().toFile() });
51
getWt().check(treeStatus.getStatusAsArray(), getProject().getLocation().toFile().getCanonicalPath());
81
53
CommitCommand cmd = new CommitCommand(resources, "test commit", new ArrayList<Option>(0));
82
54
IResource[] commitedResources = cmd.execute(new NullProgressMonitor());
89
61
public void testExecuteEncoding() throws Exception {
90
62
final List<IBzrLocalResource> resources = new ArrayList<IBzrLocalResource>();
91
final IFile res = project.getFile(new Path("file_in_root.txt"));
63
final IFile res = getProject().getFile(new Path("file_in_root.txt"));
92
64
assertNotNull(res);
93
65
IBzrLocalResource bzrRes = BzrWorkspaceRoot.getBzrFileFor(res);
94
66
assertNotNull(bzrRes);