Skip to content

Commit bb8edba

Browse files
committed
fix login in ITs
1 parent 322561d commit bb8edba

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/test/java/ch/psi/ord/api/EndpointTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.databind.JsonNode;
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import io.quarkus.test.InjectMock;
7+
import jakarta.inject.Inject;
78
import java.io.ByteArrayOutputStream;
89
import java.io.IOException;
910
import java.net.URI;
@@ -12,30 +13,36 @@
1213
import java.net.http.HttpResponse;
1314
import java.util.zip.ZipEntry;
1415
import java.util.zip.ZipOutputStream;
16+
import org.eclipse.microprofile.config.inject.ConfigProperty;
1517

1618
public abstract class EndpointTest {
1719
@InjectMock protected ScicatClient scicatClient;
1820

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+
1929
protected String accessToken = "";
2030

2131
public static String CONTENT_TYPE_JSON_RES = "application/json;charset=UTF-8";
2232

2333
public String login() {
2434
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";
2836
HttpRequest request =
2937
HttpRequest.newBuilder()
3038
.uri(URI.create(url))
3139
.header("Content-Type", "application/json")
3240
.header("Accept", "application/json")
33-
.POST(HttpRequest.BodyPublishers.ofString(jsonInputString))
41+
.POST(HttpRequest.BodyPublishers.ofString(loginPayload))
3442
.build();
3543
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
36-
ObjectMapper objectMapper = new ObjectMapper();
3744
JsonNode jsonResponse = objectMapper.readTree(response.body());
38-
return jsonResponse.get("id").asText();
45+
return jsonResponse.get(backendV4 ? "access_token" : "id").asText();
3946
} catch (IOException | InterruptedException e) {
4047
throw new RuntimeException("Failed to fetch SciCat access token, aborting tests");
4148
}

0 commit comments

Comments
 (0)