From b5af1f410ca2a2f87fcae756c867388cf3fcc8a7 Mon Sep 17 00:00:00 2001 From: srosse <none@none> Date: Wed, 8 Aug 2012 11:11:40 +0200 Subject: [PATCH] OO-291: test reservations, add unit tests for open group with a date limitation --- .../course/nodes/en/EnrollmentManager.java | 2 +- .../database/mysql/setupDatabase.sql | 11 +++++ .../postgresql/alter_8_1_x_to_8_2_0.sql | 48 ++++++++++++------- .../database/postgresql/setupDatabase.sql | 10 ++++ .../olat/group/test/BusinessGroupDAOTest.java | 39 +++++++++++++++ .../java/org/olat/test/AllTestsJunit4.java | 1 + 6 files changed, 93 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java index 4179d7b3db1..42ebb442d57 100644 --- a/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java +++ b/src/main/java/org/olat/course/nodes/en/EnrollmentManager.java @@ -108,7 +108,7 @@ public class EnrollmentManager extends BasicManager { //reservation has the highest priority over max participant ResourceReservation reservation = acService.getReservation(identity, reloadedGroup.getResource()); logInfo("doEnroll - participantsCounter: " + participantsCounter + ", reservations: " + reservations + " maxParticipants: " + reloadedGroup.getMaxParticipants().intValue(), identity.getName()); - if (reservation == null || (participantsCounter + reservations) >= reloadedGroup.getMaxParticipants().intValue()) { + if (reservation == null && (participantsCounter + reservations) >= reloadedGroup.getMaxParticipants().intValue()) { // already full, show error and updated choose page again if (!reloadedGroup.getWaitingListEnabled().booleanValue()) { // No Waiting List => List is full diff --git a/src/main/resources/database/mysql/setupDatabase.sql b/src/main/resources/database/mysql/setupDatabase.sql index ae904ee0124..86744e93cd3 100644 --- a/src/main/resources/database/mysql/setupDatabase.sql +++ b/src/main/resources/database/mysql/setupDatabase.sql @@ -933,6 +933,16 @@ create table if not exists o_ac_transaction ( primary key (transaction_id) ); +create table if not exists o_ac_reservation ( + reservation_id bigint NOT NULL, + creationdate datetime, + lastmodified datetime, + version mediumint unsigned not null, + fk_identity bigint not null, + fk_resource bigint not null, + primary key (reservation_id) +); + create table if not exists o_ac_paypal_transaction ( transaction_id int8 not null, version int8 not null, @@ -1297,6 +1307,7 @@ alter table o_ac_order ENGINE = InnoDB; alter table o_ac_order_part ENGINE = InnoDB; alter table o_ac_order_line ENGINE = InnoDB; alter table o_ac_transaction ENGINE = InnoDB; +alter table o_ac_offer ENGINE = InnoDB; alter table o_ac_paypal_transaction ENGINE = InnoDB; alter table o_as_eff_statement ENGINE = InnoDB; alter table o_as_user_course_infos ENGINE = InnoDB; diff --git a/src/main/resources/database/postgresql/alter_8_1_x_to_8_2_0.sql b/src/main/resources/database/postgresql/alter_8_1_x_to_8_2_0.sql index 7dbba80081d..1cabe48a32d 100644 --- a/src/main/resources/database/postgresql/alter_8_1_x_to_8_2_0.sql +++ b/src/main/resources/database/postgresql/alter_8_1_x_to_8_2_0.sql @@ -159,27 +159,41 @@ create table o_ac_paypal_transaction ( order_part_id int8 not null, method_id int8 not null, success_uuid varchar(32) not null, - cancel_uuid varchar(32) not null, - amount_amount DECIMAL, - amount_currency_code VARCHAR(3), + cancel_uuid varchar(32) not null, + amount_amount DECIMAL, + amount_currency_code VARCHAR(3), pay_response_date timestamp, pay_key varchar(255), - ack varchar(255), - build varchar(255), - coorelation_id varchar(255), - payment_exec_status varchar(255), - ipn_transaction_id varchar(255), - ipn_transaction_status varchar(255), - ipn_sender_transaction_id varchar(255), - ipn_sender_transaction_status varchar(255), - ipn_sender_email varchar(255), - ipn_verify_sign varchar(255), - ipn_pending_reason varchar(255), - trx_status VARCHAR(32) not null default 'NEW', - trx_amount DECIMAL, - trx_currency_code VARCHAR(3), + ack varchar(255), + build varchar(255), + coorelation_id varchar(255), + payment_exec_status varchar(255), + ipn_transaction_id varchar(255), + ipn_transaction_status varchar(255), + ipn_sender_transaction_id varchar(255), + ipn_sender_transaction_status varchar(255), + ipn_sender_email varchar(255), + ipn_verify_sign varchar(255), + ipn_pending_reason varchar(255), + trx_status VARCHAR(32) not null default 'NEW', + trx_amount DECIMAL, + trx_currency_code VARCHAR(3), primary key (transaction_id) ); create index paypal_pay_key_idx on o_ac_paypal_transaction (pay_key); create index paypal_pay_trx_id_idx on o_ac_paypal_transaction (ipn_transaction_id); create index paypal_pay_s_trx_id_idx on o_ac_paypal_transaction (ipn_sender_transaction_id); + +create table if not exists o_ac_reservation ( + reservation_id int8 NOT NULL, + creationdate timestamp, + lastmodified timestamp, + version int4 not null, + fk_identity int8 not null, + fk_resource int8 not null, + primary key (reservation_id) +); + + + + diff --git a/src/main/resources/database/postgresql/setupDatabase.sql b/src/main/resources/database/postgresql/setupDatabase.sql index 141062171c5..94a02dff1c1 100644 --- a/src/main/resources/database/postgresql/setupDatabase.sql +++ b/src/main/resources/database/postgresql/setupDatabase.sql @@ -797,6 +797,16 @@ create table o_ac_transaction ( primary key (transaction_id) ); +create table if not exists o_ac_reservation ( + reservation_id bigint NOT NULL, + creationdate datetime, + lastmodified datetime, + version mediumint unsigned not null, + fk_identity bigint not null, + fk_resource bigint not null, + primary key (reservation_id) +); + create table o_ac_paypal_transaction ( transaction_id int8 not null, version int8 not null, diff --git a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java index a717207ea18..8aa247b6a6e 100644 --- a/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java +++ b/src/test/java/org/olat/group/test/BusinessGroupDAOTest.java @@ -22,6 +22,7 @@ package org.olat.group.test; import static org.junit.Assert.assertNotNull; import java.util.ArrayList; +import java.util.Calendar; import java.util.Collections; import java.util.Date; import java.util.List; @@ -924,6 +925,44 @@ public class BusinessGroupDAOTest extends OlatTestCase { } } + @Test + public void findPublicGroupsLimitedDate() { + //create a group with an access control limited by a valid date + BusinessGroup groupVisible = businessGroupDao.createAndPersist(null, "access-grp-2", "access-grp-2-desc", 0, 5, true, false, true, false, false); + //create and save an offer + Offer offer = acService.createOffer(groupVisible.getResource(), "TestBGWorkflow"); + + Calendar cal = Calendar.getInstance(); + cal.add(Calendar.HOUR_OF_DAY, -1); + offer.setValidFrom(cal.getTime()); + cal.add(Calendar.HOUR_OF_DAY, 2); + offer.setValidTo(cal.getTime()); + assertNotNull(offer); + acService.save(offer); + + //create a group with an access control limited by dates in the past + BusinessGroup oldGroup = businessGroupDao.createAndPersist(null, "access-grp-3", "access-grp-3-desc", 0, 5, true, false, true, false, false); + //create and save an offer + Offer oldOffer = acService.createOffer(oldGroup.getResource(), "TestBGWorkflow"); + cal.add(Calendar.HOUR_OF_DAY, -5); + oldOffer.setValidFrom(cal.getTime()); + cal.add(Calendar.HOUR_OF_DAY, -5); + oldOffer.setValidTo(cal.getTime()); + assertNotNull(oldOffer); + acService.save(oldOffer); + + dbInstance.commitAndCloseSession(); + + //retrieve the offer + SearchBusinessGroupParams paramsAll = new SearchBusinessGroupParams(); + paramsAll.setPublicGroups(Boolean.TRUE); + List<BusinessGroup> accessGroups = businessGroupDao.findBusinessGroups(paramsAll, null, 0, 0); + Assert.assertNotNull(accessGroups); + Assert.assertTrue(accessGroups.size() >= 1); + Assert.assertTrue(accessGroups.contains(groupVisible)); + Assert.assertFalse(accessGroups.contains(oldGroup)); + } + @Test public void findBusinessGroupsWithResources() { //create a group attach to a resource diff --git a/src/test/java/org/olat/test/AllTestsJunit4.java b/src/test/java/org/olat/test/AllTestsJunit4.java index c734890e470..e0d2f333dff 100644 --- a/src/test/java/org/olat/test/AllTestsJunit4.java +++ b/src/test/java/org/olat/test/AllTestsJunit4.java @@ -155,6 +155,7 @@ import org.junit.runners.Suite; org.olat.resource.accesscontrol.ACOfferManagerTest.class, org.olat.resource.accesscontrol.ACOrderManagerTest.class, org.olat.resource.accesscontrol.ACTransactionManagerTest.class, + org.olat.resource.accesscontrol.ACReservationDAOTest.class, org.olat.core.util.vfs.VersionManagerTest.class, /** * Pure JUnit test without need of framework -- GitLab