Search in sources :

Example 11 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method getHttp.

public HttpTestServer getHttp() throws Exception {
    HttpTestServer.Config config = new Config();
    config.https = false;
    HttpTestServer http = new Httpbin(config);
    http.start();
    return http;
}
Also used : Config(aQute.http.testservers.HttpTestServer.Config) Config(aQute.http.testservers.HttpTestServer.Config) Httpbin(aQute.http.testservers.Httpbin) HttpTestServer(aQute.http.testservers.HttpTestServer)

Example 12 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method testGet.

public void testGet() throws Exception {
    try (HttpTestServer http = getHttp()) {
        Map<String, ?> map = get(http, MAP_REF, "/get");
        assertNotNull(map.get("headers"));
    }
}
Also used : HttpTestServer(aQute.http.testservers.HttpTestServer)

Example 13 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method testCorrectCommonName.

public void testCorrectCommonName() throws Exception {
    HttpTestServer http = getHttps();
    X509Certificate cert = http.getCertificateChain()[0];
    String name = cert.getSubjectDN().getName();
    Matcher m = DN_P.matcher(name);
    assertTrue(m.find());
    assertEquals(m.group("cn"), http.getAddress().getHostName());
}
Also used : Matcher(java.util.regex.Matcher) HttpTestServer(aQute.http.testservers.HttpTestServer) X509Certificate(java.security.cert.X509Certificate)

Example 14 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method testStatus.

public void testStatus() throws Exception {
    try (HttpTestServer http = getHttp()) {
        URL uri = new URI(http.getBaseURI() + "/status/500").toURL();
        HttpURLConnection connection = (HttpURLConnection) uri.openConnection();
        assertEquals(500, connection.getResponseCode());
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) HttpTestServer(aQute.http.testservers.HttpTestServer) URI(java.net.URI) URL(java.net.URL)

Example 15 with HttpTestServer

use of aQute.http.testservers.HttpTestServer in project bnd by bndtools.

the class HttpTestServerTest method testURI.

public void testURI() throws Exception {
    try (HttpTestServer http = getHttps()) {
        URI uri = http.getBaseURI();
        assertEquals(http.getAddress().getPort(), uri.getPort());
        assertEquals(http.getAddress().getHostName(), uri.getHost());
        assertEquals("https", uri.getScheme());
    }
}
Also used : HttpTestServer(aQute.http.testservers.HttpTestServer) URI(java.net.URI)

Aggregations

HttpTestServer (aQute.http.testservers.HttpTestServer)22 URL (java.net.URL)10 HttpURLConnection (java.net.HttpURLConnection)7 Workspace (aQute.bnd.build.Workspace)5 FixedIndexedRepo (aQute.bnd.deployer.repository.FixedIndexedRepo)2 Repository (aQute.bnd.jpm.Repository)2 ResourceDescriptor (aQute.bnd.service.repository.SearchableRepository.ResourceDescriptor)2 Config (aQute.http.testservers.HttpTestServer.Config)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 URI (java.net.URI)2 HttpClient (aQute.bnd.http.HttpClient)1 URLConnector (aQute.bnd.service.url.URLConnector)1 Version (aQute.bnd.version.Version)1 Httpbin (aQute.http.testservers.Httpbin)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 X509Certificate (java.security.cert.X509Certificate)1 Matcher (java.util.regex.Matcher)1 GZIPInputStream (java.util.zip.GZIPInputStream)1