Skip to content

Commit

Permalink
Cucumber Http UrlWrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
nhojpatrick committed Sep 29, 2022
1 parent 55f7dfb commit de42a9d
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
package com.github.nhojpatrick.cucumber.http.core.url;

import java.util.List;
import java.util.Map;

public interface UrlWrapper {

void addQueryParam(final String queryParam);

void addQueryParam(final String queryParamName, final String queryParamValue);

void addHeader(String headerName,
String headerValue);

boolean isFollowRedirects();

String getHref();

Map<String, String> getHeaders();

List<String> getQueryParams();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,70 @@

import com.github.nhojpatrick.cucumber.http.core.url.UrlWrapper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Objects.isNull;

public class UrlWrapperImpl
implements UrlWrapper {

private boolean followRedirects = false;
private final Map<String, String> headers;
private final String href;
private List<String> queryParam;

public UrlWrapperImpl(final String href) {
this(href, true, null, null);
}

public UrlWrapperImpl(final String href,
final boolean followRedirects,
final Map<String, String> headers,
final List<String> queryParam) {
this.followRedirects = followRedirects;
this.href = href;
this.headers = isNull(headers) ? new HashMap<>() : new HashMap<>(headers);
this.queryParam = isNull(queryParam) ? new ArrayList<>() : new ArrayList<>(queryParam);
}

@Override
public void addQueryParam(final String queryParam) {
this.queryParam.add(queryParam);
}

@Override
public void addQueryParam(final String queryParamName, final String queryParamValue) {
final String queryParam = String.format("%s=%s", queryParamName, queryParamValue);
this.queryParam.add(queryParam);
}

@Override
public void addHeader(final String headerName,
final String headerValue) {
this.headers.put(headerName, headerValue);
}

@Override
public boolean isFollowRedirects() {
return this.followRedirects;
}

@Override
public String getHref() {
return this.href;
}

@Override
public Map<String, String> getHeaders() {
return new HashMap<>(this.headers);
}

@Override
public List<String> getQueryParams() {
return new ArrayList<>(this.queryParam);
}

}

0 comments on commit de42a9d

Please sign in to comment.