Browse Source

[testing] DELETE & PUT + asciidoc documentation v0.2

master
art.dambrine 3 years ago
parent
commit
3349914617
  1. 4
      docs/deletePartner/curl-request.adoc
  2. 6
      docs/deletePartner/http-request.adoc
  3. 5
      docs/deletePartner/http-response.adoc
  4. 4
      docs/deletePartner/httpie-request.adoc
  5. 8
      docs/deletePartner/path-parameters.adoc
  6. 4
      docs/deletePartner/request-body.adoc
  7. 4
      docs/deletePartner/response-body.adoc
  8. 41
      docs/partnerapi.adoc
  9. 6
      docs/updatePartner/curl-request.adoc
  10. 9
      docs/updatePartner/http-request.adoc
  11. 8
      docs/updatePartner/http-response.adoc
  12. 5
      docs/updatePartner/httpie-request.adoc
  13. 8
      docs/updatePartner/path-parameters.adoc
  14. 4
      docs/updatePartner/request-body.adoc
  15. 4
      docs/updatePartner/response-body.adoc
  16. 24
      docs/updatePartner/response-fields.adoc
  17. 34
      src/test/java/com/example/apispringgradleb2boost/restdoc/ApiPartnerDocIntegrationTest.java

4
docs/deletePartner/curl-request.adoc

@ -0,0 +1,4 @@
[source,bash]
----
$ curl 'http://localhost:8080/partner/2' -i -X DELETE
----

6
docs/deletePartner/http-request.adoc

@ -0,0 +1,6 @@
[source,http,options="nowrap"]
----
DELETE /partner/2 HTTP/1.1
Host: localhost:8080
----

5
docs/deletePartner/http-response.adoc

@ -0,0 +1,5 @@
[source,http,options="nowrap"]
----
HTTP/1.1 200 OK
----

4
docs/deletePartner/httpie-request.adoc

@ -0,0 +1,4 @@
[source,bash]
----
$ http DELETE 'http://localhost:8080/partner/2'
----

8
docs/deletePartner/path-parameters.adoc

@ -0,0 +1,8 @@
.+/partner/{id}+
|===
|Parameter|Description
|`+id+`
|The id of the partner to delete
|===

4
docs/deletePartner/request-body.adoc

@ -0,0 +1,4 @@
[source,options="nowrap"]
----
----

4
docs/deletePartner/response-body.adoc

@ -0,0 +1,4 @@
[source,options="nowrap"]
----
----

41
docs/partnerapi.adoc

@ -34,11 +34,11 @@ Most of the following sections have been generated with https://spring.io/proje
A `GET` request is used to access all the partners read. A `GET` request is used to access all the partners read.
==== Request structure ==== Request structure
include::getAllPartners/http-request.adoc[] include::./getAllPartners/http-request.adoc[]
==== Example response ==== Example response
include::getAllPartners/http-response.adoc[] include::./getAllPartners/http-response.adoc[]
==== CURL request ==== CURL request
include::getAllPartners/curl-request.adoc[] include::getAllPartners/curl-request.adoc[]
@ -61,7 +61,7 @@ include::getAPartner/curl-request.adoc[]
=== Accessing the partner POST === Accessing the partner POST
A `POST` request is used to add a partners resource. A `POST` request is used to add a partner resource.
==== Request structure ==== Request structure
include::createPartner/http-request.adoc[] include::createPartner/http-request.adoc[]
@ -71,3 +71,38 @@ include::createPartner/http-response.adoc[]
==== CURL request ==== CURL request
include::createPartner/curl-request.adoc[] include::createPartner/curl-request.adoc[]
=== Accessing the partner PUT
A `PUT` request is used to update a partner resource.
==== Request structure
include::./updatePartner/http-request.adoc[]
==== Example response
include::./updatePartner/http-response.adoc[]
==== CURL request
include::./updatePartner/curl-request.adoc[]
=== Accessing the partner DELETE
A `DELETE` request is used to delete the partner.
==== Request structure
include::./deletePartner/http-request.adoc[]
==== Path Parameters
include::./deletePartner/path-parameters.adoc[]
==== Example response
include::./deletePartner/http-response.adoc[]
==== CURL request
include::./deletePartner/curl-request.adoc[]
== Conseils de déploiement
Build le jar pour le deploiement :
----
gradle clean bootJar
----
NOTE: build/libs/monjardeproduction.jar

6
docs/updatePartner/curl-request.adoc

