// Path: node-extensions/file-extension/src/test/java/io/sterodium/extensions/node/BaseServletTest.java
// public abstract class BaseServletTest {
// 
//     public static final String ZIP_FILE_NAME = "test_entry.txt";
// 
//     protected Server startServerForServlet(HttpServlet servlet, String path) throws Exception {
//         Server server = new Server(0);
// 
//         ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
//         context.setContextPath("/");
//         server.setHandler(context);
// 
//         context.addServlet(new ServletHolder(servlet), path);
//         server.start();
// 
//         return server;
//     }
// 
//     protected File createZipArchiveWithTextFile() throws IOException {
//         final File zipArchive = File.createTempFile("temp_zip_", ".zip");
//         try (
//                 final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipArchive))) {
//             ZipEntry e = new ZipEntry(ZIP_FILE_NAME);
//             out.putNextEntry(e);
//             IOUtils.write("test data", out, StandardCharsets.UTF_8);
//             out.closeEntry();
//         }
//         return zipArchive;
//     }
// 
//     protected void deleteIfExists(File... files) {
//         for (File file : files) {
//             if (file != null && file.exists()) {
//                 assertThat("Couldn't clean file after tests", file.delete(), is(true));
//             }
//         }
//     }
// }


import io.sterodium.extensions.node.BaseServletTest;
import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;
import org.apache.commons.io.IOUtils;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.seleniumhq.jetty9.server.AbstractNetworkConnector;
import org.seleniumhq.jetty9.server.Server;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
package io.sterodium.extensions.node.upload;





/**
 * @author Alexey Nikolaenko alexey@tcherezov.com
 *         Date: 24/09/2015
 */
public class FileUploadServletTest extends BaseServletTest {

    private int port;
    private File zipArchive;
    private Server fileUploadServer;
    private File unzippedFile;
    private File unzippedArchive;

    @Before
    public void setUp() throws Exception {
        fileUploadServer = startServerForServlet(new FileUploadServlet(), "/" + FileUploadServlet.class.getSimpleName() + "/*");
        port = ((AbstractNetworkConnector) fileUploadServer.getConnectors()[0]).getLocalPort();

        zipArchive = createZipArchiveWithTextFile();
    }

    @Test
    public void testDoPost() throws IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();

        HttpPost httpPost = new HttpPost("http://localhost:" + port + "/FileUploadServlet/");
// Path: node-extensions/file-extension/src/test/java/io/sterodium/extensions/node/BaseServletTest.java
// public abstract class BaseServletTest {
// 
//     public static final String ZIP_FILE_NAME = "test_entry.txt";
// 
//     protected Server startServerForServlet(HttpServlet servlet, String path) throws Exception {
//         Server server = new Server(0);
// 
//         ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
//         context.setContextPath("/");
//         server.setHandler(context);
// 
//         context.addServlet(new ServletHolder(servlet), path);
//         server.start();
// 
//         return server;
//     }
// 
//     protected File createZipArchiveWithTextFile() throws IOException {
//         final File zipArchive = File.createTempFile("temp_zip_", ".zip");
//         try (
//                 final ZipOutputStream out = new ZipOutputStream(new FileOutputStream(zipArchive))) {
//             ZipEntry e = new ZipEntry(ZIP_FILE_NAME);
//             out.putNextEntry(e);
//             IOUtils.write("test data", out, StandardCharsets.UTF_8);
//             out.closeEntry();
//         }
//         return zipArchive;
//     }
// 
//     protected void deleteIfExists(File... files) {
//         for (File file : files) {
//             if (file != null && file.exists()) {
//                 assertThat("Couldn't clean file after tests", file.delete(), is(true));
//             }
//         }
//     }
// }


// Path: node-extensions/file-extension/src/test/java/io/sterodium/extensions/node/upload/FileUploadServletTest.java
import io.sterodium.extensions.node.BaseServletTest;
import com.google.common.net.HttpHeaders;
import com.google.common.net.MediaType;
import org.apache.commons.io.IOUtils;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.InputStreamEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.seleniumhq.jetty9.server.AbstractNetworkConnector;
import org.seleniumhq.jetty9.server.Server;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

package io.sterodium.extensions.node.upload;





/**
 * @author Alexey Nikolaenko alexey@tcherezov.com
 *         Date: 24/09/2015
 */
public class FileUploadServletTest extends BaseServletTest {

    private int port;
    private File zipArchive;
    private Server fileUploadServer;
    private File unzippedFile;
    private File unzippedArchive;

    @Before
    public void setUp() throws Exception {
        fileUploadServer = startServerForServlet(new FileUploadServlet(), "/" + FileUploadServlet.class.getSimpleName() + "/*");
        port = ((AbstractNetworkConnector) fileUploadServer.getConnectors()[0]).getLocalPort();

        zipArchive = createZipArchiveWithTextFile();
    }

    @Test
    public void testDoPost() throws IOException {
        CloseableHttpClient httpClient = HttpClients.createDefault();

        HttpPost httpPost = new HttpPost("http://localhost:" + port + "/FileUploadServlet/");
        httpPost.setHeader(HttpHeaders.CONTENT_TYPE, MediaType.OCTET_STREAM.toString());