Skip to content

Commit c4d7f10

Browse files
committed
Random improvements.
Signed-off-by: Jacek Bilski <jacek@bilski.tech>
1 parent 6352f7d commit c4d7f10

14 files changed

Lines changed: 300 additions & 330 deletions

File tree

api/src/main/java/io/cloudevents/rw/CloudEventContextWriter.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ default CloudEventContextWriter withContextAttribute(String name, OffsetDateTime
8585
* @throws IllegalArgumentException if you're trying to set the specversion attribute.
8686
*
8787
* @deprecated CloudEvent specification only permits {@link Integer} type as a
88-
* numeric value.
88+
* numeric value. Use {@link #withContextAttribute(String, Integer)} instead.
8989
*/
90+
@Deprecated
9091
default CloudEventContextWriter withContextAttribute(String name, Number value) throws CloudEventRWException {
9192
return withContextAttribute(name, value.toString());
9293
}
@@ -122,7 +123,7 @@ default CloudEventContextWriter withContextAttribute(String name, Boolean value)
122123
}
123124

124125
/**
125-
* Set attribute with a binary type.
126+
* Set the attribute with a binary type.
126127
* This setter should not be invoked for specversion, because the writer should
127128
* already know the specversion or because it doesn't need it to correctly write the value.
128129
*

core/src/main/java/io/cloudevents/core/data/BytesCloudEventData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public class BytesCloudEventData implements CloudEventData {
1616
* @param value the bytes to wrap
1717
* @deprecated use {@link BytesCloudEventData#wrap(byte[])}
1818
*/
19+
@Deprecated
1920
public BytesCloudEventData(byte[] value) {
2021
Objects.requireNonNull(value);
2122
this.value = value;

examples/amqp-proton/src/main/java/io/cloudevents/examples/amqp/vertx/AmqpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.nio.charset.StandardCharsets;
1919

2020
/**
21-
* A example vertx-based AMQP client that interacts with a remote AMQP server to send and receive CloudEvent messages.
21+
* An example vertx-based AMQP client that interacts with a remote AMQP server to send and receive CloudEvent messages.
2222
*/
2323
public class AmqpClient {
2424

examples/restful-ws-spring-boot/src/main/java/io/cloudevents/examples/springboot/MainResource.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,40 +22,40 @@
2222
import io.cloudevents.core.builder.CloudEventBuilder;
2323
import io.cloudevents.core.data.PojoCloudEventData;
2424
import io.cloudevents.jackson.PojoCloudEventDataMapper;
25-
import org.springframework.beans.factory.annotation.Autowired;
2625

27-
import jakarta.ws.rs.POST;
28-
import jakarta.ws.rs.Path;
29-
import jakarta.ws.rs.core.MediaType;
30-
import jakarta.ws.rs.core.Response;
26+
import org.springframework.http.MediaType;
27+
import org.springframework.http.ResponseEntity;
28+
import org.springframework.web.bind.annotation.PostMapping;
29+
import org.springframework.web.bind.annotation.RequestBody;
30+
import org.springframework.web.bind.annotation.RestController;
3131

3232
import static io.cloudevents.core.CloudEventUtils.mapData;
3333

34-
@Path("/")
34+
@RestController
3535
public class MainResource {
3636

3737
public static final String HAPPY_BIRTHDAY_EVENT_TYPE = "happybirthday.myapplication";
3838

39-
@Autowired
40-
ObjectMapper objectMapper;
39+
private final ObjectMapper objectMapper;
4140

42-
@POST
43-
@Path("happy_birthday")
44-
public Response handleHappyBirthdayEvent(CloudEvent inputEvent) {
41+
public MainResource(ObjectMapper objectMapper) {
42+
this.objectMapper = objectMapper;
43+
}
44+
45+
@PostMapping("/happy_birthday")
46+
public ResponseEntity handleHappyBirthdayEvent(@RequestBody CloudEvent inputEvent) {
4547
if (!inputEvent.getType().equals(HAPPY_BIRTHDAY_EVENT_TYPE)) {
46-
return Response.status(Response.Status.BAD_REQUEST)
47-
.type(MediaType.TEXT_PLAIN)
48-
.entity("Event type should be \"" + HAPPY_BIRTHDAY_EVENT_TYPE + "\" but is \"" + inputEvent.getType() + "\"")
49-
.build();
48+
return ResponseEntity.badRequest()
49+
.contentType(MediaType.TEXT_PLAIN)
50+
.body("Event type should be \"" + HAPPY_BIRTHDAY_EVENT_TYPE + "\" but is \"" + inputEvent.getType() + "\"");
5051
}
5152

5253
PojoCloudEventData<User> cloudEventData = mapData(inputEvent, PojoCloudEventDataMapper.from(objectMapper, User.class));
5354

5455
if (cloudEventData == null) {
55-
return Response.status(Response.Status.BAD_REQUEST)
56-
.type(MediaType.TEXT_PLAIN)
57-
.entity("Event should contain the user")
58-
.build();
56+
return ResponseEntity.badRequest()
57+
.contentType(MediaType.TEXT_PLAIN)
58+
.body("Event should contain the user");
5959
}
6060

6161
User user = cloudEventData.getValue();
@@ -65,6 +65,6 @@ public Response handleHappyBirthdayEvent(CloudEvent inputEvent) {
6565
.withData(PojoCloudEventData.wrap(user, objectMapper::writeValueAsBytes))
6666
.build();
6767

68-
return Response.ok(outputEvent).build();
68+
return ResponseEntity.ok(outputEvent);
6969
}
7070
}

examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/DemoApplicationTests.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import org.junit.jupiter.api.Test;
77
import org.springframework.beans.factory.annotation.Autowired;
8+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
89
import org.springframework.boot.test.context.SpringBootTest;
910
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
1011
import org.springframework.http.MediaType;
@@ -14,6 +15,7 @@
1415
import io.cloudevents.core.builder.CloudEventBuilder;
1516
import static org.assertj.core.api.Assertions.assertThat;
1617

18+
@AutoConfigureWebTestClient
1719
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
1820
public class DemoApplicationTests {
1921

@@ -49,12 +51,13 @@ void structuredRequestResponseEvents() {
4951

5052
rest.post().uri("/event") //
5153
.contentType(new MediaType("application", "cloudevents+json")) //
52-
.bodyValue("{" //
53-
+ "\"id\":\"12345\"," //
54-
+ "\"specversion\":\"1.0\"," //
55-
+ "\"type\":\"io.spring.event\"," //
56-
+ "\"source\":\"https://spring.io/events\"," //
57-
+ "\"data\":{\"value\":\"Dave\"}}") //
54+
.bodyValue("""
55+
{
56+
"id":"12345",
57+
"specversion":"1.0",
58+
"type":"io.spring.event",
59+
"source":"https://spring.io/events",
60+
"data":{"value":"Dave"}}""") //
5861
.exchange() //
5962
.expectStatus().isOk() //
6063
.expectHeader().exists("ce-id") //

examples/spring-reactive/src/test/java/io/cloudevents/examples/spring/WebClientTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import org.junit.jupiter.api.BeforeEach;
99
import org.junit.jupiter.api.Test;
1010
import org.springframework.beans.factory.annotation.Autowired;
11+
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
1112
import org.springframework.boot.test.context.SpringBootTest;
1213
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
1314
import org.springframework.boot.test.web.server.LocalServerPort;
@@ -22,6 +23,7 @@
2223
* content of the request and response are asserted separately in
2324
* {@link DemoApplicationTests}.
2425
*/
26+
@AutoConfigureWebTestClient
2527
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
2628
public class WebClientTests {
2729

formats/json-jackson/src/main/java/io/cloudevents/jackson/JsonCloudEventData.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class JsonCloudEventData implements CloudEventData {
3434
* @param node the json node to wrap
3535
* @deprecated You should use {@link #wrap(JsonNode)}
3636
*/
37+
@Deprecated
3738
public JsonCloudEventData(JsonNode node) {
3839
Objects.requireNonNull(node);
3940
this.node = node;

formats/xml/src/main/java/io/cloudevents/xml/OccurrenceTracker.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ class OccurrenceTracker {
3737
}
3838

3939
/**
40-
* Record an occurrence of attribute name.
41-
* @param name The name to track.
40+
* Record an occurrence of an attribute name.
41+
* @param name The name to track.
4242
* @return boolean true => accepted, false => duplicate name.
4343
*/
4444
boolean trackOccurrence(String name) {

formats/xml/src/main/java/io/cloudevents/xml/XMLFormat.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import io.cloudevents.CloudEvent;
2020
import io.cloudevents.CloudEventData;
2121
import io.cloudevents.core.builder.CloudEventBuilder;
22-
import io.cloudevents.core.format.ContentType;
2322
import io.cloudevents.core.format.EventDeserializationException;
2423
import io.cloudevents.core.format.EventFormat;
2524
import io.cloudevents.core.format.EventSerializationException;

formats/xml/src/test/java/io/cloudevents/xml/XMLUtilsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void testChildCount() throws ParserConfigurationException {
5050

5151
assertThat(XMLUtils.countOfChildElements(root)).isEqualTo(1);
5252

53-
// Add a another child
53+
// Add another child
5454
Element c2 = doc.createElement("ChildTwo");
5555
root.appendChild(c2);
5656

0 commit comments

Comments
 (0)