Skip to content

Commit fb0e209

Browse files
authored
Merge branch 'master' into bugfix/fix-http-repo-headers-config
2 parents 25b1006 + 7835e76 commit fb0e209

File tree

16 files changed

+137
-123
lines changed

16 files changed

+137
-123
lines changed

Diff for: documentation/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
<parent>
2525
<groupId>io.knotx</groupId>
2626
<artifactId>knotx-root</artifactId>
27-
<version>1.3.1-SNAPSHOT</version>
27+
<version>1.4.0-SNAPSHOT</version>
2828
</parent>
2929

3030
<artifactId>documentation</artifactId>

Diff for: knotx-adapter/knotx-adapter-common/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>io.knotx</groupId>
2525
<artifactId>knotx-adapter</artifactId>
26-
<version>1.3.1-SNAPSHOT</version>
26+
<version>1.4.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>knotx-adapter-common</artifactId>

Diff for: knotx-adapter/knotx-adapter-service-http/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>io.knotx</groupId>
2525
<artifactId>knotx-adapter</artifactId>
26-
<version>1.3.1-SNAPSHOT</version>
26+
<version>1.4.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>knotx-adapter-service-http</artifactId>

Diff for: knotx-adapter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>io.knotx</groupId>
2525
<artifactId>knotx-root</artifactId>
26-
<version>1.3.1-SNAPSHOT</version>
26+
<version>1.4.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>knotx-adapter</artifactId>

Diff for: knotx-core/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>io.knotx</groupId>
2525
<artifactId>knotx-root</artifactId>
26-
<version>1.3.1-SNAPSHOT</version>
26+
<version>1.4.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>knotx-core</artifactId>

