Author: solomax
Date: Thu Dec 26 18:08:59 2013
New Revision: 1553534

URL: http://svn.apache.org/r1553534
Log:
[OPENMEETINGS-864] tests are fixed; code clean up

Modified:
    openmeetings/trunk/singlewebapp/WebContent/swf10/hibAdapter.lzx
    
openmeetings/trunk/singlewebapp/src/db/java/org/apache/openmeetings/db/entity/calendar/Appointment.java
    
openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/remote/FLVRecorderService.java
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/AbstractJUnitDefaults.java
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestDatabaseStructureGetAppointmentByRange.java
    
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestGetAppointment.java

Modified: openmeetings/trunk/singlewebapp/WebContent/swf10/hibAdapter.lzx
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/WebContent/swf10/hibAdapter.lzx?rev=1553534&r1=1553533&r2=1553534&view=diff
==============================================================================
--- openmeetings/trunk/singlewebapp/WebContent/swf10/hibAdapter.lzx (original)
+++ openmeetings/trunk/singlewebapp/WebContent/swf10/hibAdapter.lzx Thu Dec 26 
18:08:59 2013
@@ -341,8 +341,7 @@
        <method name="updateCursorScreenSharing" args="value">
                <![CDATA[
                        if (canvas.screenSharingDialogContainer != null) {
-                               var obj = canvas.screenSharingDialogContainer
-                                               
.searchForSession(value.streamPublishName);
+                               var obj = 
canvas.screenSharingDialogContainer.searchForSession(value.streamPublishName);
                                obj.updateCursor(value.cursor_x, 
value.cursor_y);
                        }
                ]]>

Modified: 
openmeetings/trunk/singlewebapp/src/db/java/org/apache/openmeetings/db/entity/calendar/Appointment.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/db/java/org/apache/openmeetings/db/entity/calendar/Appointment.java?rev=1553534&r1=1553533&r2=1553534&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/db/java/org/apache/openmeetings/db/entity/calendar/Appointment.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/db/java/org/apache/openmeetings/db/entity/calendar/Appointment.java
 Thu Dec 26 18:08:59 2013
@@ -48,10 +48,9 @@ import org.simpleframework.xml.Root;
 @Entity
 @Table(name = "appointments")
 @NamedQueries({
-    @NamedQuery(name="getAppointmentById", query="SELECT DISTINCT a FROM 
Appointment a LEFT JOIN FETCH a.meetingMembers"
-               + " WHERE a.deleted = false AND a.id = :id")
+    @NamedQuery(name="getAppointmentById", query="SELECT a FROM Appointment a 
WHERE a.deleted = false AND a.id = :id")
     , @NamedQuery(name="appointmentsInRange",
-       query="SELECT DISTINCT a FROM Appointment a LEFT JOIN FETCH 
a.meetingMembers "
+       query="SELECT a FROM Appointment a "
                        + "WHERE a.deleted = false "
                        + "     AND ( "
                        + "             (a.start BETWEEN :starttime AND 
:endtime) "
@@ -61,7 +60,7 @@ import org.simpleframework.xml.Root;
                        + "     AND a.owner.user_id = :userId"
        )
     , @NamedQuery(name="joinedAppointmentsInRange",
-               query="SELECT DISTINCT a FROM MeetingMember mm INNER JOIN 
mm.appointment a LEFT JOIN FETCH a.meetingMembers "
+               query="SELECT a FROM MeetingMember mm INNER JOIN mm.appointment 
a "
                        + "WHERE mm.deleted = false AND mm.user.user_id <> 
a.owner.user_id AND mm.user.user_id = :userId "
                        + "     AND a.id NOT IN (SELECT a.id FROM Appointment a 
WHERE a.owner.user_id = :userId)"
                        + "     AND mm.connectedEvent = false " //TODO review: 
isConnectedEvent is set for the MeetingMember if event is created from "Private 
Messages", it is weird
@@ -72,7 +71,7 @@ import org.simpleframework.xml.Root;
                        + "     )"
        )
     , @NamedQuery(name="appointmentsInRangeRemind",
-               query="SELECT DISTINCT a FROM MeetingMember mm INNER JOIN 
mm.appointment a LEFT JOIN FETCH a.meetingMembers "
+               query="SELECT a FROM MeetingMember mm INNER JOIN mm.appointment 
a "
                        //only ReminderType simple mail is concerned!
                        + "WHERE mm.deleted = false AND a.deleted = false AND 
a.reminderEmailSend = false"
                        + " AND (a.remind.typId = 2 OR a.remind.typId = 3) "
@@ -82,8 +81,7 @@ import org.simpleframework.xml.Root;
                        + "             OR (a.start < :starttime AND a.end > 
:endtime) "
                        + "     )"
        )
