Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect Path of Flare Base URL #82

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
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public FlareWebserviceClientImpl(HttpClient httpClient, URI flareBaseUrl) {

@Override
public int requestFeasibility(byte[] structuredQuery) throws IOException, InterruptedException {
var req = new HttpPost(flareBaseUrl.resolve("/query/execute"));
var req = new HttpPost(flareBaseUrl.resolve((flareBaseUrl.getPath() + "/query/execute").replaceAll("//", "/")));
req.setEntity(new ByteArrayEntity(structuredQuery));
req.setHeader(new BasicHeader(HEADER_CONTENT_TYPE, "application/sq+json"));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.junit.jupiter.MockitoExtension;

import java.io.IOException;
Expand All @@ -23,6 +25,7 @@ public class FlareWebserviceClientImplTest {

private org.apache.http.client.HttpClient httpClient;
private FlareWebserviceClient flareWebserviceClient;
@Captor ArgumentCaptor<HttpPost> postCaptor;

@BeforeEach
public void setUp() throws URISyntaxException {
Expand Down Expand Up @@ -60,4 +63,18 @@ public void testRequestFeasibility() throws IOException, InterruptedException {

assertEquals(15, feasibility);
}

@Test
public void testName() throws Exception {
String path = "/foo/bar/";
flareWebserviceClient = new FlareWebserviceClientImpl(httpClient, URI.create("http://foo.bar:1234" + path));
var structuredQuery = "foo".getBytes();

when(httpClient.execute(postCaptor.capture(), any(BasicResponseHandler.class)))
.thenReturn("99");

var feasibility = flareWebserviceClient.requestFeasibility(structuredQuery);

assertEquals(path + "query/execute", postCaptor.getValue().getURI().getPath());
}
}