Diff for: knotx-core/src/test/java/io/knotx/assembler/UnprocessedFragmentStrategyTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import io.knotx.dataobjects.Fragment;
2222
import io.knotx.fragments.SnippetPatterns;
23-
import io.knotx.junit5.KnotxArgumentConverter;
23+
import io.knotx.junit.converter.FragmentArgumentConverter;
2424
import io.knotx.junit5.util.FileReader;
2525
import io.knotx.options.SnippetOptions;
2626
import org.junit.jupiter.params.ParameterizedTest;
@@ -37,7 +37,7 @@ public class UnprocessedFragmentStrategyTest {
3737
"io/knotx/assembler/customTagAndParamsPrefix_snippet.txt;io/knotx/assembler/customTagAndParamsPrefix_snippet.txt;knotx:snippet;"
3838
})
3939
public void asIs_whenConfiguredSnippetTag_expectIgnoredContent(
40-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment,
40+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment,
4141
String expectedContentFileName, String snippetTagName, String paramsPrefix) throws Exception {
4242
final String unwrappedContent = UnprocessedFragmentStrategy.AS_IS
4343
.get(fragment, new SnippetPatterns(buildOptions(snippetTagName, paramsPrefix)));
@@ -54,7 +54,7 @@ public void asIs_whenConfiguredSnippetTag_expectIgnoredContent(
5454
"io/knotx/assembler/customTagAndParamsPrefix_snippet.txt|knotx:snippet|;io/knotx/assembler/simple_snippet-expected_unwrapped_content.txt;knotx:snippet;"
5555
})
5656
public void unwrap_whenConfiguredSnippetTag_expectDefinedContentWithComments(
57-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment,
57+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment,
5858
String expectedContentFileName, String snippetTagName, String paramsPrefix) throws Exception {
5959
final String unwrappedContent = UnprocessedFragmentStrategy.UNWRAP
6060
.get(fragment, new SnippetPatterns(buildOptions(snippetTagName, paramsPrefix)));
@@ -71,7 +71,7 @@ public void unwrap_whenConfiguredSnippetTag_expectDefinedContentWithComments(
7171
//when fragment is a raw fragment, it is not ignored
7272
})
7373
public void ignore_whenConfiguredSnippetTag_expectIgnoredContent(
74-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment,
74+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment,
7575
String expectedContentFileName, String snippetTagName, String paramsPrefix) throws Exception {
7676
final String unwrappedContent = UnprocessedFragmentStrategy.IGNORE
7777
.get(fragment, new SnippetPatterns(buildOptions(snippetTagName, paramsPrefix)));

Diff for: knotx-core/src/test/java/io/knotx/fragments/FragmentContentExtractorTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import static org.mockito.Mockito.when;
2424

2525
import io.knotx.dataobjects.Fragment;
26-
import io.knotx.junit5.KnotxArgumentConverter;
26+
import io.knotx.junit.converter.FragmentArgumentConverter;
2727
import java.io.IOException;
2828
import org.jsoup.nodes.Element;
2929
import org.junit.jupiter.api.Test;
@@ -42,7 +42,7 @@ public class FragmentContentExtractorTest {
4242
"io/knotx/fragments/complex_custom_snippet.txt|knotx:snippet;io/knotx/fragments/complex_snippet-expected_content.txt"
4343
})
4444
public void unwrappedContent_withFragment_expectDefinedContent(
45-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment,
45+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment,
4646
String expectedContentFileName) throws Exception {
4747
final String expectedContent = readText(expectedContentFileName);
4848
final String unwrappedContent = FragmentContentExtractor.unwrapContent(fragment);
@@ -74,7 +74,7 @@ public void unwrappedContent_withString_expectDefinedContent(
7474
"io/knotx/fragments/complex_custom_snippet.txt;io/knotx/fragments/complex_snippet-expected_content.txt"
7575
})
7676
public void unwrapFragmentContent_withFragment_expectDefinedContent(
77-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment,
77+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment,
7878
String expectedContentFileName) throws Exception {
7979

8080
final String expectedContent = readText(expectedContentFileName);
@@ -89,7 +89,7 @@ public void unwrapFragmentContent_withFragment_expectDefinedContent(
8989
"io/knotx/fragments/raw_snippet.txt"
9090
})
9191
public void getUnwrappedContent_withRawFragment_expectNotChangedContent(
92-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment) throws Exception {
92+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment) throws Exception {
9393
final String unwrappedContent = FragmentContentExtractor.unwrapContent(fragment);
9494

9595
assertThat(unwrappedContent, equalToIgnoringWhiteSpace(fragment.content()));

Diff for: knotx-core/src/test/java/io/knotx/junit/coercers/KnotxCoercers.java

-100
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
/*
2+
* Copyright (C) 2016 Cognifide Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.knotx.junit.converter;
17+
18+
import static org.mockito.Mockito.when;
19+
20+
import io.knotx.dataobjects.Fragment;
21+
import io.knotx.fragments.SnippetPatterns;
22+
import io.knotx.junit5.util.FileReader;
23+
import io.knotx.options.SnippetOptions;
24+
import java.io.IOException;
25+
import org.apache.commons.lang3.StringUtils;
26+
import org.junit.jupiter.params.ParameterizedTest;
27+
import org.junit.jupiter.params.converter.ArgumentConversionException;
28+
import org.junit.jupiter.params.converter.SimpleArgumentConverter;
29+
import org.mockito.Mockito;
30+
31+
/**
32+
* Simplifies argument type conversion for parameterized tests (these annotated with {@linkplain
33+
* ParameterizedTest})
34+
*/
35+
public class FragmentArgumentConverter extends SimpleArgumentConverter {
36+
37+
private static final String DEFAULT_SNIPPET_TAG_NAME = "script";
38+
private static final String DEFAULT_SNIPPET_PARAM_PREFIX = "data-knotx-";
39+
private static final String PARAMETER_SEPARATOR_REGEX = "\\|";
40+
private static final String PARAMETER_SEPARATOR = "|";
41+
42+
@Override
43+
protected Object convert(Object source, Class<?> targetType) throws ArgumentConversionException {
44+
if (!String.class.equals(source.getClass())) {
45+
throw new ArgumentConversionException("This converter supports only String as source object");
46+
}
47+
48+
String toConvert = String.valueOf(source);
49+
50+
if (targetType.equals(Fragment.class)) {
51+
try {
52+
return createFragmentMock(toConvert);
53+
} catch (IOException e) {
54+
throw new ArgumentConversionException("Exception thrown during conversion", e);
55+
}
56+
}
57+
58+
throw new ArgumentConversionException(
59+
"Unsupported object type for conversion: " + targetType.toString());
60+
}
61+
62+
/**
63+
* Builds mock of {@link io.knotx.dataobjects.Fragment} from provided fragmentParameters. The only
64+
* mandatory value of the fragmentParameters is fragment content file, that will be the fragment
65+
* content. There 2 additional params:
66+
*
67+
* <ul>
68+
* <li>custom snippet tag name (default value is <bb>script</bb>)
69+
* <li>custom snippet parameters prefix (default value is <bb>data-knotx-</bb>)
70+
* </ul>
71+
*
72+
* You can embed them in the fragmentParameters, separated by <bb>|</bb> character.<br>
73+
* <br>
74+
* <i>Example:</i> "content.txt|knotx:snippet|data-knotx-" will produce Fragment mock with
75+
* content read from content.txt, snippet tag name set to "knotx:snippet" and snippet parameters
76+
* prefix set to "data-knotx-". If the last character of fragmentParameters is the separator
77+
* <bb>|</bb>, then snippet parameters prefix will be set to empty string (no prefix).
78+
*/
79+
static Fragment createFragmentMock(String fragmentParameters) throws IOException {
80+
final String[] params = fragmentParameters.split(PARAMETER_SEPARATOR_REGEX);
81+
final String fragmentContentFile = params[0];
82+
final String snippetTagName = extractSnippetTagName(params);
83+
final String fragmentContent = FileReader.readText(fragmentContentFile);
84+
final String snippetParamPrefix = extractSnippetParamPrefix(params, fragmentParameters);
85+
final SnippetPatterns patterns =
86+
new SnippetPatterns(buildOptions(snippetTagName, snippetParamPrefix));
87+
88+
Fragment fragmentMock = Mockito.mock(Fragment.class);
89+
when(fragmentMock.content()).thenReturn(fragmentContent);
90+
when(fragmentMock.isRaw())
91+
.thenReturn(!patterns.getAnySnippetPattern().matcher(fragmentContent).matches());
92+
return fragmentMock;
93+
}
94+
95+
private static SnippetOptions buildOptions(String snippetTagName, String snippetParamPrefix) {
96+
return new SnippetOptions().setTagName(snippetTagName).setParamsPrefix(snippetParamPrefix);
97+
}
98+
99+
private static String extractSnippetTagName(String[] params) {
100+
if (params.length > 1) {
101+
return params[1];
102+
}
103+
return DEFAULT_SNIPPET_TAG_NAME;
104+
}
105+
106+
private static String extractSnippetParamPrefix(String[] params, String fragmentParameters) {
107+
if (params.length > 2) {
108+
return params[2];
109+
} else if (StringUtils.endsWith(fragmentParameters, PARAMETER_SEPARATOR)) {
110+
return "";
111+
}
112+
return DEFAULT_SNIPPET_PARAM_PREFIX;
113+
}
114+
}

Diff for: knotx-knot/knotx-knot-action/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>io.knotx</groupId>
2525
<artifactId>knotx-knot</artifactId>
26-
<version>1.3.1-SNAPSHOT</version>
26+
<version>1.4.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>knotx-knot-action</artifactId>

Diff for: knotx-knot/knotx-knot-handlebars/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>io.knotx</groupId>
2525
<artifactId>knotx-knot</artifactId>
26-
<version>1.3.1-SNAPSHOT</version>
26+
<version>1.4.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>knotx-knot-handlebars</artifactId>

Diff for: knotx-knot/knotx-knot-service/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>io.knotx</groupId>
2525
<artifactId>knotx-knot</artifactId>
26-
<version>1.3.1-SNAPSHOT</version>
26+
<version>1.4.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>knotx-knot-service</artifactId>

Diff for: knotx-knot/knotx-knot-service/src/test/java/io/knotx/knot/service/impl/FragmentContextTest.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import static uk.co.datumedge.hamcrest.json.SameJSONAs.sameJSONAs;
2121

2222
import io.knotx.dataobjects.Fragment;
23-
import io.knotx.junit5.KnotxArgumentConverter;
23+
import io.knotx.junit.converter.FragmentArgumentConverter;
2424
import io.knotx.knot.service.service.ServiceEntry;
2525
import io.vertx.core.json.JsonObject;
2626
import org.junit.jupiter.params.ParameterizedTest;
@@ -38,7 +38,7 @@ public class FragmentContextTest {
3838
"snippet_one_service_many_params-no-prefix.txt;{\"path\":\"/overridden/path\",\"anotherParam\":\"someValue\"}",
3939
})
4040
public void from_whenFragmentContainsOneService_expectFragmentContextWithExtractedParamsParams(
41-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment, String expectedParameters) {
41+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment, String expectedParameters) {
4242

4343
final FragmentContext fragmentContext = FragmentContext.from(fragment);
4444
final ServiceEntry serviceEntry = fragmentContext.services.get(0);
@@ -56,7 +56,7 @@ public void from_whenFragmentContainsOneService_expectFragmentContextWithExtract
5656
"snippet_one_service_many_params-no-prefix.txt;1"
5757
})
5858
public void from_whenFragmentContainsServices_expectFragmentContextWithProperNumberOfServicesExtracted(
59-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment, int numberOfExpectedServices) {
59+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment, int numberOfExpectedServices) {
6060

6161
final FragmentContext fragmentContext = FragmentContext.from(fragment);
6262
assertThat(fragmentContext.services.size(), is(numberOfExpectedServices));
@@ -69,7 +69,7 @@ public void from_whenFragmentContainsServices_expectFragmentContextWithProperNum
6969
"snippet_four_services_with_params_and_extra_param-no-prefix.txt;{\"a\":{\"a\":\"a\"},\"b\":{\"b\":\"b\"},\"c\":{\"c\":\"c\"},\"d\":{\"d\":\"d\"}}"
7070
})
7171
public void from_whenFragmentContainsServices_expectProperlyAssignedParams(
72-
@ConvertWith(KnotxArgumentConverter.class) Fragment fragment, JsonObject parameters) {
72+
@ConvertWith(FragmentArgumentConverter.class) Fragment fragment, JsonObject parameters) {
7373

7474
final FragmentContext fragmentContext = FragmentContext.from(fragment);
7575
fragmentContext.services.forEach(serviceEntry ->

0 commit comments

Comments
 (0)