Skip to content

Commit 90b21e7

Browse files
rusg77baev
authored andcommitted
fix readme and templates for allure-okhttp (via allure-framework#159)
1 parent c849500 commit 90b21e7

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,25 +77,28 @@ You can specify custom templateName:
7777
.filter(new AllureRestAssured().withTemplate("/templates/custom_template.ftl"))
7878
```
7979

80-
## Retrofit
80+
## OkHttp
8181

82-
Interceptor for retrofit http client, that generates attachment for allure.
82+
Interceptor for OkHttp client, that generates attachment for allure.
8383

8484
```xml
8585
<dependency>
8686
<groupId>io.qameta.allure</groupId>
87-
<artifactId>allure-retrofit</artifactId>
87+
<artifactId>allure-okhttp3</artifactId>
8888
<version>$LATEST_VERSION</version>
8989
</dependency>
9090
```
9191

9292
Usage example:
9393
```
94-
.addInterceptor(new AllureLoggingInterceptor())
94+
.addInterceptor(new AllureOkHttp3())
9595
```
96-
You can specify custom templateName:
96+
You can specify custom templates, which should be placed in src/main/resources/tpl folder:
9797
```
98-
.addInterceptor(new AllureLoggingInterceptor().withTemplate("/templates/custom_template.ftl"))
98+
.addInterceptor(new AllureOkHttp3()
99+
.withRequestTemplate("custom-http-request.ftl")
100+
.withResponseTemplate("custom-http-response.ftl"))
101+
99102
```
100103

101104

allure-okhttp3/src/main/java/io/qameta/allure/okhttp3/AllureOkHttp3.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,22 @@
2121
import java.util.Objects;
2222

2323
/**
24-
* Allure interceptor logger for Retrofit.
24+
* Allure interceptor logger for OkHttp.
2525
*/
2626
public class AllureOkHttp3 implements Interceptor {
2727

28+
private String requestTemplatePath = "http-request.ftl";
29+
private String responseTemplatePath = "http-response.ftl";
30+
31+
public AllureOkHttp3 withRequestTemplate(final String templatePath) {
32+
this.requestTemplatePath = templatePath;
33+
return this;
34+
}
35+
36+
public AllureOkHttp3 withResponseTemplate(final String templatePath) {
37+
this.responseTemplatePath = templatePath;
38+
return this;
39+
}
2840

2941
@Override
3042
public Response intercept(final Chain chain) throws IOException {
@@ -40,7 +52,7 @@ public Response intercept(final Chain chain) throws IOException {
4052
requestAttachmentBuilder.withBody(readRequestBody(requestBody));
4153
}
4254
final HttpRequestAttachment requestAttachment = requestAttachmentBuilder.build();
43-
processor.addAttachment(requestAttachment, new FreemarkerAttachmentRenderer("http-request.ftl"));
55+
processor.addAttachment(requestAttachment, new FreemarkerAttachmentRenderer(requestTemplatePath));
4456

4557
final Response response = chain.proceed(request);
4658
final HttpResponseAttachment.Builder responseAttachmentBuilder = HttpResponseAttachment.Builder
@@ -57,7 +69,7 @@ public Response intercept(final Chain chain) throws IOException {
5769
}
5870

5971
final HttpResponseAttachment responseAttachment = responseAttachmentBuilder.build();
60-
processor.addAttachment(responseAttachment, new FreemarkerAttachmentRenderer("http-response.ftl"));
72+
processor.addAttachment(responseAttachment, new FreemarkerAttachmentRenderer(responseTemplatePath));
6173

6274
return responseBuilder.build();
6375
}

0 commit comments

Comments
 (0)