// Path: src/main/java/org/bigtesting/fixd/Method.java
// public enum Method {
// 
//     GET, POST, PUT, TRACE, OPTIONS, HEAD, DELETE
// }
// 
// Path: src/main/java/org/bigtesting/fixd/ServerFixture.java
// public class ServerFixture {
// 
//     private final int port;
//     private final FixtureContainer container;
//     
//     private Server server;
//     private Connection connection;
//     private InetSocketAddress actualConnectionAddress;
//     
//     /**
//      * Constructs a ServerFixture with the port chosen automatically.
//      * The actual port used can be obtained from the {@link #getPort() getPort} method.
//      */
//     public ServerFixture() {
//         this(0);
//     }
//     
//     public ServerFixture(int port) {
//         
//         this.port = port;
//         this.container = new FixtureContainer();
//     }
//     
//     public ServerFixture(int port, int aysncThreadPoolSize) {
//         
//         this.port = port;
//         this.container = new FixtureContainer(aysncThreadPoolSize);
//     }
//     
//     public void start() throws IOException {
//         
//         server = new FixdServer(new ContainerServer(container));
//         connection = new SocketConnection(server, new LoggingAgent());
//         SocketAddress address = new InetSocketAddress(port);
//         
//         actualConnectionAddress = (InetSocketAddress)connection.connect(address);
//     }
//     
//     public void stop() throws IOException {
//         
//         if (connection == null || server == null) {
//             throw new IllegalStateException("server has not been started");
//         }
//         container.stop();
//         connection.close();
//         server.stop();
//     }
//     
//     public int getPort() {
//         
//         if (actualConnectionAddress == null) {
//             throw new IllegalStateException("server has not been started");
//         }
//         return actualConnectionAddress.getPort();
//     }
//     
//     public RequestHandler handle(Method method, String resource) {
//         
//         RequestHandlerImpl handler = new RequestHandlerImpl(container);
//         container.addHandler(handler, method, resource);
//         return handler;
//     }
//     
//     public RequestHandler handle(Method method, String resource, String contentType) {
//         
//         RequestHandlerImpl handler = new RequestHandlerImpl(container);
//         container.addHandler(handler, method, resource, contentType);
//         return handler;
//     }
//     
//     public Collection<CapturedRequest> capturedRequests() {
//         
//         return container.getCapturedRequests();
//     }
//     
//     public CapturedRequest request() {
//         
//         return container.nextCapturedRequest();
//     }
//     
//     public void setMaxCapturedRequests(int limit) {
//         
//         container.setCapturedRequestLimit(limit);
//     }
//     
//     public RequestMarshaller marshal(String contentType) {
//         
//         RequestMarshallerImpl marshaller = new RequestMarshallerImpl(contentType);
//         container.addContentMarshaller(contentType, marshaller);
//         return marshaller;
//     }
//     
//     public RequestUnmarshaller unmarshal(String contentType) {
//         
//         RequestUnmarshallerImpl marshaller = new RequestUnmarshallerImpl(contentType);
//         container.addContentUnmarshaller(contentType, marshaller);
//         return marshaller;
//     }
// }
// 
// Path: src/main/java/org/bigtesting/fixd/capture/CapturedRequest.java
// public interface CapturedRequest {
// 
//     String getPath();
//     
//     String getRequestLine();
//     
//     String getMethod();
//     
//     List<String> getHeaders();
//     
//     byte[] getBody();
//     
//     String getBody(String encoding);
//     
//     /**
//      * Returns true if this request was broadcast to any subscribers.
//      */
//     boolean isBroadcast();
// }


import static org.junit.Assert.*;
import org.bigtesting.fixd.Method;
import org.bigtesting.fixd.ServerFixture;
import org.bigtesting.fixd.capture.CapturedRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.ning.http.client.AsyncHttpClient;
/*
 * Copyright (C) 2015 BigTesting.org
 *
 * 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 org.bigtesting.fixd.tests;




/**
 * 
 * @author Luis Antunes
 */
public class TestCapturedRequest {

    private ServerFixture server;

    private AsyncHttpClient client;
    
    @Before
    public void beforeEachTest() throws Exception {
        server = new ServerFixture(8080);
        server.start();
        client = new AsyncHttpClient();
    }
    
