Skip to content

Commit

Permalink
Merge pull request Azure#315 from RikkiGibson/WithRequestPolicies
Browse files Browse the repository at this point in the history
Add withRequestPolicies
  • Loading branch information
RikkiGibson authored Dec 5, 2017
2 parents 7fc95c1 + eb28d89 commit f9f781c
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

}
}

0 comments on commit f9f781c

Please sign in to comment.