Skip to content

Commit

Permalink
xsunit tests for PrintQueue sapmentors#25
Browse files Browse the repository at this point in the history
  • Loading branch information
gregorwolf authored and open-ui5 committed Oct 14, 2016
1 parent c2f3e54 commit 10163f4
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
89 changes: 86 additions & 3 deletions odatareceptionist/procedures/PrintQueue.xsjslib
Original file line number Diff line number Diff line change
@@ -1,13 +1,96 @@
function PrintQueueUpdate(param){
function readParticipant(_ParticipantID) {
var conn;
var participant = {};

try {
conn = $.db.getConnection();
var select = 'SELECT "ID", "EventID", "FirstName", "LastName", "Twitter"'
+ ' FROM "com.sap.sapmentors.sitreg.data::SITreg.Participant"'
+ ' WHERE "ID" = ?';
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _ParticipantID);
var rs = pStmt.executeQuery();
if (rs.next()) {
participant.ParticipantID = rs.getInteger(1);
participant.EventID = rs.getInteger(2);
participant.FirstName = rs.getNString(3);
participant.LastName = rs.getNString(4);
participant.Twitter = rs.getNString(5);
}
rs.close();
pStmt.close();
conn.close();
} catch (e) {
participant.error = "Error: exception caught: <br />" + e.toString();
}
return participant;
}

function isParticipantInPrintQueue(_ParticipantID) {
var conn;
var count;
try {
conn = $.db.getConnection();
var select = 'SELECT COUNT("ParticipantID") AS count '
+ 'FROM "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" '
+ 'WHERE "ParticipantID" = ?';
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _ParticipantID);
var rs = pStmt.executeQuery();
if (rs.next()) {
count = rs.getInteger(1);
}
pStmt.close();
} catch (e) {
$.trace.debug("Error: exception caught: <br />" + e.toString());
}
return count;
}

function addParticipantToPrintQueue(_participant) {
var conn;
var status = {};
try {
conn = $.db.getConnection();
status.count = isParticipantInPrintQueue(_participant.ParticipantID);
if(status.count === 0) {
var select = 'INSERT INTO "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" '
+ 'VALUES(?, ?, ?, ?, ?, ?, '
+ 'CURRENT_USER, CURRENT_TIMESTAMP, CURRENT_USER, CURRENT_TIMESTAMP )';
var pStmt = conn.prepareStatement(select);
pStmt.setInteger(1, _participant.ParticipantID);
pStmt.setInteger(2, _participant.EventID);
pStmt.setString(3, _participant.FirstName);
pStmt.setString(4, _participant.LastName);
pStmt.setString(5, _participant.Twitter);
pStmt.setString(6, _participant.PrintStatus);
pStmt.executeUpdate();
conn.commit();
pStmt.close();
} else {
status.error = "Entry does already exist";
}
conn.close();
} catch (e) {
status.error = "Error: exception caught: <br />" + e.toString();
}
return status;
}

function PrintQueueUpdateAfterTicketUpdate(param){
$.trace.debug('entered function PrintQueueUpdate');
// let before = param.beforeTableName;
let after = param.afterTableName;
// Update PrintQueue
let pStmt = param.connection.prepareStatement('SELECT * FROM "' + after + '"' );
let rs = pStmt.executeQuery();
if (rs.next()) {
var ParticipantID = rs.getNString(1);
var TicketUsed = rs.getNString(4);
}
$.trace.debug('TicketUsed: ' + TicketUsed);
$.trace.debug('ParticipantID:' + ParticipantID + 'TicketUsed: ' + TicketUsed);
// var participant = readParticipant(ParticipantID);
rs.close();
pStmt.close();
$.trace.debug('leave function PrintQueueUpdate');
}
}
1 change: 1 addition & 0 deletions odatareceptionist/procedures/PrintQueue.xsunit.xsjslib
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
describe("Print Queue Tests", function() { var cut = $.import("com.sap.sapmentors.sitreg.odatareceptionist.procedures", "PrintQueue"); var participant; var ParticipantID; var EventID; beforeOnce(function() { var select = 'SELECT TOP 1 "ID", "Participant"."EventID" ' + 'FROM "com.sap.sapmentors.sitreg.data::SITreg.Participant" AS "Participant" ' + 'LEFT JOIN "com.sap.sapmentors.sitreg.data::SITreg.Device" AS "Device" ' + 'ON "Device"."EventID" = "Participant"."EventID" '; var pStmt = jasmine.dbConnection.prepareStatement(select); var rs = pStmt.executeQuery(); if (rs.next()) { ParticipantID = rs.getInteger(1); EventID = rs.getInteger(1); } pStmt.close(); }); it('should read participant details', function() { participant = cut.readParticipant(ParticipantID); expect(participant.ParticipantID).toBe(ParticipantID); }); it('should fill print queue', function() { participant.PrintStatus = 'P'; var status = cut.addParticipantToPrintQueue(participant); expect(status.error).toBe(undefined); expect(status.count).toBe(0); }); it('check if participant was inserted', function() { var count = cut.isParticipantInPrintQueue(ParticipantID); expect(count).toBe(1); }); afterOnce(function() { var select = 'DELETE FROM "com.sap.sapmentors.sitreg.data::SITreg.PrintQueue" ' + 'WHERE "ParticipantID" = ?'; var pStmt = jasmine.dbConnection.prepareStatement(select); pStmt.setInteger(1, participant.ParticipantID); pStmt.execute(); jasmine.dbConnection.commit(); pStmt.close(); });});
Expand Down
3 changes: 2 additions & 1 deletion odatareceptionist/service.xsodata
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ service {
"com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketRead" as "Ticket" key ("ParticipantID")
create forbidden
update using "com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketUpdate"
events ( after "com.sap.sapmentors.sitreg.odatareceptionist.procedures:PrintQueue.xsjslib::PrintQueueUpdate" )
events (
after "com.sap.sapmentors.sitreg.odatareceptionist.procedures:PrintQueue.xsjslib::PrintQueueUpdateAfterTicketUpdate" )
delete forbidden;

association "Event_Ticket" principal "Events"("ID") multiplicity "1"
Expand Down
1 change: 1 addition & 0 deletions roles/admin.hdbrole
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ role com.sap.sapmentors.sitreg.roles::admin {
sql object com.sap.sapmentors.sitreg.data::SITreg.Participant: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.data::SITreg.Organizer: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.data::SITreg.Ticket: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.data::SITreg.PrintQueue: SELECT, INSERT, UPDATE, DELETE;
sql object com.sap.sapmentors.sitreg.odataparticipant.procedures::TicketCreate: EXECUTE;
sql object com.sap.sapmentors.sitreg.odataadmin.procedures::TicketCreateMissing: EXECUTE;
sql object com.sap.sapmentors.sitreg.odataadmin.procedures::ParticipantUpdateWaitingList: EXECUTE;
Expand Down
2 changes: 1 addition & 1 deletion roles/receptionist.hdbrole
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ role com.sap.sapmentors.sitreg.roles::receptionist {
sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketRead: SELECT;
sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketCheck: EXECUTE;
sql object com.sap.sapmentors.sitreg.odatareceptionist.procedures::TicketUpdate: EXECUTE;
sql object com.sap.sapmentors.sitreg.data::SITreg.PrintQueue: SELECT, UPDATE;
sql object com.sap.sapmentors.sitreg.data::SITreg.PrintQueue: SELECT, INSERT, UPDATE;
}

0 comments on commit 10163f4

Please sign in to comment.