@ -0,0 +1,6 @@
[source,bash]
----
$ curl 'http://localhost:8080/partner/3' -i -X PUT \
-H 'Content-Type: application/json' \
-d '{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"}'
----

9
docs/updatePartner/http-request.adoc

@ -0,0 +1,9 @@
[source,http,options="nowrap"]
----
PUT /partner/3 HTTP/1.1
Content-Type: application/json
Content-Length: 97
Host: localhost:8080
{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"}
----

8
docs/updatePartner/http-response.adoc

@ -0,0 +1,8 @@
[source,http,options="nowrap"]
----
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 104
{"id":3,"name":"DHL","reference":"FYI255","locale":"de_DE","expirationTime":"2022-05-23T12:18:46+01:00"}
----

5
docs/updatePartner/httpie-request.adoc

@ -0,0 +1,5 @@
[source,bash]
----
$ echo '{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"}' | http PUT 'http://localhost:8080/partner/3' \
'Content-Type:application/json'
----

8
docs/updatePartner/path-parameters.adoc

@ -0,0 +1,8 @@
.+/partner/{id}+
|===
|Parameter|Description
|`+id+`
|The id of the partner to update
|===

4
docs/updatePartner/request-body.adoc

@ -0,0 +1,4 @@
[source,options="nowrap"]
----
{"reference":"FYI255","expirationTime":"2022-05-23T12:18:46+01:00","name":"DHL","locale":"de_DE"}
----

4
docs/updatePartner/response-body.adoc

@ -0,0 +1,4 @@
[source,options="nowrap"]
----
{"id":3,"name":"DHL","reference":"FYI255","locale":"de_DE","expirationTime":"2022-05-23T12:18:46+01:00"}
----

24
docs/updatePartner/response-fields.adoc

@ -0,0 +1,24 @@
|===
|Path|Type|Description
|`+id+`
|`+Number+`
|The id of the updated partner
|`+name+`
|`+String+`
|The name of the partner
|`+reference+`
|`+String+`
|The unique reference of the partner
|`+locale+`
|`+String+`
|A valid Locale of the partner
|`+expirationTime+`
|`+String+`
|The ISO-8601 UTC date time when the partner is going to expire
|===

34
src/test/java/com/example/apispringgradleb2boost/restdoc/ApiPartnerDocIntegrationTest.java

@ -25,8 +25,7 @@ import java.util.Map;
import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsString;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration; import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.documentationConfiguration;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*;
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.*; import static org.springframework.restdocs.operation.preprocess.Preprocessors.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*; import static org.springframework.restdocs.payload.PayloadDocumentation.*;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName; import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
@ -100,4 +99,35 @@ public class ApiPartnerDocIntegrationTest {
fieldWithPath("locale").description("A valid Locale of the partner"), fieldWithPath("locale").description("A valid Locale of the partner"),
fieldWithPath("expirationTime").description("The ISO-8601 UTC date time when the partner is going to expire")))); fieldWithPath("expirationTime").description("The ISO-8601 UTC date time when the partner is going to expire"))));
} }
@Test
@DisplayName("Example DELETE /partner")
public void whenDeletePartner_thenSuccessful() throws Exception {
this.mockMvc.perform(delete("/partner/{id}", 2))
.andExpect(status().isOk())
.andDo(document("deletePartner", pathParameters(parameterWithName("id").description("The id of the partner to delete"))));
}
@Test
@DisplayName("Example PUT /partner")
public void whenUpdatePartner_thenSuccessful() throws Exception {
ConstraintDescriptions desc = new ConstraintDescriptions(Partner.class);
Map<String, Object> partner = new HashMap<>();
partner.put("name", "DHL");
partner.put("reference", "FYI255");
partner.put("locale", "de_DE");
partner.put("expirationTime", "2022-05-23T12:18:46+01:00");
this.mockMvc.perform(put("/partner/{id}", 3).contentType(MediaType.APPLICATION_JSON)
.content(this.objectMapper.writeValueAsString(partner)))
.andExpect(status().isOk())
.andDo(document("updatePartner", pathParameters(parameterWithName("id").description("The id of the partner to update")),
responseFields(fieldWithPath("id").description("The id of the updated partner" + collectionToDelimitedString(desc.descriptionsForProperty("id"), ". ")),
fieldWithPath("name").description("The name of the partner"),
fieldWithPath("reference").description("The unique reference of the partner"),
fieldWithPath("locale").description("A valid Locale of the partner"),
fieldWithPath("expirationTime").description("The ISO-8601 UTC date time when the partner is going to expire"))));
}
} }

Loading…
Cancel
Save