Skip to content

Commit 3deb871

Browse files
committed
add deleteArchive implementation, adds tests #11
1 parent cf3c6ff commit 3deb871

File tree

3 files changed

+52
-3
lines changed

3 files changed

+52
-3
lines changed

src/main/java/com/opentok/OpenTok.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ public Archive stopArchive(String archiveId) throws OpenTokException {
420420
*
421421
* @param archiveId The archive ID of the archive you want to delete.
422422
*/
423-
// public void deleteArchive(String archiveId) throws OpenTokException {
424-
// HttpClient.makeDeleteRequest("/v2/partner/" + this.apiKey + "/archive/" + archiveId);
425-
// }
423+
public void deleteArchive(String archiveId) throws OpenTokException {
424+
this.client.deleteArchive(archiveId);
425+
}
426426
}

src/main/java/com/opentok/util/HttpClient.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,36 @@ public String stopArchive(String archiveId) {
208208
return responseString;
209209
}
210210

211+
public String deleteArchive(String archiveId) {
212+
String responseString = null;
213+
Future<Response> request = null;
214+
String url = this.apiUrl+"/v2/partner/"+this.apiKey+"/archive/"+archiveId;
215+
216+
try {
217+
request = this.prepareDelete(url).execute();
218+
} catch (IOException e) {
219+
// TODO: throw OpenTokException
220+
e.printStackTrace();
221+
}
222+
223+
try {
224+
Response response = request.get();
225+
// TODO: check response code
226+
responseString = response.getResponseBody();
227+
} catch (InterruptedException e) {
228+
// TODO: throw OpenTokException
229+
e.printStackTrace();
230+
} catch (ExecutionException e) {
231+
// TODO: throw OpenTokException
232+
e.printStackTrace();
233+
} catch (IOException e) {
234+
// TODO: throw OpenTokException
235+
e.printStackTrace();
236+
}
237+
238+
return responseString;
239+
}
240+
211241
// protected static String makeDeleteRequest(String resource) throws OpenTokException {
212242
// BoundRequestBuilder get = client.prepareDelete(apiUrl + resource);
213243
// addCommonHeaders(get);

src/test/java/com/opentok/test/OpenTokTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,8 @@ public void testStartArchive() throws OpenTokException {
494494
assertNotNull(archive.getId());
495495

496496
verify(postRequestedFor(urlMatching("/v2/partner/"+this.apiKey+"/archive"))
497+
// TODO: find a way to match JSON without caring about spacing
498+
//.withRequestBody(matching(".*"+".*"))
497499
.withHeader("X-TB-PARTNER-AUTH", matching(this.apiKey+":"+this.apiSecret))
498500
.withHeader("User-Agent", matching(".*Opentok-Java-SDK/"+ Version.VERSION+".*")));
499501
}
@@ -533,4 +535,21 @@ public void testStopArchive() throws OpenTokException {
533535
.withHeader("User-Agent", matching(".*Opentok-Java-SDK/"+ Version.VERSION+".*")));
534536
}
535537

538+
// TODO: test stop archive failure scenarios
539+
540+
@Test
541+
public void testDeleteArchive() throws OpenTokException {
542+
String archiveId = "ARCHIVEID";
543+
stubFor(delete(urlEqualTo("/v2/partner/"+this.apiKey+"/archive/"+archiveId))
544+
.willReturn(aResponse()
545+
.withStatus(204)
546+
.withHeader("Content-Type", "application/json")));
547+
548+
sdk.deleteArchive(archiveId);
549+
550+
verify(deleteRequestedFor(urlMatching("/v2/partner/"+this.apiKey+"/archive/"+archiveId))
551+
.withHeader("X-TB-PARTNER-AUTH", matching(this.apiKey+":"+this.apiSecret))
552+
.withHeader("User-Agent", matching(".*Opentok-Java-SDK/"+ Version.VERSION+".*")));
553+
}
554+
536555
}

0 commit comments

Comments
 (0)