Skip to content

Commit

Permalink
Merge pull request Azure#5 from samvaity/checkstyle-updates
Browse files Browse the repository at this point in the history
Fix checkstyle errors
  • Loading branch information
billwert authored Feb 6, 2023
2 parents 9800570 + c0cc351 commit 62abeaa
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.azure.core.test;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public class TestProxyPlaybackClient implements HttpClient {
private static final List<TestProxySanitizer> DEFAULT_SANITIZERS = loadSanitizers();
private final List<TestProxySanitizer> sanitizers = new ArrayList<>();

/**
* Create an instance of {@link TestProxyPlaybackClient} with a list of custom sanitizers.
*
* @param customSanitizers the list of custom sanitizers to be added to {@link TestProxyPlaybackClient}
*/
public TestProxyPlaybackClient(List<TestProxySanitizer> customSanitizers) {
this.sanitizers.addAll(DEFAULT_SANITIZERS);
this.sanitizers.addAll(customSanitizers == null ? Collections.emptyList() : customSanitizers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public TestProxyTestServer() {
res.addHeader(requestHeader.getKey(), requestHeader.getValue());
}
return res.status(HttpResponseStatus.OK)
.addHeader("Content-Type","application/json")
.addHeader("Content-Type", "application/json")
.sendString(Mono.just(TEST_JSON_RESPONSE_BODY));
})
.get("/fr/path/2",
(req, res) -> res.status(HttpResponseStatus.OK)
.addHeader("Content-Type","application/json")
.addHeader("Content-Type", "application/json")
.sendString(Mono.just(TEST_XML_RESPONSE_BODY))))
.bindNow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public String getGroupForReplace() {
/**
* Set the group for replace.
*
* @param groupForReplace th value to set
* @return
* @param groupForReplace The name of the group to replace.
* @return the {@link TestProxySanitizer} itself.
*/
public TestProxySanitizer setGroupForReplace(String groupForReplace) {
this.groupForReplace = groupForReplace;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,17 @@ public enum TestProxySanitizerType {
*/
HEADER("HeaderRegexSanitizer");

public final String name;
private final String name;

TestProxySanitizerType(String name) {
this.name = name;
}

/**
* Gets the name value of the enum.
* @return the name value of the enum.
*/
public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ public class TestProxyRecordPolicy implements HttpPipelinePolicy {
private final List<TestProxySanitizer> sanitizers = new ArrayList<>();
private static final List<TestProxySanitizer> DEFAULT_SANITIZERS = loadSanitizers();

/**
* Create an instance of {@link TestProxyRecordPolicy} with a list of custom sanitizers.
*
* @param customSanitizers the list of custom sanitizers to be added to {@link TestProxyRecordPolicy}
*/
public TestProxyRecordPolicy(List<TestProxySanitizer> customSanitizers) {
this.sanitizers.addAll(DEFAULT_SANITIZERS);
this.sanitizers.addAll(customSanitizers == null ? Collections.emptyList() : customSanitizers);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
import java.util.List;
import java.util.Map;

/**
* A {@link HttpClient} that uses the JDK {@link HttpURLConnection}.
*/
public class HttpURLConnectionHttpClient implements HttpClient {

@Override
Expand All @@ -40,7 +43,7 @@ public HttpResponse sendSync(HttpRequest request, Context context) {
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (connection != null ) {
if (connection != null) {
connection.disconnect();
}
}
Expand All @@ -60,7 +63,7 @@ public Mono<HttpResponse> send(HttpRequest request) {
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (connection != null ) {
if (connection != null) {
connection.disconnect();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
import com.azure.core.util.logging.ClientLogger;
import com.azure.core.util.logging.LogLevel;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveException;
import org.apache.commons.compress.archivers.ArchiveInputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.utils.IOUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ public static void changeHeaders(HttpRequest request, String xRecordingId, Strin
}
}

/**
* Registers the default set of sanitizers for sanitizing request and responses
* @return the list of default sanitizers to be added.
*/
public static List<TestProxySanitizer> loadSanitizers() {
List<TestProxySanitizer> sanitizers = new ArrayList<>();
sanitizers.addAll(addDefaultRegexSanitizers());
Expand All @@ -94,23 +98,30 @@ public static List<TestProxySanitizer> loadSanitizers() {
return sanitizers;
}

public static String createUrlRegexRequestBody(String regexValue, String redactedValue) {
private static String createUrlRegexRequestBody(String regexValue, String redactedValue) {
return String.format("{\"value\":\"%s\",\"regex\":\"%s\"}", redactedValue, regexValue);
}

public static String createBodyJsonKeyRequestBody(String regexValue, String redactedValue) {
private static String createBodyJsonKeyRequestBody(String regexValue, String redactedValue) {
return String.format("{\"value\":\"%s\",\"jsonPath\":\"%s\"}", redactedValue, regexValue);
}


public static String createBodyRegexRequestBody(String regexValue, String redactedValue, String groupForReplace) {
private static String createBodyRegexRequestBody(String regexValue, String redactedValue, String groupForReplace) {
return String.format("{\"value\":\"%s\",\"regex\":\"%s\",\"groupForReplace\":\"%s\"}", redactedValue, regexValue, groupForReplace);
}

public static String createHeaderRegexRequestBody(String regexValue, String redactedValue) {
private static String createHeaderRegexRequestBody(String regexValue, String redactedValue) {
return String.format("{\"value\":\"%s\",\"key\":\"%s\"}", redactedValue, regexValue);
}

/**
* Creates a list of sanitizer requests to be sent to the test proxy server.
*
* @param sanitizers the list of sanitizers to be added
* @return the list of sanitizer {@link HttpRequest requests} to be sent.
* @throws RuntimeException if {@link TestProxySanitizerType} is not supported.
*/
public static List<HttpRequest> getSanitizerRequests(List<TestProxySanitizer> sanitizers) {
return sanitizers.stream().map(testProxySanitizer -> {
String requestBody;
Expand All @@ -119,22 +130,22 @@ public static List<HttpRequest> getSanitizerRequests(List<TestProxySanitizer> sa
case URL:
requestBody =
createUrlRegexRequestBody(testProxySanitizer.getRegex(), testProxySanitizer.getRedactedValue());
sanitizerType = TestProxySanitizerType.URL.name;
sanitizerType = TestProxySanitizerType.URL.getName();
break;
case BODY_REGEX:
requestBody = createBodyRegexRequestBody(testProxySanitizer.getRegex(),
testProxySanitizer.getRedactedValue(), testProxySanitizer.getGroupForReplace());
sanitizerType = TestProxySanitizerType.BODY_REGEX.name;
sanitizerType = TestProxySanitizerType.BODY_REGEX.getName();
break;
case BODY:
requestBody = createBodyJsonKeyRequestBody(testProxySanitizer.getRegex(),
testProxySanitizer.getRedactedValue());
sanitizerType = TestProxySanitizerType.BODY.name;
sanitizerType = TestProxySanitizerType.BODY.getName();
break;
case HEADER:
requestBody = createHeaderRegexRequestBody(testProxySanitizer.getRegex(),
testProxySanitizer.getRedactedValue());
sanitizerType = TestProxySanitizerType.HEADER.name;
sanitizerType = TestProxySanitizerType.HEADER.getName();
break;
default:
throw new RuntimeException(String.format("Sanitizer type {%s} not supported", testProxySanitizer.getType()));
Expand Down

0 comments on commit 62abeaa

Please sign in to comment.