Files
tlw-database-tool/src/test/java/de/jeyp91/googlecalendar/TippligaGoogleEventManagerTest.java

110 lines
4.1 KiB
Java

package de.jeyp91.googlecalendar;
import com.google.api.client.util.DateTime;
import com.google.api.services.calendar.model.Event;
import de.jeyp91.tippliga.TLWMatchday;
import de.jeyp91.tippliga.TLWMatchdaysCreator;
import org.junit.Test;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static de.jeyp91.googlecalendar.TippligaGoogleEventManager.*;
import static org.junit.Assert.assertEquals;
public class TippligaGoogleEventManagerTest {
@Test
public void getAllEventsStartingFromDateTimeTest()
{
DateTime dateTime = new DateTime("2022-11-07T00:00:00");
List<Event> events = getAllEventsStartingFromDateTime(dateTime);
assertEquals("Tippliga 20. Spieltag tippen!", events.get(0).getSummary());
DateTime startExpected = new DateTime("2020-01-17T20:30:00+01:00");
DateTime startActual = events.get(0).getStart().getDateTime();
assertEquals(startExpected, startActual);
assertEquals("Tippliga 21. Spieltag tippen!", events.get(1).getSummary());
startExpected = new DateTime("2020- 01-24T20:30:00+01:00");
startActual = events.get(1).getStart().getDateTime();
assertEquals(startExpected, startActual);
}
@Test
public void createOrUpdateEventsForMatchdayTippligaTest() {
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 1, "Tippliga");
ArrayList<TLWMatchday> matchdays = creator.getMatchdays();
matchdays.forEach(TippligaGoogleEventManager::createOrUpdateEventsForMatchday);
}
@Test
public void findEventTest() {
List<Event> allEvents = getAllEvents(2023);
Event event = findEvent(allEvents, 2023, 1, 15, 1);
assert event != null;
assertEquals(event.getStart().size(), 2);
}
@Test
public void updateEventTest() {
List<Event> allEvents = getAllEvents(2023);
Event event1 = findEvent(allEvents, 2023, 1, 15, 1);
Event event2 = findEvent(allEvents, 2023, 1, 15, 2);
TLWMatchday matchday = new TLWMatchday(2023, 1, 15, 0, "2022-11-08 18:30:00", "2022-11-09 18:30:00", "", "15. Spieltag", 12);
assert event1 != null;
assert event2 != null;
updateEvent(event1, matchday, matchday.getDeliveryDate(), 1);
updateEvent(event2, matchday, matchday.getDeliveryDate2(), 2);
assertEquals(event1.size(), 18);
assertEquals(event2.size(), 18);
}
@Test
public void createOrUpdateEventsForMatchdayWTLPokalTest() {
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 48, "WTL-Pokal");
ArrayList<TLWMatchday> matchdays = creator.getMatchdays();
// createOrUpdateEventsForMatchday(matchdays.get(4));
matchdays.forEach(TippligaGoogleEventManager::createOrUpdateEventsForMatchday);
}
@Test
public void createOrUpdateEventTest() {
TLWMatchday matchday = new TLWMatchday(2023, 1, 1, 0, "2022-08-05 20:30:00", "", "", "1. Spieltag", 12);
createOrUpdateEvent(matchday, matchday.getDeliveryDate(), 1);
}
@Test
public void deleteEventTippligaTest() {
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 1, "Tippliga");
ArrayList<TLWMatchday> matchdays = creator.getMatchdays();
matchdays.forEach(tlwMatchday -> {
TippligaGoogleEventManager.deleteEvent(tlwMatchday, 1);
TippligaGoogleEventManager.deleteEvent(tlwMatchday, 2);
TippligaGoogleEventManager.deleteEvent(tlwMatchday, 3);
});
}
@Test
public void deleteEventWTLPokalTest() {
TLWMatchdaysCreator creator = new TLWMatchdaysCreator(2022, 48, "WTL-Pokal");
ArrayList<TLWMatchday> matchdays = creator.getMatchdays();
matchdays.forEach(tlwMatchday -> {
TippligaGoogleEventManager.deleteEvent(tlwMatchday, 1);
TippligaGoogleEventManager.deleteEvent(tlwMatchday, 2);
TippligaGoogleEventManager.deleteEvent(tlwMatchday, 3);
});
}
@Test
public void deleteAllEventsTest() throws IOException {
TippligaGoogleEventManager.deleteAllEvents(2023);
}
}