Skip to content

Commit

Permalink
Merge pull request #5 from jianghaolu/no-core-netty-fluxutil
Browse files Browse the repository at this point in the history
Move Netty tests azure-core-http-netty
  • Loading branch information
JonathanGiles authored Aug 12, 2019
2 parents 6c69d62 + c7bbfbd commit 5bb4c21
Show file tree
Hide file tree
Showing 9 changed files with 87 additions and 225 deletions.
8 changes: 8 additions & 0 deletions sdk/core/azure-core-http-netty/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@
<artifactId>reactor-netty</artifactId>
</dependency>

<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-core</artifactId>
<version>1.0.0-preview.3</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.implementation;
package com.azure.core.http.netty;

import com.azure.core.http.HttpClient;
import com.azure.core.http.ProxyOptions;
import com.azure.core.http.ProxyOptions.Type;
import com.azure.core.implementation.RestProxyTests;
import org.junit.Ignore;

import java.net.InetSocketAddress;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.implementation;
package com.azure.core.http.netty;

import com.azure.core.http.HttpClient;
import com.azure.core.implementation.RestProxyTests;

public class RestProxyWithNettyTests extends RestProxyTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ private static Map<String, String> queryToMap(String url) {
}

private static String bodyToString(HttpRequest request) throws IOException {
Mono<String> asyncString = FluxUtil.collectBytesInByteBufferStream(request.body(), false)
Mono<String> asyncString = FluxUtil.collectBytesInByteBufferStream(request.body())
.map(bytes -> new String(bytes, StandardCharsets.UTF_8));
return asyncString.block();
}
Expand Down
14 changes: 14 additions & 0 deletions sdk/core/azure-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,20 @@
<classpathScope>test</classpathScope>
</configuration>
</plugin>

<!-- RestProxyTests is inherited by tests in azure-core-http-netty -->
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-jar</id>
<phase>test-compile</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@
public class HttpPipelineTests {
@Test
public void constructorWithNoArguments() {
HttpPipeline pipeline = HttpPipeline.builder().build();
HttpPipeline pipeline = HttpPipeline.builder()
.httpClient(new MockHttpClient() {
@Override
public Mono<HttpResponse> send(HttpRequest request) {
// do nothing
return null;
}
}).build();
assertEquals(0, pipeline.getPolicyCount());
assertNotNull(pipeline.httpClient());
}
Expand All @@ -34,7 +41,13 @@ public void withRequestPolicy() {
.policies(new PortPolicy(80, true),
new ProtocolPolicy("ftp", true),
new RetryPolicy())
.build();
.httpClient(new MockHttpClient() {
@Override
public Mono<HttpResponse> send(HttpRequest request) {
// do nothing
return null;
}
}).build();

assertEquals(3, pipeline.getPolicyCount());
assertEquals(PortPolicy.class, pipeline.getPolicy(0).getClass());
Expand All @@ -49,7 +62,13 @@ public void withRequestOptions() throws MalformedURLException {
.policies(new PortPolicy(80, true),
new ProtocolPolicy("ftp", true),
new RetryPolicy())
.build();
.httpClient(new MockHttpClient() {
@Override
public Mono<HttpResponse> send(HttpRequest request) {
// do nothing
return null;
}
}).build();

HttpPipelineCallContext context = new HttpPipelineCallContext(new HttpRequest(HttpMethod.GET, new URL("http://foo.com")));
assertNotNull(context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,7 @@
import com.azure.core.implementation.util.FluxUtil;
import reactor.core.publisher.Mono;

import java.io.ByteArrayOutputStream;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.time.OffsetDateTime;
Expand All @@ -25,7 +23,6 @@
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;
import java.util.stream.Collectors;

/**
* This HttpClient attempts to mimic the behavior of http://httpbin.org without ever making a network call.
Expand Down Expand Up @@ -143,7 +140,7 @@ public Mono<HttpResponse> send(HttpRequest request) {
json.data(createHttpBinResponseDataForRequest(request));
response = new MockHttpResponse(request, 200, json);
} else if (requestPathLower.equals("/post")) {
if ("x-www-form-urlencoded".equalsIgnoreCase(contentType)) {
if (contentType != null && contentType.contains("x-www-form-urlencoded")) {
Map<String, String> parsed = bodyToMap(request);
final HttpBinFormDataJSON json = new HttpBinFormDataJSON();
Form form = new Form();
Expand All @@ -153,6 +150,7 @@ public Mono<HttpResponse> send(HttpRequest request) {
form.pizzaSize(PizzaSize.valueOf(parsed.get("size")));
form.toppings(Arrays.asList(parsed.get("toppings").split(",")));
json.form(form);
response = new MockHttpResponse(request, 200, RESPONSE_HEADERS, json);
} else {
final HttpBinJSON json = new HttpBinJSON();
json.url(request.url().toString());
Expand Down

This file was deleted.

Loading

0 comments on commit 5bb4c21

Please sign in to comment.