Skip to content

Commit 62bc6d9

Browse files
committed
[for 0.7.0 release] Fix step to set browser cookies to HTTP context
1 parent cd20dad commit 62bc6d9

File tree

5 files changed

+25
-28
lines changed

5 files changed

+25
-28
lines changed

vividus-plugin-rest-api/src/main/java/org/vividus/http/HttpTestContext.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -54,11 +54,6 @@ public void addRequestHeaders(List<Header> requestHeaders)
5454
getData().requestHeaders.addAll(requestHeaders);
5555
}
5656

57-
public void putCookieStore(CookieStore cookieStore)
58-
{
59-
getData().cookieStore = cookieStore;
60-
}
61-
6257
public void putConnectionDetails(ConnectionDetails connectionDetails)
6358
{
6459
getData().connectionDetails = connectionDetails;

vividus-plugin-rest-api/src/test/java/org/vividus/http/HttpTestContextTests.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2023 the original author or authors.
2+
* Copyright 2019-2024 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,6 @@
2727
import java.util.Optional;
2828

2929
import org.apache.hc.client5.http.config.RequestConfig;
30-
import org.apache.hc.client5.http.cookie.CookieStore;
3130
import org.apache.hc.core5.http.ContentType;
3231
import org.apache.hc.core5.http.Header;
3332
import org.apache.hc.core5.http.HttpEntity;
@@ -58,14 +57,6 @@ void testPutAndGetRequest()
5857
assertEquals(Optional.of(requestEntity), httpTestContext.getRequestEntity());
5958
}
6059

