Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit942f805

Browse files
committed
Improve tests (still not working)
1 parent213a559 commit942f805

File tree

3 files changed

+91
-82
lines changed

3 files changed

+91
-82
lines changed

‎client/src/test/java/org/asynchttpclient/BasicAuthTest.java‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR
131131
}
132132
}
133133

134-
privatestaticclassSimpleHandlerextendsAbstractHandler {
134+
publicstaticclassSimpleHandlerextendsAbstractHandler {
135135

136136
publicvoidhandle(Strings,Requestr,HttpServletRequestrequest,HttpServletResponseresponse)throwsIOException,ServletException {
137137

@@ -142,20 +142,21 @@ public void handle(String s, Request r, HttpServletRequest request, HttpServletR
142142
}else {
143143
response.addHeader("X-Auth",request.getHeader("Authorization"));
144144
response.addHeader("X-" +CONTENT_LENGTH,String.valueOf(request.getContentLength()));
145+
response.setIntHeader("X-" +CONTENT_LENGTH,request.getContentLength());
145146
response.setStatus(200);
146147

147148
intsize =10 *1024;
148-
if (request.getContentLength() >0) {
149-
size =request.getContentLength();
150-
}
151149
byte[]bytes =newbyte[size];
152150
intcontentLength =0;
153151
if (bytes.length >0) {
154-
intread =request.getInputStream().read(bytes);
155-
if (read >0) {
156-
contentLength =read;
157-
response.getOutputStream().write(bytes,0,read);
158-
}
152+
intread =0;
153+
do {
154+
read =request.getInputStream().read(bytes);
155+
if (read >0) {
156+
contentLength +=read;
157+
response.getOutputStream().write(bytes,0,read);
158+
}
159+
}while (read >=0);
159160
}
160161
response.setContentLength(contentLength);
161162
}

‎client/src/test/java/org/asynchttpclient/request/body/FastUnauthorizedMultipartTest.java‎

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright (c) 2017 AsyncHttpClient Project. All rights reserved.
3+
*
4+
* This program is licensed to you under the Apache License Version 2.0,
5+
* and you may not use this file except in compliance with the Apache License Version 2.0.
6+
* You may obtain a copy of the Apache License Version 2.0 at
7+
* http://www.apache.org/licenses/LICENSE-2.0.
8+
*
9+
* Unless required by applicable law or agreed to in writing,
10+
* software distributed under the Apache License Version 2.0 is distributed on an
11+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the Apache License Version 2.0 for the specific language governing permissions and limitations there under.
13+
*/
14+
packageorg.asynchttpclient.request.body.multipart;
15+
16+
importstaticio.netty.handler.codec.http.HttpHeaderNames.CONTENT_LENGTH;
17+
importstaticio.netty.handler.codec.http.HttpHeaderValues.APPLICATION_OCTET_STREAM;
18+
importstaticjava.nio.charset.StandardCharsets.UTF_8;
19+
importstaticorg.asynchttpclient.Dsl.*;
20+
importstaticorg.asynchttpclient.test.TestUtils.*;
21+
importstaticorg.testng.Assert.assertEquals;
22+
23+
importjava.io.File;
24+
25+
importorg.asynchttpclient.AbstractBasicTest;
26+
importorg.asynchttpclient.AsyncHttpClient;
27+
importorg.asynchttpclient.BasicAuthTest;
28+
importorg.asynchttpclient.Response;
29+
importorg.eclipse.jetty.server.Server;
30+
importorg.eclipse.jetty.server.ServerConnector;
31+
importorg.eclipse.jetty.server.handler.AbstractHandler;
32+
importorg.testng.annotations.BeforeClass;
33+
importorg.testng.annotations.Test;
34+
35+
publicclassMultipartBasicAuthTestextendsAbstractBasicTest {
36+
37+
@BeforeClass(alwaysRun =true)
38+
@Override
39+
publicvoidsetUpGlobal()throwsException {
40+
41+
server =newServer();
42+
ServerConnectorconnector1 =addHttpConnector(server);
43+
addBasicAuthHandler(server,configureHandler());
44+
server.start();
45+
port1 =connector1.getLocalPort();
46+
logger.info("Local HTTP server started successfully");
47+
}
48+
49+
@Override
50+
publicAbstractHandlerconfigureHandler()throwsException {
51+
returnnewBasicAuthTest.SimpleHandler();
52+
}
53+
54+
@Test(groups ="standalone",enabled =false)
55+
publicvoidtestNoRealm()throwsException {
56+
Filefile =createTempFile(1024 *1024);
57+
58+
try (AsyncHttpClientclient =asyncHttpClient()) {
59+
for (inti =0;i <20;i++) {
60+
Responseresponse =client.preparePut(getTargetUrl())//
61+
.addBodyPart(newFilePart("test",file,APPLICATION_OCTET_STREAM.toString(),UTF_8)).execute().get();
62+
assertEquals(response.getStatusCode(),401);
63+
}
64+
}
65+
}
66+
67+
@Test(groups ="standalone",enabled =false)
68+
publicvoidtestAuthorizedRealm()throwsException {
69+
Filefile =createTempFile(1024 *1024);
70+
71+
try (AsyncHttpClientclient =asyncHttpClient()) {
72+
for (inti =0;i <20;i++) {
73+
Responseresponse =client.preparePut(getTargetUrl())//
74+
.setRealm(basicAuthRealm(USER,ADMIN).build())//
75+
.addBodyPart(newFilePart("test",file,APPLICATION_OCTET_STREAM.toString(),UTF_8)).execute().get();
76+
assertEquals(response.getStatusCode(),200);
77+
assertEquals(response.getResponseBodyAsBytes().length,Integer.valueOf(response.getHeader("X-" +CONTENT_LENGTH)).intValue());
78+
}
79+
}
80+
}
81+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp