Skip to content

Commit

Permalink
More tests, javadocs updates
Browse files Browse the repository at this point in the history
  • Loading branch information
centic9 committed Mar 1, 2018
1 parent d5a014a commit a64933f
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 9 deletions.
21 changes: 13 additions & 8 deletions src/main/java/org/dstadler/commons/svn/SVNCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public enum MergeResult {
* @param branches The list of branches to fetch logs for, currently only the first entry is used!
* @param startRevision The SVN revision to use as starting point for the log-entries.
* @param baseUrl The SVN url to connect to
*@param user The SVN user or null if the default user from the machine should be used
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return A mapping of revision numbers to the {@link LogEntry}.
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand All @@ -82,7 +82,7 @@ public static Map<Long, LogEntry> getBranchLog(String[] branches, long startRevi
* @param startRevision The SVN revision to use as starting point for the log-entries.
* @param endRevision The SVN revision to use as end point for the log-entries. In case <code>endRevision</code> is <code>-1</code>, HEAD revision is being used
* @param baseUrl The SVN url to connect to
*@param user The SVN user or null if the default user from the machine should be used
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return A mapping of revision numbers to the {@link LogEntry}.
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand All @@ -103,7 +103,7 @@ public static Map<Long, LogEntry> getBranchLog(String[] branches, long startRevi
* @param startDate The starting date for the log-entries that are fetched
* @param endDate The end date for the log-entries that are fetched
* @param baseUrl The SVN url to connect to
*@param user The SVN user or null if the default user from the machine should be used
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return A mapping of revision numbers to the {@link LogEntry}.
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand All @@ -124,7 +124,7 @@ public static Map<Long, LogEntry> getBranchLog(String[] branches, Date startDate
* @param branches The list of branches to fetch logs for, currently only the first entry is used!
* @param startRevision The SVN revision to use as starting point for the log-entries.
* @param baseUrl The SVN url to connect to
*@param user The SVN user or null if the default user from the machine should be used
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return The result of the "svn log -xml" call, should be closed by the caller
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand All @@ -144,7 +144,7 @@ public static InputStream getBranchLogStream(String[] branches, long startRevisi
* @param startRevision The SVN revision to use as starting point for the log-entries.
* @param endRevision The SVN revision to use as end point for the log-entries. In case <code>endRevision</code> is <code>-1</code>, HEAD revision is being used
* @param baseUrl The SVN url to connect to
*@param user The SVN user or null if the default user from the machine should be used
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return A stream that can be used to read the XML data, should be closed by the caller
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand Down Expand Up @@ -173,7 +173,7 @@ public static InputStream getBranchLogStream(String[] branches, long startRevisi
* @param startDate The starting date for the log-entries that are fetched
* @param endDate In case <code>endDate</code> is not specified, the current date is used
* @param baseUrl The SVN url to connect to
*@param user The SVN user or null if the default user from the machine should be used
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return A stream that can be used to read the XML data, should be closed by the caller
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand All @@ -198,8 +198,9 @@ public static InputStream getBranchLogStream(String[] branches, Date startDate,
* Retrieve the contents of a file from the web-interface of the SVN server.
*
* @param file The file to fetch from the SVN server via
* @param revision The SVN revision to use
* @param baseUrl The SVN url to connect to
*@param user The SVN user or null if the default user from the machine should be used
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return The contents of the file.
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand Down Expand Up @@ -281,6 +282,8 @@ public static long getBranchRevision(String branch, String baseUrl) throws IOExc
*
* @param branch The name of the branch including the path to the branch, e.g. branches/4.2.x
* @param baseUrl The SVN url to connect to
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return The contents of the file.
* @return The last revision where a check-in was made on the branch
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand Down Expand Up @@ -593,7 +596,7 @@ public static MergeResult mergeRevision(long revision, File directory, String br
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
*/
public static String getMergedRevisions(File directory, String[] branches) throws IOException {
public static String getMergedRevisions(File directory, String... branches) throws IOException {
// we could also use svn mergeinfo --show-revs merged ^/trunk ^/branches/test
CommandLine cmdLine;
cmdLine = new CommandLine(SVN_CMD);
Expand Down Expand Up @@ -692,6 +695,8 @@ public static void cleanup(File directory) throws IOException {
*
* @param url The SVN URL that should be checked out
* @param directory The location where the working copy is created.
* @param user The SVN user or null if the default user from the machine should be used
* @param pwd The SVN password or null if the default user from the machine should be used @return The contents of the file.
* @return A stream with output from the command, should be closed by the caller
* @throws IOException Execution of the SVN sub-process failed or the
* sub-process returned a exit value indicating a failure
Expand Down
79 changes: 78 additions & 1 deletion src/test/java/org/dstadler/commons/svn/SVNCommandsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ public void testGetBranchLogRevision() throws Exception {
assertNotNull(DateFormatUtils.ISO_8601_EXTENDED_DATETIME_FORMAT.parse(date));
}

@Test
public void testGetBranchLogStream() throws Exception {
assumeTrue("SVN not available at " + BASE_URL, serverAvailable());

InputStream str = SVNCommands.getBranchLogStream(new String[]{""}, 0, BASE_URL, USERNAME, PASSWORD);
String result = IOUtils.toString(str, "UTF-8");
assertNotNull(result);
assertTrue(result.contains("revision=\"1\""));
assertTrue(result.contains("/README"));
str.close();
}

@Test
public void testGetBranchLogDate() throws Exception {
assumeTrue("SVN not available at " + BASE_URL, serverAvailable());
Expand Down Expand Up @@ -238,7 +250,6 @@ public void testGetBranchRevision() throws IOException {
System.out.println(IOUtils.toString(stream, "UTF-8"));
}

// check that the necessary structures were created
try {
SVNCommands.getBranchRevision("", BASE_URL);
fail("Should throw exception here");
Expand Down Expand Up @@ -374,6 +385,72 @@ public void testGetConflicts() throws IOException {
}
}

@Test
public void testGetLastRevision() throws IOException {
assumeTrue("SVN not available at " + BASE_URL, serverAvailable());

File tempDir = File.createTempFile("SVNCommandsTest", ".dir");
try {
assertTrue(tempDir.delete());
try (InputStream stream = SVNCommands.checkout(BASE_URL, tempDir, USERNAME, PASSWORD)) {
System.out.println(IOUtils.toString(stream, "UTF-8"));
}

long rev = SVNCommands.getLastRevision("", BASE_URL, USERNAME, PASSWORD);
assertTrue(rev >= 1);
} finally {
FileUtils.deleteDirectory(tempDir);
}
}

@Test
public void testRecordMerge() throws IOException {
assumeTrue("SVN not available at " + BASE_URL, serverAvailable());

File tempDir = File.createTempFile("SVNCommandsTest", ".dir");
try {
assertTrue(tempDir.delete());
try (InputStream stream = SVNCommands.checkout(BASE_URL, tempDir, USERNAME, PASSWORD)) {
System.out.println(IOUtils.toString(stream, "UTF-8"));
}

// add some minimal content
assertTrue(new File(tempDir, "bugfix").mkdir());

CommandLine cmdLine = new CommandLine(SVNCommands.SVN_CMD);
cmdLine.addArgument("add");
cmdLine.addArgument("bugfix");

try (InputStream result = ExecutionHelper.getCommandResult(cmdLine, tempDir, 0, 360000)) {
log.info("Svn-add reported:\n" + SVNCommands.extractResult(result));
}

cmdLine = new CommandLine(SVNCommands.SVN_CMD);
cmdLine.addArgument("commit");
cmdLine.addArgument("-m");
cmdLine.addArgument("comment");

try (InputStream result = ExecutionHelper.getCommandResult(cmdLine, tempDir, 0, 360000)) {
log.info("Svn-commit reported:\n" + SVNCommands.extractResult(result));
}

SVNCommands.update(tempDir);

long rev = SVNCommands.getLastRevision("/bugfix", BASE_URL, USERNAME, PASSWORD);

//assertEquals(rev, SVNCommands.getBranchRevision("/bugfix", BASE_URL));

InputStream bugfix = SVNCommands.recordMerge(tempDir, "/bugfix", rev);
assertNotNull(bugfix);

/*String revs = SVNCommands.getMergedRevisions(tempDir, "");
assertNotNull(revs);
assertEquals("" + rev, revs);*/
} finally {
FileUtils.deleteDirectory(tempDir);
}
}

@Test
public void testMergeResult() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
TestHelpers.EnumTest(SVNCommands.MergeResult.Normal, SVNCommands.MergeResult.class,
Expand Down

0 comments on commit a64933f

Please sign in to comment.