Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions src/main/java/org/pkwmtt/timetable/TimetableCacheService.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ public TimetableDTO getGeneralGroupSchedule (String generalGroupName)
public Map<String, String> getGeneralGroupsMap () throws WebPageContentNotAvailableException {
var url = mainUrl + "lista.html";
var html = fetchData(url);
String json = cache.get("generalGroupMap", () -> mapper.writeValueAsString(parser.parseGeneralGroups(html)));
String json = cache.get(
"generalGroupMap",
() -> mapper.writeValueAsString(parser.parseGeneralGroups(html))
);

return getMappedValue(
json, "generalGroupList", cache, new TypeReference<>() {
Expand All @@ -88,6 +91,30 @@ public Map<String, String> getGeneralGroupsMap () throws WebPageContentNotAvaila
* @throws WebPageContentNotAvailableException if hour definition page can't be loaded
*/
public List<String> getListOfHours () throws WebPageContentNotAvailableException {

//Hard coded values for hours, caused by inconsistent timetable hours range
return List.of(
"7:30-8:15",
"8:15-9:00",
"9:15-10:00",
"10:00-10:45",
"11:00-11:45",
"11:45-12:30",
"12:45-13:30",
"13:30-14:15",
"14:30-15:15",
"15:15-16:00",
"16:15-17:00",
"17:00-17:45",
"18:00-18:45",
"18:45-19:30",
"19:45-20:30",
"20:30-21:15"
);
}

@SuppressWarnings("unused")
private List<String> fetchListOfHours () {
String url = mainUrl + "plany/o25.html";
String json = cache.get("hourList", () -> mapper.writeValueAsString(parser.parseHours(fetchData(url))));

Expand All @@ -97,9 +124,8 @@ public List<String> getListOfHours () throws WebPageContentNotAvailableException
);

//Delete useless spaces
result = result.stream().map(item -> item.replaceAll(" ", "")).toList();
return result.stream().map(item -> item.replaceAll(" ", "")).toList();

return result;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions src/test/java/org/pkwmtt/cache/CacheConfigTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.pkwmtt.cache;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.pkwmtt.ValuesForTest;
import org.pkwmtt.timetable.TimetableCacheService;
Expand Down Expand Up @@ -62,6 +63,7 @@ void testCacheKeyPresent_Schedule () {
}

@Test
@Disabled("hard coded hours")
void testCacheKeyPresent_HoursList () {
//given

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.pkwmtt.ValuesForTest;
import org.pkwmtt.cache.CacheInspector;
Expand Down Expand Up @@ -39,6 +40,7 @@ public void initWireMock () {
}

@Test
@Disabled("hard coded values")
public void shouldHourListBePresentInCache () {
//given
var key = "hourList";
Expand Down