use of io.knotx.fragments.SnippetPatterns in project knotx by Cognifide.
the class UnprocessedFragmentStrategyTest method ignore_whenConfiguredSnippetTag_expectIgnoredContent.
@TestWith({ "simple_snippet.txt;simple_snippet-expected_ignored_content.txt;script", "customTag_snippet.txt;simple_snippet-expected_ignored_content.txt;knotx:snippet", // when fragment is a raw fragment, it is not ignored
"raw_fragment.txt;raw_fragment.txt;script" })
public void ignore_whenConfiguredSnippetTag_expectIgnoredContent(Fragment fragment, String expectedContentFileName, String snippetTagName) throws Exception {
final String unwrappedContent = UnprocessedFragmentStrategy.IGNORE.get(fragment, new SnippetPatterns(snippetTagName));
final String expectedContent = FileReader.readText(expectedContentFileName);
assertThat(unwrappedContent, equalToIgnoringWhiteSpace(expectedContent));
}
use of io.knotx.fragments.SnippetPatterns in project knotx by Cognifide.
the class UnprocessedFragmentStrategyTest method unwrap_whenConfiguredSnippetTag_expectDefinedContentWithComments.
@TestWith({ "simple_snippet.txt;simple_snippet-expected_unwrapped_content.txt;script", "customTag_snippet.txt|knotx:snippet;simple_snippet-expected_unwrapped_content.txt;knotx:snippet", "big_snippet.txt;big_snippet-expected_unwrapped_content.txt;script" })
public void unwrap_whenConfiguredSnippetTag_expectDefinedContentWithComments(Fragment fragment, String expectedContentFileName, String snippetTagName) throws Exception {
final String unwrappedContent = UnprocessedFragmentStrategy.UNWRAP.get(fragment, new SnippetPatterns(snippetTagName));
final String expectedContent = FileReader.readText(expectedContentFileName);
assertThat(unwrappedContent, equalToIgnoringWhiteSpace(expectedContent));
}
use of io.knotx.fragments.SnippetPatterns in project knotx by Cognifide.
the class UnprocessedFragmentStrategyTest method asIs_whenConfiguredSnippetTag_expectIgnoredContent.
@TestWith({ "simple_snippet.txt;simple_snippet.txt;script", "customTag_snippet.txt;customTag_snippet.txt;knotx:snippet", "raw_fragment.txt;raw_fragment.txt;script" })
public void asIs_whenConfiguredSnippetTag_expectIgnoredContent(Fragment fragment, String expectedContentFileName, String snippetTagName) throws Exception {
final String unwrappedContent = UnprocessedFragmentStrategy.AS_IS.get(fragment, new SnippetPatterns(snippetTagName));
final String expectedContent = FileReader.readText(expectedContentFileName);
assertThat(unwrappedContent, equalToIgnoringWhiteSpace(expectedContent));
}
use of io.knotx.fragments.SnippetPatterns in project knotx by Cognifide.
the class KnotxCoercers method provideFragment.
public Fragment provideFragment(String fragmentContentFileWithDefinedSnippetTagName) throws IOException {
final String[] params = fragmentContentFileWithDefinedSnippetTagName.split("\\|");
final String fragmentContentFile = params[0];
final String snippetTagName;
if (params.length > 1) {
snippetTagName = params[1];
} else {
snippetTagName = FragmentConstants.DEFAULT_SNIPPET_TAG_NAME;
}
final String fragmentContent = FileReader.readText(fragmentContentFile);
final SnippetPatterns patterns = new SnippetPatterns(snippetTagName);
Fragment fragmentMock = Mockito.mock(Fragment.class);
when(fragmentMock.content()).thenReturn(fragmentContent);
when(fragmentMock.isRaw()).thenReturn(!patterns.getAnySnippetPattern().matcher(fragmentContent).matches());
return fragmentMock;
}
Aggregations