Skip to content

Commit

Permalink
Fix url encoding for hoverfly admin api path
Browse files Browse the repository at this point in the history
  • Loading branch information
tommysitu committed May 2, 2024
1 parent d82e32a commit 5533af4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io.specto.hoverfly.junit.core.model.Journal;
import io.specto.hoverfly.junit.core.model.Simulation;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -217,7 +218,7 @@ public void addJournalIndex(JournalIndexCommand journalIndexCommand) {
@Override
public void deleteJournalIndex(String indexName) {
try {
final Request.Builder builder = createRequestBuilderWithUrl(JOURNAL_INDEX_PATH + "/" + indexName);
final Request.Builder builder = createRequestBuilderWithUrl(JOURNAL_INDEX_PATH, indexName);
final Request request = builder.delete().build();
exchange(request);
} catch (Exception e) {
Expand Down Expand Up @@ -270,7 +271,7 @@ public void addCsvDataSource(CsvDataSource dataSource) {
@Override
public void deleteCsvDataSource(String name) {
try {
final Request.Builder builder = createRequestBuilderWithUrl(CSV_DATA_SOURCE_PATH + "/" + name);
final Request.Builder builder = createRequestBuilderWithUrl(CSV_DATA_SOURCE_PATH, name);
final Request request = builder.delete().build();
exchange(request);
} catch (Exception e) {
Expand Down Expand Up @@ -306,7 +307,7 @@ public void updatePostServeAction(PostServeAction postServeAction) {
@Override
public void deletePostServeAction(String actionName) {
try {
final Request.Builder builder = createRequestBuilderWithUrl(POST_SERVE_ACTION_PATH + "/" + actionName);
final Request.Builder builder = createRequestBuilderWithUrl(POST_SERVE_ACTION_PATH, actionName);
final Request request = builder.delete().build();
exchange(request);
} catch (Exception e) {
Expand Down Expand Up @@ -473,9 +474,13 @@ private void putModeRequest(ModeCommand modeCommand) {
}

// Create request builder from Admin API path
private Request.Builder createRequestBuilderWithUrl(String path) {
return new Request.Builder()
.url(baseUrl.newBuilder().addPathSegments(path).build());
private Request.Builder createRequestBuilderWithUrl(String path, String ...pathSegments) {
HttpUrl.Builder urlBuilder = baseUrl.newBuilder()
.addPathSegments(path);
Arrays.stream(pathSegments)
.forEach(urlBuilder::addPathSegment);
return new Request.Builder().url(urlBuilder.build());

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,19 @@ public void shouldBeAbleToGetUpdateAndDeleteJournalIndex() {
assertThat(client.getJournalIndex()).isEmpty();
}

@Test
public void shouldBeAbleToGetUpdateAndDeleteJournalIndexWithCorrectUrlEncoding() {

assertThat(client.getJournalIndex()).isEmpty();

client.addJournalIndex(new JournalIndexCommand("Request.Body xpath //header/partnerOrderId"));
assertThat(client.getJournalIndex()).usingRecursiveFieldByFieldElementComparator()
.containsExactly(new JournalIndexView("Request.Body xpath //header/partnerOrderId", null));

client.deleteJournalIndex("Request.Body xpath //header/partnerOrderId");
assertThat(client.getJournalIndex()).isEmpty();
}

@Test
public void shouldBeAbleToGetUpdateAndDeleteCsvDataSources() {

Expand Down

0 comments on commit 5533af4

Please sign in to comment.