Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ group = 'com.github.PersephonyAPI'

sourceCompatibility = 1.7 // java 7
targetCompatibility = 1.7
version = '1.0.0'

repositories {
mavenCentral()
Expand Down
52 changes: 46 additions & 6 deletions src/main/java/com/vailsys/persephony/api/call/Call.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,18 @@ public class Call extends PersyCommon {
* The time this call was started.
*/
private Date startTime;
/**
* The time this call was answered.
*/
private Date connectTime;
/**
* The time this call ended.
*/
private Date endTime;
/** The duration of this call in seconds. */
private Integer durationSec;
private Integer duration;
Comment thread
Deseao marked this conversation as resolved.
/** The duration that this call was connected in seconds. */
private Integer connectDuration;
/**
* The direction (inbound, outbound, etc.) of this call.
* @see com.vailsys.persephony.api.call.Direction
Expand Down Expand Up @@ -170,6 +176,14 @@ public CallStatus getStatus() {
public Date getStartTime() {
return this.startTime;
}
/**
* Retrieve the time this call was answered from the object.
*
* @return The time this call was answered.
*/
public Date getConnectTime() {
return this.connectTime;
}
/**
* Retrieve the end time for this call from the object.
*
Expand All @@ -183,8 +197,16 @@ public Date getEndTime() {
*
* @return The duration for this call in seconds.
*/
public Integer getDurationSec() {
return this.durationSec;
public Integer getDuration() {
return this.duration;
}
/**
* Retrieve the connection duration, in seconds, for this call from the object.
*
* @return The connection duration for this call in seconds.
*/
public Integer getConnectDuration() {
return this.connectDuration;
}
/**
* Retrieve the direction of this call from the object.
Expand Down Expand Up @@ -285,17 +307,35 @@ public boolean equals(Call that) {
} else {
result = result && that.status == null;
}

if(this.startTime != null) {
result = result && this.startTime.equals(that.startTime);
} else {
result = result && that.startTime == null;
}

if(this.connectTime != null) {
result = result && this.connectTime.equals(that.connectTime);
} else {
result = result && that.connectTime == null;
}

if(this.endTime != null) {
result = result && this.endTime.equals(that.endTime);
} else {
result = result && that.endTime == null;
}

if(this.durationSec != null) {
result = result && this.durationSec.equals(that.durationSec);
if(this.duration != null) {
result = result && this.duration.equals(that.duration);
} else {
result = result && that.duration == null;
}

if(this.connectDuration != null) {
result = result && this.connectDuration.equals(that.connectDuration);
} else {
result = result && that.durationSec == null;
result = result && that.connectDuration == null;
}

if(this.answeredBy != null) {
Expand Down
24 changes: 18 additions & 6 deletions src/test/java/com/vailsys/persephony/api/call/CallTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@
import cucumber.api.java.en.Then;

import static org.hamcrest.CoreMatchers.is;

import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assert.*;

public class CallTest {
private String origJSON;
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\" } }";
private Call theCall;

@Given("^Some JSON representing a call.$")
public void storeJSON() {
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\" } }";
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\" } }";
}

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

dateString = new StringBuffer();
PersyDateFormat.format(this.theCall.getConnectTime(), dateString, new FieldPosition(0));
assertThat((String)jsonMap.get("connectTime"), is(dateString.toString()));

dateString = new StringBuffer();
PersyDateFormat.format(this.theCall.getEndTime(), dateString, new FieldPosition(0));
assertThat((String)jsonMap.get("endTime"), is(dateString.toString()));

assertThat((Integer)jsonMap.get("durationSec"), is(this.theCall.getDurationSec()));
assertThat((Integer) ((Double) jsonMap.get("duration")).intValue(), is(this.theCall.getDuration()));
assertThat((Integer) ((Double) jsonMap.get("connectDuration")).intValue(), is(this.theCall.getConnectDuration()));

String outboundAPI = gson.toJson(Direction.OUTBOUND_API);
outboundAPI = outboundAPI.substring(1,outboundAPI.length()-1);
Expand All @@ -77,4 +80,13 @@ public void checkCallAgainstJson() {
assertThat((String)mmm.get("recordings"), is(this.theCall.getSubresourceUris().get("recordings")));
assertThat((String)mmm.get("notifications"), is(this.theCall.getSubresourceUris().get("notifications")));
}

@Then("^check the call is( not)? equal.$")
public void checkEqual(String not) throws Throwable {
if (not == null) {
assertTrue(this.theCall.equals(Call.fromJson(origJSON)));
} else {
assertFalse(this.theCall.equals(Call.fromJson(otherJSON)));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ Feature: Call
Given Some JSON representing a call.
Then build a Call object from that JSON.
Then check the contents of that object.

Scenario: Check the Call equals method
Given Some JSON representing a call.
Then build a Call object from that JSON.
Then check the call is equal.
Then check the call is not equal.