| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 1 | package de.ids_mannheim.korap.web; |
| 2 | |
| 3 | import static org.junit.Assert.assertEquals; |
| 4 | |
| 5 | import java.net.URI; |
| 6 | |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 7 | import org.eclipse.jetty.http.HttpStatus; |
| 8 | import org.junit.Test; |
| 9 | |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 10 | import de.ids_mannheim.korap.config.SpringJerseyTest; |
| 11 | import de.ids_mannheim.korap.exceptions.KustvaktException; |
| margaretha | 96c309d | 2023-08-16 12:24:12 +0200 | [diff] [blame] | 12 | import jakarta.ws.rs.core.MediaType; |
| 13 | import jakarta.ws.rs.core.Response; |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 14 | |
| margaretha | 5c67dd5 | 2018-12-18 17:27:05 +0100 | [diff] [blame] | 15 | /** |
| 16 | * @author margaretha |
| 17 | * |
| 18 | */ |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 19 | public class ApiVersionTest extends SpringJerseyTest { |
| 20 | |
| 21 | @Test |
| 22 | public void testSearchWithoutVersion () throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 23 | Response response = target().path("api").path("search") |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 24 | .queryParam("q", "[orth=der]").queryParam("ql", "poliqarp") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 25 | .request() |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 26 | .accept(MediaType.APPLICATION_JSON).get(); |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 27 | assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus()); |
| 28 | URI location = response.getLocation(); |
| margaretha | f7abb36 | 2018-09-18 20:09:37 +0200 | [diff] [blame] | 29 | assertEquals("/api/"+API_VERSION+"/search", location.getPath()); |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | @Test |
| 33 | public void testSearchWrongVersion () throws KustvaktException { |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 34 | Response response = target().path("api").path("v0.2") |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 35 | .path("search").queryParam("q", "[orth=der]") |
| abcpro1 | 241bc4f | 2022-11-07 20:13:57 +0000 | [diff] [blame] | 36 | .queryParam("ql", "poliqarp") |
| 37 | .request() |
| 38 | .accept(MediaType.APPLICATION_JSON) |
| abcpro1 | 73fe8f2 | 2022-11-08 19:56:52 +0000 | [diff] [blame] | 39 | .get(); |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 40 | assertEquals(HttpStatus.PERMANENT_REDIRECT_308, response.getStatus()); |
| 41 | URI location = response.getLocation(); |
| margaretha | f7abb36 | 2018-09-18 20:09:37 +0200 | [diff] [blame] | 42 | assertEquals("/api/"+API_VERSION+"/search", location.getPath()); |
| margaretha | 7926adc | 2018-08-30 13:45:33 +0200 | [diff] [blame] | 43 | } |
| 44 | } |