-    , @NamedQuery(name="getAppointmentByRoomId", query="SELECT DISTINCT a FROM 
Appointment a LEFT JOIN FETCH a.meetingMembers"
-               + " WHERE a.deleted = false AND a.room.rooms_id = :room_id")
+    , @NamedQuery(name="getAppointmentByRoomId", query="SELECT a FROM 
Appointment a WHERE a.deleted = false AND a.room.rooms_id = :room_id")
        //TODO this query returns duplicates if the user books an appointment 
with
        //his own user as second meeting-member, swagner 19.02.2012
     , @NamedQuery(name="appointmentsInRangeByUser",
@@ -191,7 +189,7 @@ public class Appointment implements Seri
        @Element(data=true, required=false)
        private String icalId;
 
-       @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
+       @OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
        @JoinColumn(name = "appointment_id")
        private List<MeetingMember> meetingMembers;
        

Modified: 
openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/remote/FLVRecorderService.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/remote/FLVRecorderService.java?rev=1553534&r1=1553533&r2=1553534&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/remote/FLVRecorderService.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/main/java/org/apache/openmeetings/remote/FLVRecorderService.java
 Thu Dec 26 18:08:59 2013
@@ -156,8 +156,7 @@ public class FLVRecorderService implemen
                                        if (conn instanceof 
IServiceCapableConnection) {
                                                Client rcl = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
 
-                                               // Send every user a 
notification that the recording did
-                                               // start
+                                               // Send every user a 
notification that the recording did start
                                                if (!rcl.getIsAVClient()) {
                                                        
((IServiceCapableConnection) conn).invoke("startedRecording", new Object[] { 
currentClient }, this);
                                                }
@@ -340,14 +339,6 @@ public class FLVRecorderService implemen
                                        if (conn instanceof 
IServiceCapableConnection) {
                                                Client rcl = 
sessionManager.getClientByStreamId(conn.getClient().getId(), null);
 
-                                               // FIXME: Check if this 
function is really in use at
-                                               // the moment
-                                               // if 
(!rcl.getIsScreenClient()) {
-                                               // ((IServiceCapableConnection)
-                                               // 
conn).invoke("stoppedRecording",new Object[] {
-                                               // currentClient }, this);
-                                               // }
-
                                                log.debug("is this users still 
alive? stop it :" + rcl);
 
                                                if (rcl.getIsScreenClient()) {

Modified: 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/AbstractJUnitDefaults.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/AbstractJUnitDefaults.java?rev=1553534&r1=1553533&r2=1553534&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/AbstractJUnitDefaults.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/AbstractJUnitDefaults.java
 Thu Dec 26 18:08:59 2013
@@ -22,12 +22,18 @@ import static org.junit.Assert.assertNot
 import static org.junit.Assert.assertTrue;
 
 import java.util.Date;
+import java.util.List;
 
 import org.apache.openmeetings.data.user.UserManager;
 import org.apache.openmeetings.db.dao.basic.ConfigurationDao;
 import org.apache.openmeetings.db.dao.calendar.AppointmentDao;
+import org.apache.openmeetings.db.dao.calendar.AppointmentReminderTypDao;
+import org.apache.openmeetings.db.dao.room.RoomTypeDao;
 import org.apache.openmeetings.db.dao.user.UserDao;
 import org.apache.openmeetings.db.entity.calendar.Appointment;
+import org.apache.openmeetings.db.entity.calendar.AppointmentReminderTyps;
+import org.apache.openmeetings.db.entity.room.Room;
+import org.apache.openmeetings.db.entity.room.RoomType;
 import org.apache.openmeetings.db.entity.user.User;
 import org.apache.openmeetings.installation.ImportInitvalues;
 import org.apache.openmeetings.installation.InstallationConfig;
@@ -37,8 +43,8 @@ import org.slf4j.Logger;
 import org.springframework.beans.factory.annotation.Autowired;
 
 public abstract class AbstractJUnitDefaults extends AbstractSpringTest {
-       
        private static final Logger log = 
Red5LoggerFactory.getLogger(AbstractJUnitDefaults.class);
+       public static final String OM_URL = 
"http://testserver.apache.org/openmeetings";;
        
        protected static final String username = "swagner";
        protected static final String userpass = "qweqwe";
@@ -49,6 +55,10 @@ public abstract class AbstractJUnitDefau
        @Autowired
        private AppointmentDao appointmentDao;
        @Autowired
+       private AppointmentReminderTypDao reminderTypeDao;
+       @Autowired
+       private RoomTypeDao roomTypeDao;
+       @Autowired
        private UserManager userManager;
        @Autowired
        private UserDao userDao;
@@ -56,6 +66,9 @@ public abstract class AbstractJUnitDefau
        private ImportInitvalues importInitvalues;
        @Autowired
        private ConfigurationDao configurationDao;
+       
+       private List<AppointmentReminderTyps> remindTypes;
+       private List<RoomType> roomTypes;
 
        @Before
        public void setUp() throws Exception {
@@ -66,9 +79,18 @@ public abstract class AbstractJUnitDefau
         } else {
             log.info("Default scheme already created");
         }
+        remindTypes = reminderTypeDao.getAppointmentReminderTypList(1L);
+        roomTypes = roomTypeDao.getAll(1L);
     }
 
-       public Appointment createAppointment() throws Exception {
+       public Appointment createAppointment() {
+               Date appointmentstart = new Date();
+               Date appointmentend = new Date();
+               appointmentend.setTime(appointmentstart.getTime() + 3600);
+               return createAppointment(appointmentstart, appointmentend);
+       }
+       
+       public Appointment getAppointment(Date start, Date end) {
                assertNotNull("Can't access to appointment dao implimentation", 
appointmentDao);
 
                // add new appointment
@@ -77,12 +99,44 @@ public abstract class AbstractJUnitDefau
                ap.setTitle("appointmentName");
                ap.setLocation("appointmentLocation");
 
-               Date appointmentstart = new Date();
-               Date appointmentend = new Date();
-               appointmentend.setTime(appointmentstart.getTime() + 3600);
+               ap.setStart(start);
+               ap.setEnd(end);
+               ap.setDescription("appointmentDescription");
+               ap.setInserted(new Date());
+               ap.setDeleted(false);
+               ap.setIsDaily(false);
+               ap.setIsWeekly(false);
+               ap.setIsMonthly(false);
+               ap.setIsYearly(false);
+               ap.setPasswordProtected(false);
+
+               ap.setOwner(userDao.get(1L));
+               ap.setConnectedEvent(false);
+
+               if (ap.getRemind() == null && !remindTypes.isEmpty()) {
+                       ap.setRemind(remindTypes.get(0));
+               }
+               
+               Room r = new Room();
+               if (!roomTypes.isEmpty()) {
+                       r.setRoomtype(roomTypes.get(0));
+               }
+               r.setAppointment(true);
+               ap.setRoom(r);
+               return ap;
+       }
+
+       public Appointment createAppointment(Date start, Date end) {
+               assertNotNull("Can't access to appointment dao implimentation", 
appointmentDao);
+
+               // add new appointment
+               Appointment ap = new Appointment();
+
+               ap.setTitle("appointmentName");
+               ap.setLocation("appointmentLocation");
 
-               ap.setStart(appointmentstart);
-               ap.setEnd(appointmentend);
+               ap.setStart(start);
+               ap.setEnd(end);
                ap.setDescription("appointmentDescription");
                ap.setInserted(new Date());
                ap.setDeleted(false);
@@ -104,7 +158,7 @@ public abstract class AbstractJUnitDefau
                // add user
                u.setFirstname("firstname" + rnd);
                u.setLastname("lastname" + rnd);
-               u.setLogin("login");
+               u.setLogin("login" + rnd);
                u.updatePassword(configurationDao, "pass" + rnd);
                u.setLanguage_id(1L);
                Long user_id = userManager.addUser(u);
@@ -124,7 +178,7 @@ public abstract class AbstractJUnitDefau
                importInitvalues.loadAll(cfg, false);
        }
 
-       public User createUserContact(int rnd, Long ownerId) throws Exception {
+       public User createUserContact(int rnd, Long ownerId) {
                User user = userDao.getContact("email" + rnd, "firstname" + 
rnd, "lastname" + rnd, ownerId);
                user = userDao.update(user, ownerId);
                assertNotNull("Cann't add user", user);

Modified: 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestDatabaseStructureGetAppointmentByRange.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestDatabaseStructureGetAppointmentByRange.java?rev=1553534&r1=1553533&r2=1553534&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestDatabaseStructureGetAppointmentByRange.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestDatabaseStructureGetAppointmentByRange.java
 Thu Dec 26 18:08:59 2013
@@ -18,12 +18,16 @@
  */
 package org.apache.openmeetings.test.calendar;
 
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
 import java.util.Calendar;
-import java.util.List;
+import java.util.Random;
 
 import org.apache.log4j.Logger;
 import org.apache.openmeetings.db.dao.calendar.AppointmentDao;
 import org.apache.openmeetings.db.entity.calendar.Appointment;
+import org.apache.openmeetings.db.entity.calendar.MeetingMember;
 import org.apache.openmeetings.test.AbstractJUnitDefaults;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -35,11 +39,66 @@ public class TestDatabaseStructureGetApp
 
        @Test
        public void test() {
-               List<Appointment> listAppoints = 
appointmentDao.getAppointmentsByRange(1L,
-                               Calendar.getInstance().getTime(), 
Calendar.getInstance().getTime());
+               log.debug("Test started");
+               Long userId = 1L;
+               
+               Random rnd = new Random();
+               Calendar now = Calendar.getInstance();
+               Calendar rangeStart = Calendar.getInstance();
+               rangeStart.setTime(now.getTime());
+               rangeStart.add(Calendar.DATE, -1);
+               Calendar rangeEnd = Calendar.getInstance();
+               rangeEnd.add(Calendar.DATE, 1);
+               rangeEnd.setTime(now.getTime());
+               
+               Calendar a1End = Calendar.getInstance();
+               a1End.setTime(now.getTime());
+               a1End.add(Calendar.HOUR_OF_DAY, 1);
+               Appointment a1 = getAppointment(now.getTime(), a1End.getTime());
+               a1.setTitle("AppointmentByRange_a1");
 
-               for (Appointment appoints : listAppoints) {
-                       log.debug("" + appoints);
+               Appointment a2 = getAppointment(now.getTime(), a1End.getTime());
+               a2.setTitle("AppointmentByRange_a2");
+               a2.setMeetingMembers(new ArrayList<MeetingMember>());
+               MeetingMember mm1 = new MeetingMember();
+               mm1.setUser(createUserContact(rnd.nextInt(), userId));
+               mm1.setAppointment(a2);
+               a2.getMeetingMembers().add(mm1);
+               
+               Appointment a3 = getAppointment(now.getTime(), a1End.getTime());
+               a3.setTitle("AppointmentByRange_a3");
+               a3.setMeetingMembers(new ArrayList<MeetingMember>());
+               MeetingMember mm2 = new MeetingMember();
+               mm2.setUser(createUserContact(rnd.nextInt(), userId));
+               mm2.setAppointment(a3);
+               a3.getMeetingMembers().add(mm2);
+               MeetingMember mm3 = new MeetingMember();
+               mm3.setUser(createUserContact(rnd.nextInt(), userId));
+               mm3.setAppointment(a3);
+               a3.getMeetingMembers().add(mm3);
+               
+               a1 = appointmentDao.update(a1, OM_URL, userId);
+               a2 = appointmentDao.update(a2, OM_URL, userId);
+               a3 = appointmentDao.update(a3, OM_URL, userId);
+               
+               int a1found = 0, a2found = 0, a3found = 0;
+               for (Appointment a : 
appointmentDao.getAppointmentsByRange(userId, rangeStart.getTime(), 
rangeEnd.getTime())) {
+                       int mmCount = a.getMeetingMembers() == null ? 0 : 
a.getMeetingMembers().size();
+                       if (a.getId().equals(a1.getId())) {
+                               assertEquals("Inapropriate MeetingMembers 
count", 0, mmCount);
+                               a1found++;
+                       }
+                       if (a.getId().equals(a2.getId())) {
+                               assertEquals("Inapropriate MeetingMembers 
count", 1, mmCount);
+                               a2found++;
+                       }
+                       if (a.getId().equals(a3.getId())) {
+                               assertEquals("Inapropriate MeetingMembers 
count", 2, mmCount);
+                               a3found++;
+                       }
                }
+               assertEquals("Inappropriate count of appointments without 
members found", 1, a1found);
+               assertEquals("Inappropriate count of appointments with 1 member 
found", 1, a2found);
+               assertEquals("Inappropriate count of appointments with 2 
members found", 1, a3found);
        }
 }

Modified: 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestGetAppointment.java
URL: 
http://svn.apache.org/viewvc/openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestGetAppointment.java?rev=1553534&r1=1553533&r2=1553534&view=diff
==============================================================================
--- 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestGetAppointment.java
 (original)
+++ 
openmeetings/trunk/singlewebapp/src/test/java/org/apache/openmeetings/test/calendar/TestGetAppointment.java
 Thu Dec 26 18:08:59 2013
@@ -18,20 +18,19 @@
  */
 package org.apache.openmeetings.test.calendar;
 
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
 
 import java.util.Calendar;
-import java.util.GregorianCalendar;
 
 import org.apache.log4j.Logger;
 import org.apache.openmeetings.db.dao.calendar.AppointmentDao;
+import org.apache.openmeetings.db.entity.calendar.Appointment;
 import org.apache.openmeetings.test.AbstractJUnitDefaults;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
-public class TestGetAppointment extends
-AbstractJUnitDefaults {
-
+public class TestGetAppointment extends AbstractJUnitDefaults {
        private static final Logger log = 
Logger.getLogger(TestGetAppointment.class);
 
        @Autowired
@@ -42,17 +41,18 @@ AbstractJUnitDefaults {
                log.debug("getAppoinment enter");
                Long userId = 1L;
                
-               Calendar starttime = GregorianCalendar.getInstance();
-
-               starttime.set(Calendar.MONTH, starttime.get(Calendar.MONTH-1));
-
-               Calendar endtime = GregorianCalendar.getInstance();
-               
-               appointmentDao.getAppointmentsByRange(userId, 
starttime.getTime(),
-                               endtime.getTime());
+               Calendar now = Calendar.getInstance();
+               Calendar a1End = Calendar.getInstance();
+               a1End.setTime(now.getTime());
+               a1End.add(Calendar.HOUR_OF_DAY, 1);
+               Appointment a1 = getAppointment(now.getTime(), a1End.getTime());
+               a1.setTitle("GetAppointment");
                
-               assertTrue(true);
+               a1 = appointmentDao.update(a1, OM_URL, userId);
                
+               Appointment a = appointmentDao.get(a1.getId());
+               assertNotNull("Failed to get Appointment By id", a);
+               assertEquals("Inapropriate MeetingMembers count", 0, 
a.getMeetingMembers() == null ? 0 : a.getMeetingMembers().size());
        }
        
 }


Reply via email to