Skip to content

Commit a7d745a

Browse files
committed
Support for Surround SCM history - Added history test class.
1 parent d294908 commit a7d745a

File tree

2 files changed

+167
-0
lines changed

2 files changed

+167
-0
lines changed

src/org/opensolaris/opengrok/history/SSCMHistoryParser.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
package org.opensolaris.opengrok.history;
2121

2222
import java.io.BufferedReader;
23+
import java.io.ByteArrayInputStream;
2324
import java.io.File;
2425
import java.io.IOException;
2526
import java.io.InputStream;
@@ -59,6 +60,13 @@ public class SSCMHistoryParser implements Executor.StreamHandler {
5960

6061
private History history;
6162

63+
/**
64+
* Process the output from the history command and insert the HistoryEntries
65+
* into the history field.
66+
*
67+
* @param input The output from the process
68+
* @throws java.io.IOException If an error occurs while reading the stream
69+
*/
6270
@Override
6371
public void processStream(InputStream input) throws IOException {
6472
DateFormat df = repository.getDateFormat();
@@ -141,4 +149,16 @@ History parse(File file, String sinceRevision) throws HistoryException {
141149

142150
return history;
143151
}
152+
153+
/**
154+
* Parse the given string.
155+
*
156+
* @param buffer The string to be parsed
157+
* @return The parsed history
158+
* @throws IOException if we fail to parse the buffer
159+
*/
160+
History parse(String buffer) throws IOException {
161+
processStream(new ByteArrayInputStream(buffer.getBytes("UTF-8")));
162+
return history;
163+
}
144164
}
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* See LICENSE.txt included in this distribution for the specific
9+
* language governing permissions and limitations under the License.
10+
*
11+
* When distributing Covered Code, include this CDDL HEADER in each
12+
* file and include the License file at LICENSE.txt.
13+
* If applicable, add the following below this CDDL HEADER, with the
14+
* fields enclosed by brackets "[]" replaced with your own identifying
15+
* information: Portions Copyright [yyyy] [name of copyright owner]
16+
*
17+
* CDDL HEADER END
18+
*/
19+
20+
package org.opensolaris.opengrok.history;
21+
22+
import org.junit.After;
23+
import org.junit.AfterClass;
24+
import static org.junit.Assert.assertEquals;
25+
import static org.junit.Assert.assertNotNull;
26+
import static org.junit.Assert.assertTrue;
27+
import org.junit.Before;
28+
import org.junit.BeforeClass;
29+
import org.junit.Test;
30+
import org.opensolaris.opengrok.configuration.RuntimeEnvironment;
31+
import org.opensolaris.opengrok.util.TestRepository;
32+
33+
/**
34+
*
35+
* @author michailf
36+
*/
37+
public class SSCMHistoryParserTest {
38+
39+
SSCMHistoryParser instance;
40+
41+
public SSCMHistoryParserTest() {
42+
}
43+
44+
@BeforeClass
45+
public static void setUpClass() throws Exception {
46+
}
47+
48+
@AfterClass
49+
public static void tearDownClass() throws Exception {
50+
}
51+
52+
@Before
53+
public void setUp() {
54+
instance = new SSCMHistoryParser(new SSCMRepository());
55+
}
56+
57+
@After
58+
public void tearDown() {
59+
instance = null;
60+
}
61+
62+
/**
63+
* Test of parse method, of class GitHistoryParser.
64+
*/
65+
@Test
66+
public void parseEmpty() throws Exception {
67+
History result = instance.parse("");
68+
assertNotNull(result);
69+
assertTrue("Should not contain any history entries", 0 == result.getHistoryEntries().size());
70+
}
71+
72+
/**
73+
* Test of parsing output similar to that in Surround SCM own repository.
74+
*/
75+
@Test
76+
public void ParseALaSSCM() throws Exception {
77+
// This is the new line that is generated by sscm (2011) history command
78+
String newLine = "\r\r\n";
79+
80+
String author1 = "Michailf";
81+
String author3 = "Joec";
82+
String author4 = "user4";
83+
String author5 = "user5";
84+
String date1 = "9/7/2013 1:10 PM";
85+
String date2 = "10/8/2013 1:13 PM";
86+
String date3 = "10/8/2013 1:14 PM";
87+
String date4 = "10/8/2013 1:15 PM";
88+
String date5 = "10/18/2013 11:16 PM";
89+
String comment3 = "Change with check in." + newLine +
90+
"" + newLine +
91+
"Third comment line";
92+
String comment5 = "Comment with promote";
93+
String output =
94+
"Full file path: Branch1/Repo with spaces/readme.txt" + newLine +
95+
"Branch: Branch1" + newLine +
96+
"Working directory: C:\\scm\\Branch1\\Repo with spaces" + newLine +
97+
"Action: User: Version: Date:" + newLine +
98+
"add Michailf 1 " + date1 + newLine +
99+
"add to branch[Bug#00000008 - Branch to work on changes.]" + newLine +
100+
" Joec 1 " + date2 + newLine +
101+
"checkin Joec 2 " + date3 + newLine +
102+
" Comments - " + comment3 + newLine +
103+
"promote from[Bug#00000008 - Branch to work on changes. v. 2]" + newLine +
104+
" user4 3 " + date4 + newLine +
105+
"promote from[Bug#00000008 - Branch to work on changes. v. 3]" + newLine +
106+
" user5 4 " + date5 + newLine +
107+
" Comments - " + comment5 + newLine;
108+
109+
History result = instance.parse(output);
110+
assertNotNull(result);
111+
// History entries that do not increment version number are not included
112+
// (no file changes)
113+
assertTrue("Should contain four history entries", 4 == result.getHistoryEntries().size());
114+
// History entries are reversed (newest first)
115+
{
116+
HistoryEntry e0 = result.getHistoryEntries().get(0);
117+
assertEquals("4", e0.getRevision());
118+
assertEquals(author5, e0.getAuthor());
119+
assertTrue(!e0.getMessage().isEmpty());
120+
assertEquals(0, e0.getFiles().size());
121+
}
122+
123+
{
124+
HistoryEntry e1 = result.getHistoryEntries().get(1);
125+
assertEquals("3", e1.getRevision());
126+
assertEquals(author4, e1.getAuthor());
127+
assertTrue(!e1.getMessage().isEmpty());
128+
assertEquals(0, e1.getFiles().size());
129+
}
130+
131+
{
132+
HistoryEntry e2 = result.getHistoryEntries().get(2);
133+
assertEquals("2", e2.getRevision());
134+
assertEquals(author3, e2.getAuthor());
135+
assertTrue(!e2.getMessage().isEmpty());
136+
assertEquals(0, e2.getFiles().size());
137+
}
138+
139+
{
140+
HistoryEntry e3 = result.getHistoryEntries().get(3);
141+
assertEquals("1", e3.getRevision());
142+
assertEquals(author1, e3.getAuthor());
143+
assertTrue(e3.getMessage().isEmpty());
144+
assertEquals(0, e3.getFiles().size());
145+
}
146+
}
147+
}

0 commit comments

Comments
 (0)