Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies {
annotationProcessor libs.lombok
testImplementation platform(libs.junitBom)
testImplementation libs.junit
testImplementation project(path: ":test-resources", configuration: "testArtifacts")
}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.ByteArrayOutputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -63,20 +65,18 @@ class JsoupFunPayParserTest {
private MockWebServer mockWebServer;
private JsoupFunPayParser parser;

private static final String PARSE_LOT_HTML_RESPONSE_PATH =
"src/test/resources/html/client/parseLotResponse.html";
private static final String PARSE_LOT_HTML_RESPONSE_PATH = "html/client/getLotResponse.html";
private static final String PARSE_PROMO_GAMES_JSON_RESPONSE_PATH =
"src/test/resources/json/client/parsePromoGamesResponse.json";
"json/client/getPromoGamesResponse.json";
private static final String PARSE_OFFER_HTML_RESPONSE_PATH =
"src/test/resources/html/client/parseOfferResponse.html";
private static final String PARSE_USER_HTML_RESPONSE_PATH =
"src/test/resources/html/client/parseUserResponse.html";
"html/client/getOfferResponse.html";
private static final String PARSE_USER_HTML_RESPONSE_PATH = "html/client/getUserResponse.html";
private static final String PARSE_SELLER_REVIEWS_HTML_RESPONSE_PATH =
"src/test/resources/html/client/parseSellerReviewsResponse.html";
"html/client/getSellerReviewsResponse.html";
private static final String PARSE_TRANSACTIONS_HTML_RESPONSE_PATH =
"src/test/resources/html/client/parseTransactionsResponse.html";
"html/client/getTransactionsResponse.html";
private static final String PARSE_ORDER_HTML_RESPONSE_PATH =
"src/test/resources/html/client/parseOrderResponse.html";
"html/client/getOrderResponse.html";
private static final String BASE_URL = "/";

@BeforeEach
Expand All @@ -95,8 +95,7 @@ void tearDown() throws IOException {

@Test
void testParseLot() throws Exception {
String htmlContent =
new String(Files.readAllBytes(Paths.get(PARSE_LOT_HTML_RESPONSE_PATH)));
String htmlContent = readResource(PARSE_LOT_HTML_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(htmlContent).setResponseCode(200));

long lotId = 149L;
Expand Down Expand Up @@ -136,8 +135,7 @@ void testParseLotNotFound() throws Exception {

@Test
void testParsePromoGames() throws Exception {
String jsonContent =
new String(Files.readAllBytes(Paths.get(PARSE_PROMO_GAMES_JSON_RESPONSE_PATH)));
String jsonContent = readResource(PARSE_PROMO_GAMES_JSON_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(jsonContent).setResponseCode(200));

String query = "dota";
Expand All @@ -158,8 +156,7 @@ void testParsePromoGames() throws Exception {

@Test
void testParseOffer() throws Exception {
String htmlContent =
new String(Files.readAllBytes(Paths.get(PARSE_OFFER_HTML_RESPONSE_PATH)));
String htmlContent = readResource(PARSE_OFFER_HTML_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(htmlContent).setResponseCode(200));

long offerId = 33502824L;
Expand Down Expand Up @@ -198,8 +195,7 @@ void testParseOfferNotFound() throws Exception {

@Test
void testParseUserWithoutGoldenKey() throws Exception {
String htmlContent =
new String(Files.readAllBytes(Paths.get(PARSE_USER_HTML_RESPONSE_PATH)));
String htmlContent = readResource(PARSE_USER_HTML_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(htmlContent).setResponseCode(200));

long userId = 2L;
Expand Down Expand Up @@ -232,8 +228,7 @@ void testParseUserWithoutGoldenKey() throws Exception {

@Test
void testParseUserWithGoldenKey() throws Exception {
String htmlContent =
new String(Files.readAllBytes(Paths.get(PARSE_USER_HTML_RESPONSE_PATH)));
String htmlContent = readResource(PARSE_USER_HTML_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(htmlContent).setResponseCode(200));

String goldenKey = "some_golden_key";
Expand Down Expand Up @@ -267,8 +262,7 @@ void testParseUserNotFound() throws Exception {

@Test
void testParseSellerReviews() throws Exception {
String htmlContent =
new String(Files.readAllBytes(Paths.get(PARSE_SELLER_REVIEWS_HTML_RESPONSE_PATH)));
String htmlContent = readResource(PARSE_SELLER_REVIEWS_HTML_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(htmlContent).setResponseCode(200));

long userId = 2L;
Expand Down Expand Up @@ -305,8 +299,7 @@ void testParseSellerReviewsUserNotFound() throws Exception {

@Test
void testParseTransactions() throws Exception {
String htmlContent =
new String(Files.readAllBytes(Paths.get(PARSE_TRANSACTIONS_HTML_RESPONSE_PATH)));
String htmlContent = readResource(PARSE_TRANSACTIONS_HTML_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(htmlContent).setResponseCode(200));

String goldenKey = "test-golden-key";
Expand Down Expand Up @@ -341,8 +334,7 @@ void testParseTransactionsUserNotFound() throws Exception {

@Test
void testParseOrder() throws Exception {
String htmlContent =
new String(Files.readAllBytes(Paths.get(PARSE_ORDER_HTML_RESPONSE_PATH)));
String htmlContent = readResource(PARSE_ORDER_HTML_RESPONSE_PATH);
mockWebServer.enqueue(new MockResponse().setBody(htmlContent).setResponseCode(200));

String goldenKey = "some_golden_key";
Expand Down Expand Up @@ -400,4 +392,20 @@ void testParseCsrfTokenAndPHPSESSID() throws Exception {
assertEquals(csrfToken, result.getCsrfToken());
assertEquals(phpSessId, result.getPHPSESSID());
}

private static String readResource(String resourcePath) throws IOException {
try (InputStream is =
JsoupFunPayParser.class.getClassLoader().getResourceAsStream(resourcePath)) {
if (is == null) {
throw new FileNotFoundException("Resource not found: " + resourcePath);
}
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
byte[] data = new byte[4096];
int nRead;
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
return new String(buffer.toByteArray(), StandardCharsets.UTF_8);
}
}
}

This file was deleted.

123 changes: 0 additions & 123 deletions client/src/test/resources/html/client/parseLotResponse.html

This file was deleted.

Loading