Search in sources :

Example 6 with Fragment

use of io.knotx.dataobjects.Fragment 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;
}
Also used : Fragment(io.knotx.dataobjects.Fragment) SnippetPatterns(io.knotx.fragments.SnippetPatterns)

Example 7 with Fragment

use of io.knotx.dataobjects.Fragment in project knotx by Cognifide.

the class FragmentContentExtractorTest method provideFragment.

@Coercion
public Fragment provideFragment(String fragmentContentFile) throws IOException {
    final String fragmentContent = readText(fragmentContentFile);
    Fragment fragmentMock = Mockito.mock(Fragment.class);
    when(fragmentMock.isRaw()).thenReturn(!fragmentContent.contains(FragmentConstants.SNIPPET_IDENTIFIER_NAME));
    when(fragmentMock.content()).thenReturn(fragmentContent);
    return fragmentMock;
}
Also used : Fragment(io.knotx.dataobjects.Fragment) Coercion(com.googlecode.zohhak.api.Coercion)

Aggregations

Fragment (io.knotx.dataobjects.Fragment)7 KnotContext (io.knotx.dataobjects.KnotContext)3 KnotxConfiguration (io.knotx.junit.rule.KnotxConfiguration)3 Test (org.junit.Test)3 Coercion (com.googlecode.zohhak.api.Coercion)1 SnippetPatterns (io.knotx.fragments.SnippetPatterns)1 ServiceAttributeUtil (io.knotx.knot.service.service.ServiceAttributeUtil)1 ServiceEntry (io.knotx.knot.service.service.ServiceEntry)1 Observable (io.reactivex.Observable)1 JsonObject (io.vertx.core.json.JsonObject)1 List (java.util.List)1 Map (java.util.Map)1 Function (java.util.function.Function)1 MatchResult (java.util.regex.MatchResult)1 Matcher (java.util.regex.Matcher)1 Collectors (java.util.stream.Collectors)1 Jsoup (org.jsoup.Jsoup)1 Attribute (org.jsoup.nodes.Attribute)1 Document (org.jsoup.nodes.Document)1 Element (org.jsoup.nodes.Element)1