<commit_before>/*
 * Knot.x - Reactive microservice assembler - Templating Engine Verticle
 *
 * Copyright (C) 2016 Cognifide Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cognifide.knotx.engine;

import com.cognifide.knotx.engine.parser.HtmlFragment;
import com.cognifide.knotx.engine.parser.HtmlParser;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.List;
import java.util.stream.IntStream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

public class HtmlParserTest extends AbstractKnotxConfigurationTest {

    @Rule
    public final ExpectedException expectedException = ExpectedException.none();
    private String TEST_HTML = "test.html";
    private String TEST_NO_FRAGMENTS_HTML = "test-no-fragments.html";
    private String TEST_ONE_FRAGMENT_HTML = "test-one-fragment.html";

    private String EXPECTED_ONE_FRAGMENT = "<script data-api-type=\"templating\" data-call-uri=\"/service/mock/first.json\" type=\"text/x-handlebars-template\"><h2>{{message}}</h2></script>";


    private List<HtmlFragment> test;
    private List<HtmlFragment> testNoTemplates;
    private List<HtmlFragment> testOneTemplates;

    @Before
    public void setUp() throws Exception {
        test = new HtmlParser(readText(TEST_HTML)).getFragments();
        testNoTemplates = new HtmlParser(readText(TEST_NO_FRAGMENTS_HTML)).getFragments();
        testOneTemplates = new HtmlParser(readText(TEST_ONE_FRAGMENT_HTML)).getFragments();
    }

    @Test
    @Ignore
    public void testComposeFragmetns() throws Exception {
        StringBuilder result = new StringBuilder();
        IntStream.rangeClosed(0, 6).forEach(idx -> result.append(test.get(idx).getContent()));

        assertThat(result.toString().trim(), equalTo(readText(TEST_HTML).trim()));
    }

    @Test
    @Ignore
    public void testNoFragments() throws Exception {
        assertThat(testNoTemplates.size(), equalTo(1));
        assertThat(testNoTemplates.get(0).hasHandlebarsTemplate(), equalTo(false));
        assertThat(testNoTemplates.get(0).getContent(), equalTo(readText(TEST_NO_FRAGMENTS_HTML)));
    }

    @Test
    public void testOneFragment() throws Exception {
        assertThat(testOneTemplates.size(), equalTo(3));
        assertThat(testOneTemplates.get(0).hasHandlebarsTemplate(), equalTo(false));
        assertThat(testOneTemplates.get(1).hasHandlebarsTemplate(), equalTo(true));
        assertThat(testOneTemplates.get(1).getContent(), equalTo(EXPECTED_ONE_FRAGMENT));
        assertThat(testOneTemplates.get(2).hasHandlebarsTemplate(), equalTo(false));
    }<commit_msg>remove @Ignore from some tests. Issue #20<commit_after>/*
 * Knot.x - Reactive microservice assembler - Templating Engine Verticle
 *
 * Copyright (C) 2016 Cognifide Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cognifide.knotx.engine;

import com.cognifide.knotx.engine.parser.HtmlFragment;
import com.cognifide.knotx.engine.parser.HtmlParser;

import org.junit.Before;
import org.junit.Ignore;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;

import java.util.List;
import java.util.stream.IntStream;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;

public class HtmlParserTest extends AbstractKnotxConfigurationTest {

    @Rule
    public final ExpectedException expectedException = ExpectedException.none();
    private String TEST_HTML = "test.html";
    private String TEST_NO_FRAGMENTS_HTML = "test-no-fragments.html";
    private String TEST_ONE_FRAGMENT_HTML = "test-one-fragment.html";

    private String EXPECTED_ONE_FRAGMENT = "<script data-api-type=\"templating\" data-call-uri=\"/service/mock/first.json\" type=\"text/x-handlebars-template\"><h2>{{message}}</h2></script>";


    private List<HtmlFragment> test;
    private List<HtmlFragment> testNoTemplates;
    private List<HtmlFragment> testOneTemplates;

    @Before
    public void setUp() throws Exception {
        test = new HtmlParser(readText(TEST_HTML)).getFragments();
        testNoTemplates = new HtmlParser(readText(TEST_NO_FRAGMENTS_HTML)).getFragments();
        testOneTemplates = new HtmlParser(readText(TEST_ONE_FRAGMENT_HTML)).getFragments();
    }

    @Test
    public void testComposeFragmetns() throws Exception {
        StringBuilder result = new StringBuilder();
        IntStream.rangeClosed(0, 6).forEach(idx -> result.append(test.get(idx).getContent()));

        assertThat(result.toString().trim(), equalTo(readText(TEST_HTML).trim()));
    }

    @Test
    public void testNoFragments() throws Exception {
        assertThat(testNoTemplates.size(), equalTo(1));
        assertThat(testNoTemplates.get(0).hasHandlebarsTemplate(), equalTo(false));
        assertThat(testNoTemplates.get(0).getContent(), equalTo(readText(TEST_NO_FRAGMENTS_HTML)));
    }

    @Test
    public void testOneFragment() throws Exception {
        assertThat(testOneTemplates.size(), equalTo(3));
        assertThat(testOneTemplates.get(0).hasHandlebarsTemplate(), equalTo(false));
        assertThat(testOneTemplates.get(1).hasHandlebarsTemplate(), equalTo(true));
        assertThat(testOneTemplates.get(1).getContent(), equalTo(EXPECTED_ONE_FRAGMENT));
        assertThat(testOneTemplates.get(2).hasHandlebarsTemplate(), equalTo(false));
    }
{'fraction_non_alphanumeric': 0.1101720958819914, 'fraction_numerical': 0.00645359557467732, 'mean_word_length': 4.469747899159664, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6652523', 'n_tokens_mistral': 1909, 'n_tokens_neox': 1884, 'n_words': 436}