< prev index next >

test/java/net/httpclient/SmokeTest.java

Print this page




 234             }
 235         }
 236         int count() {
 237             return count;
 238         }
 239     }
 240 
 241     // Basic test
 242     static void test1(String target, boolean fixedLen) throws Exception {
 243         System.out.print("test1: " + target);
 244         URI uri = new URI(target);
 245 
 246         HttpRequest.Builder builder = HttpRequest.newBuilder().uri(uri).GET();
 247 
 248         if (fixedLen) {
 249             builder.header("XFixed", "yes");
 250         }
 251 
 252         HttpRequest request = builder.build();
 253 
 254         HttpResponse<String> response = client.send(request, asString());

 255 
 256         String body = response.body();
 257         if (!body.equals("This is foo.txt\r\n")) {
 258             throw new RuntimeException();
 259         }
 260 
 261         // repeat async
 262         HttpResponse<String> response1 = client.sendAsync(request, asString())
 263                                                .join();
 264 
 265         String body1 = response1.body();
 266         if (!body1.equals("This is foo.txt\r\n")) {
 267             throw new RuntimeException();
 268         }
 269         System.out.println(" OK");
 270     }
 271 
 272     // POST use echo to check reply
 273     static void test2(String s, String body) throws Exception {
 274         System.out.print("test2: " + s);




 234             }
 235         }
 236         int count() {
 237             return count;
 238         }
 239     }
 240 
 241     // Basic test
 242     static void test1(String target, boolean fixedLen) throws Exception {
 243         System.out.print("test1: " + target);
 244         URI uri = new URI(target);
 245 
 246         HttpRequest.Builder builder = HttpRequest.newBuilder().uri(uri).GET();
 247 
 248         if (fixedLen) {
 249             builder.header("XFixed", "yes");
 250         }
 251 
 252         HttpRequest request = builder.build();
 253 
 254         BodyHandler<String> bh = BodyHandler.buffering(asString(), 13);
 255         HttpResponse<String> response = client.send(request, bh);
 256 
 257         String body = response.body();
 258         if (!body.equals("This is foo.txt\r\n")) {
 259             throw new RuntimeException();
 260         }
 261 
 262         // repeat async
 263         HttpResponse<String> response1 = client.sendAsync(request, asString())
 264                                                .join();
 265 
 266         String body1 = response1.body();
 267         if (!body1.equals("This is foo.txt\r\n")) {
 268             throw new RuntimeException();
 269         }
 270         System.out.println(" OK");
 271     }
 272 
 273     // POST use echo to check reply
 274     static void test2(String s, String body) throws Exception {
 275         System.out.print("test2: " + s);


< prev index next >