📄 svntests.java
字号:
} return admDirName; } /** * internal class which implements the OutputInterface to write the data * to a file. */ public class FileOutputer implements OutputInterface { /** * the output file stream */ FileOutputStream myStream; /** * create new object * @param outputName the file to write the data to * @throws IOException */ public FileOutputer(File outputName) throws IOException { myStream = new FileOutputStream(outputName); } /** * write the bytes in data to java * @param data the data to be writtem * @throws IOException throw in case of problems. */ public int write(byte[] data) throws IOException { myStream.write(data); return data.length; } /** * close the output * @throws IOException throw in case of problems. */ public void close() throws IOException { myStream.close(); } } /** * internal class implements the OutputInterface, but ignores the data */ public class IgnoreOutputer implements OutputInterface { /** * write the bytes in data to java * @param data the data to be writtem * @throws IOException throw in case of problems. */ public int write(byte[] data) throws IOException { return data.length; } /** * close the output * @throws IOException throw in case of problems. */ public void close() throws IOException { } } /** * internal class which implements the InputInterface to read the data * from a file. */ public class FileInputer implements InputInterface { /** * input file stream */ FileInputStream myStream; /** * create a new object * @param inputName the file from which the data is read * @throws IOException */ public FileInputer(File inputName) throws IOException { myStream = new FileInputStream(inputName); } /** * read the number of data.length bytes from input. * @param data array to store the read bytes. * @throws IOException throw in case of problems. */ public int read(byte[] data) throws IOException { return myStream.read(data); } /** * close the input * @throws IOException throw in case of problems. */ public void close() throws IOException { myStream.close(); } } /** * this internal class represent the repository and the working copy for * one test. */ protected class OneTest { /** * the file name of repository (used by SVNAdmin) */ protected File repository; /** * the file name of the working copy directory */ protected File workingCopy; /** * the url of the repository (used by SVNClient) */ protected String url; /** * the expected layout of the working copy after the next subversion * command */ protected WC wc; /** * build a new test setup with a new repository, a new working and a * new expected working layout * @throws Exception */ protected OneTest() throws Exception { String testName = testBaseName + ++testCounter; wc = greekWC.copy(); repository = createStartRepository(testName); url = makeReposUrl(repository); workingCopy = createStartWorkingCopy(repository, testName); } /** * Copy the working copy and the expected working copy layout for tests * which need multiple working copy * @param append append to the working copy name of the original * @return second test object. * @throws Exception */ protected OneTest copy(String append) throws Exception { return new OneTest(this, append); } /** * constructor for create a copy * @param orig original test * @param append append this to the directory name of the original * test * @throws Exception */ private OneTest(OneTest orig, String append) throws Exception { String testName = testBaseName + testCounter +append; repository = orig.getRepository(); url = orig.getUrl(); wc = orig.wc.copy(); workingCopy = createStartWorkingCopy(repository, testName); } /** * Return the directory of the repository * @return the repository directory name */ public File getRepository() { return repository; } /** * Return the name of the directory of the repository * @return the name of repository directory */ public String getRepositoryPath() { return repository.getAbsolutePath(); } /** * Return the working copy directory * @return the working copy directory */ public File getWorkingCopy() { return workingCopy; } /** * Return the working copy directory name * @return the name of the working copy directory */ public String getWCPath() { return workingCopy.getAbsolutePath(); } /** * Returns the url of repository * @return the url */ public String getUrl() { return url; } /** * Returns the expected working copy content * @return the expected working copy content */ public WC getWc() { return wc; } /** * Create the repository for the beginning of the test * @param testName the name of the test * @return the repository directory * @throws Exception */ protected File createStartRepository(String testName) throws Exception { // build a clean repository directory File repos = new File(repositories, testName); removeDirectoryWithContent(repos); // create and load the repository from the default repository dump admin.create(repos.getAbsolutePath(), true, false, conf.getAbsolutePath(), SVNAdmin.BDB); admin.load(repos.getAbsolutePath(), new FileInputer(greekDump), new IgnoreOutputer(), false, false, null); return repos; } /** * Create the working copy for the beginning of the test * @param repos the repository directory * @param testName the name of the test * @return the directory of the working copy * @throws Exception */ protected File createStartWorkingCopy(File repos, String testName) throws Exception { // build a clean working directory String uri = makeReposUrl(repos); workingCopy = new File(workingCopies, testName); removeDirectoryWithContent(workingCopy); // checkout the repository client.checkout(uri, workingCopy.getAbsolutePath(), null, true); // sanity check the working with its expected status checkStatus(); return workingCopy; } /** * Check if the working copy has the expected status * @throws Exception */ public void checkStatus() throws Exception { Status[] states = client.status(workingCopy.getAbsolutePath(), true, false, true, true); wc.check(states, workingCopy.getAbsolutePath()); } } /** * internal class to receive the request for the log messages to check if * the expected commit items are presented */ class MyCommitMessage implements CommitMessage { /** * Retrieve a commit message from the user based on the items to be commited * @param elementsToBeCommited Array of elements to be commited * @return the log message of the commit. */ public String getLogMessage(CommitItem[] elementsToBeCommited) { // check all received CommitItems are expected as received for (int i = 0; i < elementsToBeCommited.length; i++) { CommitItem commitItem = elementsToBeCommited[i]; // since imports do not provide a url, the key is either url or // path String key; if(commitItem.getUrl() != null) key = commitItem.getUrl(); else key = commitItem.getPath(); MyCommitItem myItem = (MyCommitItem) expectedCommitItems.get( key); // check commit item is expected and has the expected data assertNotNull("commit item for "+key+ " not expected", myItem); myItem.test(commitItem, key); } // all remaining expected commit items are missing for (Iterator iterator = expectedCommitItems.keySet().iterator(); iterator.hasNext();) { String str = (String) iterator.next(); fail("commit item for "+str+" not found"); } return logMessage; } } /** * internal class to describe an expected commit item */ class MyCommitItem { /** * the path of the item */ String myPath; /** * the kind of node (file, directory or none, see NodeKind) */ int myNodeKind; /** * the reason why this item is commited (see CommitItemStateFlag) */ int myStateFlags; /** * the url of the item */ String myUrl; /** * build one expected commit item * @param path the expected path * @param nodeKind the expected node kind * @param stateFlags the expected state flags * @param url the expected url */ private MyCommitItem(String path, int nodeKind, int stateFlags, String url) { myPath = path; myNodeKind = nodeKind; myStateFlags = stateFlags; myUrl = url; } /** * Check if the commit item has the expected data * @param ci the commit item to check * @param key the key of the item */ private void test(CommitItem ci, String key) { assertEquals("commit item path", ci.getPath(), myPath); assertEquals("commit item node kind", ci.getNodeKind(), myNodeKind); assertEquals("commit item state flags", ci.getStateFlags(), myStateFlags); assertEquals("commit item url", ci.getUrl(), myUrl); // after the test, remove the item from the expected map expectedCommitItems.remove(key); } } class MyNotifier implements Notify2 { /** * Handler for Subversion notifications. * <p/> * Override this function to allow Subversion to send notifications * * @param info everything to know about this event */ public void onNotify(NotifyInformation info) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -