Package appointment.test

Source Code of appointment.test.AppointmentCollisionTest

package appointment.test;

import static org.junit.Assert.assertEquals;

import java.util.Calendar;
import java.util.Date;
import java.util.List;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import appointment.core.IAddAppointmentRemote;
import appointment.core.IRegisterRemote;
import appointment.core.IRemoveUserRemote;
import appointment.core.IViewAppointmentRemote;
import appointment.helper.BeanConnector;
import appointment.objects.AppointmentState;
import appointment.test.objects.TestUser;

public class AppointmentCollisionTest {
  private IAddAppointmentRemote addAppointmentBean;
  private IRegisterRemote registerUserBean;
  private IRemoveUserRemote removeUserBean;
  private IViewAppointmentRemote viewAppointmentBean;
  private TestUser user1;
  private TestUser user2;

  @Before
  public void setUp() {

    registerUserBean = BeanConnector.getBean("IRegister/remote",
        IRegisterRemote.class);

    addAppointmentBean = BeanConnector.getBean("IAddAppointment/remote",
        IAddAppointmentRemote.class);

    viewAppointmentBean = BeanConnector.getBean("IViewAppointment/remote",
        IViewAppointmentRemote.class);

    // Testnutzerobjekte anlegen
    user1 = new TestUser("Horst", "blubb");
    user2 = new TestUser("Hans", "bla");

    // Nutzer registrieren
    registerUserBean.register(user1.name, "test@test.de", user1.password);
    registerUserBean.register(user2.name, "test@tester.de", user2.password);
  }

  @Test
  public void singleCollisonTest() {

    // erstes Appointment
    Date start = new Date();
    Date end = new Date();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR, 2);
    end = cal.getTime();

    Boolean appointmentAdded = false;

    appointmentAdded = addAppointmentBean.addAppointment(user1.name, start,
        end, "test_title1", "should be public",
        AppointmentState.BLOCKED, true);

    assertEquals(true, appointmentAdded);

    long appointmentId = viewAppointmentBean.getAppointments(user1.name)
        .get(0);

    assertEquals("test_title1", viewAppointmentBean.getTitle(appointmentId));

    // zweites Appointment
    Date start2 = new Date();
    Date end2 = new Date();

    Calendar cal2 = Calendar.getInstance();
    cal2.add(Calendar.HOUR, 1);
    start2 = cal2.getTime();
    cal2.add(Calendar.HOUR, 4);
    end2 = cal2.getTime();

    List<Long> appOverlapIdList = addAppointmentBean
        .getOverlappedAppointments(user1.name, start2, end2,
            AppointmentState.BLOCKED);

    // Titel des �berlappenden Termins
    assertEquals("test_title1",
        viewAppointmentBean.getTitle(appOverlapIdList.get(0)));
  }

  @Test
  public void multipleCollisonTest() {

    // erstes Appointment
    Date start = new Date();
    Date end = new Date();

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.HOUR_OF_DAY, 2);
    end = cal.getTime();

    Boolean appointmentAdded = false;

    appointmentAdded = addAppointmentBean.addAppointment(user1.name, start,
        end, "test_title1", "should be public",
        AppointmentState.BLOCKED, true);

    // wird normal angelegt
    assertEquals(true, appointmentAdded);

    long appointmentId = viewAppointmentBean.getAppointments(user1.name)
        .get(0);

    assertEquals("test_title1", viewAppointmentBean.getTitle(appointmentId));
   
    // zweites Appointment
    Date start2 = new Date();
    Date end2 = new Date();

    Calendar cal2 = Calendar.getInstance();
    cal2.add(Calendar.HOUR_OF_DAY, 3);
    start2 = cal2.getTime();
    cal2.add(Calendar.HOUR_OF_DAY, 6);
    end2 = cal2.getTime();

    Boolean appointmentAdded2 = false;

    appointmentAdded2 = addAppointmentBean.addAppointment(user1.name,
        start2, end2, "test_title3", "should be public",
        AppointmentState.BLOCKED, true);

    // wird normal angelegt
    assertEquals(true, appointmentAdded2);
   
   
    // drittes Appointment
    Date start3 = new Date();
    Date end3 = new Date();

    Calendar cal3 = Calendar.getInstance();
    cal3.add(Calendar.HOUR_OF_DAY, 7);
    start3 = cal3.getTime();
    cal3.add(Calendar.HOUR_OF_DAY, 2);
    end3 = cal3.getTime();

    Boolean appointmentAdded3 = false;

    appointmentAdded3 = addAppointmentBean.addAppointment(user1.name,
        start3, end3, "test_title3", "should be public",
        AppointmentState.BLOCKED, true);

    // wird normal angelegt
    assertEquals(true, appointmentAdded3);

    //viertes Appointment
    Date start4 = new Date();
    Date end4 = new Date();

    Calendar cal4 = Calendar.getInstance();
    cal4.add(Calendar.HOUR_OF_DAY, 1);
    start4 = cal4.getTime();
    cal4.add(Calendar.HOUR_OF_DAY, 7);
    end4 = cal4.getTime();

    List<Long> appOverlapIdList = addAppointmentBean
        .getOverlappedAppointments(user1.name, start4, end4,
            AppointmentState.BLOCKED);

    // Kollision mit den zwei ersten Terminen
    assertEquals(3, appOverlapIdList.size());

  }

  @After
  public void tearDown() {

    removeUserBean = BeanConnector.getBean("IRemoveUser/remote",
        IRemoveUserRemote.class);

    removeUserBean.remove(user1.name);
    removeUserBean.remove(user2.name);

  }
}
TOP

Related Classes of appointment.test.AppointmentCollisionTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.