Skip to content

Commit

Permalink
MSB-193: Modify CallDetailRecordsDaoTest, add cdr filter by type test
Browse files Browse the repository at this point in the history
  • Loading branch information
abdulazizali77 committed Nov 24, 2017
1 parent 1d88565 commit c6eba04
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import org.junit.Before;
import org.junit.Test;
import org.restcomm.connect.commons.dao.Sid;
import org.restcomm.connect.commons.telephony.CreateCallType;
import org.restcomm.connect.dao.CallDetailRecordsDao;
import org.restcomm.connect.dao.entities.CallDetailRecord;
import org.restcomm.connect.dao.entities.CallDetailRecordFilter;
Expand Down Expand Up @@ -105,6 +106,7 @@ public void createReadUpdateDelete() {
builder.setApiVersion("2012-04-24");
builder.setCallerName("Alice");
builder.setUri(url);
builder.setType(CreateCallType.PSTN);
CallDetailRecord cdr = builder.build();
final CallDetailRecordsDao cdrs = manager.getCallDetailRecordsDao();
// Create a new CDR in the data store.
Expand All @@ -129,6 +131,7 @@ public void createReadUpdateDelete() {
assertTrue(result.getApiVersion().equals(cdr.getApiVersion()));
assertTrue(result.getCallerName().equals(cdr.getCallerName()));
assertTrue(result.getUri().equals(cdr.getUri()));
assertTrue(result.getType().equals(cdr.getType()));
// Update the CDR.
cdr = cdr.setDuration(2);
cdr = cdr.setPrice(new BigDecimal("1.00"));
Expand All @@ -147,6 +150,31 @@ public void createReadUpdateDelete() {
assertTrue(cdrs.getCallDetailRecord(sid) == null);
}

@Test
public void testReadByType() {
Sid accountSid = new Sid("AC00000000000000000000000000000001");
CallDetailRecordsDao dao = manager.getCallDetailRecordsDao();
try {
CallDetailRecordFilter filterPSTN = new CallDetailRecordFilter(accountSid.toString(), null, null, null, null, null, null, null, null, 0, 0, CreateCallType.PSTN);
CallDetailRecordFilter filterUSSD = new CallDetailRecordFilter(accountSid.toString(), null, null, null, null, null, null, null, null, 0, 0, CreateCallType.USSD);
CallDetailRecordFilter filterSIP = new CallDetailRecordFilter(accountSid.toString(), null, null, null, null, null, null, null, null, 0, 0, CreateCallType.SIP);
CallDetailRecordFilter filterCLIENT = new CallDetailRecordFilter(accountSid.toString(), null, null, null, null, null, null, null, null, 0, 0, CreateCallType.CLIENT);
List<CallDetailRecord> callsPstn = dao.getCallDetailRecords(filterPSTN);
List<CallDetailRecord> callsUssd = dao.getCallDetailRecords(filterUSSD);
List<CallDetailRecord> callsSip = dao.getCallDetailRecords(filterSIP);
List<CallDetailRecord> callsClient = dao.getCallDetailRecords(filterCLIENT);
Assert.assertEquals(4, callsPstn.size());
Assert.assertEquals(3, callsUssd.size());
Assert.assertEquals(2, callsSip.size());
Assert.assertEquals(1, callsClient.size());
Assert.assertEquals(4, dao.getTotalCallDetailRecords(filterPSTN).intValue());
Assert.assertEquals(3, dao.getTotalCallDetailRecords(filterUSSD).intValue());
Assert.assertEquals(2, dao.getTotalCallDetailRecords(filterSIP).intValue());
Assert.assertEquals(1, dao.getTotalCallDetailRecords(filterCLIENT).intValue());
} catch (ParseException e) {
}
}

@Test
public void testReadDeleteByAccount() {
final Sid sid = Sid.generate(Sid.Type.CALL);
Expand Down Expand Up @@ -435,7 +463,7 @@ public void retrieveAccountCdrsRecursively() throws ParseException {
// read from a single account but using the 'accountSidSet' interface
List<String> accountSidSet = new ArrayList<String>();
accountSidSet.add("AC00000000000000000000000000000000");
CallDetailRecordFilter filter = new CallDetailRecordFilter(null, accountSidSet, null, null, null, null, null, null, null, null, null);
CallDetailRecordFilter filter = new CallDetailRecordFilter(null, accountSidSet, null, null, null, null, null, null, null, null, null, null);
Assert.assertEquals(12, dao.getTotalCallDetailRecords(filter).intValue());
// read cdrs of three accounts
accountSidSet.add("AC00000000000000000000000000000000");
Expand All @@ -446,13 +474,13 @@ public void retrieveAccountCdrsRecursively() throws ParseException {
accountSidSet.clear();
Assert.assertEquals(0, dao.getTotalCallDetailRecords(filter).intValue());
// if both an accountSid and a accountSid set are passed, only accountSidSet is taken into account
filter = new CallDetailRecordFilter("ACae6e420f425248d6a26948c17a9e2acf", accountSidSet, null, null, null, null, null, null, null, null, null);
filter = new CallDetailRecordFilter("ACae6e420f425248d6a26948c17a9e2acf", accountSidSet, null, null, null, null, null, null, null, null, null, null);
accountSidSet.add("AC00000000000000000000000000000000");
accountSidSet.add("AC11111111111111111111111111111111");
accountSidSet.add("AC22222222222222222222222222222222");
Assert.assertEquals(25, dao.getTotalCallDetailRecords(filter).intValue());
// if no (null) accountSidSet is passed the method still works
filter = new CallDetailRecordFilter("AC00000000000000000000000000000000", null, null, null, null, null, null, null, null, null, null);
filter = new CallDetailRecordFilter("AC00000000000000000000000000000000", null, null, null, null, null, null, null, null, null, null, null);
Assert.assertEquals(12, dao.getTotalCallDetailRecords(filter).intValue());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,24 @@
<mapper namespace="org.mobicents.servlet.sip.restcomm.dao.CallDetailRecordsDao">
<insert id="addCallDetailRecord" parameterType="map">
INSERT INTO "restcomm_call_detail_records" ("sid", "instanceid", "parent_call_sid", "date_created", "date_updated", "account_sid", "recipient", "sender", "phone_number_sid", "status",
"start_time", "end_time", "duration", "price", "direction", "answered_by", "api_version", "forwarded_from", "caller_name", "uri", "call_path", "ring_duration", "conference_sid", "muted", "start_conference_on_enter", "end_conference_on_exit", "on_hold")
"start_time", "end_time", "duration", "price", "direction", "answered_by", "api_version", "forwarded_from", "caller_name", "uri", "call_path", "ring_duration", "conference_sid", "muted", "start_conference_on_enter", "end_conference_on_exit", "on_hold", "ms_id", "call_type")
VALUES (#{sid}, #{instanceid}, #{parent_call_sid}, #{date_created},
#{date_updated}, #{account_sid}, #{to}, #{from}, #{phone_number_sid}, #{status}, #{start_time}, #{end_time}, #{duration}, #{price}, #{direction},
#{answered_by}, #{api_version}, #{forwarded_from}, #{caller_name}, #{uri}, #{call_path}, #{ring_duration}, #{conference_sid}, #{muted}, #{start_conference_on_enter}, #{end_conference_on_exit}, #{on_hold});
#{answered_by}, #{api_version}, #{forwarded_from}, #{caller_name}, #{uri}, #{call_path}, #{ring_duration}, #{conference_sid}, #{muted}, #{start_conference_on_enter}, #{end_conference_on_exit}, #{on_hold}, #{ms_id}, #{call_type});
</insert>

<select id="getCallDetailRecord" parameterType="string" resultType="hashmap">
SELECT * FROM "restcomm_call_detail_records" WHERE "sid"=#{sid};
</select>

<select id="getInProgressCallsByClientName" parameterType="string" resultType="int">
SELECT COUNT(*) FROM "restcomm_call_detail_records" WHERE (UPPER("status") = ('IN_PROGRESS') OR UPPER("status") = ('IN-PROGRESS')) AND "parent_call_sid" IS NULL AND "sender"=#{sender};
</select>

<select id="getInProgressCallsByAccountSid" parameterType="string" resultType="int">
SELECT COUNT(*) FROM "restcomm_call_detail_records" WHERE (UPPER("status") = ('IN_PROGRESS') OR UPPER("status") = ('IN-PROGRESS')) AND "parent_call_sid" IS NULL AND "account_sid"=#{accountSid};
</select>

<!-- Issue 153: https://bitbucket.org/telestax/telscale-restcomm/issue/153 -->
<!-- Issue 153: https://bitbucket.org/telestax/telscale-restcomm/issue/110 -->
<select id="getTotalCallDetailRecordByUsingFilters" parameterType="org.restcomm.connect.dao.entities.CallDetailRecordFilter" resultType="int">
Expand Down Expand Up @@ -62,7 +70,9 @@
<if test="endTime != null">
AND "end_time" &lt;= DATE_ADD(#{endTime},INTERVAL 1 DAY)
</if>

<if test="callType != null">
AND "call_type" = #{callType}
</if>
</select>

<!-- Issue 153: https://bitbucket.org/telestax/telscale-restcomm/issue/153 -->
Expand Down Expand Up @@ -111,8 +121,12 @@
<if test="endTime != null">
AND "end_time" &lt;= DATE_ADD(#{endTime},INTERVAL 1 DAY)
</if>
<if test="callType != null">
AND "call_type" = #{callType}
</if>
order by "start_time"
LIMIT #{limit} OFFSET #{offset}

</select>

<!-- Issue 1215: https://github.com/RestComm/Restcomm-Connect/issues/1215 -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ SET FILES LOG SIZE 200
CREATE USER SA PASSWORD DIGEST 'd41d8cd98f00b204e9800998ecf8427e'
CREATE SCHEMA PUBLIC AUTHORIZATION DBA
SET SCHEMA PUBLIC
CREATE MEMORY TABLE "restcomm_call_detail_records"("sid" VARCHAR(1000) NOT NULL PRIMARY KEY,"parent_call_sid" VARCHAR(1000),"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"sender" VARCHAR(30) NOT NULL,"recipient" VARCHAR(64) NOT NULL,"phone_number_sid" VARCHAR(34),"status" VARCHAR(20) NOT NULL,"start_time" DATETIME,"end_time" DATETIME,"duration" INTEGER,"price" VARCHAR(8),"direction" VARCHAR(20) NOT NULL,"answered_by" VARCHAR(64),"api_version" VARCHAR(10) NOT NULL,"forwarded_from" VARCHAR(30),"caller_name" VARCHAR(50),"uri" LONGVARCHAR NOT NULL, "call_path" VARCHAR(255),"ring_duration" INTEGER, "instanceid" VARCHAR(255) NOT NULL, "conference_sid" VARCHAR(34),"muted" BOOLEAN, "start_conference_on_enter" BOOLEAN, "end_conference_on_exit" BOOLEAN, "on_hold" BOOLEAN)
CREATE MEMORY TABLE "restcomm_call_detail_records"("sid" VARCHAR(1000) NOT NULL PRIMARY KEY,"parent_call_sid" VARCHAR(1000),"date_created" DATETIME NOT NULL,"date_updated" DATETIME NOT NULL,"account_sid" VARCHAR(34) NOT NULL,"sender" VARCHAR(255) NOT NULL,"recipient" VARCHAR(64) NOT NULL,"phone_number_sid" VARCHAR(34),"status" VARCHAR(20) NOT NULL,"start_time" DATETIME,"end_time" DATETIME,"duration" INTEGER,"price" VARCHAR(8),"direction" VARCHAR(20) NOT NULL,"answered_by" VARCHAR(64),"api_version" VARCHAR(10) NOT NULL,"forwarded_from" VARCHAR(30),"caller_name" VARCHAR(50),"uri" LONGVARCHAR NOT NULL, "call_path" VARCHAR(255),"ring_duration" INTEGER, "instanceid" VARCHAR(255) NOT NULL, "conference_sid" VARCHAR(34),"muted" BOOLEAN, "start_conference_on_enter" BOOLEAN, "end_conference_on_exit" BOOLEAN, "on_hold" BOOLEAN, "ms_id" VARCHAR(34), "call_type" VARCHAR(34))
ALTER SEQUENCE SYSTEM_LOBS.LOB_ID RESTART WITH 1
SET DATABASE DEFAULT INITIAL SCHEMA PUBLIC
GRANT USAGE ON DOMAIN INFORMATION_SCHEMA.SQL_IDENTIFIER TO PUBLIC
Expand Down Expand Up @@ -143,3 +143,13 @@ INSERT INTO "restcomm_call_detail_records" VALUES('CA3a28d89482ec4e46a9f1e2ff5c4
INSERT INTO "restcomm_call_detail_records" VALUES('CA3b30eb7cc24f47489f53d9e033385a2a',NULL,'2013-08-22 14:13:30.336000000','2013-08-22 14:13:30.501000000','ACae6e420f425248d6a26948c17a9e2acf','Anonymous','+15126002188',NULL,'in-progress','2013-08-22 14:13:30.501000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA3b30eb7cc24f47489f53d9e033385a2a', NULL,NULL, NULL, NULL, NULL)
INSERT INTO "restcomm_call_detail_records" VALUES('CA3c2386d4942f4028b714c24af404c239',NULL,'2013-08-13 14:14:31.402000000','2013-08-13 14:14:32.519000000','ACae6e420f425248d6a26948c17a9e2acf','19549376176','+15126002188',NULL,'in-progress','2013-08-13 14:14:32.519000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA3c2386d4942f4028b714c24af404c239', NULL,NULL, NULL, NULL, NULL)
INSERT INTO "restcomm_call_detail_records" VALUES('CA3d386ded326f4aba9e495959b0ac5218',NULL,'2013-07-17 14:55:01.225000000','2013-07-17 14:55:01.361000000','ACae6e420f425248d6a26948c17a9e2acf','19549376176','+15126002188',NULL,'in-progress','2013-07-17 14:55:01.361000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA3d386ded326f4aba9e495959b0ac5218', NULL,NULL, NULL, NULL, NULL)
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000001',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000001', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'PSTN')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000002',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000002', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'PSTN')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000003',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000003', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'PSTN')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000004',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000004', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'PSTN')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000005',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000005', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'USSD')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000006',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000006', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'USSD')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000007',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000007', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'USSD')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000008',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000008', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'SIP')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000009',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000009', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'SIP')
INSERT INTO "restcomm_call_detail_records" VALUES('CA00000000000000000000000000000010',NULL,'2017-11-01 00:00:00.000000000','2017-11-01 00:00:00.000000000','AC00000000000000000000000000000001','19549376176','+15126002188',NULL,'completed','2017-11-01 00:00:00.000000000',NULL,NULL,'0.00','inbound',NULL,'2012-04-24',NULL,NULL,'/2012-04-24/Accounts/ACae6e420f425248d6a26948c17a9e2acf/Calls/CA00000000000000000000000000000010', NULL,NULL, NULL, NULL, NULL, NULL,NULL, NULL, NULL, 'CLIENT')

0 comments on commit c6eba04

Please sign in to comment.