Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: fdba408a9dd280e7a8da513cf20ee775228909d4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*******************************************************************************
 * Copyright (c) 2012 Wind River Systems, Inc. and others. 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:
 * Wind River Systems - initial API and implementation
 *******************************************************************************/
package org.eclipse.tcf.te.tests.tcf.filesystem.operations;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSCopy;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSCreateFile;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSCreateFolder;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSDelete;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSMove;
import org.eclipse.tcf.te.tcf.filesystem.internal.operations.FSRename;
import org.eclipse.tcf.te.tcf.filesystem.model.FSTreeNode;
import org.eclipse.tcf.te.tests.tcf.filesystem.FSPeerTestCase;

@SuppressWarnings("restriction")
public class OperationTestBase extends FSPeerTestCase {

	protected FSTreeNode copy(FSTreeNode file, FSTreeNode folder) throws Exception {
		printDebugMessage("Copy " + file.getLocation() + " to " + folder.getLocation() + "..."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
		List<FSTreeNode> files = new ArrayList<FSTreeNode>();
		files.add(file);
		FSCopy copy = new FSCopy(files, folder);
		copy.run(new NullProgressMonitor());
		String location = folder.getLocation();
		String path = location + getPathSep() + file.name;
		return getFSNode(path);
	}

	protected FSTreeNode createFile(String fileName, FSTreeNode folder) throws Exception {
		printDebugMessage("Create " + fileName + " at " + folder.getLocation()); //$NON-NLS-1$ //$NON-NLS-2$
		FSCreateFile create = new FSCreateFile(folder, fileName);
		create.run(new NullProgressMonitor());
		String location = folder.getLocation();
		String path = location + getPathSep() + fileName;
		return getFSNode(path);
	}

	protected FSTreeNode createFolder(String folderName, FSTreeNode folder) throws Exception {
		printDebugMessage("Create " + folderName + " at " + folder.getLocation()); //$NON-NLS-1$ //$NON-NLS-2$
		FSCreateFolder create = new FSCreateFolder(folder, folderName);
		create.run(new NullProgressMonitor());
		String location = folder.getLocation();
		String path = location + getPathSep() + folderName;
		return getFSNode(path);
	}

	protected FSTreeNode move(FSTreeNode src, FSTreeNode dest) throws Exception {
		printDebugMessage("Move " + src.getLocation() + " to " + dest.getLocation()); //$NON-NLS-1$ //$NON-NLS-2$
		List<FSTreeNode> nodes = new ArrayList<FSTreeNode>();
		nodes.add(src);
		FSMove fsmove = new FSMove(nodes, dest);
		fsmove.run(new NullProgressMonitor());
		String path = dest.getLocation() + getPathSep() + src.name;
		return getFSNode(path);
	}

	protected FSTreeNode rename(FSTreeNode node, String newName) throws Exception {
		printDebugMessage("Rename " + node.name + " to " + newName); //$NON-NLS-1$ //$NON-NLS-2$
		FSRename fsmove = new FSRename(node, newName);
		fsmove.run(new NullProgressMonitor());
		String newPath = node.parent.getLocation()+getPathSep()+newName;
		return getFSNode(newPath);
	}

	protected void delete(FSTreeNode node) throws Exception {
		printDebugMessage("Delete " + node.getLocation() + "..."); //$NON-NLS-1$ //$NON-NLS-2$
		List<FSTreeNode> files = new ArrayList<FSTreeNode>();
		files.add(node);
		FSDelete delete = new FSDelete(files);
		delete.run(new NullProgressMonitor());
	}
}

Back to the top