Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
EricKruse committed Aug 7, 2022
2 parents e48543a + f832233 commit f014a79
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 68 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import java.util.Optional;

public class s_Appointment extends sessionParentClass {
/** function to create a new appointment
*/
void createAppointment(String _Title,
boolean _isPublic,
int _Semester,
Expand Down Expand Up @@ -146,7 +148,7 @@ public List<Appointment> listAllAppointments() {
* @param personId show appointments from one organizer
* @return list of type <Appointment> containing matching appointments
*/
public List<Appointment> searchAppointments(String searchTerm, Integer semester, Timestamp fromDate, Timestamp toDate, BigInteger courseID,
public List<Appointment> searchAppointments(String searchTerm, Integer semester, LocalDateTime fromDate, LocalDateTime toDate, BigInteger courseID,
BigInteger facultyID, BigInteger locationID, BigInteger personId) {
getSessionFactory();
try (Session session = sessionFactory.openSession()) {
Expand All @@ -160,22 +162,22 @@ public List<Appointment> searchAppointments(String searchTerm, Integer semester,
predicates.add(cb.like(root.get("Title"), "%" + searchTerm + "%"));
}
if (fromDate != null && toDate != null) {
predicates.add(cb.or(cb.lessThan(root.get("Start"), toDate), cb.greaterThan(root.get("End"), fromDate )));
predicates.add(cb.and(cb.lessThan(root.get("startDateTime"), toDate), cb.greaterThan(root.get("endDateTime"), fromDate )));
}
if (semester != null) {
predicates.add(cb.equal(root.get("Semester"), semester));
}
if (courseID != null) {
predicates.add(cb.equal(root.get("COURSE_ID"), courseID));
predicates.add(cb.equal(root.get("CourseID"), courseID));
}
if (facultyID != null) {
predicates.add(cb.equal(root.get("FACULTY_ID"), facultyID));
predicates.add(cb.equal(root.get("FacultyID"), facultyID));
}
if (locationID != null) {
predicates.add(cb.equal(root.get("LOCATION_ID"), locationID));
predicates.add(cb.equal(root.get("LocationID"), locationID));
}
if (personId != null) {
predicates.add(cb.equal(root.get("PERSON_ID"), personId));
predicates.add(cb.equal(root.get("PersonID"), personId));
}
Predicate[] array = predicates.toArray(new Predicate[0]);
cr.select(root).where(array);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.junit.jupiter.api.Test;

import java.math.BigInteger;
import java.sql.Timestamp;
import java.time.LocalDateTime;


Expand All @@ -28,7 +27,9 @@ void createCourse() {
}



/**
* verifying that the number of total appointments increases whenever an appointment is added
*/
@Test
void createSomeAppointments() {

Expand All @@ -38,21 +39,6 @@ void createSomeAppointments() {
LocalDateTime.parse("2022-07-04T20:34:50.63")
,45,4,6,2);

var all_appointments_list = session.listAllAppointments();
Assertions.assertEquals(all_appointments_list.size(), 1);

session.createAppointment("IT-KOM 2022", true, 2,
LocalDateTime.parse("2022-02-04T19:34:50.63"),
LocalDateTime.parse("2022-02-04T21:34:50.63")
,54,2,6,2);

all_appointments_list = session.listAllAppointments();
Assertions.assertEquals(all_appointments_list.size(), 2);

}
@Test
void searchAppointments() {
var session = new s_Appointment();
session.createAppointment("Klausur Mathe 2", true, 2,
LocalDateTime.parse("2022-01-04T19:34:50.63"),
LocalDateTime.parse("2022-01-04T21:34:50.63")
Expand All @@ -73,47 +59,61 @@ void searchAppointments() {
LocalDateTime.parse("2022-03-02T21:34:50.63"),
7,4,6,7);

var all_appointments_list = session.listAllAppointments();
var numberOfAppointments = all_appointments_list.size();

session.createAppointment("IT-KOM 2022", true, 2,
LocalDateTime.parse("2022-02-04T19:34:50.63"),
LocalDateTime.parse("2022-02-04T21:34:50.63")
,54,2,6,2);

all_appointments_list = session.listAllAppointments();
Assertions.assertEquals(all_appointments_list.size(), numberOfAppointments + 1);

}

/**
* testing the searchAppointments function
*/
@Test
void searchAppointments() {
var session = new s_Appointment();


var searchResults = session.searchAppointments("Klausur",2,null,null,null, null,null,null);
Assertions.assertEquals(searchResults.size(), 2);
Assertions.assertNotEquals(searchResults.size(), 0);

searchResults = session.searchAppointments("Klausur",3,null,null,null, null,null,null);
Assertions.assertEquals(searchResults.size(), 0);

for (Appointment result : searchResults) {
Assertions.assertTrue(result.toString().contains("Semester = 2"));
Assertions.assertTrue(result.toString().contains("Klausur"));}

searchResults = session.searchAppointments(null,2,null,null,null,null,null,null);
Assertions.assertEquals(searchResults.size(), 3);
searchResults = session.searchAppointments(null,2,LocalDateTime.parse("2037-04-02T19:34:50.63"),LocalDateTime.parse("2038-04-02T19:34:50.63"),null,null,null,null);
Assertions.assertEquals(searchResults.size(), 0);
for (Appointment result : searchResults) {
Assertions.assertTrue(result.toString().contains("Semester = 2"));}

searchResults = session.searchAppointments(null,4,null,null,null,null,null,null);
Assertions.assertEquals(searchResults.size(), 1);
searchResults = session.searchAppointments(null,4, LocalDateTime.parse("2022-04-02T19:34:50.63"),LocalDateTime.parse("2022-05-02T19:34:50.63"),null,null,null,null);
Assertions.assertNotEquals(searchResults.size(), 0);
for (Appointment result : searchResults) {
Assertions.assertTrue(result.toString().contains("Semester = 4"));}

session.changeAppointment(3, null,true,2,null,null
,null,null,null,null);

searchResults = session.searchAppointments("Graphentheorie",2,null,null,null, null,null,null);
Assertions.assertEquals(searchResults.size(), 1);
}

/**
* changing some attributes fron existing appointment and verifying the results
*/
@Test
void ChangeAttributes(){
var session = new s_Appointment();

session.createAppointment("Klausur Graphentheorie", true, 4,
LocalDateTime.parse("2022-04-02T19:34:50.63"),
LocalDateTime.parse("2022-04-02T21:34:50.63")
,2,4,6,3);
var searchResults = session.searchAppointments("Klausur Graphentheorie",4,null,null,null, null,null,null);
Assertions.assertEquals(searchResults.size(), 1);

session.changeAppointment(1, "Klausur Spanisch",null,2,null,null
,null,null,null,null);

searchResults = session.searchAppointments("Klausur Spanisch",2,Timestamp.valueOf(LocalDateTime.parse("2022-04-02T19:34:50.63")),null,null, null,null,null);
Assertions.assertEquals(searchResults.size(), 1);

searchResults = session.searchAppointments("Klausur Graphentheorie",4, null,null,null, null,null,null);
Assertions.assertEquals(searchResults.size(), 0);
var searchResults = session.searchAppointments("Klausur Spanisch",2,LocalDateTime.parse("2022-04-02T19:34:50.63"),null,null, null,null,null);
Assertions.assertNotEquals(searchResults.size(), 0);

}
}

This file was deleted.

0 comments on commit f014a79

Please sign in to comment.