blob: cc17b66ee1af5ca9ea58ee4ad253f4fb65851605 [file] [log] [blame]
margaretha7926adc2018-08-30 13:45:33 +02001package de.ids_mannheim.korap.web;
2
3import static org.junit.Assert.assertEquals;
4
5import java.net.URI;
6
margaretha7926adc2018-08-30 13:45:33 +02007import org.eclipse.jetty.http.HttpStatus;
8import org.junit.Test;
9
margaretha7926adc2018-08-30 13:45:33 +020010import de.ids_mannheim.korap.config.SpringJerseyTest;
11import de.ids_mannheim.korap.exceptions.KustvaktException;
margaretha96c309d2023-08-16 12:24:12 +020012import jakarta.ws.rs.core.MediaType;
13import jakarta.ws.rs.core.Response;
margaretha7926adc2018-08-30 13:45:33 +020014
margaretha5c67dd52018-12-18 17:27:05 +010015/**
16 * @author margaretha
17 *
18 */
margaretha7926adc2018-08-30 13:45:33 +020019public class ApiVersionTest extends SpringJerseyTest {
20
21 @Test
22 public void testSearchWithoutVersion () throws KustvaktException {
abcpro173fe8f22022-11-08 19:56:52 +000023 Response response = target().path("api").path("search")
margaretha7926adc2018-08-30 13:45:33 +020024 .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp")
abcpro1241bc4f2022-11-07 20:13:57 +000025 .request()
abcpro173fe8f22022-11-08 19:56:52 +000026 .accept(MediaType.APPLICATION_JSON).get();
margaretha7926adc2018-08-30 13:45:33 +020027 assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
28 URI location = response.getLocation();
margarethaf7abb362018-09-18 20:09:37 +020029 assertEquals("/api/"+API_VERSION+"/search", location.getPath());
margaretha7926adc2018-08-30 13:45:33 +020030 }
31
32 @Test
33 public void testSearchWrongVersion () throws KustvaktException {
abcpro173fe8f22022-11-08 19:56:52 +000034 Response response = target().path("api").path("v0.2")
margaretha7926adc2018-08-30 13:45:33 +020035 .path("search").queryParam("q", "[orth=der]")
abcpro1241bc4f2022-11-07 20:13:57 +000036 .queryParam("ql", "poliqarp")
37 .request()
38 .accept(MediaType.APPLICATION_JSON)
abcpro173fe8f22022-11-08 19:56:52 +000039 .get();
margaretha7926adc2018-08-30 13:45:33 +020040 assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus());
41 URI location = response.getLocation();
margarethaf7abb362018-09-18 20:09:37 +020042 assertEquals("/api/"+API_VERSION+"/search", location.getPath());
margaretha7926adc2018-08-30 13:45:33 +020043 }
44}