|
4 | 4 | import com.fasterxml.jackson.databind.JsonNode; |
5 | 5 | import com.fasterxml.jackson.databind.ObjectMapper; |
6 | 6 | import io.quarkus.test.InjectMock; |
| 7 | +import jakarta.inject.Inject; |
7 | 8 | import java.io.ByteArrayOutputStream; |
8 | 9 | import java.io.IOException; |
9 | 10 | import java.net.URI; |
|
12 | 13 | import java.net.http.HttpResponse; |
13 | 14 | import java.util.zip.ZipEntry; |
14 | 15 | import java.util.zip.ZipOutputStream; |
| 16 | +import org.eclipse.microprofile.config.inject.ConfigProperty; |
15 | 17 |
|
16 | 18 | public abstract class EndpointTest { |
17 | 19 | @InjectMock protected ScicatClient scicatClient; |
18 | 20 |
|
| 21 | + @Inject |
| 22 | + @ConfigProperty(name = "scicat.v4") |
| 23 | + boolean backendV4; |
| 24 | + |
| 25 | + private HttpClient client = HttpClient.newHttpClient(); |
| 26 | + private final String loginPayload = "{\"username\":\"rocrate\", \"password\":\"rocrate\"}"; |
| 27 | + private ObjectMapper objectMapper = new ObjectMapper(); |
| 28 | + |
19 | 29 | protected String accessToken = ""; |
20 | 30 |
|
21 | 31 | public static String CONTENT_TYPE_JSON_RES = "application/json;charset=UTF-8"; |
22 | 32 |
|
23 | 33 | public String login() { |
24 | 34 | try { |
25 | | - String url = "http://backend.localhost/api/v3/Users/login"; |
26 | | - String jsonInputString = "{\"username\":\"rocrate\", \"password\":\"rocrate\"}"; |
27 | | - HttpClient client = HttpClient.newHttpClient(); |
| 35 | + String url = "http://backend.localhost/api/v3/" + (backendV4 ? "auth" : "Users") + "/login"; |
28 | 36 | HttpRequest request = |
29 | 37 | HttpRequest.newBuilder() |
30 | 38 | .uri(URI.create(url)) |
31 | 39 | .header("Content-Type", "application/json") |
32 | 40 | .header("Accept", "application/json") |
33 | | - .POST(HttpRequest.BodyPublishers.ofString(jsonInputString)) |
| 41 | + .POST(HttpRequest.BodyPublishers.ofString(loginPayload)) |
34 | 42 | .build(); |
35 | 43 | HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString()); |
36 | | - ObjectMapper objectMapper = new ObjectMapper(); |
37 | 44 | JsonNode jsonResponse = objectMapper.readTree(response.body()); |
38 | | - return jsonResponse.get("id").asText(); |
| 45 | + return jsonResponse.get(backendV4 ? "access_token" : "id").asText(); |
39 | 46 | } catch (IOException | InterruptedException e) { |
40 | 47 | throw new RuntimeException("Failed to fetch SciCat access token, aborting tests"); |
41 | 48 | } |
|
0 commit comments