Skip to content
Open
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
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,7 +71,6 @@ public void executeHttpRequest(HttpMethod httpMethod, String endpoint, Optional<
ClassicHttpRequest request = requestBuilder.build();

HttpClientContext context = new HttpClientContext();
httpTestContext.getCookieStore().ifPresent(context::setCookieStore);
httpTestContext.getRequestConfig().ifPresent(context::setRequestConfig);

HttpResponse response = httpClient.execute(request, context);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,6 @@
import java.util.Optional;

import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.CookieStore;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.vividus.http.client.HttpResponse;
Expand Down Expand Up @@ -54,11 +53,6 @@ public void addRequestHeaders(List<Header> requestHeaders)
getData().requestHeaders.addAll(requestHeaders);
}

public void putCookieStore(CookieStore cookieStore)
{
getData().cookieStore = cookieStore;
}

public void putConnectionDetails(ConnectionDetails connectionDetails)
{
getData().connectionDetails = connectionDetails;
Expand Down Expand Up @@ -108,11 +102,6 @@ public String getJsonContext()
return getData().jsonElement.orElse(getResponse() == null ? null : getResponse().getResponseBodyAsString());
}

public Optional<CookieStore> getCookieStore()
{
return Optional.ofNullable(getData().cookieStore);
}

public Optional<RequestConfig> getRequestConfig()
{
return Optional.ofNullable(getData().requestConfig);
Expand All @@ -133,7 +122,6 @@ private static final class HttpTestContextData
{
private HttpEntity requestEntity;
private List<Header> requestHeaders = new ArrayList<>();
private CookieStore cookieStore;
private ConnectionDetails connectionDetails;

private HttpResponse response;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.ArgumentMatchers.isA;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

Expand All @@ -38,7 +37,6 @@
import com.github.valfirst.slf4jtest.TestLoggerFactory;
import com.github.valfirst.slf4jtest.TestLoggerFactoryExtension;

import org.apache.hc.client5.http.cookie.CookieStore;
import org.apache.hc.client5.http.protocol.HttpClientContext;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.ConnectionClosedException;
Expand Down Expand Up @@ -72,7 +70,6 @@ class HttpRequestExecutorTests
@Test
void testExecuteHttpRequestFirstTime() throws IOException
{
when(httpTestContext.getCookieStore()).thenReturn(Optional.empty());
when(httpTestContext.getRequestConfig()).thenReturn(Optional.empty());
HttpResponse httpResponse = mockHttpResponse();
httpRequestExecutor.executeHttpRequest(HttpMethod.GET, URL, Optional.empty());
Expand All @@ -97,23 +94,6 @@ void testExecuteHttpRequestWithContent() throws IOException
verify(httpTestContext).releaseRequestData();
}

@Test
void testExecuteShouldUseCookieStoreFromContext() throws IOException
{
CookieStore cookieStore = mock();
when(httpTestContext.getCookieStore()).thenReturn(Optional.of(cookieStore));
HttpResponse httpResponse = mockHttpResponse();
httpRequestExecutor.executeHttpRequest(HttpMethod.GET, URL, Optional.empty());

verify(httpClient).execute(argThat(ClassicHttpRequest.class::isInstance),
argThat(e -> e != null && e.getCookieStore() == cookieStore));
InOrder orderedHttpTestContext = inOrder(httpTestContext);
verifyHttpTestContext(orderedHttpTestContext, httpResponse);
orderedHttpTestContext.verify(httpTestContext).releaseRequestData();
orderedHttpTestContext.verifyNoMoreInteractions();
assertThat(logger.getLoggingEvents(), equalTo(List.of(createResponseTimeLogEvent(httpResponse))));
}

@Test
void testExecuteHttpRequestWithIllegalUrl() throws IOException
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2023 the original author or authors.
* Copyright 2019-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -27,7 +27,6 @@
import java.util.Optional;

import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.CookieStore;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
Expand Down Expand Up @@ -58,14 +57,6 @@ void testPutAndGetRequest()
assertEquals(Optional.of(requestEntity), httpTestContext.getRequestEntity());
}

@Test
void testPutAndGetCookieStore()
{
CookieStore cookieStore = mock();
httpTestContext.putCookieStore(cookieStore);
assertEquals(Optional.of(cookieStore), httpTestContext.getCookieStore());
}

@Test
void testPutAndGetRequestConfig()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.jbehave.core.annotations.When;
import org.openqa.selenium.Cookie;
import org.vividus.http.CookieStoreProvider;
import org.vividus.http.HttpTestContext;
import org.vividus.reporter.event.AttachmentPublisher;
import org.vividus.ui.web.action.CookieManager;
import org.vividus.ui.web.action.NavigateActions;
Expand All @@ -33,17 +32,14 @@ public class HttpRequestSteps
private static final String ATTACHMENT_TEMPLATE_PATH = "org/vividus/steps/integration/browser-cookies.ftl";
private static final String TEMPLATE_COOKIES_KEY = "cookies";
private final CookieManager<Cookie> cookieManager;
private final HttpTestContext httpTestContext;
private final AttachmentPublisher attachmentPublisher;
private final CookieStoreProvider cookieStoreProvider;
private final NavigateActions navigateActions;

public HttpRequestSteps(CookieManager<Cookie> cookieManager, HttpTestContext httpTestContext,
AttachmentPublisher attachmentPublisher, CookieStoreProvider cookieStoreProvider,
NavigateActions navigateActions)
public HttpRequestSteps(CookieManager<Cookie> cookieManager, AttachmentPublisher attachmentPublisher,
CookieStoreProvider cookieStoreProvider, NavigateActions navigateActions)
{
this.cookieManager = cookieManager;
this.httpTestContext = httpTestContext;
this.attachmentPublisher = attachmentPublisher;
this.cookieStoreProvider = cookieStoreProvider;
this.navigateActions = navigateActions;
Expand All @@ -58,9 +54,11 @@ public HttpRequestSteps(CookieManager<Cookie> cookieManager, HttpTestContext htt
public void executeRequestUsingBrowserCookies()
{
CookieStore cookieStore = cookieManager.getCookiesAsHttpCookieStore();
List<org.apache.hc.client5.http.cookie.Cookie> cookies = cookieStore.getCookies();
attachmentPublisher.publishAttachment(ATTACHMENT_TEMPLATE_PATH,
Map.of(TEMPLATE_COOKIES_KEY, cookieStore.getCookies()), "Browser cookies");
httpTestContext.putCookieStore(cookieStore);
Map.of(TEMPLATE_COOKIES_KEY, cookies), "Browser cookies");
CookieStore httpCookieStore = cookieStoreProvider.getCookieStore();
cookies.forEach(httpCookieStore::addCookie);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.vividus.http.CookieStoreProvider;
import org.vividus.http.HttpTestContext;
import org.vividus.reporter.event.AttachmentPublisher;
import org.vividus.ui.web.action.CookieManager;
import org.vividus.ui.web.action.NavigateActions;
Expand All @@ -46,7 +45,6 @@ class HttpRequestStepsTests
private static final String ATTACHMENT_TEMPLATE_PATH = "org/vividus/steps/integration/browser-cookies.ftl";
private static final String TEMPLATE_COOKIES_KEY = "cookies";

@Mock private HttpTestContext httpTestContext;
@Mock private CookieManager<Cookie> cookieManager;
@Mock private AttachmentPublisher attachmentPublisher;
@Mock private CookieStoreProvider cookieStoreProvider;
Expand All @@ -57,12 +55,15 @@ class HttpRequestStepsTests
void shouldSetCookiesFromBrowserAndDelegateRequestToApiSteps()
{
CookieStore cookieStore = mock(CookieStore.class);
CookieStore httpCookieStore = mock(CookieStore.class);
when(cookieManager.getCookiesAsHttpCookieStore()).thenReturn(cookieStore);
when(cookieStoreProvider.getCookieStore()).thenReturn(httpCookieStore);
BasicClientCookie cookie1 = new BasicClientCookie("key", "value");
BasicClientCookie cookie2 = new BasicClientCookie("key1", "value1");
when(cookieStore.getCookies()).thenReturn(List.of(cookie1, cookie2));
httpRequestSteps.executeRequestUsingBrowserCookies();
verify(httpTestContext).putCookieStore(cookieStore);
verify(httpCookieStore).addCookie(cookie1);
verify(httpCookieStore).addCookie(cookie2);
var cookiesCaptor = ArgumentCaptor.forClass(Map.class);
verify(attachmentPublisher).publishAttachment(eq(ATTACHMENT_TEMPLATE_PATH),
cookiesCaptor.capture(), eq("Browser cookies"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,22 @@ When I execute HTTP GET request for resource with URL `https://httpbingo.org/coo
Then cookie with name that is equal to `c1` is not set
When I set HTTP context cookies to browser
Then cookie with name that is equal to `c1` is set
When I set all cookies for current domain:
|cookieName |cookieValue |path |
|customCookie |customValue |/cookies |
Then text `v1` exists
Then text `customValue` exists
When I set browser cookies to HTTP context
When I remove all cookies from current domain
Then cookie with name that is equal to `c1` is not set
Then cookie with name that is equal to `customCookie` is not set
Then text `v1` does not exist
Then text `customValue` does not exist
When I execute HTTP GET request for resource with URL `https://httpbingo.org/cookies/set?c2=v2`
When I set HTTP context cookies to browser without applying changes
Then cookie with name that is equal to `c1` is set
Then cookie with name that is equal to `c2` is set
Then text `v1` exists
Then cookie with name that is equal to `customCookie` is set
Then text `v1` does not exist
Then text `v2` does not exist
Then text `customValue` does not exist
Loading