8000 [vividus] Add expression `#{extractSchemeFromUrl(..)}` by valfirst · Pull Request #5011 · vividus-framework/vividus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

[vividus] Add expression #{extractSchemeFromUrl(..)} #5011

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

Merged
merged 2 commits into from
Apr 29, 2024
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
45 changes: 32 additions & 13 deletions docs/modules/commons/pages/expressions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1058,11 +1058,30 @@ Given I initialize scenario variable `my-data` with value `#{resourceToBase64(/d
----

== URL parsing
:url-argument: pass:quotes[*`$url`* - the URL to extract component from.]
:url-argument: pass:quotes[*`$url`* - the URL to extract the component from.]

=== `extractSchemeFromUrl`

Extracts the scheme component from the given URL.

[source, subs="+quotes"]
----
#{extractSchemeFromUrl(*$url*)}
----

[subs="specialchars,attributes,quotes,replacements,macros,post_replacements"]
* {url-argument}

.Validate URL protocol
[source,gherkin]
----
Then `#{extractHostFromUrl(file://server/folder/data.xml?id=123)}` is equal to `file`
Then `#{extractHostFromUrl(https://docs.vividus.dev/vividus/latest?page=2)}` is equal to `https`
----

=== `extractHostFromUrl`

Extracts host component from the given URL.
Extracts the host component from the given URL.

[source, subs="+quotes"]
----
Expand All @@ -1072,16 +1091,16 @@ Extracts host component from the given URL.
[subs="specialchars,attributes,quotes,replacements,macros,post_replacements"]
* {url-argument}

.Validate host component from URL
.Validate the host component from URL
[source,gherkin]
----
Then `#{extractHostFromUrl(file://server/folder/data.xml?id=123)}` is = `server`
Then `#{extractHostFromUrl(https://docs.vividus.dev/vividus/latest?page=2)}` is = `docs.vividus.dev`
Then `#{extractHostFromUrl(file://server/folder/data.xml?id=123)}` is equal to `server`
Then `#{extractHostFromUrl(https://docs.vividus.dev/vividus/latest?page=2)}` is equal to `docs.vividus.dev`
----

=== `extractPathFromUrl`

Extracts decoded path component from the given URL.
Extracts the decoded path component from the given URL.

[source, subs="+quotes"]
----
Expand All @@ -1091,16 +1110,16 @@ Extracts decoded path component from the given URL.
[subs="specialchars,attributes,quotes,replacements,macros,post_replacements"]
* {url-argument}

.Validate path component from URL
.Validate the path component from URL
[source,gherkin]
----
Then `#{extractPathFromUrl(file://server/folder/data.xml?id=123)}` is = `/folder/data.xml`
Then `#{extractPathFromUrl(https://docs.vividus.dev/vividus/latest?page=2)}` is = `/vividus/latest`
Then `#{extractPathFromUrl(file://server/folder/data.xml?id=123)}` is equal to `/folder/data.xml`
Then `#{extractPathFromUrl(https://docs.vividus.dev/vividus/latest?page=2)}` is equal to `/vividus/latest`
----

=== `extractQueryFromUrl`

Extracts decoded query component from the given URL.
Extracts the decoded query component from the given URL.

[source, subs="+quotes"]
----
Expand All @@ -1110,11 +1129,11 @@ Extracts decoded query component from the given URL.
[subs="specialchars,attributes,quotes,replacements,macros,post_replacements"]
* {url-argument}

.Validate query component from URL
.Validate the query component from URL
[source,gherkin]
----
Then `#{extractQueryFromUrl(file://server/folder/data.xml?id=123)}` is = `id=123`
Then `#{extractQueryFromUrl(https://docs.vividus.dev/vividus/latest?page=2)}` is = `page=2`
Then `#{extractQueryFromUrl(file://server/folder/data.xml?id=123)}` is equal to `id=123`
Then `#{extractQueryFromUrl(https://docs.vividus.dev/vividus/latest?page=2)}` is equal to `page=2`
----

== Script evaluation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ Scenario: Validate expressions parsing URLs
Then `#{<expression>}` is = `<expected>`
Examples:
|expression |expected |
|extractSchemeFromUrl(${vividus-test-site-url}/windows.html?query=test) |https |
|extractHostFromUrl(${vividus-test-site-url}/windows.html?query=test) |${vividus-test-site-host} |
|extractPathFromUrl(${vividus-test-site-url}/windows.html?query=test) |/windows.html |
|extractPathFromUrl(${vividus-test-site-url}/encoded%E2%82%AC/windows.html?query=test) |/encoded€/windows.html |
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,6 +27,7 @@ public class UrlExpressionProcessors extends DelegatingExpressionProcessor
public UrlExpressionProcessors()
{
super(List.of(
new SingleArgExpressionProcessor<>("extractSchemeFromUrl", url -> UriUtils.createUri(url).getScheme()),
new SingleArgExpressionProcessor<>("extractHostFromUrl", url -> UriUtils.createUri(url).getHost()),
new SingleArgExpressionProcessor<>("extractPathFromUrl", url -> UriUtils.createUri(url).getPath()),
new SingleArgExpressionProcessor<>("extractQueryFromUrl", url -> UriUtils.createUri(url).getQuery())
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 @@ -28,6 +28,7 @@
class UrlExpressionProcessorsTests
{
private static final String EXAMPLE_URL = "https://www.example.com/one/two?id=0&name=temp";
private static final String URL_SCHEME = "https";
private static final String URL_HOST = "www.example.com";
private static final String URL_PATH = "/one/two";
private static final String URL_QUERY = "id=0&name=temp";
Expand All @@ -38,6 +39,8 @@ static Stream<Arguments> validExpressionSource()
{
// CHECKSTYLE:OFF
return Stream.of(
arguments("extractSchemeFromUrl(tel:37127123567)", "tel"),
arguments(String.format("extractSchemeFromUrl(%s)", EXAMPLE_URL), URL_SCHEME),
arguments(String.format("extractHostFromUrl(%s)", EXAMPLE_URL), URL_HOST),
arguments(String.format("extractPathFromUrl(%s)", EXAMPLE_URL), URL_PATH),
arguments(String.format("extractQueryFromUrl(%s)", EXAMPLE_URL), URL_QUERY)
Expand Down
Loading
0