👽️ Update Savoy ticket filter
[rhynodge.git] / src / test / java / net / pterodactylus / rhynodge / filters / webpages / savoy / MovieExtractorTest.java
1 package net.pterodactylus.rhynodge.filters.webpages.savoy;
2
3 import kotlin.Pair;
4 import org.hamcrest.Description;
5 import org.hamcrest.Matcher;
6 import org.hamcrest.TypeSafeDiagnosingMatcher;
7 import org.jsoup.nodes.Document;
8 import org.junit.Test;
9
10 import java.io.IOException;
11 import java.io.InputStream;
12 import java.time.LocalDateTime;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.List;
16 import java.util.Optional;
17
18 import static java.time.LocalDateTime.of;
19 import static java.util.Optional.empty;
20 import static org.hamcrest.MatcherAssert.assertThat;
21 import static org.hamcrest.Matchers.containsInAnyOrder;
22 import static org.jsoup.Jsoup.parse;
23
24 /**
25  * Unit test for {@link MovieExtractor}.
26  *
27  * @author <a href="mailto:bombe@pterodactylus.net">David â€˜Bombe’ Roden</a>
28  */
29 public class MovieExtractorTest {
30
31         private final Document document;
32         private final MovieExtractor movieExtractor = new MovieExtractor();
33         private Collection<Movie> movies;
34
35         public MovieExtractorTest() throws IOException {
36                 document = loadDocument("savoy.html", "https://savoy.premiumkino.de/programmwoche");
37                 movies = movieExtractor.getMovies(document);
38         }
39
40         private Document loadDocument(String resourceName, String baseUri) throws IOException {
41                 InputStream inputStream = getClass().getResourceAsStream(resourceName);
42                 return parse(inputStream, "UTF-8", baseUri);
43         }
44
45         @Test
46         public void moviesAreLocated() throws IOException {
47                 assertThat(movies, containsInAnyOrder(
48                                 movie("All of Us Strangers",
49                                                 new Pair<>(of(2024, 2, 9, 16, 15), "https://savoy.premiumkino.de/vorstellung/all-of-us-strangers/20240209/1615/HkKdhlHMvtfSMy1fqYYtYuVdgGIKtnT7i7ddY5jzRfY~"),
50                                                 new Pair<>(of(2024, 2, 10, 22, 15), "https://savoy.premiumkino.de/vorstellung/all-of-us-strangers/20240210/2215/znWqm8FQUNSbrODY_A0jw8Au2nW6uSqbFE7Co8UgQv0~"),
51                                                 new Pair<>(of(2024, 2, 11, 20, 15), "https://savoy.premiumkino.de/vorstellung/all-of-us-strangers/20240211/2015/I642oTHBKpy7sz2RULHIQK6cykSCPi57_c0TApiKbUk~"),
52                                                 new Pair<>(of(2024, 2, 12, 17, 15), "https://savoy.premiumkino.de/vorstellung/all-of-us-strangers/20240212/1715/2lEiqVP1hueXZhWwy9FSUfRgFKf8iTCKRMdJOTfBf8A~"),
53                                                 new Pair<>(of(2024, 2, 13, 20, 30), "https://savoy.premiumkino.de/vorstellung/all-of-us-strangers/20240213/2030/M0mIWdKm5gZkan5na6zOVFBzsHWAHhqod8RCmG2Fr0Y~"),
54                                                 new Pair<>(of(2024, 2, 14, 14, 30), "https://savoy.premiumkino.de/vorstellung/all-of-us-strangers/20240214/1430/VZhgxh4PZutWWlLPEAe9dfOUJkB3sLnXzWoduICJYTk~")
55                                 ),
56                                 movie("Dune",
57                                                 new Pair<>(of(2024, 2, 9, 19, 0), "https://savoy.premiumkino.de/vorstellung/dune/20240209/1900/o9jDuan4yyxaW7-Jg3hCJpiAM4CLZei8J2IX-O5-hA0~"),
58                                                 new Pair<>(of(2024, 2, 10, 15, 30), "https://savoy.premiumkino.de/vorstellung/dune/20240210/1530/jXbZnYD8R5djVnj3Ojjcsc9qdSJ0JBMVhn7PeP88HyY~"),
59                                                 new Pair<>(of(2024, 2, 11, 13, 30), "https://savoy.premiumkino.de/vorstellung/dune/20240211/1330/aJmlM8wOaGl_jtuWDvWG9TF7RR1zRpNrSZeArCBhn90~"),
60                                                 new Pair<>(of(2024, 2, 12, 20, 0), "https://savoy.premiumkino.de/vorstellung/dune/20240212/2000/2KLOCZy5zU060zKj-4zafxm3oalEyT4tNi2Fxnw5D7E~"),
61                                                 new Pair<>(of(2024, 2, 13, 17, 0), "https://savoy.premiumkino.de/vorstellung/dune/20240213/1700/QCphOtH-WrZ2tRbENwaxXPskrN2gH3I8dHR0Y5L3l0Y~")
62                                 ),
63                                 movie("SAVOY Sneak-Preview",
64                                                 new Pair<>(of(2024, 2, 9, 22, 30), "https://savoy.premiumkino.de/vorstellung/sneak-preview/20240209/2230/GtYBcOR_Jy7a8xDxwwPHI0wfY_v_Ep2P6rV0w4wJ7SM~"),
65                                                 new Pair<>(of(2024, 2, 16, 22, 0), "https://savoy.premiumkino.de/vorstellung/sneak-preview/20240216/2200/ZRC7iir9Hu8nIpH1PsiA_UDvckcj7yGqgMEYXHAs9Qw~")
66                                 ),
67                                 movie("Der Junge und der Reiher",
68                                                 new Pair<>(of(2024, 2, 10, 12, 30), "https://savoy.premiumkino.de/vorstellung/der-junge-und-der-reiher/20240210/1230/F0atZERI4Gssj3LGC-2fQlLF3rM9Uk8IbpOzHaXyx7w~")
69                                 ),
70                                 movie("Poor Things",
71                                                 new Pair<>(of(2024, 2, 10, 19, 0), "https://savoy.premiumkino.de/vorstellung/poor-things/20240210/1900/SqolavKZAlBMZH_JAN-OqdZqowBv-aRqhPGHvPTphao~"),
72                                                 new Pair<>(of(2024, 2, 11, 17, 0), "https://savoy.premiumkino.de/vorstellung/poor-things/20240211/1700/UrS33k-jY7_ZAsm4B7wydy0SBfdVjdd73On68HtIy9E~"),
73                                                 new Pair<>(of(2024, 2, 13, 13, 45), "https://savoy.premiumkino.de/vorstellung/poor-things/20240213/1345/gma7KCzuaJQCSoBm8NMJb3ATjtMISm4M9IiwiVNpXpw~"),
74                                                 new Pair<>(of(2024, 2, 14, 17, 15), "https://savoy.premiumkino.de/vorstellung/poor-things/20240214/1715/cBjQj4qRrJaSX3m_acvfxNL1Tclg0Rrt_X63Md0rkEw~")
75                                 ),
76                                 movie("Vergiss mein nicht- Eternal Sunshine of the Spotless Mind",
77                                                 new Pair<>(of(2024, 2, 14, 20, 30), "https://savoy.premiumkino.de/vorstellung/vergiss-mein-nicht-eternal-sunshine-of-the-spotless-mind/20240214/2030/QqoCtd4ls09AD04rGSNh8qPkf02rcRzp2wFfF2BoobE~")
78                                 ),
79                                 movie("Bob Marley: One Love",
80                                                 new Pair<>(of(2024, 2, 15, 20, 15), "https://savoy.premiumkino.de/vorstellung/bob-marley-one-love/20240215/2015/q4dxyPDNVvZDEeIuh1r9Y4OJ7UK36CKSr2d7p3h9LMs~")
81                                 ),
82                                 movie("The Hateful 8",
83                                                 new Pair<>(of(2024, 2, 18, 19, 45), "https://savoy.premiumkino.de/vorstellung/the-hateful-8/20240218/1945/dusKDbTYgF79OipGmQO0Q4P5K02rclkjIV9At8qKfOA~")
84                                 ),
85                                 movie("Prinzessin Mononoke",
86                                                 new Pair<>(of(2024, 2, 19, 20, 15), "https://savoy.premiumkino.de/vorstellung/prinzessin-mononoke/20240219/2015/LmbLtOrTZxBgPlBMzoRZ4_C-PfO64GeXNIKr5KGs-2M~"),
87                                                 new Pair<>(of(2024, 2, 22, 20, 15), "https://savoy.premiumkino.de/vorstellung/prinzessin-mononoke/20240222/2015/mvbGK2fA5AgPbADOzm7sqFYYzm2qdqqdwqdLu4rMPrg~")
88                                 ),
89                                 movie("Das fĂźnfte Element (Best of Cinema)",
90                                                 new Pair<>(of(2024, 2, 20, 20, 30), "https://savoy.premiumkino.de/vorstellung/das-fuenfte-element-best-of-cinema/20240220/2030/QcJZ5Yh8P2j_HKLSP8cjcXsqkbdqYdYGTexCF3RF2R4~")
91                                 ),
92                                 movie("Heaven Can Wait - wir leben jetzt",
93                                                 new Pair<>(of(2024, 2, 21, 11, 0), "https://savoy.premiumkino.de/vorstellung/heaven-can-wait-wir-leben-jetzt/20240221/1100/GW7pwEYabwN3-e8uTGmSPTfdbyXoKe4la-B2L1SI8XI~")
94                                 ),
95                                 movie("Demon Slayer: Kimetsu no yaiba - Zum Training der Säulen",
96                                                 new Pair<>(of(2024, 2, 27, 20, 30), "https://savoy.premiumkino.de/vorstellung/demon-slayer-kimetsu-no-yaiba-zum-training-der-saeulen/20240227/2030/UsAsz9NQPZGfdyLelrAHZ50MXeoElhNIPcgg3unBR0o~")
97                                 ),
98                                 movie("Double Feature DUNE 1&2",
99                                                 new Pair<>(of(2024, 2, 28, 17, 30), "https://savoy.premiumkino.de/vorstellung/double-feature-dune-1und2/20240228/1730/Ni6Yo0fA4k7gEZiJB8Cnq33Axjnw85JBG2lBIVRwYok~"),
100                                                 new Pair<>(of(2024, 3, 3, 10, 0), "https://savoy.premiumkino.de/vorstellung/double-feature-dune-1und2/20240303/1000/AXcH4nnYJB9Ar0aR5zFl3Bfa238POna3UVY66_nHL6c~")
101                                 ),
102                                 movie("Dune: Part Two",
103                                                 new Pair<>(of(2024, 2, 29, 12, 30), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240229/1230/Osq78ODtBKchFFx1HgAmEPAAIWLC6JgxWqC638UaRws~"),
104                                                 new Pair<>(of(2024, 2, 29, 16, 15), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240229/1615/hJ3kXaFB-LjfZu2pYBVx0R_2UoqOJANwWX_AS4KW6FI~"),
105                                                 new Pair<>(of(2024, 2, 29, 20, 0), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240229/2000/EwA7Z5KlKNnIr0e4o_tXGpYp6xN90juBl92wcTVIZ-Q~"),
106                                                 new Pair<>(of(2024, 3, 1, 13, 45), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240301/1345/-kxmskcNJYhWCr9z5MfK0p2w2qlu3CDu8rVtDLmxSQA~"),
107                                                 new Pair<>(of(2024, 3, 1, 17, 30), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240301/1730/yXQQSsMug0nRQGN1BNpBXEA3Udf_asggPHwk4a4zdBE~"),
108                                                 new Pair<>(of(2024, 3, 1, 21, 15), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240301/2115/FN7huOUR4eLA-2EKxi9lTykJUFQNYc4LTHRHtyDlAgo~"),
109                                                 new Pair<>(of(2024, 3, 2, 10, 0), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240302/1000/84ntwEOFY6aqexIEd9tXESW6qrl9aXk-x2l-LsHWvfk~"),
110                                                 new Pair<>(of(2024, 3, 2, 13, 45), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240302/1345/9lxXFXQU6FHmyv1WpKX5ETpd24daZT16hNvXUJEUwik~"),
111                                                 new Pair<>(of(2024, 3, 2, 17, 30), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240302/1730/ynmy2dsbgYygz2hPUS_vx-9YL13m2KZ0-9tw37XuBMQ~"),
112                                                 new Pair<>(of(2024, 3, 2, 21, 15), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240302/2115/rH8i8BAFaaDjfNJBbZjj_7CV2dzOWcEOzyL618KYQVo~"),
113                                                 new Pair<>(of(2024, 3, 3, 16, 30), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240303/1630/fU4VOzrp34B48KdsB1vpo2pi18sWSo2Tkknk03sO4HY~"),
114                                                 new Pair<>(of(2024, 3, 3, 20, 15), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240303/2015/b1yBhvNosqm0nbWju1aCfb7LRBhRnMo_Y_h0VLZwmr0~"),
115                                                 new Pair<>(of(2024, 3, 4, 12, 30), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240304/1230/DcGmb0KshRY0qv55Tuo4ydiJswd1H9wonrYGF1zGqQ0~"),
116                                                 new Pair<>(of(2024, 3, 4, 16, 15), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240304/1615/BEd4wzePEH_Sxxuum4cXpsoOubN8fA6oecrWpwGJpcc~"),
117                                                 new Pair<>(of(2024, 3, 4, 20, 0), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240304/2000/7Qldfc-0lDNALUw_lzuzM3KfarQWQAUi91qz2cMrNDk~"),
118                                                 new Pair<>(of(2024, 3, 5, 12, 30), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240305/1230/QiP6Vvb9htMnFyTSUZRte1b_Ykw_n_yzaGpErBLFjOE~"),
119                                                 new Pair<>(of(2024, 3, 5, 16, 15), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240305/1615/eY9ufKz1UM777apocN37PLvlsWwSJXc0xu7LMHecCbk~"),
120                                                 new Pair<>(of(2024, 3, 5, 20, 0), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240305/2000/2gqVyU2_3NXv_fZiiAxV8Utom82nPW52kzVxzUDrMkI~"),
121                                                 new Pair<>(of(2024, 3, 6, 16, 0), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240306/1600/Y8x2dIEq1QbEpZf7Td-6-3xqg-d4iDQU9p1fIjxJB0M~"),
122                                                 new Pair<>(of(2024, 3, 6, 19, 45), "https://savoy.premiumkino.de/vorstellung/dune-part-two/20240306/1945/mSiOQk7DuM02IdmaVIvsv5nechCpRkWZwsK37hoXTyg~")
123                                 ),
124                                 movie("791 KM",
125                                                 new Pair<>(of(2024, 3, 6, 11, 0), "https://savoy.premiumkino.de/vorstellung/791-km/20240306/1100/Mcvtz3tawhaIuyCtLtBkHwt6EI8b7oGXwh5OV4YWwNQ~")
126                                 ),
127                                 movie("Following",
128                                                 new Pair<>(of(2024, 3, 9, 12, 0), "https://savoy.premiumkino.de/vorstellung/following/20240309/1200/-Aetrz3gC8l4rgVfGc98XXU7B87mTA4RCbWCgZuXHzc~")
129                                 ),
130                                 movie("Donnie Darko (Best of Cinema)",
131                                                 new Pair<>(of(2024, 3, 16, 22, 15), "https://savoy.premiumkino.de/vorstellung/donnie-darko-best-of-cinema/20240316/2215/ZIBOwCyKuZ7A6OyYZWQ1AqF9O487dY_LAMmURYrGqUs~")
132                                 ),
133                                 movie("NT: Vanya",
134                                                 new Pair<>(of(2024, 3, 18, 20, 30), "https://savoy.premiumkino.de/vorstellung/nt-vanya/20240318/2030/X9L2eAn_XElOtZRg7u4eiQ6kUCqcuJhrwQ5T76OAt2s~"),
135                                                 new Pair<>(of(2024, 3, 23, 22, 15), "https://savoy.premiumkino.de/vorstellung/nt-vanya/20240323/2215/xXgXAH_I7xX3GsQ4eA4rZsOOrJqAtK0hCCXexFMj0Fk~"),
136                                                 new Pair<>(of(2024, 4, 8, 20, 30), "https://savoy.premiumkino.de/vorstellung/nt-vanya/20240408/2030/PDQ-R_ltFWo8QAn-BbloxETvgegcTyaQyCZrG_MwQfo~")
137                                 ),
138                                 movie("No Country For Old Men",
139                                                 new Pair<>(of(2024, 3, 26, 20, 15), "https://savoy.premiumkino.de/vorstellung/no-country-for-old-men/20240326/2015/jtZD6DfmChngY1mDGWlaaV8kZdUPL_QT2Fh-t0clBpU~")
140                                 ),
141                                 movie("Lisa Achatzi: Vom Traum zum Trauma - und zurĂźck",
142                                                 new Pair<>(of(2024, 4, 14, 12, 0), "https://savoy.premiumkino.de/vorstellung/lisa-achatzi-vom-traum-zum-trauma-und-zurueck/20240414/1200/MOLgymd988D7m8ZOvhM75aDc5suv3VO9aHobbLsaOgQ~")
143                                 ),
144                                 movie("Movie Quiz: Test Your Movie Knowledge",
145                                                 new Pair<>(of(2024, 4, 15, 20, 15), "https://savoy.premiumkino.de/vorstellung/movie-quiz-test-your-movie-knowledge/20240415/2015/DMAaL86yGoobZhPTDdU2ksO9RUTFoPCiQKGOY7TO6tg~")
146                                 )
147                 ));
148         }
149
150         private Matcher<Movie> movie(String name, Pair<LocalDateTime, String>... presentationTimesAndLinks) {
151                 return new TypeSafeDiagnosingMatcher<Movie>() {
152                         @Override
153                         protected boolean matchesSafely(Movie movie, Description mismatchDescription) {
154                                 if (!movie.getName().equals(name)) {
155                                         mismatchDescription.appendText("movie is named ").appendValue(movie.getName());
156                                         return false;
157                                 }
158                                 List<TicketLink> ticketLinks = new ArrayList<>(movie.getTicketLinks());
159                                 if (ticketLinks.size() != presentationTimesAndLinks.length) {
160                                         mismatchDescription.appendText("has ").appendValue(ticketLinks.size()).appendText(" presentations");
161                                         return false;
162                                 }
163                                 for (Pair<LocalDateTime, String> presentationTimeAndLink : presentationTimesAndLinks) {
164                                         Optional<TicketLink> foundTicketLink = empty();
165                                         for (TicketLink ticketLink : ticketLinks) {
166                                                 if (ticketLink.getPresentationTime().equals(presentationTimeAndLink.getFirst()) && ticketLink.getLink().equals(presentationTimeAndLink.getSecond())) {
167                                                         foundTicketLink = Optional.of(ticketLink);
168                                                         break;
169                                                 }
170                                         }
171                                         if (!foundTicketLink.isPresent()) {
172                                                 mismatchDescription.appendValue("has no presentation at ").appendValue(presentationTimeAndLink.getFirst());
173                                                 return false;
174                                         }
175                                         ticketLinks.remove(foundTicketLink.get());
176                                 }
177                                 if (!ticketLinks.isEmpty()) {
178                                         mismatchDescription.appendText("has no presentations at ").appendValueList("", ", ", "", ticketLinks);
179                                         return false;
180                                 }
181                                 return true;
182                         }
183
184                         @Override
185                         public void describeTo(Description description) {
186                                 description.appendText("movie with name ").appendValue(name);
187                                 description.appendText(" and ").appendValue(presentationTimesAndLinks.length).appendText(" presentations");
188                         }
189                 };
190         }
191
192 }