1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package com.mavlushechka.a1qa.project.utils;
import com.mavlushechka.a1qa.framework.utils.JsonParser;
import com.mavlushechka.a1qa.framework.utils.UrlConnectionManager;
import com.mavlushechka.a1qa.project.constants.SiteApiMethod;
import com.mavlushechka.a1qa.project.models.Test;
import java.io.IOException;
import java.util.Base64;
public class SiteApiUtils {
private static final String url = "%s/api".formatted(JsonParser.parseData("config", "browser.url"));
private SiteApiUtils() {
}
public static String generateToken(int variant) throws IOException {
return UrlConnectionManager.post("%s%s?variant=%d".formatted(url, SiteApiMethod.TOKEN_GET.url, variant));
}
public static String getTestsJson(int projectId) throws IOException {
return UrlConnectionManager.post("%s%s?projectId=%d".formatted(url, SiteApiMethod.TEST_GET_JSON.url, projectId));
}
public static int putTest(String sid, String projectName, Test test, String env) throws IOException {
return Integer.parseInt(
UrlConnectionManager.post(
"%s%s?SID=%s&projectName=%s&testName=%s&methodName=%s&env=%s"
.formatted(url, SiteApiMethod.TEST_PUT.url, sid, projectName, test.name(), test.method(), env)
)
);
}
public static void putLogToTest(int testId, String content) throws IOException {
UrlConnectionManager.post("%s%s?testId=%d&content=%s".formatted(url, SiteApiMethod.TEST_PUT_LOG.url, testId, content));
}
public static void putAttachmentToTest(int testId, byte[] content, String contentType) throws IOException {
UrlConnectionManager.post(
"%s%s?testId=%d&content=%s&contentType=%s"
.formatted(url, SiteApiMethod.TEST_PUT_ATTACHMENT.url, testId, Base64.getEncoder().encodeToString(content), contentType)
);
}
}
|