61-
@Test
62-
void testPutAndGetCookieStore()
63-
{
64-
CookieStore cookieStore = mock();
65-
httpTestContext.putCookieStore(cookieStore);
66-
assertEquals(Optional.of(cookieStore), httpTestContext.getCookieStore());
67-
}
68-
6960
@Test
7061
void testPutAndGetRequestConfig()
7162
{

vividus-plugin-web-app-to-rest-api/src/main/java/org/vividus/steps/integration/HttpRequestSteps.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.jbehave.core.annotations.When;
2424
import org.openqa.selenium.Cookie;
2525
import org.vividus.http.CookieStoreProvider;
26-
import org.vividus.http.HttpTestContext;
2726
import org.vividus.reporter.event.AttachmentPublisher;
2827
import org.vividus.ui.web.action.CookieManager;
2928
import org.vividus.ui.web.action.NavigateActions;
@@ -33,17 +32,14 @@ public class HttpRequestSteps
3332
private static final String ATTACHMENT_TEMPLATE_PATH = "org/vividus/steps/integration/browser-cookies.ftl";
3433
private static final String TEMPLATE_COOKIES_KEY = "cookies";
3534
private final CookieManager<Cookie> cookieManager;
36-
private final HttpTestContext httpTestContext;
3735
private final AttachmentPublisher attachmentPublisher;
3836
private final CookieStoreProvider cookieStoreProvider;
3937
private final NavigateActions navigateActions;
4038

41-
public HttpRequestSteps(CookieManager<Cookie> cookieManager, HttpTestContext httpTestContext,
42-
AttachmentPublisher attachmentPublisher, CookieStoreProvider cookieStoreProvider,
43-
NavigateActions navigateActions)
39+
public HttpRequestSteps(CookieManager<Cookie> cookieManager, AttachmentPublisher attachmentPublisher,
40+
CookieStoreProvider cookieStoreProvider, NavigateActions navigateActions)
4441
{
4542
this.cookieManager = cookieManager;
46-
this.httpTestContext = httpTestContext;
4743
this.attachmentPublisher = attachmentPublisher;
4844
this.cookieStoreProvider = cookieStoreProvider;
4945
this.navigateActions = navigateActions;
@@ -58,9 +54,11 @@ public HttpRequestSteps(CookieManager<Cookie> cookieManager, HttpTestContext htt
5854
public void executeRequestUsingBrowserCookies()
5955
{
6056
CookieStore cookieStore = cookieManager.getCookiesAsHttpCookieStore();
57+
List<org.apache.hc.client5.http.cookie.Cookie> cookies = cookieStore.getCookies();
6158
attachmentPublisher.publishAttachment(ATTACHMENT_TEMPLATE_PATH,
62-
Map.of(TEMPLATE_COOKIES_KEY, cookieStore.getCookies()), "Browser cookies");
63-
httpTestContext.putCookieStore(cookieStore);
59+
Map.of(TEMPLATE_COOKIES_KEY, cookies), "Browser cookies");
60+
CookieStore httpCookieStore = cookieStoreProvider.getCookieStore();
61+
cookies.forEach(httpCookieStore::addCookie);
6462
}
6563

6664
/**

vividus-plugin-web-app-to-rest-api/src/test/java/org/vividus/steps/integration/HttpRequestStepsTests.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import org.mockito.Mock;
3636
import org.mockito.junit.jupiter.MockitoExtension;
3737
import org.vividus.http.CookieStoreProvider;
38-
import org.vividus.http.HttpTestContext;
3938
import org.vividus.reporter.event.AttachmentPublisher;
4039
import org.vividus.ui.web.action.CookieManager;
4140
import org.vividus.ui.web.action.NavigateActions;
@@ -46,7 +45,6 @@ class HttpRequestStepsTests
4645
private static final String ATTACHMENT_TEMPLATE_PATH = "org/vividus/steps/integration/browser-cookies.ftl";
4746
private static final String TEMPLATE_COOKIES_KEY = "cookies";
4847

49-
@Mock private HttpTestContext httpTestContext;
5048
@Mock private CookieManager<Cookie> cookieManager;
5149
@Mock private AttachmentPublisher attachmentPublisher;
5250
@Mock private CookieStoreProvider cookieStoreProvider;
@@ -57,12 +55,15 @@ class HttpRequestStepsTests
5755
void shouldSetCookiesFromBrowserAndDelegateRequestToApiSteps()
5856
{
5957
CookieStore cookieStore = mock(CookieStore.class);
58+
CookieStore httpCookieStore = mock(CookieStore.class);
6059
when(cookieManager.getCookiesAsHttpCookieStore()).thenReturn(cookieStore);
60+
when(cookieStoreProvider.getCookieStore()).thenReturn(httpCookieStore);
6161
BasicClientCookie cookie1 = new BasicClientCookie("key", "value");
6262
BasicClientCookie cookie2 = new BasicClientCookie("key1", "value1");
6363
when(cookieStore.getCookies()).thenReturn(List.of(cookie1, cookie2));
6464
httpRequestSteps.executeRequestUsingBrowserCookies();
65-
verify(httpTestContext).putCookieStore(cookieStore);
65+
verify(httpCookieStore).addCookie(cookie1);
66+
verify(httpCookieStore).addCookie(cookie2);
6667
var cookiesCaptor = ArgumentCaptor.forClass(Map.class);
6768
verify(attachmentPublisher).publishAttachment(eq(ATTACHMENT_TEMPLATE_PATH),
6869
cookiesCaptor.capture(), eq("Browser cookies"));

vividus-tests/src/main/resources/story/integration/WebAndRestCookieSteps.story

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ When I execute HTTP GET request for resource with URL `https://httpbingo.org/coo
77
Then cookie with name that is equal to `c1` is not set
88
When I set HTTP context cookies to browser
99
Then cookie with name that is equal to `c1` is set
10+
When I set all cookies for current domain:
11+
|cookieName |cookieValue |path |
12+
|customCookie |customValue |/cookies |
1013
Then text `v1` exists
14+
Then text `customValue` exists
15+
When I set browser cookies to HTTP context
16+
When I remove all cookies from current domain
17+
Then cookie with name that is equal to `c1` is not set
18+
Then cookie with name that is equal to `customCookie` is not set
19+
Then text `v1` does not exist
20+
Then text `customValue` does not exist
1121
When I execute HTTP GET request for resource with URL `https://httpbingo.org/cookies/set?c2=v2`
1222
When I set HTTP context cookies to browser without applying changes
1323
Then cookie with name that is equal to `c1` is set
1424
Then cookie with name that is equal to `c2` is set
15-
Then text `v1` exists
25+
Then cookie with name that is equal to `customCookie` is set
26+
Then text `v1` does not exist
1627
Then text `v2` does not exist
28+
Then text `customValue` does not exist

0 commit comments

Comments
 (0)