diff --git a/doc/issues/0000tn5.rst b/doc/issues/0000tn5.rst new file mode 100644 index 0000000..6d24376 --- /dev/null +++ b/doc/issues/0000tn5.rst @@ -0,0 +1,9 @@ +Add unit tests. +=============== + +---- + +========= ========== +Created: 2011-06-28 +Resolved: YYYY-MM-DD +========= ========== diff --git a/lib/runtime/jar/signpost-commonshttp4-1.2.1.1.jar b/lib/runtime/jar/signpost-commonshttp4-1.2.1.1.jar deleted file mode 100644 index e8dae4d..0000000 Binary files a/lib/runtime/jar/signpost-commonshttp4-1.2.1.1.jar and /dev/null differ diff --git a/lib/runtime/jar/signpost-core-1.2.1.1.jar b/lib/runtime/jar/signpost-core-1.2.1.1.jar deleted file mode 100644 index 86e9dac..0000000 Binary files a/lib/runtime/jar/signpost-core-1.2.1.1.jar and /dev/null differ diff --git a/release/timestamper-lib-1.1.jar b/release/timestamper-lib-1.1.jar deleted file mode 100644 index 7aca496..0000000 Binary files a/release/timestamper-lib-1.1.jar and /dev/null differ diff --git a/release/timestamper-lib-1.2.jar b/release/timestamper-lib-1.2.jar new file mode 100644 index 0000000..8948848 Binary files /dev/null and b/release/timestamper-lib-1.2.jar differ diff --git a/src/main/com/jdblabs/timestamper/core/JDBLabsWebTimelineSource.groovy b/src/main/com/jdblabs/timestamper/core/JDBLabsWebTimelineSource.groovy index 7175455..05f2be1 100644 --- a/src/main/com/jdblabs/timestamper/core/JDBLabsWebTimelineSource.groovy +++ b/src/main/com/jdblabs/timestamper/core/JDBLabsWebTimelineSource.groovy @@ -37,9 +37,20 @@ public class JDBLabsWebTimelineSource extends TimelineSource { password = config.getProperty(CONFIG_PWD, "") timelineId = config.getProperty(CONFIG_TIMELINE, "") - baseUri = new URI(uri.scheme + "://" + uri.authority) + baseUri = new URI(uri.scheme + "://" + uri.authority + "/ts_api/") http = new HTTPBuilder(baseUri) + // set some default error handlers + http.handler.'500' = { resp, json -> + throw new IOException("The web timeline reported an internal " + + "error: ${json.error ?: 'no details available'}") } + + http.handler.failure = {resp, json -> + throw new IOException("Unable to complete the operation: error " + + "communicating to the web timeline.\n" + + "${resp.statusLine}: ${json}") } + + // init our hash of known entries entryHashes = [:] } @@ -53,9 +64,15 @@ public class JDBLabsWebTimelineSource extends TimelineSource { authenticate() // load the timeline information - timelineJSON = http.get( - path: "/ts_api/timelines/${username}/${timelineId}", - contentType: JSON) { resp, json -> json } + http.request(GET, JSON) { + uri.path = "timelines/${username}/${timelineId}" + + response.'404' = { resp -> + throw new IOException("No timeline '${timelineId}' for user " + + "'${username}'") } + + response.success = { resp, json -> timelineJSON = json } + } timeline = new Timeline() @@ -68,7 +85,7 @@ public class JDBLabsWebTimelineSource extends TimelineSource { // load the timeline entries entryListJSON = http.get( - path: "/ts_api/entries/${username}/${timelineId}", + path: "entries/${username}/${timelineId}", contentType: JSON, query: [ byDate: true, @@ -115,11 +132,11 @@ public class JDBLabsWebTimelineSource extends TimelineSource { // delete all entries that used to be present but are not any longer deletedEntries.each { hash, entryId -> http.request(DELETE) { - uri.path = "/ts_api/entries/${username}/${timelineId}/${entryId}" - } + uri.path = "entries/${username}/${timelineId}/${entryId}" - // TODO: error handling, make sure this only happens on success - entryHashes.remove(hash) + response.'404' = { resp -> entryHashes.remove(hash) } + response.success = { resp -> entryHashes.remove(hash) } + } } // add all new entries @@ -131,32 +148,30 @@ public class JDBLabsWebTimelineSource extends TimelineSource { timestamp: isoDateFormat.format(entry.timestamp) ] - // TODO: error handling - http.post( - path: "/ts_api/entries/${username}/${timelineId}", - contentType: JSON, - requestContentType: JSON, - body: entryBody) { resp, json -> - entryHashes.put(fullHash(entry), entry) - json + http.request(POST, JSON) { + uri.path = "entries/${username}/${timelineId}" + requestContentType = JSON + body = entryBody + + response.success = { entryHashes.put(fullHash(entry), entry.id) } } } - } - public boolean isAuthenticated() { - // TODO - } + public boolean isAuthenticated() { return false; } - public void authenticate() { - // TODO: error detection - http.post( - path: '/ts_api/login', - contentType: JSON, - requestContentType: JSON, - body: [ username: this.username, - password: this.password ]) { resp, json -> json } + public void authenticate() throws AuthenticationException { + http.request(POST, JSON) { req -> + uri.path = '/ts_api/login' + requestContentType = JSON + body = [ username: this.username, + password: this.password ] + response.'401' = { resp -> + throw new AuthenticationException( + "Unable to connect to ${baseUri}: " + + "Invalid username/password combination.") } + } } protected int fullHash(TimelineMarker tm) {