3
* ====================================================================
4
* Licensed to the Apache Software Foundation (ASF) under one
5
* or more contributor license agreements. See the NOTICE file
6
* distributed with this work for additional information
7
* regarding copyright ownership. The ASF licenses this file
8
* to you under the Apache License, Version 2.0 (the
9
* "License"); you may not use this file except in compliance
10
* with the License. You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing,
15
* software distributed under the License is distributed on an
16
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17
* KIND, either express or implied. See the License for the
18
* specific language governing permissions and limitations
20
* ====================================================================
23
package org.apache.subversion.javahl;
25
import org.apache.subversion.javahl.callback.*;
26
import org.apache.subversion.javahl.types.*;
29
import java.io.FileOutputStream;
30
import java.io.FileNotFoundException;
31
import java.io.FileReader;
32
import java.io.IOException;
33
import java.io.PrintWriter;
34
import java.io.ByteArrayOutputStream;
35
import java.io.UnsupportedEncodingException;
36
import java.nio.ByteBuffer;
37
import java.nio.channels.ReadableByteChannel;
38
import java.nio.channels.WritableByteChannel;
39
import java.text.ParseException;
40
import java.util.Collection;
41
import java.util.Arrays;
42
import java.util.ArrayList;
43
import java.util.Date;
44
import java.util.HashMap;
45
import java.util.HashSet;
46
import java.util.List;
49
import java.text.DateFormat;
50
import java.text.SimpleDateFormat;
54
* Tests the basic functionality of javahl binding (inspired by the
55
* tests in subversion/tests/cmdline/basic_tests.py).
57
public class ExceptionTests extends SVNTests
60
* Base name of all our tests.
62
public final static String testName = "exception_test";
64
public ExceptionTests()
69
public ExceptionTests(String name)
76
* Initialize the testBaseName and the testCounter, if this is the
77
* first test of this class.
81
if (!testName.equals(testBaseName))
84
testBaseName = testName;
89
* Specific exception class to verify if the marshalling of errors
90
* through Subversion is handled properly.
92
final class TestException extends RuntimeException
94
private static final long serialVersionUID = 1L;
96
public TestException(String message)
101
public TestException(String message, Throwable cause)
103
super(message, cause);
107
public void testStatusCallback() throws Exception
109
// build the test setup
110
OneTest thisTest = new OneTest();
112
final TestException theException = new TestException("The Exception");
113
boolean handled = false;
114
// Test status of non-existent file
117
client.status(thisTest.getWorkingCopy() + "/A", Depth.immediates,
118
false, true, true, false, false, false, null,
121
public void doStatus(String path, Status status)
123
throw new TestException("inner", theException);
127
catch (ClientException e)
129
if (VerifyCause(e, theException))
137
public void testInfoCallback() throws Exception
139
// build the test setup
140
OneTest thisTest = new OneTest();
142
final TestException theException = new TestException("The Exception");
143
boolean handled = false;
144
// Test status of non-existent file
147
client.info(thisTest.getWorkingCopy() + "/A", null, null, Depth.immediates,
148
true, true, false, null,
151
public void singleInfo(Info info)
153
throw new TestException("inner", theException);
157
catch (ClientException e)
159
if (VerifyCause(e, theException))
167
public void testListCallback() throws Exception
169
// build the test setup
170
OneTest thisTest = new OneTest();
172
final TestException theException = new TestException("The Exception");
173
boolean handled = false;
174
// Test status of non-existent file
177
client.list(thisTest.getWorkingCopy() + "/A", null, null, Depth.immediates,
181
public void doEntry(DirEntry dirent, Lock lock)
183
throw new TestException("inner", theException);
187
catch (ClientException e)
189
if (VerifyCause(e, theException))
197
public void testBlameCallback() throws Exception
199
// build the test setup
200
OneTest thisTest = new OneTest();
202
final TestException theException = new TestException("The Exception");
203
boolean handled = false;
204
// Test status of non-existent file
207
client.blame(thisTest.getWorkingCopy() + "/iota",
208
Revision.getInstance(1), Revision.getInstance(1),
209
Revision.getInstance(1), false, false,
212
public void singleLine(long lineNum, long revision,
213
Map<String, byte[]> revProps, long mergedRevision,
214
Map<String, byte[]> mergedRevProps,
215
String mergedPath, String line,
218
throw new TestException("inner", theException);
222
catch (ClientException e)
224
if (VerifyCause(e, theException))
232
public void testLogMessageCallback() throws Exception
234
// build the test setup
235
OneTest thisTest = new OneTest();
237
final TestException theException = new TestException("The Exception");
238
boolean handled = false;
239
// Test status of non-existent file
242
List<RevisionRange> ranges = new ArrayList<RevisionRange>(1);
243
ranges.add(new RevisionRange(null, null));
244
client.logMessages(thisTest.getWorkingCopy() + "/iota",
245
Revision.getInstance(1), ranges,
248
new LogMessageCallback()
250
public void singleMessage(
251
Set<ChangePath> changedPaths,
253
Map<String, byte[]> revprops,
256
throw new TestException("inner",
261
catch (ClientException e)
263
if (VerifyCause(e, theException))
271
public void testDiffSummaryReceiver() throws Exception
273
// build the test setup
274
OneTest thisTest = new OneTest();
276
final TestException theException = new TestException("The Exception");
277
boolean handled = false;
278
// Test status of non-existent file
281
List<RevisionRange> ranges = new ArrayList<RevisionRange>(1);
282
ranges.add(new RevisionRange(null, null));
283
client.diffSummarize(thisTest.getUrl() + "/A",
284
Revision.getInstance(1),
285
thisTest.getUrl() + "/A",
286
Revision.getInstance(0),
287
Depth.infinity, null, true,
288
new DiffSummaryCallback()
290
public void onSummary(
291
DiffSummary descriptor)
293
throw new TestException("inner",
298
catch (ClientException e)
300
if (VerifyCause(e, theException))
308
public void testNotify() throws Exception
310
// build the test setup
311
OneTest thisTest = new OneTest();
313
final TestException theException = new TestException("The Exception");
314
boolean handled = false;
315
// Test status of non-existent file
318
client.notification2(new ClientNotifyCallback()
320
public void onNotify(ClientNotifyInformation info)
322
throw new TestException("inner",
327
client.remove(thisTest.getWCPathSet("/A"), false, false,
330
catch (ClientException e)
332
if (VerifyCause(e, theException))
341
* Verifies if a specific throwable instance is recorded in the exception chain
343
private boolean VerifyCause(Throwable caught, Throwable needle)
345
if (caught == needle)
348
Throwable cause = caught.getCause();
352
return VerifyCause(cause, needle);