// Path: client/src/main/java/com/nesscomputing/httpclient/HttpClientResponse.java
// public interface HttpClientResponse {
// 	/**
// 	 * Returns the status code for the request.
// 	 *
// 	 * @return the status code, use the related {@link HttpServletRequest} constants
// 	 */
// 	int getStatusCode();
// 
// 	/**
// 	 * Returns the status text for the request.
// 	 *
// 	 * @return the status text
// 	 */
// 	String getStatusText();
// 
// 	/**
// 	 * Returns an input stream for the response body.
// 	 *
// 	 * @return the input stream
// 	 * @throws IOException on error
// 	 */
// 	InputStream getResponseBodyAsStream() throws IOException;
// 
// 	/** @return the URI of the request. */
// 	URI getUri();
// 
// 	/** @return Content type of the response. */
// 	String getContentType();
// 
// 	/**
// 	 * @return Length of the content, if present. Can be null (not present), -1 (chunked) or 0 (no
// 	 *         content).
// 	 */
// 	@CheckForNull
// 	Long getContentLength();
// 
// 	/** @return Content charset if present in the header. Can be null. */
// 	@CheckForNull
// 	String getCharset();
// 
// 	/**
// 	 * @param name the header name
// 	 * @return The named header from the response. Response can be null.
// 	 */
// 	@CheckForNull
// 	String getHeader(String name);
// 
// 	/**
// 	 * @param name the header name
// 	 * @return all values for the given header. Response can be null.
// 	 */
// 	@CheckForNull
// 	List<String> getHeaders(String name);
// 
// 	/** @return Map of header name -> list of values for each header name */
//     @Nonnull
// 	public Map<String, List<String>> getAllHeaders();
// 
// 	/** @return true if the response redirects to another object. */
// 	boolean isRedirected();
// }
// 
// Path: client/src/main/java/com/nesscomputing/httpclient/response/ContentConverter.java
// public interface ContentConverter<T>
// {
//     /**
//      * Called when the ContentResponseHandler wants to convert an input stream
//      * into a response object. Calling this method does *not* imply a 2xx response code,
//      * this method will be called for all response codes if no error occurs while processing
//      * the response.
//      *
//      * @param response The response object from the Http client.
//      * @param inputStream The response body as stream.
//      * @return The result object. Can be null.
//      * @throws IOException
//      */
//     T convert(HttpClientResponse response, InputStream inputStream) throws IOException;
// 
//     /**
//      * Called if an exception occured while trying to convert the response data stream
//      * into a response object.
//      *
//      * @param response The response object from the Http client.
//      * @param ex Exception triggering this call.
//      * @return A response object or null.
//      * @throws IOException
//      */
//     T handleError(HttpClientResponse response, IOException ex) throws IOException;
// }


import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.concurrent.Immutable;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import com.nesscomputing.httpclient.HttpClientResponse;
import com.nesscomputing.httpclient.response.ContentConverter;
/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * 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.nesscomputing.httpclient.testsupport;







@Immutable
public class StringResponseConverter implements ContentConverter<String>
{
    private final int responseCode;


    public StringResponseConverter()
    {
        this(HttpServletResponse.SC_OK);
    }

    public StringResponseConverter(final int responseCode)
    {
        this.responseCode = responseCode;
    }

    @Override
    public String convert(final HttpClientResponse response, final InputStream inputStream)
        throws IOException
    {
// Path: client/src/main/java/com/nesscomputing/httpclient/HttpClientResponse.java
// public interface HttpClientResponse {
// 	/**
// 	 * Returns the status code for the request.
// 	 *
// 	 * @return the status code, use the related {@link HttpServletRequest} constants
// 	 */
// 	int getStatusCode();
// 
// 	/**
// 	 * Returns the status text for the request.
// 	 *
// 	 * @return the status text
// 	 */
// 	String getStatusText();
// 
// 	/**
// 	 * Returns an input stream for the response body.
// 	 *
// 	 * @return the input stream
// 	 * @throws IOException on error
// 	 */
// 	InputStream getResponseBodyAsStream() throws IOException;
// 
// 	/** @return the URI of the request. */
// 	URI getUri();
// 
// 	/** @return Content type of the response. */
// 	String getContentType();
// 
// 	/**
// 	 * @return Length of the content, if present. Can be null (not present), -1 (chunked) or 0 (no
// 	 *         content).
// 	 */
// 	@CheckForNull
// 	Long getContentLength();
// 
// 	/** @return Content charset if present in the header. Can be null. */
// 	@CheckForNull
// 	String getCharset();
// 
// 	/**
// 	 * @param name the header name
// 	 * @return The named header from the response. Response can be null.
// 	 */
// 	@CheckForNull
// 	String getHeader(String name);
// 
// 	/**
// 	 * @param name the header name
// 	 * @return all values for the given header. Response can be null.
// 	 */
// 	@CheckForNull
// 	List<String> getHeaders(String name);
// 
// 	/** @return Map of header name -> list of values for each header name */
//     @Nonnull
// 	public Map<String, List<String>> getAllHeaders();
// 
// 	/** @return true if the response redirects to another object. */
// 	boolean isRedirected();
// }
// 
// Path: client/src/main/java/com/nesscomputing/httpclient/response/ContentConverter.java
// public interface ContentConverter<T>
// {
//     /**
//      * Called when the ContentResponseHandler wants to convert an input stream
//      * into a response object. Calling this method does *not* imply a 2xx response code,
//      * this method will be called for all response codes if no error occurs while processing
//      * the response.
//      *
//      * @param response The response object from the Http client.
//      * @param inputStream The response body as stream.
//      * @return The result object. Can be null.
//      * @throws IOException
//      */
//     T convert(HttpClientResponse response, InputStream inputStream) throws IOException;
// 
//     /**
//      * Called if an exception occured while trying to convert the response data stream
//      * into a response object.
//      *
//      * @param response The response object from the Http client.
//      * @param ex Exception triggering this call.
//      * @return A response object or null.
//      * @throws IOException
//      */
//     T handleError(HttpClientResponse response, IOException ex) throws IOException;
// }


// Path: client/src/test/java/com/nesscomputing/httpclient/testsupport/StringResponseConverter.java
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import java.io.IOException;
import java.io.InputStream;
import javax.annotation.concurrent.Immutable;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.junit.Assert;
import com.nesscomputing.httpclient.HttpClientResponse;
import com.nesscomputing.httpclient.response.ContentConverter;

/**
 * Copyright (C) 2012 Ness Computing, Inc.
 *
 * 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.nesscomputing.httpclient.testsupport;







@Immutable
public class StringResponseConverter implements ContentConverter<String>
{
    private final int responseCode;


    public StringResponseConverter()
    {
        this(HttpServletResponse.SC_OK);
    }

    public StringResponseConverter(final int responseCode)
    {
        this.responseCode = responseCode;
    }

    @Override
    public String convert(final HttpClientResponse response, final InputStream inputStream)
        throws IOException
    {
        Assert.assertThat(response.getStatusCode(), is(equalTo(responseCode)));