<commit_before>/*
 * Copyright 2014 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at http://www.eclipse.org/legal/epl-v10.html
 */
package io.liveoak.filesystem.aggregating;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import io.liveoak.common.codec.DefaultResourceState;
import io.liveoak.filesystem.aggregating.extension.AggregatingFilesystemExtension;
import io.liveoak.spi.resource.RootResource;
import io.liveoak.spi.resource.async.Resource;
import io.liveoak.spi.state.ResourceState;
import io.liveoak.testtools.AbstractHTTPResourceTestCase;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class HTTPAggregatingFilesystemResourceTest extends AbstractHTTPResourceTestCase {


    @Override
    public void loadExtensions() throws Exception {
        loadExtension( "aggr-fs", new AggregatingFilesystemExtension() );
        installResource( "aggr-fs", "aggr", JsonNodeFactory.instance.objectNode() );
    }

    @Override
    protected File applicationDirectory() {
        return this.projectRoot;
    }

    @Before
    public void before() {
        File dataDir = new File( this.projectRoot, "aggr" );

        // create some files in there
        try {
            FileWriter out = new FileWriter(new File(dataDir, "aggregate.js.aggr"));
            out.write("require first.js\n");
            out.write("require second.js\n");
            out.close();

            out = new FileWriter(new File(dataDir, "first.js"));
            out.write("// first.js\n");
            out.close();

            out = new FileWriter(new File(dataDir, "second.js"));
            out.write("// second.js\n");
            out.close();
        } catch (IOException e) {
            throw new RuntimeException("Failed to create a test file: ", e);
        }
    }

    @After
    public void after() {
        File dataDir = new File( this.projectRoot, "aggr" );
        new File(dataDir, "aggregate.js.aggr").delete();
        new File(dataDir, "first.js").delete();
        new File(dataDir, "second.js").delete();
    }

    @Test
    public void testReadAggregate() throws Exception {<commit_msg>Debug to debug CI failure.<commit_after>/*
 * Copyright 2014 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at http://www.eclipse.org/legal/epl-v10.html
 */
package io.liveoak.filesystem.aggregating;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import io.liveoak.common.codec.DefaultResourceState;
import io.liveoak.filesystem.aggregating.extension.AggregatingFilesystemExtension;
import io.liveoak.spi.resource.RootResource;
import io.liveoak.spi.resource.async.Resource;
import io.liveoak.spi.state.ResourceState;
import io.liveoak.testtools.AbstractHTTPResourceTestCase;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;

/**
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 */
public class HTTPAggregatingFilesystemResourceTest extends AbstractHTTPResourceTestCase {


    @Override
    public void loadExtensions() throws Exception {
        loadExtension( "aggr-fs", new AggregatingFilesystemExtension() );
        installResource( "aggr-fs", "aggr", JsonNodeFactory.instance.objectNode() );
    }

    @Override
    protected File applicationDirectory() {
        return this.projectRoot;
    }

    @Before
    public void before() {
        File dataDir = new File( this.projectRoot, "aggr" );

        System.err.println( "ATTEMPT TO CREATE TEST FILES IN: " + dataDir );

        // create some files in there
        try {
            FileWriter out = new FileWriter(new File(dataDir, "aggregate.js.aggr"));
            out.write("require first.js\n");
            out.write("require second.js\n");
            out.close();

            out = new FileWriter(new File(dataDir, "first.js"));
            out.write("// first.js\n");
            out.close();

            out = new FileWriter(new File(dataDir, "second.js"));
            out.write("// second.js\n");
            out.close();
        } catch (IOException e) {
            throw new RuntimeException("Failed to create a test file: ", e);
        }
    }

    @After
    public void after() {
        File dataDir = new File( this.projectRoot, "aggr" );
        new File(dataDir, "aggregate.js.aggr").delete();
        new File(dataDir, "first.js").delete();
        new File(dataDir, "second.js").delete();
    }

    @Test
    public void testReadAggregate() throws Exception {
{'fraction_non_alphanumeric': 0.12373496276494177, 'fraction_numerical': 0.003055184265801031, 'mean_word_length': 3.1244094488188976, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '6726700', 'n_tokens_mistral': 1569, 'n_tokens_neox': 1522, 'n_words': 346}