Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
test are green
Browse files Browse the repository at this point in the history
  • Loading branch information
narcoticfresh committed Dec 5, 2023
1 parent 32e96d0 commit 851a6e9
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: Set up JDK 17
- name: Set up JDK 21
uses: actions/setup-java@v3
with:
java-version: '17'
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
Expand Down
2 changes: 1 addition & 1 deletion .java-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
17
jdk-21.0.1+12
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>com.github.libgraviton</groupId>
<artifactId>worker-base</artifactId>
<packaging>jar</packaging>
<version>3.12.0-SNAPSHOT</version>
<version>4.0.0-SNAPSHOT</version>
<name>Graviton Worker Base Library</name>
<url>https://github.com/libgraviton/graviton-worker-base-java</url>
<inceptionYear>2015</inceptionYear>
Expand Down Expand Up @@ -501,8 +501,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>17</source>
<target>17</target>
<source>21</source>
<target>21</target>
</configuration>
<executions>
<execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.activej.inject.module.AbstractModule;

import java.io.IOException;
import java.net.http.HttpClient;
import java.text.SimpleDateFormat;
import java.util.Properties;
import java.util.TimeZone;
Expand Down Expand Up @@ -75,13 +76,18 @@ public static GravitonApi gravitonApi(EndpointManager endpointManager, ObjectMap
}

@Provides
public static Methanol getHttpClient() throws Exception {
public static Methanol getMethanol() throws Exception {
final boolean hasRetry = WorkerProperties.HTTP_CLIENT_DORETRY.get().equals("true");
final boolean trustAll = WorkerProperties.HTTP_CLIENT_TLS_TRUST_ALL.get().equals("true");

return MethanolGatewayFactory.getInstance(hasRetry, trustAll);
}

@Provides
public static HttpClient getHttpClient() throws Exception {
return getMethanol();
}

@Provides
public static RequestExecutor requestExecutor(ObjectMapper objectMapper, GravitonGateway gateway) {
return new RequestExecutor(objectMapper, gateway);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,50 @@
package com.github.libgraviton.workerbase.util;

import com.github.libgraviton.workertestbase.WorkerTestExtension;
import com.github.tomakehurst.wiremock.stubbing.StubMapping;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.io.File;
import java.util.Map;

import static com.github.tomakehurst.wiremock.client.WireMock.*;

public class DownloadClientTest {

@RegisterExtension
public static WorkerTestExtension workerTestExtension = (new WorkerTestExtension())
.setStartWiremock(true);

@Test
public void testBasicDownload() {
DownloadClient.downloadFile("", "", Map.of());
String target = "/tmp/PDF-TEST-FILE.pdf";
String url = workerTestExtension.getWiremockUrl() + "/test.pdf";

StubMapping redir = workerTestExtension.getWireMockServer()
.stubFor(
get(urlMatching("/test.pdf"))
.withHeader("FRANZ", equalTo("TEST"))
.willReturn(
aResponse().withStatus(301).withHeader("location", "/file/test.pdf")
)
);

StubMapping filestub = workerTestExtension.getWireMockServer()
.stubFor(
get(urlMatching("/file/test.pdf"))
// the transient headers
.willReturn(
aResponse().withBodyFile("test.pdf").withStatus(200)
)
);

DownloadClient.downloadFile(url, target, Map.of("FRANZ", "TEST"));

File file = new File(target);
Assertions.assertEquals(7021, file.length());
file.delete();
}

}
File renamed without changes.

0 comments on commit 851a6e9

Please sign in to comment.