diff --git a/client-runtime/src/main/java/com/microsoft/rest/v2/http/HttpPipeline.java b/client-runtime/src/main/java/com/microsoft/rest/v2/http/HttpPipeline.java index ce1c645464d1a..4942087a89a12 100644 --- a/client-runtime/src/main/java/com/microsoft/rest/v2/http/HttpPipeline.java +++ b/client-runtime/src/main/java/com/microsoft/rest/v2/http/HttpPipeline.java @@ -243,6 +243,19 @@ public Builder withRequestPolicy(int index, RequestPolicy.Factory requestPolicyF return this; } + /** + * Add the provided RequestPolicy factories to this HttpPipeline builder. + * @param requestPolicyFactories The RequestPolicy factories to add to this + * HttpPipeline builder. + * @return This HttpPipeline builder. + */ + public Builder withRequestPolicies(RequestPolicy.Factory... requestPolicyFactories) { + for (RequestPolicy.Factory factory : requestPolicyFactories) { + withRequestPolicy(factory); + } + return this; + } + /** * Add the provided RequestPolicy factory to this HttpPipeline builder * directly before the first instance of the provided RequestPolicy diff --git a/client-runtime/src/test/java/com/microsoft/rest/v2/http/HttpPipelineBuilderTests.java b/client-runtime/src/test/java/com/microsoft/rest/v2/http/HttpPipelineBuilderTests.java index a7e35845e4f49..392f5d3a2c9de 100644 --- a/client-runtime/src/test/java/com/microsoft/rest/v2/http/HttpPipelineBuilderTests.java +++ b/client-runtime/src/test/java/com/microsoft/rest/v2/http/HttpPipelineBuilderTests.java @@ -110,4 +110,37 @@ public void withRequestPolicyAfter() { assertEquals(LoggingPolicy.Factory.class, builder.requestPolicyFactories().get(2).getClass()); assertEquals(PortPolicy.Factory.class, builder.requestPolicyFactories().get(3).getClass()); } + + @Test + public void withRequestPolicyArray() { + final HttpPipeline.Builder builder = new HttpPipeline.Builder(); + + builder.withRequestPolicies( + new ProtocolPolicy.Factory("http"), + new PortPolicy.Factory(80), + new LoggingPolicy.Factory(LoggingPolicy.LogLevel.BODY)); + + assertEquals(3, builder.requestPolicyFactories().size()); + assertEquals(LoggingPolicy.Factory.class, builder.requestPolicyFactories().get(0).getClass()); + assertEquals(PortPolicy.Factory.class, builder.requestPolicyFactories().get(1).getClass()); + assertEquals(ProtocolPolicy.Factory.class, builder.requestPolicyFactories().get(2).getClass()); + } + + @Test + public void appendingRequestPolicyArray() { + final HttpPipeline.Builder builder = new HttpPipeline.Builder(); + + builder.withRequestPolicy(new RetryPolicy.Factory()); + builder.withRequestPolicies( + new ProtocolPolicy.Factory("http"), + new PortPolicy.Factory(80), + new LoggingPolicy.Factory(LoggingPolicy.LogLevel.BODY)); + + assertEquals(4, builder.requestPolicyFactories().size()); + assertEquals(LoggingPolicy.Factory.class, builder.requestPolicyFactories().get(0).getClass()); + assertEquals(PortPolicy.Factory.class, builder.requestPolicyFactories().get(1).getClass()); + assertEquals(ProtocolPolicy.Factory.class, builder.requestPolicyFactories().get(2).getClass()); + assertEquals(RetryPolicy.Factory.class, builder.requestPolicyFactories().get(3).getClass()); + + } }