Skip to content

Commit 9cea359

Browse files
authored
Merge pull request #9 from PersephonyAPI/newCallFields
Added connectTime and connectDuration fields to Call and fixed bug wi…
2 parents 8d7c42a + 93e486a commit 9cea359

4 files changed

Lines changed: 71 additions & 12 deletions

File tree

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ group = 'com.github.PersephonyAPI'
99

1010
sourceCompatibility = 1.7 // java 7
1111
targetCompatibility = 1.7
12+
version = '1.0.0'
1213

1314
repositories {
1415
mavenCentral()

src/main/java/com/vailsys/persephony/api/call/Call.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,18 @@ public class Call extends PersyCommon {
5959
* The time this call was started.
6060
*/
6161
private Date startTime;
62+
/**
63+
* The time this call was answered.
64+
*/
65+
private Date connectTime;
6266
/**
6367
* The time this call ended.
6468
*/
6569
private Date endTime;
6670
/** The duration of this call in seconds. */
67-
private Integer durationSec;
71+
private Integer duration;
72+
/** The duration that this call was connected in seconds. */
73+
private Integer connectDuration;
6874
/**
6975
* The direction (inbound, outbound, etc.) of this call.
7076
* @see com.vailsys.persephony.api.call.Direction
@@ -170,6 +176,14 @@ public CallStatus getStatus() {
170176
public Date getStartTime() {
171177
return this.startTime;
172178
}
179+
/**
180+
* Retrieve the time this call was answered from the object.
181+
*
182+
* @return The time this call was answered.
183+
*/
184+
public Date getConnectTime() {
185+
return this.connectTime;
186+
}
173187
/**
174188
* Retrieve the end time for this call from the object.
175189
*
@@ -183,8 +197,16 @@ public Date getEndTime() {
183197
*
184198
* @return The duration for this call in seconds.
185199
*/
186-
public Integer getDurationSec() {
187-
return this.durationSec;
200+
public Integer getDuration() {
201+
return this.duration;
202+
}
203+
/**
204+
* Retrieve the connection duration, in seconds, for this call from the object.
205+
*
206+
* @return The connection duration for this call in seconds.
207+
*/
208+
public Integer getConnectDuration() {
209+
return this.connectDuration;
188210
}
189211
/**
190212
* Retrieve the direction of this call from the object.
@@ -285,17 +307,35 @@ public boolean equals(Call that) {
285307
} else {
286308
result = result && that.status == null;
287309
}
310+
311+
if(this.startTime != null) {
312+
result = result && this.startTime.equals(that.startTime);
313+
} else {
314+
result = result && that.startTime == null;
315+
}
316+
317+
if(this.connectTime != null) {
318+
result = result && this.connectTime.equals(that.connectTime);
319+
} else {
320+
result = result && that.connectTime == null;
321+
}
288322

289323
if(this.endTime != null) {
290324
result = result && this.endTime.equals(that.endTime);
291325
} else {
292326
result = result && that.endTime == null;
293327
}
294328

295-
if(this.durationSec != null) {
296-
result = result && this.durationSec.equals(that.durationSec);
329+
if(this.duration != null) {
330+
result = result && this.duration.equals(that.duration);
331+
} else {
332+
result = result && that.duration == null;
333+
}
334+
335+
if(this.connectDuration != null) {
336+
result = result && this.connectDuration.equals(that.connectDuration);
297337
} else {
298-
result = result && that.durationSec == null;
338+
result = result && that.connectDuration == null;
299339
}
300340

301341
if(this.answeredBy != null) {

src/test/java/com/vailsys/persephony/api/call/CallTest.java

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,18 +19,16 @@
1919
import cucumber.api.java.en.Then;
2020

2121
import static org.hamcrest.CoreMatchers.is;
22-
23-
import static org.junit.Assert.assertThat;
24-
import static org.junit.Assert.assertTrue;
25-
import static org.junit.Assert.fail;
22+
import static org.junit.Assert.*;
2623

2724
public class CallTest {
2825
private String origJSON;
26+
private String otherJSON = "{ \"uri\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CA42ed11f93dc08b952027ffbc406d0868\", \"dateCreated\": \"Tue, 12 Aug 2014 08:02:17 GMT\", \"dateUpdated\": \"Tue, 12 Aug 2014 08:02:47 GMT\", \"revision\": 1, \"callId\": \"CA42ed11f93dc08b952027ffbc40600000\", \"parentcallId\": null, \"accountId\": \"AC142c48f2ee663e214c19ea459516068c\", \"to\": \"+14153855708\", \"from\": \"+14158141819\", \"phoneNumberId\": null, \"status\": \"completed\", \"startTime\": \"Tue, 12 Aug 2014 08:02:31 GMT\", \"connectTime\": \"Tue, 12 Aug 2014 08:02:50 GMT\", \"endTime\": \"Tue, 12 Aug 2014 08:02:47 GMT\", \"duration\": 16, \"connectDuration\": 13, \"direction\": \"outboundAPI\", \"answeredBy\": null, \"callerName\": null, \"subresourceUris\": { \t\"notifications\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications\", \t\"recordings\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings\" } }";
2927
private Call theCall;
3028

3129
@Given("^Some JSON representing a call.$")
3230
public void storeJSON() {
33-
this.origJSON = "{ \"uri\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CA42ed11f93dc08b952027ffbc406d0868\", \"dateCreated\": \"Tue, 12 Aug 2014 08:02:17 GMT\", \"dateUpdated\": \"Tue, 12 Aug 2014 08:02:47 GMT\", \"revision\": 1, \"callId\": \"CA42ed11f93dc08b952027ffbc406d0868\", \"parentcallId\": null, \"accountId\": \"AC142c48f2ee663e214c19ea459516068c\", \"to\": \"+14153855708\", \"from\": \"+14158141819\", \"phoneNumberId\": null, \"status\": \"completed\", \"startTime\": \"Tue, 12 Aug 2014 08:02:31 GMT\", \"endTime\": \"Tue, 12 Aug 2014 08:02:47 GMT\", \"duration\": \"16\", \"direction\": \"outboundAPI\", \"answeredBy\": null, \"callerName\": null, \"subresourceUris\": { \t\"notifications\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications\", \t\"recordings\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings\" } }";
31+
this.origJSON = "{ \"uri\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CA42ed11f93dc08b952027ffbc406d0868\", \"dateCreated\": \"Tue, 12 Aug 2014 08:02:17 GMT\", \"dateUpdated\": \"Tue, 12 Aug 2014 08:02:47 GMT\", \"revision\": 1, \"callId\": \"CA42ed11f93dc08b952027ffbc406d0868\", \"parentcallId\": null, \"accountId\": \"AC142c48f2ee663e214c19ea459516068c\", \"to\": \"+14153855708\", \"from\": \"+14158141819\", \"phoneNumberId\": null, \"status\": \"completed\", \"startTime\": \"Tue, 12 Aug 2014 08:02:31 GMT\", \"connectTime\": \"Tue, 12 Aug 2014 08:02:50 GMT\", \"endTime\": \"Tue, 12 Aug 2014 08:02:47 GMT\", \"duration\": 16, \"connectDuration\": 13, \"direction\": \"outboundAPI\", \"answeredBy\": null, \"callerName\": null, \"subresourceUris\": { \t\"notifications\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Notifications\", \t\"recordings\": \"/Accounts/AC142c48f2ee663e214c19ea459516068c/Calls/CAe1644a7eed5088b159577c5802d8be38/Recordings\" } }";
3432
}
3533

3634
@Then("^build a Call object from that JSON.$")
@@ -59,11 +57,16 @@ public void checkCallAgainstJson() {
5957
PersyDateFormat.format(this.theCall.getStartTime(), dateString, new FieldPosition(0));
6058
assertThat((String)jsonMap.get("startTime"), is(dateString.toString()));
6159

60+
dateString = new StringBuffer();
61+
PersyDateFormat.format(this.theCall.getConnectTime(), dateString, new FieldPosition(0));
62+
assertThat((String)jsonMap.get("connectTime"), is(dateString.toString()));
63+
6264
dateString = new StringBuffer();
6365
PersyDateFormat.format(this.theCall.getEndTime(), dateString, new FieldPosition(0));
6466
assertThat((String)jsonMap.get("endTime"), is(dateString.toString()));
6567

66-
assertThat((Integer)jsonMap.get("durationSec"), is(this.theCall.getDurationSec()));
68+
assertThat((Integer) ((Double) jsonMap.get("duration")).intValue(), is(this.theCall.getDuration()));
69+
assertThat((Integer) ((Double) jsonMap.get("connectDuration")).intValue(), is(this.theCall.getConnectDuration()));
6770

6871
String outboundAPI = gson.toJson(Direction.OUTBOUND_API);
6972
outboundAPI = outboundAPI.substring(1,outboundAPI.length()-1);
@@ -77,4 +80,13 @@ public void checkCallAgainstJson() {
7780
assertThat((String)mmm.get("recordings"), is(this.theCall.getSubresourceUris().get("recordings")));
7881
assertThat((String)mmm.get("notifications"), is(this.theCall.getSubresourceUris().get("notifications")));
7982
}
83+
84+
@Then("^check the call is( not)? equal.$")
85+
public void checkEqual(String not) throws Throwable {
86+
if (not == null) {
87+
assertTrue(this.theCall.equals(Call.fromJson(origJSON)));
88+
} else {
89+
assertFalse(this.theCall.equals(Call.fromJson(otherJSON)));
90+
}
91+
}
8092
}

src/test/resources/com/vailsys/persephony/api/call/Call.feature

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@ Feature: Call
44
Given Some JSON representing a call.
55
Then build a Call object from that JSON.
66
Then check the contents of that object.
7+
8+
Scenario: Check the Call equals method
9+
Given Some JSON representing a call.
10+
Then build a Call object from that JSON.
11+
Then check the call is equal.
12+
Then check the call is not equal.

0 commit comments

Comments
 (0)