http-testserver

CommonJava top-level parent POM.

License

License

GroupId

GroupId

org.commonjava.util
ArtifactId

ArtifactId

http-testserver
Last Version

Last Version

1.4
Release Date

Release Date

Type

Type

jar
Description

Description

http-testserver
CommonJava top-level parent POM.
Source Code Management

Source Code Management

https://github.com/Commonjava/http-testserver

Download http-testserver

How to add to project

<!-- https://jarcasting.com/artifacts/org.commonjava.util/http-testserver/ -->
<dependency>
    <groupId>org.commonjava.util</groupId>
    <artifactId>http-testserver</artifactId>
    <version>1.4</version>
</dependency>
// https://jarcasting.com/artifacts/org.commonjava.util/http-testserver/
implementation 'org.commonjava.util:http-testserver:1.4'
// https://jarcasting.com/artifacts/org.commonjava.util/http-testserver/
implementation ("org.commonjava.util:http-testserver:1.4")
'org.commonjava.util:http-testserver:jar:1.4'
<dependency org="org.commonjava.util" name="http-testserver" rev="1.4">
  <artifact name="http-testserver" type="jar" />
</dependency>
@Grapes(
@Grab(group='org.commonjava.util', module='http-testserver', version='1.4')
)
libraryDependencies += "org.commonjava.util" % "http-testserver" % "1.4"
[org.commonjava.util/http-testserver "1.4"]

Dependencies

compile (10)

Group / Artifact Type Version
io.undertow : undertow-core jar 1.1.2.Final
io.undertow : undertow-servlet jar 1.1.2.Final
org.jboss.spec.javax.servlet : jboss-servlet-api_3.0_spec jar
junit : junit jar
commons-io : commons-io jar
org.slf4j : slf4j-api jar
org.slf4j : jcl-over-slf4j jar
ch.qos.logback : logback-classic jar
commons-lang : commons-lang jar
org.apache.httpcomponents : httpclient jar

Project Modules

There are no modules declared in this project.

Simulating remote HTTP servers for functional testing

This is a test fixture, which provides a very basic servlet that registers expected requests and logs access counts for each requested method/pathParts combination. If no expectation is registered for a particular method/pathParts, 404 is returned.

Usage is pretty simple:

@Rule
public TestHttpServer server = new TestHttpServer( "repos" );

@Test
public void run()
    throws Exception
{
    final String pathParts = "/repos/pathParts/to/something.txt";
    final String content = "this is the content";
    final String url = server.formatUrl( pathParts );
    server.expect( url, 200, content );

    final HttpGet request = new HttpGet( url );
    final CloseableHttpClient client = HttpClients.createDefault();
    CloseableHttpResponse response = null;

    InputStream stream = null;
    try
    {
        response = client.execute( request );
        stream = response.getEntity()
                         .getContent();
        final String result = IOUtils.toString( stream );

        assertThat( result, notNullValue() );
        assertThat( result, equalTo( content ) );
    }
    finally
    {
        IOUtils.closeQuietly( stream );
        if ( response != null && response.getEntity() != null )
        {
            EntityUtils.consumeQuietly( response.getEntity() );
            IOUtils.closeQuietly( response );
        }

        if ( request != null )
        {
            request.reset();
        }

        if ( client != null )
        {
            IOUtils.closeQuietly( client );
        }
    }

    assertThat( server.getAccessesByPathKey()
                      .get( server.getAccessKey( CommonMethod.GET.name(), pathParts ) ), equalTo( 1 ) );
}
org.commonjava.util

Red Hat NOS

Middleware pipeline content management projects

Versions

Version
1.4
1.3
1.2
1.1
1.0