Skip to content

Commit

Permalink
yegor256#306: use http connection instead of JdkRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
lautarobock committed Jun 23, 2015
1 parent 41a0bed commit e4b7ade
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/test/java/org/takes/http/BkBasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@
import com.google.common.base.Joiner;
import com.jcabi.http.request.JdkRequest;
import com.jcabi.http.response.RestResponse;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URI;
import java.net.URL;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;
Expand Down Expand Up @@ -139,16 +142,22 @@ public boolean ready() {
}
}
).start();
try {
new JdkRequest(uri)
.fetch()
.as(RestResponse.class)
.assertStatus(HttpURLConnection.HTTP_OK)
.assertHeader("Connection", Matchers.hasItems("Keep-Alive"));
completed.countDown();
} catch (final IOException ex) {
throw new IllegalStateException(ex);
}
final HttpURLConnection conn = HttpURLConnection.class.cast(
new URL(uri).openConnection()
);
conn.setRequestMethod("GET");
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(false);
conn.addRequestProperty("Host","localhost");
MatcherAssert.assertThat(
conn.getHeaderFields(),
Matchers.hasKey("Connection")
);
MatcherAssert.assertThat(
conn.getHeaderFields().get("Connection"),
Matchers.hasItem("Keep-Alive")
);
completed.countDown();
// @checkstyle MagicNumberCheck (1 line)
completed.await(1L, TimeUnit.MINUTES);
MatcherAssert.assertThat(completed.getCount(), Matchers.equalTo(0L));
Expand Down

0 comments on commit e4b7ade

Please sign in to comment.