    @Test
    public void testGetPath_Root() throws Exception {
    
        server.handle(Method.GET, "/")
              .with(200, "text/plain", "Hello");
  
        client.prepareGet("http://localhost:8080/").execute().get();
        
// Path: src/main/java/org/bigtesting/fixd/Method.java
// public enum Method {
// 
//     GET, POST, PUT, TRACE, OPTIONS, HEAD, DELETE
// }
// 
// Path: src/main/java/org/bigtesting/fixd/ServerFixture.java
// public class ServerFixture {
// 
//     private final int port;
//     private final FixtureContainer container;
//     
//     private Server server;
//     private Connection connection;
//     private InetSocketAddress actualConnectionAddress;
//     
//     /**
//      * Constructs a ServerFixture with the port chosen automatically.
//      * The actual port used can be obtained from the {@link #getPort() getPort} method.
//      */
//     public ServerFixture() {
//         this(0);
//     }
//     
//     public ServerFixture(int port) {
//         
//         this.port = port;
//         this.container = new FixtureContainer();
//     }
//     
//     public ServerFixture(int port, int aysncThreadPoolSize) {
//         
//         this.port = port;
//         this.container = new FixtureContainer(aysncThreadPoolSize);
//     }
//     
//     public void start() throws IOException {
//         
//         server = new FixdServer(new ContainerServer(container));
//         connection = new SocketConnection(server, new LoggingAgent());
//         SocketAddress address = new InetSocketAddress(port);
//         
//         actualConnectionAddress = (InetSocketAddress)connection.connect(address);
//     }
//     
//     public void stop() throws IOException {
//         
//         if (connection == null || server == null) {
//             throw new IllegalStateException("server has not been started");
//         }
//         container.stop();
//         connection.close();
//         server.stop();
//     }
//     
//     public int getPort() {
//         
//         if (actualConnectionAddress == null) {
//             throw new IllegalStateException("server has not been started");
//         }
//         return actualConnectionAddress.getPort();
//     }
//     
//     public RequestHandler handle(Method method, String resource) {
//         
//         RequestHandlerImpl handler = new RequestHandlerImpl(container);
//         container.addHandler(handler, method, resource);
//         return handler;
//     }
//     
//     public RequestHandler handle(Method method, String resource, String contentType) {
//         
//         RequestHandlerImpl handler = new RequestHandlerImpl(container);
//         container.addHandler(handler, method, resource, contentType);
//         return handler;
//     }
//     
//     public Collection<CapturedRequest> capturedRequests() {
//         
//         return container.getCapturedRequests();
//     }
//     
//     public CapturedRequest request() {
//         
//         return container.nextCapturedRequest();
//     }
//     
//     public void setMaxCapturedRequests(int limit) {
//         
//         container.setCapturedRequestLimit(limit);
//     }
//     
//     public RequestMarshaller marshal(String contentType) {
//         
//         RequestMarshallerImpl marshaller = new RequestMarshallerImpl(contentType);
//         container.addContentMarshaller(contentType, marshaller);
//         return marshaller;
//     }
//     
//     public RequestUnmarshaller unmarshal(String contentType) {
//         
//         RequestUnmarshallerImpl marshaller = new RequestUnmarshallerImpl(contentType);
//         container.addContentUnmarshaller(contentType, marshaller);
//         return marshaller;
//     }
// }
// 
// Path: src/main/java/org/bigtesting/fixd/capture/CapturedRequest.java
// public interface CapturedRequest {
// 
//     String getPath();
//     
//     String getRequestLine();
//     
//     String getMethod();
//     
//     List<String> getHeaders();
//     
//     byte[] getBody();
//     
//     String getBody(String encoding);
//     
//     /**
//      * Returns true if this request was broadcast to any subscribers.
//      */
//     boolean isBroadcast();
// }


// Path: src/test/java/org/bigtesting/fixd/tests/TestCapturedRequest.java
import static org.junit.Assert.*;
import org.bigtesting.fixd.Method;
import org.bigtesting.fixd.ServerFixture;
import org.bigtesting.fixd.capture.CapturedRequest;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.ning.http.client.AsyncHttpClient;

/*
 * Copyright (C) 2015 BigTesting.org
 *
 * 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 org.bigtesting.fixd.tests;




/**
 * 
 * @author Luis Antunes
 */
public class TestCapturedRequest {

    private ServerFixture server;

    private AsyncHttpClient client;
    
    @Before
    public void beforeEachTest() throws Exception {
        server = new ServerFixture(8080);
        server.start();
        client = new AsyncHttpClient();
    }
    
    @Test
    public void testGetPath_Root() throws Exception {
    
        server.handle(Method.GET, "/")
              .with(200, "text/plain", "Hello");
  
        client.prepareGet("http://localhost:8080/").execute().get();
        
        CapturedRequest captured = server.request();