Skip to content

Commit 65be79e

Browse files
committed
Improved Logging/Error Messages, Fixed JUnit Test
The JUnit test did not specify a version for downloading files. This has been fixed: We test now for both project version 0.8.5 and 0.8.6.
1 parent 391f51d commit 65be79e

File tree

4 files changed

+70
-15
lines changed

4 files changed

+70
-15
lines changed

src/main/java/org/optimizationBenchmarking/documentation/examples/_ExampleDownloadJob.java

+32-12
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.optimizationBenchmarking.documentation.examples;
22

33
import java.io.BufferedReader;
4+
import java.io.IOException;
45
import java.io.InputStream;
56
import java.io.InputStreamReader;
67
import java.net.URI;
@@ -62,7 +63,7 @@ static final URI _resolveExampleURI(final URI baseUri, final String id) {
6263

6364
/** {@inheritDoc} */
6465
@Override
65-
public final Path call() throws Exception {
66+
public final Path call() throws IOException {
6667
final URI exampleUri;
6768
final Path destDirectory;
6869
final Logger logger;
@@ -168,16 +169,16 @@ public final Path call() throws Exception {
168169
* @param found
169170
* did we already create something?
170171
* @return {@code true} if a file was unpacked, {@code false} otherwise
171-
* @throws Exception
172+
* @throws IOException
172173
* if something goes wrong
173174
*/
174175
private final boolean __process(final String line, final URI baseUri,
175-
final Path destFolder, final boolean found) throws Exception {
176+
final Path destFolder, final boolean found) throws IOException {
176177
final Logger logger;
177178
final URL url;
178179
final Path destPath;
179180
final boolean zip;
180-
String path;
181+
String path, message;
181182
int index;
182183
char ch;
183184

@@ -188,9 +189,10 @@ private final boolean __process(final String line, final URI baseUri,
188189

189190
logger = this.getLogger();
190191
url = baseUri.resolve(path).toURL();
192+
message = null;
191193
if ((logger != null) && (logger.isLoggable(Level.FINE))) {
192-
logger.fine((("Now downloading resource '" + url) //$NON-NLS-1$
193-
+ '\'') + '.');
194+
message = (("resource '" + url) + '\'');//$NON-NLS-1$
195+
logger.fine(("Now downloading " + message) + '.');//$NON-NLS-1$
194196
}
195197

196198
if (!(found)) {
@@ -215,10 +217,14 @@ private final boolean __process(final String line, final URI baseUri,
215217
}
216218

217219
if ((logger != null) && (logger.isLoggable(Level.FINE))) {
218-
logger.fine((("Beginning to download resource '" + url + //$NON-NLS-1$
219-
(zip ? "' as zip archive into folder '"//$NON-NLS-1$
220-
: "' as file into file '")//$NON-NLS-1$
221-
+ destPath) + '\'') + '.');
220+
if (message == null) {
221+
message = (("resource '" + url) + '\'');//$NON-NLS-1$
222+
}
223+
message = (((message + (zip//
224+
? " as zip archive into folder '"//$NON-NLS-1$
225+
: " as file into file '"))//$NON-NLS-1$
226+
+ destPath) + '\'');
227+
logger.fine("Beginning to download " + message + '.');//$NON-NLS-1$
222228
}
223229

224230
try (final InputStream input = url.openStream()) {
@@ -227,11 +233,25 @@ private final boolean __process(final String line, final URI baseUri,
227233
} else {
228234
Files.copy(input, destPath);
229235
}
236+
} catch (final Throwable error) {
237+
if (message == null) {
238+
message = (((("resource '" + url) //$NON-NLS-1$
239+
+ (zip ? "' as zip archive into folder '"//$NON-NLS-1$
240+
: "' as file into file '"))//$NON-NLS-1$
241+
+ destPath) + '\'');
242+
}
243+
throw new IOException((("Error while downloading " //$NON-NLS-1$
244+
+ message) + '.'), error);
230245
}
231246

232247
if ((logger != null) && (logger.isLoggable(Level.FINE))) {
233-
logger.fine((("Finished downloading resource '" + url) //$NON-NLS-1$
234-
+ '\'') + '.');
248+
if (message == null) {
249+
message = (((("resource '" + url) //$NON-NLS-1$
250+
+ (zip ? "' as zip archive into folder '"//$NON-NLS-1$
251+
: "' as file into file '"))//$NON-NLS-1$
252+
+ destPath) + '\'');
253+
}
254+
logger.fine(("Finished downloading " + message) + '.');//$NON-NLS-1$
235255
}
236256

237257
return true;

src/main/java/org/optimizationBenchmarking/documentation/examples/_ExampleJobBase.java

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.optimizationBenchmarking.documentation.examples;
22

3+
import java.io.IOException;
34
import java.net.URI;
45
import java.util.logging.Level;
56
import java.util.logging.Logger;
@@ -45,6 +46,16 @@ abstract class _ExampleJobBase<T> extends ToolJob
4546
._checkFailureLevel(this.m_failureLevel = builder.m_failureLevel);
4647
}
4748

49+
/**
50+
* Perform the example job.
51+
*
52+
* @return the result object
53+
* @throws IOException
54+
* if I/O fails
55+
*/
56+
@Override
57+
public abstract T call() throws IOException;
58+
4859
/**
4960
* Extract the resource part from a given line and return it if the
5061
* currently set version permits it, return {@code null} otherwise.

src/main/java/org/optimizationBenchmarking/documentation/examples/_ExampleListJob.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.optimizationBenchmarking.documentation.examples;
22

33
import java.io.BufferedReader;
4+
import java.io.IOException;
45
import java.io.InputStream;
56
import java.io.InputStreamReader;
67
import java.net.URL;
@@ -32,7 +33,7 @@ final class _ExampleListJob
3233

3334
/** {@inheritDoc} */
3435
@Override
35-
public final ArrayListView<Example> call() throws Exception {
36+
public final ArrayListView<Example> call() throws IOException {
3637
final Logger logger;
3738
final ArrayListView<Example> result;
3839
String name;

src/test/java/test/junit/org/optimizationBenchmarking/documentation/examples/SingleExampleTest.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.optimizationBenchmarking.documentation.examples.ExampleDownloadJobBuilder;
77
import org.optimizationBenchmarking.documentation.examples.ExampleDownloadTool;
88
import org.optimizationBenchmarking.utils.io.paths.TempDir;
9+
import org.optimizationBenchmarking.utils.versioning.Version;
910

1011
import shared.junit.TestBase;
1112

@@ -27,18 +28,40 @@ protected SingleExampleTest() {
2728
protected abstract void setup(final ExampleDownloadJobBuilder builder);
2829

2930
/**
30-
* test the example download
31+
* test the example download for version 0.8.5
3132
*
3233
* @throws Exception
3334
* if I/O fails
3435
*/
3536
@Test(timeout = 3600000)
36-
public void testExampleDownload() throws Exception {
37+
public void testExampleDownload_0_8_5() throws Exception {
3738
ExampleDownloadJobBuilder builder;
3839

3940
builder = ExampleDownloadTool.getInstance().use();
4041
this.setup(builder);
4142
builder.setLogger(TestBase.getNullLogger());
43+
builder.setVersion(new Version(0, 8, 5, null, null));
44+
45+
try (final TempDir temp = new TempDir()) {
46+
builder.setDestinationPath(temp.getPath());
47+
Assert.assertNotNull(builder.create().call());
48+
}
49+
}
50+
51+
/**
52+
* test the example download for version 0.8.6
53+
*
54+
* @throws Exception
55+
* if I/O fails
56+
*/
57+
@Test(timeout = 3600000)
58+
public void testExampleDownload_0_8_6() throws Exception {
59+
ExampleDownloadJobBuilder builder;
60+
61+
builder = ExampleDownloadTool.getInstance().use();
62+
this.setup(builder);
63+
builder.setLogger(TestBase.getNullLogger());
64+
builder.setVersion(new Version(0, 8, 6, null, null));
4265

4366
try (final TempDir temp = new TempDir()) {
4467
builder.setDestinationPath(temp.getPath());

0 commit comments

Comments
 (0)